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