1 /* This is implementation of input/output routines similar to stdio. 2 purpose of this library is to hide differences between OSes (Mac OS don't 3 have stdio!) and allow general streams to strings etc. */ 4 #ifndef XIO1_H 5 #define XIO1_H 1 6 #include "config.h" 7 8 #define XIO_FAILED NULL 9 struct xio_filestruct { 10 void *data; 11 int (*fputc)(int c, struct xio_filestruct *f); 12 int (*fputs)(const char *s, struct xio_filestruct *f); 13 int (*fgetc)(struct xio_filestruct *f); 14 int (*fungetc)(int c, struct xio_filestruct *f); 15 int (*xeof)(struct xio_filestruct *f); 16 int (*fclose)(struct xio_filestruct *f); 17 int (*flush)(struct xio_filestruct *f); 18 }; 19 20 typedef struct xio_filestruct *xio_file; 21 22 #define xio_puts(s, f) (f)->fputs((s), (f)) 23 #define xio_putc(s, f) (f)->fputc((s), (f)) 24 #define xio_getc(f) (f)->fgetc((f)) 25 #define xio_ungetc(s, f) (f)->fungetc((s), (f)) 26 #define xio_feof(f) (f)->xeof((f)) 27 #define xio_close(f) (f)->fclose((f)) 28 #define xio_flush(f) \ 29 if ((f)->flush != NULL) \ 30 (f)->flush((f)) 31 32 /* Standard stdio maps. These defines says, that filenames are strings and 33 path is separated by slash or backslash (windoze, dog) 34 the main I/O routines are in the xstdio file 35 */ 36 37 #include <cstdio> 38 39 typedef char *xio_path; 40 typedef const char *xio_constpath; 41 typedef char xio_pathdata[4096]; 42 extern char *xio_appdir; /*Where application binary is */ 43 extern char *xio_homedir; 44 45 #ifdef _WIN32 46 #define XIO_PATHSEP '\\' 47 #define XIO_PATHSEPSTR "\\" 48 #define XIO_EMPTYPATH ".\\" /*Should be also call to currentdir function */ 49 #else 50 #define XIO_PATHSEP '/' 51 #define XIO_PATHSEPSTR "/" 52 #define XIO_EMPTYPATH "./" /*Should be also call to currentdir function */ 53 #endif 54 #define XIO_EOF EOF 55 56 #define xio_addfname(destination, dirrectory, filename) \ 57 { \ 58 strcpy(destination, dirrectory); \ 59 if (strlen(dirrectory) && \ 60 destination[strlen(destination) - 1] != XIO_PATHSEP) \ 61 strcat(destination, XIO_PATHSEPSTR); \ 62 strcat(destination, filename); \ 63 } 64 #define xio_addextension(destination, extension) strcat(destination, extension) 65 66 #define xio_errorstring() strerror(errno) 67 68 char *xio_fixpath(const char *name); 69 xio_file xio_ropen(xio_constpath name); 70 xio_file xio_wopen(xio_constpath name); 71 xio_file xio_strropen(const char *c); 72 xio_file xio_strwopen(void); 73 char *xio_getstring(xio_file f); 74 xio_path xio_getdirectory(xio_constpath name); 75 xio_path xio_getfilename(const char *base, const char *extension); 76 xio_file xio_getrandomexample(xio_path name); 77 xio_file xio_getcatalog(const char *name); 78 xio_file xio_gethelp(void); 79 xio_file xio_gettutorial(const char *name, xio_path result); 80 81 /*look through directory with examples, choose one file, open it (and return 82 *descriptor+put name into name parameter*/ 83 int xio_exist(xio_constpath name); 84 int xio_getfiles(xio_constpath path, char ***names, char ***dirs, int *nnames, 85 int *ndirs); 86 void xio_init(const char *c); 87 void xio_uninit(void); 88 89 #endif 90