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 );
48 void sdEnableInput( void );
49 void sdDisableInput( void );
51 #else /* PF_NO_CHARIO */
53 /* Get user prototypes or macros from include file.
54 ** API must match that defined above for the stubs.
56 /* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
57 #include PF_USER_CHARIO
59 #define sdEnableInput() /* sdTerminalOut( PF_CHAR_XON ) */
60 #define sdDisableInput() /* sdTerminalOut( PF_CHAR_XOFF ) */
63 #endif /* PF_NO_CHARIO */
65 /* Define file access modes. */
66 /* User can #undef and re#define using PF_USER_FILEIO if needed. */
67 #define PF_FAM_READ_ONLY (0)
68 #define PF_FAM_READ_WRITE (1)
69 #define PF_FAM_WRITE_ONLY (2)
70 #define PF_FAM_BINARY_FLAG (8)
72 #define PF_FAM_CREATE_WO ("w")
73 #define PF_FAM_CREATE_RW ("w+")
74 #define PF_FAM_OPEN_RO ("r")
75 #define PF_FAM_OPEN_RW ("r+")
76 #define PF_FAM_BIN_CREATE_WO ("wb")
77 #define PF_FAM_BIN_CREATE_RW ("wb+")
78 #define PF_FAM_BIN_OPEN_RO ("rb")
79 #define PF_FAM_BIN_OPEN_RW ("rb+")
83 typedef void FileStream;
85 extern FileStream *PF_STDIN;
86 extern FileStream *PF_STDOUT;
92 /* Prototypes for stubs. */
93 FileStream *sdOpenFile( const char *FileName, const char *Mode );
94 cell_t sdFlushFile( FileStream * Stream );
95 cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );
96 cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream );
97 cell_t sdSeekFile( FileStream * Stream, file_offset_t Position, int32_t Mode );
98 cell_t sdRenameFile( const char *OldName, const char *NewName );
99 cell_t sdDeleteFile( const char *FileName );
100 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
101 file_offset_t sdTellFile( FileStream * Stream );
102 cell_t sdCloseFile( FileStream * Stream );
103 cell_t sdInputChar( FileStream *stream );
109 #define PF_SEEK_SET (0)
110 #define PF_SEEK_CUR (1)
111 #define PF_SEEK_END (2)
113 ** printf() is only used for debugging purposes.
114 ** It is not required for normal operation.
116 #define PRT(x) /* No printf(). */
120 #ifdef PF_USER_FILEIO
121 /* Get user prototypes or macros from include file.
122 ** API must match that defined above for the stubs.
124 #include PF_USER_FILEIO
127 typedef FILE FileStream;
129 #define sdOpenFile fopen
130 #define sdDeleteFile remove
131 #define sdFlushFile fflush
132 #define sdReadFile fread
133 #define sdWriteFile fwrite
136 * Note that fseek() and ftell() only support a long file offset.
137 * So 64-bit offsets may not be supported on some platforms.
138 * At one point we supported fseeko() and ftello() but they require
139 * the off_t data type, which is not very portable.
140 * So we decided to sacrifice vary large file support in
141 * favor of portability.
143 #define sdSeekFile fseek
144 #define sdTellFile ftell
146 #define sdCloseFile fclose
147 #define sdRenameFile rename
148 #define sdInputChar fgetc
150 #define PF_STDIN ((FileStream *) stdin)
151 #define PF_STDOUT ((FileStream *) stdout)
153 #define PF_SEEK_SET (SEEK_SET)
154 #define PF_SEEK_CUR (SEEK_CUR)
155 #define PF_SEEK_END (SEEK_END)
157 /* TODO review the Size data type. */
158 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
161 ** printf() is only used for debugging purposes.
162 ** It is not required for normal operation.
164 #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
167 #endif /* PF_NO_FILEIO */
174 cell_t ioAccept( char *Target, cell_t n1 );
176 void ioEmit( char c );
177 void ioType( const char *s, cell_t n);
183 #endif /* _pf_io_h */