From 499ca6c243b05da176a2d4bd9a2317f0b28afc7f Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Sat, 19 May 2012 11:45:49 +0200 Subject: Introducing FWIK, the userland C++ framework. Far from complete. --- src/user/lib/fwik/include/IO/IOStream.h | 33 +++++++++++++++++++++++++++++++++ src/user/lib/fwik/include/IO/Node.h | 25 +++++++++++++++++++++++++ src/user/lib/fwik/include/IO/Term.h | 32 ++++++++++++++++++++++++++++++++ src/user/lib/fwik/include/String.h | 5 +++++ src/user/lib/fwik/include/cpp.h | 16 ++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 src/user/lib/fwik/include/IO/IOStream.h create mode 100644 src/user/lib/fwik/include/IO/Node.h create mode 100644 src/user/lib/fwik/include/IO/Term.h create mode 100644 src/user/lib/fwik/include/String.h create mode 100644 src/user/lib/fwik/include/cpp.h (limited to 'src/user/lib/fwik/include') diff --git a/src/user/lib/fwik/include/IO/IOStream.h b/src/user/lib/fwik/include/IO/IOStream.h new file mode 100644 index 0000000..e9ae246 --- /dev/null +++ b/src/user/lib/fwik/include/IO/IOStream.h @@ -0,0 +1,33 @@ +#ifndef DEF_FWIK_IO_IOSTREAM_H +#define DEF_FWIK_IO_IOSTREAM_H + +#include "Term.h" + +class IOStream { + public: + Term *term; + + IOStream() : term(0) {} + IOStream(Term *t) : term(t) {} + + void print(char* str); + void printf(char* fmt, ...); + char* readln(); + + IOStream &operator<<(char* s) { + print(s); + return *this; + } + IOStream &operator<<(int i) { + printf("%d", i); + return *this; + } + IOStream &operator<<(void* p) { + printf("%p", p); + return *this; + } +}; + +extern IOStream stdio; + +#endif diff --git a/src/user/lib/fwik/include/IO/Node.h b/src/user/lib/fwik/include/IO/Node.h new file mode 100644 index 0000000..6100fc9 --- /dev/null +++ b/src/user/lib/fwik/include/IO/Node.h @@ -0,0 +1,25 @@ +#ifndef DEF_FWIK_IO_NODE_H +#define DEF_FWIK_IO_NODE_H + +#include +#include +#include +#include + +class Term; +class Node { + public: + FILE fd; + file_info info; + bool valid; + + Node(FILE f); + Node(char* filename, int mode); + virtual ~Node() {} + + void close(); + + virtual Term* as_term() { return 0; } +}; + +#endif diff --git a/src/user/lib/fwik/include/IO/Term.h b/src/user/lib/fwik/include/IO/Term.h new file mode 100644 index 0000000..cf90789 --- /dev/null +++ b/src/user/lib/fwik/include/IO/Term.h @@ -0,0 +1,32 @@ +#ifndef DEF_FWIK_IO_TERM_H +#define DEF_FWIK_IO_TERM_H + +#include +#include "Node.h" + +#include + +class Term : public Node { + int w, h; + + readline_history hist; + + void _init(); + + public: + Term(FILE f); + Term(char* filename, int mode); + Term(const Node &n); + virtual ~Term(); + + virtual void print(char *s); + virtual void printf(char* fmt, ...); + virtual void vprintf(char* fmt, va_list ap); + virtual char* readln(); + char* readline(); + + virtual Term* as_term() { return this; } +}; + +#endif + diff --git a/src/user/lib/fwik/include/String.h b/src/user/lib/fwik/include/String.h new file mode 100644 index 0000000..2a44046 --- /dev/null +++ b/src/user/lib/fwik/include/String.h @@ -0,0 +1,5 @@ +#ifndef DEF_FWIK_STRING_H +#define DEF_FWIK_STRING_H + + +#endif diff --git a/src/user/lib/fwik/include/cpp.h b/src/user/lib/fwik/include/cpp.h new file mode 100644 index 0000000..5b66ba1 --- /dev/null +++ b/src/user/lib/fwik/include/cpp.h @@ -0,0 +1,16 @@ +#ifndef DEF_FWIK_CPPSUPPORT_H +#define DEF_FWIK_CPPSUPPORT_H + +#include + +inline void* operator new(size_t, void* p) throw() { return p; } +inline void* operator new[](size_t, void* p) throw() { return p; } +inline void operator delete (void*, void*) throw() { }; +inline void operator delete[](void*, void*) throw() { }; + +inline void* operator new (size_t size) { return malloc(size); } +inline void* operator new[] (size_t size) { return malloc(size); } +inline void operator delete (void* ptr) { return free(ptr); } +inline void operator delete[] (void* ptr) { return free(ptr); } + +#endif -- cgit v1.2.3