relicense to 0BSD
[pforth] / csrc / pf_io.h
CommitLineData
8e9db35f
PB
1/* @(#) pf_io.h 98/01/26 1.2 */
2#ifndef _pf_io_h
3#define _pf_io_h
4
5/***************************************************************
6** Include file for PForth IO
7**
8** Author: Phil Burk
9** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
10**
1f99f95d
S
11** Permission to use, copy, modify, and/or distribute this
12** software for any purpose with or without fee is hereby granted.
13**
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.
8e9db35f
PB
22**
23***************************************************************/
24
4d9c915d
PB
25#include "pf_types.h"
26
8e9db35f
PB
27#define PF_CHAR_XON (0x11)
28#define PF_CHAR_XOFF (0x13)
29
8cf4db28
PB
30#ifdef __cplusplus
31extern "C" {
32#endif
8e9db35f
PB
33int sdTerminalOut( char c );
34int sdTerminalEcho( char c );
35int sdTerminalFlush( void );
36int sdTerminalIn( void );
37int sdQueryTerminal( void );
38void sdTerminalInit( void );
39void sdTerminalTerm( void );
8cf4db28
PB
40#ifdef __cplusplus
41}
42#endif
8e9db35f
PB
43
44void ioInit( void );
45void ioTerm( void );
46
8e9db35f
PB
47#ifdef PF_NO_CHARIO
48 void sdEnableInput( void );
49 void sdDisableInput( void );
50
51#else /* PF_NO_CHARIO */
52 #ifdef PF_USER_CHARIO
53/* Get user prototypes or macros from include file.
54** API must match that defined above for the stubs.
55*/
56/* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
57 #include PF_USER_CHARIO
58 #else
59 #define sdEnableInput() /* sdTerminalOut( PF_CHAR_XON ) */
60 #define sdDisableInput() /* sdTerminalOut( PF_CHAR_XOFF ) */
61
62 #endif
63#endif /* PF_NO_CHARIO */
64
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)
71
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+")
80
81#ifdef PF_NO_FILEIO
82
83 typedef void FileStream;
84
85 extern FileStream *PF_STDIN;
86 extern FileStream *PF_STDOUT;
87
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91
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 );
4d9c915d 97 cell_t sdSeekFile( FileStream * Stream, file_offset_t Position, int32_t Mode );
6f3de396 98 cell_t sdRenameFile( const char *OldName, const char *NewName );
e0701bfb 99 cell_t sdDeleteFile( const char *FileName );
0b1e2489 100 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
4d9c915d 101 file_offset_t sdTellFile( FileStream * Stream );
8e9db35f
PB
102 cell_t sdCloseFile( FileStream * Stream );
103 cell_t sdInputChar( FileStream *stream );
104
105 #ifdef __cplusplus
106 }
107 #endif
108
109 #define PF_SEEK_SET (0)
110 #define PF_SEEK_CUR (1)
111 #define PF_SEEK_END (2)
112 /*
113 ** printf() is only used for debugging purposes.
114 ** It is not required for normal operation.
115 */
116 #define PRT(x) /* No printf(). */
117
118#else
119
120 #ifdef PF_USER_FILEIO
121/* Get user prototypes or macros from include file.
122** API must match that defined above for the stubs.
123*/
124 #include PF_USER_FILEIO
125
126 #else
127 typedef FILE FileStream;
128
129 #define sdOpenFile fopen
e0701bfb 130 #define sdDeleteFile remove
8e9db35f
PB
131 #define sdFlushFile fflush
132 #define sdReadFile fread
133 #define sdWriteFile fwrite
ccd2b2a1
PB
134
135 /*
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.
142 */
143 #define sdSeekFile fseek
144 #define sdTellFile ftell
145
8e9db35f 146 #define sdCloseFile fclose
6f3de396 147 #define sdRenameFile rename
8e9db35f
PB
148 #define sdInputChar fgetc
149
150 #define PF_STDIN ((FileStream *) stdin)
151 #define PF_STDOUT ((FileStream *) stdout)
152
1d7147ff
HE
153 #define PF_SEEK_SET (SEEK_SET)
154 #define PF_SEEK_CUR (SEEK_CUR)
155 #define PF_SEEK_END (SEEK_END)
8e9db35f 156
ccd2b2a1 157 /* TODO review the Size data type. */
0b1e2489 158 ThrowCode sdResizeFile( FileStream *, uint64_t Size);
e0701bfb 159
8e9db35f
PB
160 /*
161 ** printf() is only used for debugging purposes.
162 ** It is not required for normal operation.
163 */
164 #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
165 #endif
166
167#endif /* PF_NO_FILEIO */
168
169
170#ifdef __cplusplus
171extern "C" {
172#endif
173
174cell_t ioAccept( char *Target, cell_t n1 );
175cell_t ioKey( void);
176void ioEmit( char c );
177void ioType( const char *s, cell_t n);
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif /* _pf_io_h */