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 ** 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.
20 ***************************************************************/
24 #define PF_CHAR_XON (0x11)
25 #define PF_CHAR_XOFF (0x13)
30 int sdTerminalOut( char c );
31 int sdTerminalEcho( char c );
32 int sdTerminalFlush( void );
33 int sdTerminalIn( void );
34 int sdQueryTerminal( void );
35 void sdTerminalInit( void );
36 void sdTerminalTerm( void );
45 void sdEnableInput( void );
46 void sdDisableInput( void );
48 #else /* PF_NO_CHARIO */
50 /* Get user prototypes or macros from include file.
51 ** API must match that defined above for the stubs.
53 /* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
54 #include PF_USER_CHARIO
56 #define sdEnableInput() /* sdTerminalOut( PF_CHAR_XON ) */
57 #define sdDisableInput() /* sdTerminalOut( PF_CHAR_XOFF ) */
60 #endif /* PF_NO_CHARIO */
62 /* Define file access modes. */
63 /* User can #undef and re#define using PF_USER_FILEIO if needed. */
64 #define PF_FAM_READ_ONLY (0)
65 #define PF_FAM_READ_WRITE (1)
66 #define PF_FAM_WRITE_ONLY (2)
67 #define PF_FAM_BINARY_FLAG (8)
69 #define PF_FAM_CREATE_WO ("w")
70 #define PF_FAM_CREATE_RW ("w+")
71 #define PF_FAM_OPEN_RO ("r")
72 #define PF_FAM_OPEN_RW ("r+")
73 #define PF_FAM_BIN_CREATE_WO ("wb")
74 #define PF_FAM_BIN_CREATE_RW ("wb+")
75 #define PF_FAM_BIN_OPEN_RO ("rb")
76 #define PF_FAM_BIN_OPEN_RW ("rb+")
80 typedef void FileStream;
82 extern FileStream *PF_STDIN;
83 extern FileStream *PF_STDOUT;
89 /* Prototypes for stubs. */
90 FileStream *sdOpenFile( const char *FileName, const char *Mode );
91 cell_t sdFlushFile( FileStream * Stream );
92 cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );
93 cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );
94 cell_t sdSeekFile( FileStream * Stream, file_offset_t Position, int32_t Mode );
95 cell_t sdRenameFile( const char *OldName, const char *NewName );
96 cell_t sdDeleteFile( const char *FileName );
97 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
98 file_offset_t sdTellFile( FileStream * Stream );
99 cell_t sdCloseFile( FileStream * Stream );
100 cell_t sdInputChar( FileStream *stream );
106 #define PF_SEEK_SET (0)
107 #define PF_SEEK_CUR (1)
108 #define PF_SEEK_END (2)
110 ** printf() is only used for debugging purposes.
111 ** It is not required for normal operation.
113 #define PRT(x) /* No printf(). */
117 #ifdef PF_USER_FILEIO
118 /* Get user prototypes or macros from include file.
119 ** API must match that defined above for the stubs.
121 #include PF_USER_FILEIO
124 typedef FILE FileStream;
126 #define sdOpenFile fopen
127 #define sdDeleteFile remove
128 #define sdFlushFile fflush
129 #define sdReadFile fread
130 #define sdWriteFile fwrite
133 * Note that fseek() and ftell() only support a long file offset.
134 * So 64-bit offsets may not be supported on some platforms.
135 * At one point we supported fseeko() and ftello() but they require
136 * the off_t data type, which is not very portable.
137 * So we decided to sacrifice vary large file support in
138 * favor of portability.
140 #define sdSeekFile fseek
141 #define sdTellFile ftell
143 #define sdCloseFile fclose
144 #define sdRenameFile rename
145 #define sdInputChar fgetc
147 #define PF_STDIN ((FileStream *) stdin)
148 #define PF_STDOUT ((FileStream *) stdout)
150 #define PF_SEEK_SET (SEEK_SET)
151 #define PF_SEEK_CUR (SEEK_CUR)
152 #define PF_SEEK_END (SEEK_END)
154 /* TODO review the Size data type. */
155 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
158 ** printf() is only used for debugging purposes.
159 ** It is not required for normal operation.
161 #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
164 #endif /* PF_NO_FILEIO */
171 cell_t ioAccept( char *Target, cell_t n1 );
173 void ioEmit( char c );
174 void ioType( const char *s, cell_t n);
180 #endif /* _pf_io_h */