diff options
Diffstat (limited to 'src/user/lib/fwik')
-rw-r--r-- | src/user/lib/fwik/Makefile | 11 | ||||
-rw-r--r-- | src/user/lib/fwik/String.cpp | 176 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/Dir.h | 24 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/IOStream.h | 39 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/Node.h | 32 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/Term.h | 33 | ||||
-rw-r--r-- | src/user/lib/fwik/include/String.h | 42 | ||||
-rw-r--r-- | src/user/lib/fwik/include/cpp.h | 16 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Dir.cpp | 37 | ||||
-rw-r--r-- | src/user/lib/fwik/io/IOStream.cpp | 19 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Node.cpp | 118 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Term.cpp | 62 | ||||
-rw-r--r-- | src/user/lib/fwik/main.cpp | 37 |
13 files changed, 0 insertions, 646 deletions
diff --git a/src/user/lib/fwik/Makefile b/src/user/lib/fwik/Makefile deleted file mode 100644 index c99b288..0000000 --- a/src/user/lib/fwik/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -Out = _fwik.o -Obj = String.o io/Node.o io/Term.o io/Dir.o io/IOStream.o main.o - -ExtObj = $(SrcPath)/user/lib/libc/_libc.o - -include $(SrcPath)/common.make - -CFLAGS += -I$(SrcPath)/include -I$(SrcPath)/user/lib/libc/include -I$(SrcPath)/user/lib/fwik/include - -LDFLAGS += -r - diff --git a/src/user/lib/fwik/String.cpp b/src/user/lib/fwik/String.cpp deleted file mode 100644 index e3455e3..0000000 --- a/src/user/lib/fwik/String.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include <String.h> -#include <string.h> - -String::String() { - ptr = 0; - len = 0; -} - -String::String(const String &other) { - len = other.len; - if (len == 0) { - ptr = 0; - } else { - ptr = (char*)malloc(len + 1); - libc::memcpy(ptr, other.ptr, len + 1); - } -} - -String::String(const char* from) { - len = (from == 0 ? 0 : libc::strlen(from)); - if (len == 0) { - ptr = 0; - } else { - ptr = (char*)malloc(len + 1); - libc::memcpy(ptr, from, len + 1); - } -} - -String::String(const char* from, int l) { - len = l; - if (len < 0) len = 0; - if (len == 0) { - ptr = 0; - } else { - ptr = (char*)malloc(len + 1); - libc::memcpy(ptr, from, len); - ptr[len] = 0; - } -} - -String::String(char c, int count) { - len = count; - if (len == 0) { - ptr = 0; - } else { - ptr = (char*)malloc(len + 1); - libc::memset(ptr, c, len); - ptr[len] = 0; - } -} - -String::~String() { - if (ptr != 0) free(ptr); -} - -void String::operator=(const String &other) { - if (ptr != 0) free(ptr); - len = other.len; - if (len == 0) { - ptr = 0; - } else { - ptr = (char*)malloc(len + 1); - libc::memcpy(ptr, other.ptr, len + 1); - } -} - -void String::operator=(const char* from) { - if (ptr != 0) free(ptr); - len = (from == 0 ? 0 : libc::strlen(from)); - if (len == 0) { - ptr = 0; - } else { - ptr = (char*)malloc(len + 1); - libc::memcpy(ptr, from, len + 1); - } -} - -const char* String::c_str() const { - if (ptr == 0) return ""; - return ptr; -} - -bool String::operator==(const String& other) const { - if (len != other.len) return false; - for (int i = 0; i < len; i++) if (ptr[i] != other.ptr[i]) return false; - return true; -} - -bool String::operator==(const char* other) const { - if (other == 0) return (len == 0); - if (len != libc::strlen(other)) return false; - for (int i = 0; i < len; i++) if (ptr[i] != other[i]) return false; - return true; -} - -bool String::operator<(const String& other) const { - for (int i = 0; i < len && i < other.len; i++) { - if (ptr[i] > other.ptr[i]) return false; - if (ptr[i] < other.ptr[i]) return true; - } - if (len < other.len) return true; - return false; -} - -static char crap; -char &String::operator[](int pos) { - if (pos >= 0 && pos < len) return ptr[pos]; - crap = 0; - return crap; -} - -char String::operator[](int pos) const { - if (pos >= 0 && pos < len) return ptr[pos]; - return 0; -} - -String String::substr(int start, int count) const { - if (start + count > len) count = len - start; - return String(ptr + start, count); -} - -String String::operator+(const String& other) const { - String ret(' ', len + other.len); - libc::memcpy(ret.ptr, ptr, len); - libc::memcpy(ret.ptr + len, other.ptr, other.len); - return ret; -} - -void String::operator+=(const String& other) { - if (other.len == 0) return; - int newlen = len + other.len; - char* newptr = (char*)malloc(newlen + 1); - libc::memcpy(newptr, ptr, len); - libc::memcpy(newptr+len, other.ptr, other.len); - newptr[newlen] = 0; - free(ptr); - ptr = newptr; - len = newlen; -} - -void String::operator+=(char c) { - char* newptr = (char*)malloc(len + 2); - libc::memcpy(newptr, ptr, len); - newptr[len] = c; - len++; - newptr[len] = 0; - free(ptr); - ptr = newptr; -} - -String String::dec(int i) { - char b[16]; - const char *e = libc::format_int(b, i); - return String(b, e - b); -} - -String String::hex(uint32_t v) { - char b[16]; - const char *e = libc::format_hex(b, v); - return String(b, e - b); -} - -String String::sprintf(const char* format, ...) { - va_list ap; - va_start(ap, format); - va_list ap2; - va_copy(ap2, ap); - - String ret; - ret.len = libc::printf_str_len(format, ap2); - va_end(ap2); - ret.ptr = (char*)malloc(ret.len + 1); - ret.len = libc::vsprintf(ret.ptr, format, ap); - va_end(ap); - return ret; -} diff --git a/src/user/lib/fwik/include/IO/Dir.h b/src/user/lib/fwik/include/IO/Dir.h deleted file mode 100644 index bbfe3ed..0000000 --- a/src/user/lib/fwik/include/IO/Dir.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DEF_FWIK_IO_DIR_H -#define DEF_FWIK_IO_DIR_H - -#include "Node.h" -#include <String.h> - -class Dir : public Node { - void _init(); - - public: - int pos; - - Dir(FILE f); - Dir(const char* file, int mode); - Dir(const Node &n); - virtual ~Dir(); - - String read_ent(); - - virtual Dir* as_dir() { return this; } -}; - -#endif - diff --git a/src/user/lib/fwik/include/IO/IOStream.h b/src/user/lib/fwik/include/IO/IOStream.h deleted file mode 100644 index 2e33268..0000000 --- a/src/user/lib/fwik/include/IO/IOStream.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DEF_FWIK_IO_IOSTREAM_H -#define DEF_FWIK_IO_IOSTREAM_H - -#include "Term.h" - -#include <String.h> - -class IOStream { - public: - Term *term; - - IOStream() : term(0) {} - IOStream(Term *t) : term(t) {} - - void print(const char* str); - void printf(const char* fmt, ...); - String readln(); - - IOStream &operator<<(const char* s) { - print(s); - return *this; - } - IOStream &operator<<(const String& s) { - print(s.c_str()); - 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 deleted file mode 100644 index 6b5b063..0000000 --- a/src/user/lib/fwik/include/IO/Node.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DEF_FWIK_IO_NODE_H -#define DEF_FWIK_IO_NODE_H - -#include <tce/syscall.h> -#include <tce/vfs.h> -#include <stdio.h> -#include <cpp.h> - -#include <String.h> - -class Term; -class Dir; -class Node { - public: - FILE fd; - file_info info; - int error; // will be 0 if this is a valid file descriptor - - Node(FILE f); - Node(const char* filename, int mode); - Node(FILE parent, const char* filename, int mode); - virtual ~Node() {} - - void close(); - - virtual Term* as_term() { return 0; } - virtual Dir* as_dir() { return 0; } -}; - -String path_cat(const String &a, const String &b, bool trailing_slash = true); - -#endif diff --git a/src/user/lib/fwik/include/IO/Term.h b/src/user/lib/fwik/include/IO/Term.h deleted file mode 100644 index 5b8aba3..0000000 --- a/src/user/lib/fwik/include/IO/Term.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef DEF_FWIK_IO_TERM_H -#define DEF_FWIK_IO_TERM_H - -#include <stdio.h> -#include "Node.h" -#include <String.h> - -#include <readline.h> - -class Term : public Node { - int w, h; - - readline_history hist; - - void _init(); - - public: - Term(FILE f); - Term(const char* filename, int mode); - Term(const Node &n); - virtual ~Term(); - - virtual void print(const char *s); - virtual void printf(const char* fmt, ...); - virtual void vprintf(const char* fmt, va_list ap); - virtual String readln(); - String 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 deleted file mode 100644 index 59fa0b6..0000000 --- a/src/user/lib/fwik/include/String.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef DEF_FWIK_STRING_H -#define DEF_FWIK_STRING_H - -#include <cpp.h> - -class String { - private: - char *ptr; // zero-terminated for internal purposes. - int len; - - public: - String(); - String(const String& other); - String(const char* ptr); - String(const char* ptr, int len); - String(char c, int count); - ~String(); - void operator=(const String &string); - void operator=(const char* ptr); - - const char* c_str() const; - - bool operator==(const String& other) const; - bool operator==(const char* other) const; - bool operator<(const String& other) const; - char &operator[](int pos); - char operator[](int pos) const; - - int size() const { return len; } - operator bool() const { return len != 0; } - String substr(int start, int count) const; - - String operator+(const String& other) const; - void operator+=(const String& other); - void operator+=(char c); - - static String dec(int i); - static String hex(uint32_t v); - static String sprintf(const char* format, ...); -}; - -#endif diff --git a/src/user/lib/fwik/include/cpp.h b/src/user/lib/fwik/include/cpp.h deleted file mode 100644 index 5b66ba1..0000000 --- a/src/user/lib/fwik/include/cpp.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DEF_FWIK_CPPSUPPORT_H -#define DEF_FWIK_CPPSUPPORT_H - -#include <stdlib.h> - -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 diff --git a/src/user/lib/fwik/io/Dir.cpp b/src/user/lib/fwik/io/Dir.cpp deleted file mode 100644 index cfcc77b..0000000 --- a/src/user/lib/fwik/io/Dir.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include <IO/Dir.h> - -Dir::Dir(const Node &n) : Node(n) { - _init(); -} - -Dir::Dir(FILE f) : Node(f) { - _init(); - if (error == E_INVALID_TYPE) libc::close(fd); -} - -Dir::Dir(const char* filename, int mode) : Node(filename, mode) { - _init(); - if (error == E_INVALID_TYPE) libc::close(fd); -} - -void Dir::_init() { - if (error < 0) return; - pos = 0; - if ((info.type & FT_DIR) == 0) { - error = E_INVALID_TYPE; - } -} - -Dir::~Dir() { -} - -String Dir::read_ent() { - char buf[256]; - int l = libc::read(fd, pos, 256, buf); - if (l > 0) { - pos++; - return String(buf, l); - } else { - return ""; - } -} diff --git a/src/user/lib/fwik/io/IOStream.cpp b/src/user/lib/fwik/io/IOStream.cpp deleted file mode 100644 index 9d13251..0000000 --- a/src/user/lib/fwik/io/IOStream.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include <IO/IOStream.h> - -void IOStream::print(const char* str) { - if (term == 0) return; - term->print(str); -} - -void IOStream::printf(const char* fmt, ...) { - if (term == 0) return; - va_list ap; - va_start(ap, fmt); - term->vprintf(fmt, ap); - va_end(ap); -} - -String IOStream::readln() { - if (term == 0) return ""; - return term->readln(); -} diff --git a/src/user/lib/fwik/io/Node.cpp b/src/user/lib/fwik/io/Node.cpp deleted file mode 100644 index 5585aa8..0000000 --- a/src/user/lib/fwik/io/Node.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include <IO/Node.h> - -Node::Node(FILE f) { - fd = f; - error = libc::statf(f, &info); -} - -Node::Node(const char* filename, int mode) { - fd = libc::open(filename, mode); - if (fd < 0) { - if (fd != E_NOT_FOUND) error = libc::stat(filename, &info); - } else { - int i = libc::statf(fd, &info); - error = i; - if (error < 0) libc::close(fd); - } -} - -Node::Node(FILE parent, const char* filename, int mode) { - fd = libc::open_relative(parent, filename, mode); - if (fd < 0) { - if (fd != E_NOT_FOUND) error = libc::stat_relative(parent, filename, &info); - } else { - int i = libc::statf(fd, &info); - error = i; - if (error < 0) libc::close(fd); - } -} - -void Node::close() { - if (error == 0) libc::close(fd); - error = E_INVALID_FD; -} - -//////// - -static void simplify_path(char* p) { - char *it = p; - char *member = it; - while (*it != 0) { - if (*it == '/') { - if (it == member && it != p) { - // two consecutive slashes - char *i = member; - while (1) { - i[0] = i[1]; - if (i[0] == 0) break; - i++; - } - } else { - *it = 0; - if (libc::strcmp(member, ".") == 0) { - char *i = member; - while (1) { - i[0] = i[2]; - if (i[0] == 0) break; - i++; - } - } else if (libc::strcmp(member, "..") == 0) { - *it = '/'; - char* start = member - 2; - char* next = member + 3; - while (start > p && *start != '/') { - start--; - } - start++; - it = member = start; - while (1) { - *start = *next; - if (*start == 0) break; - start++; - next++; - } - } else { - *it = '/'; - it++; - member = it; - } - } - } else { - it++; - } - } -} - -String path_cat(const String &a, const String &b, bool trailing_slash) { - int len, la = a.size(), lb = b.size(); - if (b[0] == '/') { - len = lb + 2; - } else { - len = la + lb + 3; - } - char buf[len]; - if (b[0] == '/') { - libc::memcpy(buf, b.c_str(), lb); - if (buf[lb-1] != '/') { - buf[lb++] = '/'; - } - buf[lb] = 0; - } else { - libc::memcpy(buf, a.c_str(), la); - if (buf[la-1] != '/') { - buf[la++] = '/'; - } - libc::memcpy(buf + la, b.c_str(), lb); - if (buf[la + lb - 1] != '/') { - buf[la + lb] = '/'; - lb++; - } - buf[la + lb] = 0; - } - simplify_path(buf); - if (!trailing_slash) { - int l = libc::strlen(buf); - if (buf[l-1] == '/') buf[l-1] = 0; - } - return String(buf); -} diff --git a/src/user/lib/fwik/io/Term.cpp b/src/user/lib/fwik/io/Term.cpp deleted file mode 100644 index f8f686e..0000000 --- a/src/user/lib/fwik/io/Term.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include <IO/Term.h> - -Term::Term(const Node &n) : Node(n) { - _init(); -} - -Term::Term(FILE f) : Node(f) { - _init(); - if (error E_INVALID_TYPE) libc::close(fd); -} - -Term::Term(const char* filename, int mode) : Node(filename, mode) { - _init(); - if (error == E_INVALID_TYPE) libc::close(fd); -} - -void Term::_init() { - if (error < 0) return; - if (info.type & FT_TERMINAL) { - w = info.size >> 16; - h = info.size & 0xFFFF; - } else { - error = E_INVALID_TYPE; - } - hist.str = 0; - hist.max = 12; -} - -Term::~Term() { - if (hist.str != 0) { - for (int i = 0; i < hist.max; i++) { - if (hist.str[i] != 0) free(hist.str[i]); - } - free(hist.str); - } -} - -void Term::print(const char *s) { - libc::fprint(fd, s); -} - -void Term::printf(const char* fmt, ...) { - va_list ap; - va_start(ap, fmt); - libc::vfprintf(fd, fmt, ap); - va_end(ap); -} - -void Term::vprintf(const char* fmt, va_list ap) { - libc::vfprintf(fd, fmt, ap); -} - -String Term::readln() { - char *s = libc::freadln(fd); - String ret(s); - free(s); - return ret; -} - -String Term::readline() { - return String(libc::freadline(fd, &hist)); -} diff --git a/src/user/lib/fwik/main.cpp b/src/user/lib/fwik/main.cpp deleted file mode 100644 index e7c40c4..0000000 --- a/src/user/lib/fwik/main.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include <IO/IOStream.h> -#include <stdio.h> -#include <cpp.h> -#include <String.h> - -IOStream stdio; - -int Main(String *args); // FWIK app main - -extern "C" int main(char **args) { - stdio.term = 0; - - Node zero(libc::term); - if (zero.info.type & FT_TERMINAL) { - stdio.term = new Term(zero); - } - - int argc = 0; - while (args[argc] != 0) argc++; - String s_args[argc+1]; - for (int i = 0; i < argc; i++) s_args[i] = args[i]; - - return Main(s_args); -} - - -// C++ support - -//Enables pure virtual functions -extern "C" void __cxa_pure_virtual() { - //do nothing -} -//Enables global objects -void *__dso_handle; -extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; } - - |