bb6b2dcd |
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 |
1cb310e6 |
84 | cell_t sdFlushFile( FileStream * Stream );\r |
85 | cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );\r |
86 | cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );\r |
336369a5 |
87 | cell_t sdSeekFile( FileStream * Stream, off_t Position, int32_t Mode );\r |
88 | off_t sdTellFile( FileStream * Stream );\r |
1cb310e6 |
89 | cell_t sdCloseFile( FileStream * Stream );\r |
90 | cell_t sdInputChar( FileStream *stream );\r |
bb6b2dcd |
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 |
81dfa5e0 |
117 | #define sdDeleteFile remove\r |
bb6b2dcd |
118 | #define sdFlushFile fflush\r |
119 | #define sdReadFile fread\r |
120 | #define sdWriteFile fwrite\r |
a80283a7 |
121 | #if WIN32\r |
122 | /* TODO To support 64-bit file offset we probably need fseeki64(). */\r |
123 | #define sdSeekFile fseek\r |
124 | #define sdTellFile ftell\r |
125 | #else\r |
126 | #define sdSeekFile fseeko\r |
127 | #define sdTellFile ftello\r |
128 | #endif\r |
bb6b2dcd |
129 | #define sdCloseFile fclose\r |
130 | #define sdInputChar fgetc\r |
131 | \r |
132 | #define PF_STDIN ((FileStream *) stdin)\r |
133 | #define PF_STDOUT ((FileStream *) stdout)\r |
134 | \r |
135 | #define PF_SEEK_SET (0)\r |
136 | #define PF_SEEK_CUR (1)\r |
137 | #define PF_SEEK_END (2)\r |
138 | \r |
139 | /*\r |
140 | ** printf() is only used for debugging purposes.\r |
141 | ** It is not required for normal operation.\r |
142 | */\r |
143 | #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }\r |
144 | #endif\r |
145 | \r |
146 | #endif /* PF_NO_FILEIO */\r |
147 | \r |
148 | \r |
149 | #ifdef __cplusplus\r |
150 | extern "C" {\r |
151 | #endif\r |
152 | \r |
1cb310e6 |
153 | cell_t ioAccept( char *Target, cell_t n1 );\r |
154 | cell_t ioKey( void);\r |
bb6b2dcd |
155 | void ioEmit( char c );\r |
1cb310e6 |
156 | void ioType( const char *s, cell_t n);\r |
bb6b2dcd |
157 | \r |
158 | #ifdef __cplusplus\r |
159 | } \r |
160 | #endif\r |
161 | \r |
162 | #endif /* _pf_io_h */\r |