1 /* @(#) pf_io.h 98/01/26 1.2 */
5 /***************************************************************
6 ** Include file for PForth IO
9 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
11 ** Permission to use, copy, modify, and/or distribute this
12 ** software for any purpose with or without fee is hereby granted.
14 ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
15 ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
16 ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
17 ** THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
18 ** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
19 ** FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 ** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ***************************************************************/
27 #define PF_CHAR_XON (0x11)
28 #define PF_CHAR_XOFF (0x13)
33 int sdTerminalOut( char c );
34 int sdTerminalEcho( char c );
35 int sdTerminalFlush( void );
36 int sdTerminalIn( void );
37 int sdQueryTerminal( void );
38 void sdTerminalInit( void );
39 void sdTerminalTerm( void );
40 cell_t sdSleepMillis( cell_t msec );
49 void sdEnableInput( void );
50 void sdDisableInput( void );
52 #else /* PF_NO_CHARIO */
54 /* Get user prototypes or macros from include file.
55 ** API must match that defined above for the stubs.
57 /* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
58 #include PF_USER_CHARIO
60 #define sdEnableInput() /* sdTerminalOut( PF_CHAR_XON ) */
61 #define sdDisableInput() /* sdTerminalOut( PF_CHAR_XOFF ) */
64 #endif /* PF_NO_CHARIO */
66 /* Define file access modes. */
67 /* User can #undef and re#define using PF_USER_FILEIO if needed. */
68 #define PF_FAM_READ_ONLY (0)
69 #define PF_FAM_READ_WRITE (1)
70 #define PF_FAM_WRITE_ONLY (2)
71 #define PF_FAM_BINARY_FLAG (8)
73 #define PF_FAM_CREATE_WO ("w")
74 #define PF_FAM_CREATE_RW ("w+")
75 #define PF_FAM_OPEN_RO ("r")
76 #define PF_FAM_OPEN_RW ("r+")
77 #define PF_FAM_BIN_CREATE_WO ("wb")
78 #define PF_FAM_BIN_CREATE_RW ("wb+")
79 #define PF_FAM_BIN_OPEN_RO ("rb")
80 #define PF_FAM_BIN_OPEN_RW ("rb+")
84 typedef void FileStream;
86 extern FileStream *PF_STDIN;
87 extern FileStream *PF_STDOUT;
93 /* Prototypes for stubs. */
94 FileStream *sdOpenFile( const char *FileName, const char *Mode );
95 cell_t sdFlushFile( FileStream * Stream );
96 cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );
97 cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );
98 cell_t sdSeekFile( FileStream * Stream, file_offset_t Position, int32_t Mode );
99 cell_t sdRenameFile( const char *OldName, const char *NewName );
100 cell_t sdDeleteFile( const char *FileName );
101 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
102 file_offset_t sdTellFile( FileStream * Stream );
103 cell_t sdCloseFile( FileStream * Stream );
104 cell_t sdInputChar( FileStream *stream );
110 #define PF_SEEK_SET (0)
111 #define PF_SEEK_CUR (1)
112 #define PF_SEEK_END (2)
114 ** printf() is only used for debugging purposes.
115 ** It is not required for normal operation.
117 #define PRT(x) /* No printf(). */
121 #ifdef PF_USER_FILEIO
122 /* Get user prototypes or macros from include file.
123 ** API must match that defined above for the stubs.
125 #include PF_USER_FILEIO
128 typedef FILE FileStream;
130 #define sdOpenFile fopen
131 #define sdDeleteFile remove
132 #define sdFlushFile fflush
133 #define sdReadFile fread
134 #define sdWriteFile fwrite
137 * Note that fseek() and ftell() only support a long file offset.
138 * So 64-bit offsets may not be supported on some platforms.
139 * At one point we supported fseeko() and ftello() but they require
140 * the off_t data type, which is not very portable.
141 * So we decided to sacrifice vary large file support in
142 * favor of portability.
144 #define sdSeekFile fseek
145 #define sdTellFile ftell
147 #define sdCloseFile fclose
148 #define sdRenameFile rename
149 #define sdInputChar fgetc
151 #define PF_STDIN ((FileStream *) stdin)
152 #define PF_STDOUT ((FileStream *) stdout)
154 #define PF_SEEK_SET (SEEK_SET)
155 #define PF_SEEK_CUR (SEEK_CUR)
156 #define PF_SEEK_END (SEEK_END)
158 /* TODO review the Size data type. */
159 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
162 ** printf() is only used for debugging purposes.
163 ** It is not required for normal operation.
165 #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
168 #endif /* PF_NO_FILEIO */
175 cell_t ioAccept( char *Target, cell_t n1 );
177 void ioEmit( char c );
178 void ioType( const char *s, cell_t n);
184 #endif /* _pf_io_h */