aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/gfile.c
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-01-05 00:02:53 +1000
committerinmarket <andrewh@inmarket.com.au>2014-01-05 00:02:53 +1000
commitfb29f601f1d5e4c74af9c0d7f53cdf9b57f2cb85 (patch)
treecbe3be841dc50a9996859c72e8c08b8bc537296b /src/gfile/gfile.c
parent07869da90938e375e71081d30757cc767596b431 (diff)
downloaduGFX-fb29f601f1d5e4c74af9c0d7f53cdf9b57f2cb85.tar.gz
uGFX-fb29f601f1d5e4c74af9c0d7f53cdf9b57f2cb85.tar.bz2
uGFX-fb29f601f1d5e4c74af9c0d7f53cdf9b57f2cb85.zip
Start of GFILE module
Diffstat (limited to 'src/gfile/gfile.c')
-rw-r--r--src/gfile/gfile.c225
1 files changed, 225 insertions, 0 deletions
diff --git a/src/gfile/gfile.c b/src/gfile/gfile.c
new file mode 100644
index 00000000..bf76e8bc
--- /dev/null
+++ b/src/gfile/gfile.c
@@ -0,0 +1,225 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gfile/gfile.c
+ * @brief GFILE code.
+ *
+ */
+
+#define GFILE_IMPLEMENTATION
+#include "gfx.h"
+
+#if GFX_USE_GFILE
+
+// The chain of FileSystems
+#define GFILE_CHAINHEAD 0
+
+// The table of GFILE's
+static GFILE gfileArr[GFILE_MAX_GFILES];
+GFILE *gfileStdIn;
+GFILE *gfileStdOut;
+GFILE *gfileStdErr;
+
+/**
+ * The order of the file-systems below determines the order
+ * that they are searched to find a file.
+ * The last defined is the first searched.
+ */
+
+/********************************************************
+ * The RAM file-system VMT
+ ********************************************************/
+#if GFILE_NEED_RAMFS
+ #include "../src/gfile/inc_ramfs.c"
+#endif
+
+/********************************************************
+ * The FAT file-system VMT
+ ********************************************************/
+#ifndef GFILE_NEED_FATFS
+ #include "../src/gfile/inc_fatfs.c"
+#endif
+
+/********************************************************
+ * The native file-system
+ ********************************************************/
+#if GFILE_NEED_NATIVEFS
+ #include "../src/gfile/inc_nativefs.c"
+#endif
+
+/********************************************************
+ * The ROM file-system VMT
+ ********************************************************/
+#if GFILE_NEED_ROMFS
+ #include "../src/gfile/inc_romfs.c"
+#endif
+
+/********************************************************
+ * IO routines
+ ********************************************************/
+
+/**
+ * The chain of file systems.
+ */
+static const GFILEVMT const * FsChain = GFILE_CHAINHEAD;
+
+/**
+ * The init routine
+ */
+void _gfileInit(void) {
+ #if GFILE_NEED_NATIVEFS
+ NativeStdIn.flags = GFILEFLG_OPEN|GFILEFLG_READ;
+ NativeStdIn.vmt = &FsNativeVMT;
+ NativeStdIn.obj = (void *)stdin;
+ NativeStdIn.pos = 0;
+ gfileStdIn = &NativeStdIn;
+ NativeStdOut.flags = GFILEFLG_OPEN|GFILEFLG_WRITE|GFILEFLG_APPEND;
+ NativeStdOut.vmt = &FsNativeVMT;
+ NativeStdOut.obj = (void *)stdout;
+ NativeStdOut.pos = 0;
+ gfileStdOut = &NativeStdOut;
+ NativeStdErr.flags = GFILEFLG_OPEN|GFILEFLG_WRITE|GFILEFLG_APPEND;
+ NativeStdErr.vmt = &FsNativeVMT;
+ NativeStdErr.obj = (void *)stderr;
+ NativeStdErr.pos = 0;
+ gfileStdErr = &NativeStdErr;
+ #endif
+}
+
+bool_t gfileExists(const char *fname) {
+ const GFILEVMT *p;
+
+ if (fname[0] && fname[1] == '|') {
+ for(p = FsChain; p; p = p->next) {
+ if (p->prefix == fname[0])
+ return p->exists && p->exists(fname+2);
+ }
+ } else {
+ for(p = FsChain; p; p = p->next) {
+ if (p->exists && p->exists(fname))
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool_t gfileDelete(const char *fname) {
+ const GFILEVMT *p;
+
+ if (fname[0] && fname[1] == '|') {
+ for(p = FsChain; p; p = p->next) {
+ if (p->prefix == fname[0])
+ return p->del && p->del(fname+2);
+ }
+ } else {
+ for(p = FsChain; p; p = p->next) {
+ if (p->del && p->del(fname))
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+long int gfileGetFilesize(const char *fname) {
+ const GFILEVMT *p;
+
+ if (fname[0] && fname[1] == '|') {
+ for(p = FsChain; p; p = p->next) {
+ if (p->prefix == fname[0])
+ return p->filesize ? p->filesize(fname+2) : -1;
+ }
+ } else {
+ long int res;
+
+ for(p = FsChain; p; p = p->next) {
+ if (p->filesize && (res = p->filesize(fname)) != -1)
+ return res;
+ }
+ }
+ return -1;
+}
+
+bool_t gfileRename(const char *oldname, const char *newname) {
+ const GFILEVMT *p;
+
+ if ((oldname[0] && oldname[1] == '|') || (newname[0] && newname[1])) {
+ char ch;
+
+ if (oldname[0] && oldname[1] == '|') {
+ ch = oldname[0];
+ oldname += 2;
+ if (newname[0] && newname[1] == '|') {
+ if (newname[0] != ch)
+ return FALSE;
+ newname += 2;
+ }
+ } else {
+ ch = newname[0];
+ newname += 2;
+ }
+ for(p = FsChain; p; p = p->next) {
+ if (p->prefix == ch)
+ return p->ren && p->ren(oldname, newname);
+ }
+ } else {
+ for(p = FsChain; p; p = p->next) {
+ if (p->ren && p->ren(oldname,newname))
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+GFILE *gfileOpen(const char *fname, const char *mode) {
+
+}
+
+void gfileClose(GFILE *f) {
+
+}
+
+size_t gfileRead(GFILE *f, char *buf, size_t len) {
+
+}
+
+size_t gfileWrite(GFILE *f, const char *buf, size_t len) {
+
+}
+
+long int gfileGetPos(GFILE *f) {
+
+}
+
+bool_t gfileSetPos(GFILE *f, long int pos) {
+
+}
+
+long int gfileGetSize(GFILE *f) {
+
+}
+
+/********************************************************
+ * printg routines
+ ********************************************************/
+#if GFILE_NEED_PRINTG
+#endif
+
+/********************************************************
+ * scang routines
+ ********************************************************/
+#if GFILE_NEED_SCANG
+#endif
+
+/********************************************************
+ * stdio emulation routines
+ ********************************************************/
+#ifndef GFILE_NEED_STDIO
+ #define GFILE_NEED_STDIO FALSE
+#endif
+
+#endif /* GFX_USE_GFILE */