summaryrefslogtreecommitdiff
path: root/src/user/lib/fwik/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib/fwik/io')
-rw-r--r--src/user/lib/fwik/io/IOStream.cpp19
-rw-r--r--src/user/lib/fwik/io/Node.cpp23
-rw-r--r--src/user/lib/fwik/io/Term.cpp51
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);
+}