diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-19 11:45:49 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-19 11:45:49 +0200 |
commit | 499ca6c243b05da176a2d4bd9a2317f0b28afc7f (patch) | |
tree | f55ff788632b017ab8de83b71ad02b0998e1dda5 /src/user/lib/fwik/io | |
parent | 7b466345af0d3a7dc5622617ce443a90c64e34a4 (diff) | |
download | TCE-499ca6c243b05da176a2d4bd9a2317f0b28afc7f.tar.gz TCE-499ca6c243b05da176a2d4bd9a2317f0b28afc7f.zip |
Introducing FWIK, the userland C++ framework. Far from complete.
Diffstat (limited to 'src/user/lib/fwik/io')
-rw-r--r-- | src/user/lib/fwik/io/IOStream.cpp | 19 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Node.cpp | 23 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Term.cpp | 51 |
3 files changed, 93 insertions, 0 deletions
diff --git a/src/user/lib/fwik/io/IOStream.cpp b/src/user/lib/fwik/io/IOStream.cpp new file mode 100644 index 0000000..bcaa581 --- /dev/null +++ b/src/user/lib/fwik/io/IOStream.cpp @@ -0,0 +1,19 @@ +#include <IO/IOStream.h> + +void IOStream::print(char* str) { + if (term == 0) return; + term->print(str); +} + +void IOStream::printf(char* fmt, ...) { + if (term == 0) return; + va_list ap; + va_start(ap, fmt); + term->vprintf(fmt, ap); + va_end(ap); +} + +char* IOStream::readln() { + if (term == 0) return 0; + return term->readln(); +} diff --git a/src/user/lib/fwik/io/Node.cpp b/src/user/lib/fwik/io/Node.cpp new file mode 100644 index 0000000..1d8b7f5 --- /dev/null +++ b/src/user/lib/fwik/io/Node.cpp @@ -0,0 +1,23 @@ +#include <IO/Node.h> + +Node::Node(FILE f) { + fd = f; + int i = libc::statf(f, &info); + valid = (i == 0); +} + +Node::Node(char* filename, int mode) { + fd = libc::open(filename, mode); + if (fd < 0) { + valid = false; + } else { + int i = libc::statf(fd, &info); + valid = (i == 0); + if (!valid) libc::close(fd); + } +} + +void Node::close() { + if (valid) libc::close(fd); + valid = false; +} diff --git a/src/user/lib/fwik/io/Term.cpp b/src/user/lib/fwik/io/Term.cpp new file mode 100644 index 0000000..1c6db66 --- /dev/null +++ b/src/user/lib/fwik/io/Term.cpp @@ -0,0 +1,51 @@ +#include <IO/Term.h> + +Term::Term(const Node &n) : Node(n) { + _init(); +} + +Term::Term(FILE f) : Node(f) { + _init(); +} + +Term::Term(char* filename, int mode) : Node(filename, mode) { + _init(); +} + +void Term::_init() { + if (info.type & FT_TERMINAL) { + w = info.size >> 16; + h = info.size & 0xFFFF; + } else { + valid = false; + } + hist.str = 0; + hist.max = 12; +} + +Term::~Term() { + //TODO : free readline history +} + +void Term::print(char *s) { + libc::fprint(fd, s); +} + +void Term::printf(char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + libc::vfprintf(fd, fmt, ap); + va_end(ap); +} + +void Term::vprintf(char* fmt, va_list ap) { + libc::vfprintf(fd, fmt, ap); +} + +char* Term::readln() { + return libc::freadln(fd); +} + +char *Term::readline() { + return libc::freadline(fd, &hist); +} |