diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-01-29 00:37:16 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-01-29 00:37:16 +1000 |
commit | 5bba108949ed1f97b18f1ea732553da369e8beb0 (patch) | |
tree | 172adc3eeace617330b97f240ad3bc1e422e72eb /include | |
parent | c5ab2adbf0c14a6d0d4e2245a616d01de4b88214 (diff) | |
download | uGFX-5bba108949ed1f97b18f1ea732553da369e8beb0.tar.gz uGFX-5bba108949ed1f97b18f1ea732553da369e8beb0.tar.bz2 uGFX-5bba108949ed1f97b18f1ea732553da369e8beb0.zip |
More GFile code
Diffstat (limited to 'include')
-rw-r--r-- | include/gfile/gfile.h | 70 | ||||
-rw-r--r-- | include/gfile/options.h | 47 |
2 files changed, 81 insertions, 36 deletions
diff --git a/include/gfile/gfile.h b/include/gfile/gfile.h index 5b49a6b3..bc476956 100644 --- a/include/gfile/gfile.h +++ b/include/gfile/gfile.h @@ -45,7 +45,6 @@ typedef struct GFILE { #define GFILEFLG_MUSTEXIST 0x0100 // On open file must exist #define GFILEFLG_MUSTNOTEXIST 0x0200 // On open file must not exist #define GFILEFLG_TRUNC 0x0400 // On open truncate the file - short err; void * obj; long int pos; } GFILE; @@ -58,6 +57,7 @@ typedef struct GFILEVMT { #define GFSFLG_SEEKABLE 0x0004 #define GFSFLG_FAST 0x0010 #define GFSFLG_SMALL 0x0020 + #define GFSFLG_TEXTMODES 0x0040 char prefix; bool_t del(const char *fname); bool_t exists(const char *fname); @@ -66,7 +66,7 @@ typedef struct GFILEVMT { bool_t open(GFILE *f, const char *fname); void close(GFILE *f); int read(GFILE *f, char *buf, int size); - int write(GFILE *f, char *buf, int size); + int write(GFILE *f, const char *buf, int size); bool_t setpos(GFILE *f, long int pos); long int getsize(GFILE *f); bool_t eof(GFILE *f); @@ -112,37 +112,46 @@ extern GFILE *gfileStdOut; extern "C" { #endif - bool_t gfileExists(const char *fname); - bool_t gfileDelete(const char *fname); - long int gfileGetFilesize(const char *fname); - bool_t gfileRename(const char *oldname, const char *newname); - 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); + bool_t gfileExists(const char *fname); + bool_t gfileDelete(const char *fname); + long int gfileGetFilesize(const char *fname); + bool_t gfileRename(const char *oldname, const char *newname); + 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); + bool_t gfileSetPos(GFILE *f, long int pos); long int gfileGetSize(GFILE *f); + bool_t gfileEOF(GFILE *f); + + #if GFILE_NEED_PRINTG + int vfnprintg(GFILE *f, int maxlen, const char *fmt, va_list arg); + int fnprintg(GFILE *f, int maxlen, const char *fmt, ...); + #define vfprintg(f,m,a) vfnprintg(f,0,m,a) + #define fprintg(f,m,...) fnprintg(f,0,m,...) + #define vprintg(m,a) vfnprintg(gfileStdOut,0,m,a) + #define printg(m,...) fnprintg(gfileStdOut,0,m,...) + + #if GFILE_NEED_STRINGS + int vsnprintg(char *buf, int maxlen, const char *fmt, va_list arg); + int snprintg(char *buf, int maxlen, const char *fmt, ...); + #define vsprintg(s,m,a) vsnprintg(s,0,m,a) + #define sprintg(s,m,...) snprintg(s,0,m,...) + #endif + #endif - int vfnprintg(GFILE *f, size_t maxlen, const char *fmt, va_list arg); - int fnprintg(GFILE *f, size_t maxlen, const char *fmt, ...); - #define vfprintg(f,m,a) vfnprintg(f,0,m,a) - #define fprintg(f,m,...) fnprintg(f,0,m,...) - #define vprintg(m,a) vfnprintg(gfileStdOut,0,m,a) - #define printg(m,...) fnprintg(gfileStdOut,0,m,...) - - int vsnprintg(char *buf, size_t maxlen, const char *fmt, va_list arg); - int snprintg(char *buf, size_t maxlen, const char *fmt, ...); - #define vsprintg(s,m,a) vsnprintg(s,0,m,a) - #define sprintg(s,m,...) snprintg(s,0,m,...) #if GFILE_NEED_STDIO && !defined(GFILE_IMPLEMENTATION) #define FILE GFILE #define fopen(n,m) gfileOpen(n,m) #define fclose(f) gfileClose(f) - size_t fread(void * ptr, size_t size, size_t count, FILE *f); - size_t fwrite(const void * ptr, size_t size, size_t count, FILE *f); - int fseek(FILE *f, size_t offset, int origin); + size_t gstdioRead(void * ptr, size_t size, size_t count, FILE *f); + size_t gstdioWrite(const void * ptr, size_t size, size_t count, FILE *f); + #define fread(p,sz,cnt,f) gstdioRead(p,sz,cnt,f) + #define fwrite(p,sz,cnt,f) gstdioWrite(p,sz,cnt,f) + int gstdioSeek(FILE *f, size_t offset, int origin); + #define fseek(f,ofs,org) gstdioSeek(f,ofs,org) #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 @@ -150,13 +159,14 @@ extern "C" { #define rename(o,n) (!gfileRename(o,n)) #define fflush(f) (0) #define ftell(f) gfileGetPos(f) - typedef long int fpos_t; - int fgetpos(FILE *f, fpos_t *pos); + #define fpos_t long int + int gstdioGetpos(FILE *f, long int *pos); + #define fgetpos(f,pos) gstdioGetpos(f,pos) #define fsetpos(f, pos) (!gfileSetPos(f, *pos)) #define rewind(f) gfileSetPos(f, 0); - #define clearerr(f) do {f->err = 0; } while(0) - #define feof(f) (f->flags & GFILEFLG_EOF) - #define ferror(f) (f->err) + #define clearerr(f) (0) + #define feof(f) gfileEOF(f) + //#define ferror(f) (0) #define vfprintf(f,m,a) vfnprintg(f,0,m,a) #define fprintf(f,m,...) fnprintg(f,0,m,...) diff --git a/include/gfile/options.h b/include/gfile/options.h index 176c6270..a64937f1 100644 --- a/include/gfile/options.h +++ b/include/gfile/options.h @@ -21,13 +21,29 @@ * @{ */ /** - * @brief Include printg, fprintg, sprintg etc functions + * @brief Include printg, fprintg etc functions * @details Defaults to FALSE */ #ifndef GFILE_NEED_PRINTG #define GFILE_NEED_PRINTG FALSE #endif /** + * @brief Include scang, fscang etc functions + * @details Defaults to FALSE + */ + #ifndef GFILE_NEED_SCANG + #define GFILE_NEED_SCANG FALSE + #endif + /** + * @brief Include the string sprintg/sscang functions + * @details Defaults to FALSE + * @pre To get sprintg functions you also need to define @p GFILE_NEED_PRINTG + * @pre To get sscang functions you also need to define @p GFILE_NEED_SCANG + */ + #ifndef GFILE_NEED_STRINGS + #define GFILE_NEED_STRINGS FALSE + #endif + /** * @brief Include scang, fscang, sscang etc functions * @details Defaults to FALSE */ @@ -35,7 +51,7 @@ #define GFILE_NEED_SCANG FALSE #endif /** - * @brief Map all the stdio functions to their GFILE equivalent + * @brief Map many stdio functions to their GFILE equivalent * @details Defaults to FALSE * @note This replaces the functions in stdio.h with equivalents * - Do not include stdio.h as it has different conflicting definitions. @@ -46,7 +62,8 @@ /** * @brief Include the ROM file system * @details Defaults to FALSE - * @note To ensure that you are opening a file on the ROM file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the ROM file system by prefixing * its name with "S|" (the letter 'S', followed by a vertical bar). * @note This requires a file called romfs_files.h to be included in the * users project. This file includes all the files converted to .h files @@ -58,7 +75,8 @@ /** * @brief Include the RAM file system * @details Defaults to FALSE - * @note To ensure that you are opening a file on the RAM file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the RAM file system by prefixing * its name with "R|" (the letter 'R', followed by a vertical bar). * @note You must also define GFILE_RAMFS_SIZE with the size of the file system * to be allocated in RAM. @@ -69,7 +87,8 @@ /** * @brief Include the FAT file system driver * @details Defaults to FALSE - * @note To ensure that you are opening a file on the FAT file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the FAT file system by prefixing * its name with "F|" (the letter 'F', followed by a vertical bar). * @note You must separately include the FATFS library and code. */ @@ -79,7 +98,8 @@ /** * @brief Include the operating system's native file system * @details Defaults to FALSE - * @note To ensure that you are opening a file on the native file system, prefix + * @note If GFILE_ALLOW_DEVICESPECIFIC is on then you can ensure that you are + * opening a file on the native file system by prefixing * its name with "N|" (the letter 'N', followed by a vertical bar). * @note If defined then the gfileStdOut and gfileStdErr handles * use the operating system equivalent stdio and stderr. @@ -95,6 +115,21 @@ * @{ */ /** + * @brief Add floating point support to printg/scang etc. + */ + #ifndef GFILE_ALLOW_FLOATS + #define GFILE_ALLOW_FLOATS + #endif + /** + * @brief Can the device be specified as part of the file name. + * @note If this is on then a device letter and a vertical bar can be + * prefixed on a file name to specify that it must be on a + * specific device. + */ + #ifndef GFILE_ALLOW_DEVICESPECIFIC + #define GFILE_ALLOW_DEVICESPECIFIC FALSE + #endif + /** * @brief The maximum number of open files * @note This count excludes gfileStdIn, gfileStdOut and gfileStdErr * (if open by default). |