Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/include/xio.h
blob: 2395302422ce73b2d9cf65b6108bf641cd0e9573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* This is implementation of input/output routines similar to stdio.
   purpose of this library is to hide differences between OSes (Mac OS don't
   have stdio!) and allow general streams to strings etc. */
#ifndef XIO1_H
#define XIO1_H 1
#include <config.h>
#ifdef __cplusplus
extern "C" {
#endif


#define XIO_FAILED NULL
    struct xio_filestruct {
	void *data;
	int (*fputc) (int c, struct xio_filestruct * f);
	int (*fputs) (const char *s, struct xio_filestruct * f);
	int (*fgetc) (struct xio_filestruct * f);
	int (*fungetc) (int c, struct xio_filestruct * f);
	int (*xeof) (struct xio_filestruct * f);
	int (*fclose) (struct xio_filestruct * f);
	int (*flush) (struct xio_filestruct * f);
    };

    typedef struct xio_filestruct *xio_file;

#define xio_puts(s,f) (f)->fputs((s),(f))
#define xio_putc(s,f) (f)->fputc((s),(f))
#define xio_getc(f) (f)->fgetc((f))
#define xio_ungetc(s,f) (f)->fungetc((s),(f))
#define xio_feof(f) (f)->xeof((f))
#define xio_close(f) (f)->fclose((f))
#define xio_flush(f) if ((f)->flush!=NULL) (f)->flush((f))

/* Standard stdio maps. These defines says, that filenames are strings and
   path is separated by slash or backslash (windoze, dog)
   the main I/O routines are in the xstdio file
*/

#ifdef USE_STDIO
/* Ugly hack because of unknown problems w/ va_list in v*print* in plan9 */
#ifdef _plan9_
#define va_list char *
#endif
#include <stdio.h>

    typedef char *xio_path;
    typedef CONST char *xio_constpath;
    typedef char xio_pathdata[4096];
    extern char *xio_appdir;	/*Where application binary is */
    extern char *xio_homedir;


#ifdef _WIN32
#define XIO_PATHSEP '\\'
#define XIO_PATHSEPSTR "\\"
#define XIO_EMPTYPATH ".\\"	/*Should be also call to currentdir function */
#else
#ifdef DJGPP
#define XIO_PATHSEP '\\'
#define XIO_PATHSEPSTR "\\"
#define XIO_EMPTYPATH ".\\"	/*Should be also call to currentdir function */
#else
#define XIO_PATHSEP '/'
#define XIO_PATHSEPSTR "/"
#define XIO_EMPTYPATH "./"	/*Should be also call to currentdir function */
#endif
#endif
#define XIO_EOF EOF

#define xio_addfname(destination, dirrectory, filename) \
{strcpy(destination,dirrectory);if (strlen(dirrectory)&&destination[strlen(destination)-1]!=XIO_PATHSEP) strcat(destination,XIO_PATHSEPSTR);strcat(destination,filename);}
#define xio_addextension(destination,extension) strcat(destination,extension)

#ifdef _plan9_
#define xio_errorstring() errstr
#else
#define xio_errorstring() strerror(errno)
#endif				/*plan9 */

    char *xio_fixpath(CONST char *name);
#endif				/*USE_STDIO */

    xio_file xio_ropen(xio_constpath name);
    xio_file xio_wopen(xio_constpath name);
    xio_file xio_strropen(CONST char *c);
    xio_file xio_strwopen(void);
    char *xio_getstring(xio_file f);
    xio_path xio_getdirectory(xio_constpath name);
    xio_path xio_getfilename(CONST char *base, CONST char *extension);
    xio_file xio_getrandomexample(xio_path name);
    xio_file xio_getcatalog(CONST char *name);
    xio_file xio_gethelp(void);
    xio_file xio_gettutorial(CONST char *name, xio_path result);

    /*look trought directory with examples, choose one file, open it (and return
     *descriptor+put name into name parameter*/
    int xio_exist(xio_constpath name);
    int xio_getfiles(xio_constpath path, char ***names, char ***dirs,
		     int *nnames, int *ndirs);
    void xio_init(CONST char *c);
    void xio_uninit(void);


#ifdef __cplusplus
}
#endif
#endif