Imported Upstream version 21
[debian/pforth] / csrc / pf_io.h
1 /* @(#) pf_io.h 98/01/26 1.2 */
2 #ifndef _pf_io_h
3 #define _pf_io_h
4
5 /***************************************************************
6 ** Include file for PForth IO
7 **
8 ** Author: Phil Burk
9 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
10 **
11 ** The pForth software code is dedicated to the public domain,
12 ** and any third party may reproduce, distribute and modify
13 ** the pForth software code or any derivative works thereof
14 ** without any compensation or license.  The pForth software
15 ** code is provided on an "as is" basis without any warranty
16 ** of any kind, including, without limitation, the implied
17 ** warranties of merchantability and fitness for a particular
18 ** purpose and their equivalents under the laws of any jurisdiction.
19 **
20 ***************************************************************/
21
22 #ifdef PF_NO_CHARIO
23         int  sdTerminalOut( char c );
24         int  sdTerminalFlush( void );
25         int  sdTerminalIn( void );
26         int  sdQueryTerminal( void );
27 #else   /* PF_NO_CHARIO */
28         #ifdef PF_USER_CHARIO
29 /* Get user prototypes or macros from include file.
30 ** API must match that defined above for the stubs.
31 */
32 /* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
33                 #include PF_USER_CHARIO
34         #else
35                 #define sdTerminalOut(c)  putchar(c)
36                 #define sdTerminalIn      getchar
37 /* Since getchar() echos, define PF_KEY_ECHOS. */
38                 #define PF_KEY_ECHOS
39 /*
40  * If you know a way to implement ?TERMINAL in STANDARD ANSI 'C',
41  * please let me know.  ?TERMINAL ( -- charAvailable? )
42  */
43                 #define sdQueryTerminal()   (0)
44                 #ifdef PF_NO_FILEIO
45                         #define sdTerminalFlush() /* fflush(PF_STDOUT) */
46                 #else
47                         #define sdTerminalFlush() fflush(PF_STDOUT)
48                 #endif
49         #endif
50 #endif   /* PF_NO_CHARIO */
51
52
53 /* Define file access modes. */
54 /* User can #undef and re#define using PF_USER_FILEIO if needed. */
55 #define PF_FAM_READ_ONLY (0)
56 #define PF_FAM_READ_WRITE (1)
57
58 #define PF_FAM_CREATE  ("w+")
59 #define PF_FAM_OPEN_RO  ("r")
60 #define PF_FAM_OPEN_RW  ("r+")
61
62 #ifdef PF_NO_FILEIO
63
64         typedef void FileStream;
65
66         extern FileStream *PF_STDIN;
67         extern FileStream *PF_STDOUT;
68
69         #ifdef __cplusplus
70         extern "C" {
71         #endif
72         
73         /* Prototypes for stubs. */
74         FileStream *sdOpenFile( const char *FileName, const char *Mode );
75         int32 sdFlushFile( FileStream * Stream  );
76         int32 sdReadFile( void *ptr, int32 Size, int32 nItems, FileStream * Stream  );
77         int32 sdWriteFile( void *ptr, int32 Size, int32 nItems, FileStream * Stream  );
78         int32 sdSeekFile( FileStream * Stream, int32 Position, int32 Mode );
79         int32 sdTellFile( FileStream * Stream );
80         int32 sdCloseFile( FileStream * Stream );
81         int32 sdInputChar( FileStream *stream );
82         
83         #ifdef __cplusplus
84         }   
85         #endif
86         
87         #define  PF_SEEK_SET   (0)
88         #define  PF_SEEK_CUR   (1)
89         #define  PF_SEEK_END   (2)
90         /*
91         ** printf() is only used for debugging purposes.
92         ** It is not required for normal operation.
93         */
94         #define PRT(x) /* No printf(). */
95
96 #else
97
98         #ifdef PF_USER_FILEIO
99 /* Get user prototypes or macros from include file.
100 ** API must match that defined above for the stubs.
101 */
102                 #include PF_USER_FILEIO
103                 
104         #else
105                 typedef FILE FileStream;
106
107                 #define sdOpenFile      fopen
108                 #define sdFlushFile     fflush
109                 #define sdReadFile      fread
110                 #define sdWriteFile     fwrite
111                 #define sdSeekFile      fseek
112                 #define sdTellFile      ftell
113                 #define sdCloseFile     fclose
114                 #define sdInputChar     fgetc
115                 
116                 #define PF_STDIN  ((FileStream *) stdin)
117                 #define PF_STDOUT ((FileStream *) stdout)
118                 
119                 #define  PF_SEEK_SET   (0)
120                 #define  PF_SEEK_CUR   (1)
121                 #define  PF_SEEK_END   (2)
122                 
123                 /*
124                 ** printf() is only used for debugging purposes.
125                 ** It is not required for normal operation.
126                 */
127                 #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
128         #endif
129
130 #endif  /* PF_NO_FILEIO */
131
132
133 #ifdef __cplusplus
134 extern "C" {
135 #endif
136
137 cell ioAccept( char *Target, cell n1, FileStream *Stream );
138 cell ioKey( void);
139 void ioEmit( char c );
140 void ioType( const char *s, int32 n);
141
142 #ifdef __cplusplus
143 }   
144 #endif
145
146 #endif /* _pf_io_h */