From 37966ff16d923bbca53c9464815cb49cbd7fc3be Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 19 Feb 2014 00:36:52 +1000 Subject: Integrate the include files with each module. Simplifies structure of code. --- src/gfile/gfile.c | 12 ++-- src/gfile/gfile.mk | 1 - src/gfile/sys_defs.h | 169 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gfile/sys_make.mk | 1 + src/gfile/sys_options.h | 158 ++++++++++++++++++++++++++++++++++++++++++++ src/gfile/sys_rules.h | 23 +++++++ 6 files changed, 357 insertions(+), 7 deletions(-) delete mode 100644 src/gfile/gfile.mk create mode 100644 src/gfile/sys_defs.h create mode 100644 src/gfile/sys_make.mk create mode 100644 src/gfile/sys_options.h create mode 100644 src/gfile/sys_rules.h (limited to 'src/gfile') diff --git a/src/gfile/gfile.c b/src/gfile/gfile.c index 9edafea4..8a3abf9c 100644 --- a/src/gfile/gfile.c +++ b/src/gfile/gfile.c @@ -77,42 +77,42 @@ GFILE *gfileStdErr; * The ChibiOS BaseFileStream VMT ********************************************************/ #if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS - #include "../src/gfile/inc_chibiosfs.c" + #include "src/gfile/inc_chibiosfs.c" #endif /******************************************************** * The Memory Pointer VMT ********************************************************/ #if GFILE_NEED_MEMFS - #include "../src/gfile/inc_memfs.c" + #include "src/gfile/inc_memfs.c" #endif /******************************************************** * The RAM file-system VMT ********************************************************/ #if GFILE_NEED_RAMFS - #include "../src/gfile/inc_ramfs.c" + #include "src/gfile/inc_ramfs.c" #endif /******************************************************** * The FAT file-system VMT ********************************************************/ #ifndef GFILE_NEED_FATFS - #include "../src/gfile/inc_fatfs.c" + #include "src/gfile/inc_fatfs.c" #endif /******************************************************** * The native file-system ********************************************************/ #if GFILE_NEED_NATIVEFS - #include "../src/gfile/inc_nativefs.c" + #include "src/gfile/inc_nativefs.c" #endif /******************************************************** * The ROM file-system VMT ********************************************************/ #if GFILE_NEED_ROMFS - #include "../src/gfile/inc_romfs.c" + #include "src/gfile/inc_romfs.c" #endif /******************************************************** diff --git a/src/gfile/gfile.mk b/src/gfile/gfile.mk deleted file mode 100644 index 381bd6f6..00000000 --- a/src/gfile/gfile.mk +++ /dev/null @@ -1 +0,0 @@ -GFXSRC += $(GFXLIB)/src/gfile/gfile.c diff --git a/src/gfile/sys_defs.h b/src/gfile/sys_defs.h new file mode 100644 index 00000000..675bc4b1 --- /dev/null +++ b/src/gfile/sys_defs.h @@ -0,0 +1,169 @@ +/* + * 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/sys_defs.h + * @brief GFILE - File IO Routines header file. + * + * @addtogroup GFILE + * + * @brief Module which contains Operating system independent FILEIO + * + * @{ + */ + +#ifndef _GFILE_H +#define _GFILE_H + +#include "gfx.h" + +#if GFX_USE_GFILE || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +/** + * @brief A file pointer + */ + +#ifndef GFILE_IMPLEMENTATION + typedef void GFILE; +#else + typedef struct GFILE GFILE; +#endif + +extern GFILE *gfileStdIn; +extern GFILE *gfileStdErr; +extern GFILE *gfileStdOut; + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +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, void *buf, size_t len); + size_t gfileWrite(GFILE *f, const void *buf, size_t len); + long int gfileGetPos(GFILE *f); + bool_t gfileSetPos(GFILE *f, long int pos); + long int gfileGetSize(GFILE *f); + bool_t gfileEOF(GFILE *f); + + #if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS + GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode); + #endif + #if GFILE_NEED_MEMFS + GFILE * gfileOpenMemory(void *memptr, const char *mode); + #endif + + #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 + + #if GFILE_NEED_SCANG + int vfscang(GFILE *f, const char *fmt, va_list arg); + int fscang(GFILE *f, const char *fmt, ...); + #define vscang(f,a) vfscang(gfileStdIn,f,a) + #define scang(f,...) fscang(gfileStdIn,f,...) + + #if GFILE_NEED_STRINGS + int vsscang(const char *buf, const char *fmt, va_list arg); + int sscang(const char *buf, const char *fmt, ...); + #endif + #endif + + #if GFILE_NEED_STDIO && !defined(GFILE_IMPLEMENTATION) + #define stdin gfileStdIn + #define stdout gfileStdOut + #define stderr gfileStdErr + #define FILENAME_MAX 256 // Use a relatively small number for an embedded platform + #define L_tmpnam FILENAME_MAX + #define FOPEN_MAX GFILE_MAX_GFILES + #define TMP_MAX GFILE_MAX_GFILES + #define P_tmpdir "/tmp/" + #define FILE GFILE + #define fopen(n,m) gfileOpen(n,m) + #define fclose(f) gfileClose(f) + 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 + #define remove(n) (!gfileDelete(n)) + #define rename(o,n) (!gfileRename(o,n)) + #define fflush(f) (0) + #define ftell(f) gfileGetPos(f) + #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 feof(f) gfileEOF(f) + + #define vfprintf(f,m,a) vfnprintg(f,0,m,a) + #define fprintf(f,m,...) fnprintg(f,0,m,...) + #define vprintf(m,a) vfnprintg(gfileStdOut,0,m,a) + #define printf(m,...) fnprintg(gfileStdOut,0,m,...) + #define vsnprintf(s,n,m,a) vsnprintg(s,n,m,a) + #define snprintf(s,n,m,...) snprintg(s,n,m,...) + #define vsprintf(s,m,a) vsnprintg(s,0,m,a) + #define sprintf(s,m,...) snprintg(s,0,m,...) + //TODO + //void clearerr ( FILE * stream ); + //int ferror ( FILE * stream ); + //FILE * tmpfile ( void ); // Auto-deleting + //char * tmpnam ( char * str ); + //char * mktemp (char *template); + //FILE * freopen ( const char * filename, const char * mode, FILE * stream ); + //setbuf + //setvbuf + //fflush + //fgetc + //fgets + //fputc + //fputs + //getc + //getchar + //puts + //ungetc + //void perror (const char * str); + #endif + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_GFILE */ + +#endif /* _GFILE_H */ +/** @} */ + diff --git a/src/gfile/sys_make.mk b/src/gfile/sys_make.mk new file mode 100644 index 00000000..381bd6f6 --- /dev/null +++ b/src/gfile/sys_make.mk @@ -0,0 +1 @@ +GFXSRC += $(GFXLIB)/src/gfile/gfile.c diff --git a/src/gfile/sys_options.h b/src/gfile/sys_options.h new file mode 100644 index 00000000..6e36e6b7 --- /dev/null +++ b/src/gfile/sys_options.h @@ -0,0 +1,158 @@ +/* + * 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/sys_options.h + * @brief GFILE - File IO options header file. + * + * @addtogroup GFILE + * @{ + */ + +#ifndef _GFILE_OPTIONS_H +#define _GFILE_OPTIONS_H + +/** + * @name GFILE Functionality to be included + * @{ + */ + /** + * @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 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. + */ + #ifndef GFILE_NEED_STDIO + #define GFILE_NEED_STDIO FALSE + #endif + /** + * @brief Include the ROM file system + * @details Defaults to FALSE + * @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 in the + * users project include path. This file should include all the files + * converted to .h files using the file2c utility (using flags "-dbcs"). + */ + #ifndef GFILE_NEED_ROMFS + #define GFILE_NEED_ROMFS FALSE + #endif + /** + * @brief Include the RAM file system + * @details Defaults to FALSE + * @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. + */ + #ifndef GFILE_NEED_RAMFS + #define GFILE_NEED_RAMFS FALSE + #endif + /** + * @brief Include the FAT file system driver + * @details Defaults to FALSE + * @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. + */ + #ifndef GFILE_NEED_FATFS + #define GFILE_NEED_FATFS FALSE + #endif + /** + * @brief Include the operating system's native file system + * @details Defaults to FALSE + * @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. + * If it is not defined the gfileStdOut and gfileStdErr io is discarded. + */ + #ifndef GFILE_NEED_NATIVEFS + #define GFILE_NEED_NATIVEFS FALSE + #endif + /** + * @brief Include ChibiOS BaseFileStream support + * @details Defaults to FALSE + * @pre This is only relevant on the ChibiOS operating system. + * @note Use the @p gfileOpenBaseFileStream() call to open a GFILE based on a + * BaseFileStream. The BaseFileStream must already be open. + * @note A GFile of this type cannot be opened by filename. The BaseFileStream + * must be pre-opened using the operating system. + */ + #ifndef GFILE_NEED_CHIBIOSFS + #define GFILE_NEED_CHIBIOSFS FALSE + #endif + /** + * @brief Include raw memory pointer support + * @details Defaults to FALSE + * @note Use the @p gfileOpenMemory() call to open a GFILE based on a + * memory pointer. The GFILE opened appears to be of unlimited size. + * @note A GFile of this type cannot be opened by filename. + */ + #ifndef GFILE_NEED_MEMFS + #define GFILE_NEED_MEMFS FALSE + #endif +/** + * @} + * + * @name GFILE Optional Parameters + * @{ + */ + /** + * @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). + */ + #ifndef GFILE_MAX_GFILES + #define GFILE_MAX_GFILES 3 + #endif +/** @} */ + +#endif /* _GFILE_OPTIONS_H */ +/** @} */ diff --git a/src/gfile/sys_rules.h b/src/gfile/sys_rules.h new file mode 100644 index 00000000..8d07144d --- /dev/null +++ b/src/gfile/sys_rules.h @@ -0,0 +1,23 @@ +/* + * 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/sys_rules.h + * @brief GFILE safety rules header file. + * + * @addtogroup GFILE + * @{ + */ + +#ifndef _GFILE_RULES_H +#define _GFILE_RULES_H + +#if GFX_USE_GFILE +#endif + +#endif /* _GFILE_RULES_H */ +/** @} */ -- cgit v1.2.3