Update release notes for v2.0.0
[debian/pforth] / csrc / pf_io.h
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 **
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.
22 **
23 ***************************************************************/
24
25 #include "pf_types.h"
26
27 #define PF_CHAR_XON    (0x11)
28 #define PF_CHAR_XOFF   (0x13)
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
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 );
41 #ifdef __cplusplus
42 }
43 #endif
44
45 void ioInit( void );
46 void ioTerm( void );
47
48 #ifdef PF_NO_CHARIO
49     void sdEnableInput( void );
50     void sdDisableInput( void );
51
52 #else   /* PF_NO_CHARIO */
53     #ifdef PF_USER_CHARIO
54 /* Get user prototypes or macros from include file.
55 ** API must match that defined above for the stubs.
56 */
57 /* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
58         #include PF_USER_CHARIO
59     #else
60         #define sdEnableInput()     /* sdTerminalOut( PF_CHAR_XON ) */
61         #define sdDisableInput()    /* sdTerminalOut( PF_CHAR_XOFF ) */
62
63     #endif
64 #endif   /* PF_NO_CHARIO */
65
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)
72
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+")
81
82 #ifdef PF_NO_FILEIO
83
84     typedef void FileStream;
85
86     extern FileStream *PF_STDIN;
87     extern FileStream *PF_STDOUT;
88
89     #ifdef __cplusplus
90     extern "C" {
91     #endif
92
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 );
105
106     #ifdef __cplusplus
107     }
108     #endif
109
110     #define  PF_SEEK_SET   (0)
111     #define  PF_SEEK_CUR   (1)
112     #define  PF_SEEK_END   (2)
113     /*
114     ** printf() is only used for debugging purposes.
115     ** It is not required for normal operation.
116     */
117     #define PRT(x) /* No printf(). */
118
119 #else
120
121     #ifdef PF_USER_FILEIO
122 /* Get user prototypes or macros from include file.
123 ** API must match that defined above for the stubs.
124 */
125         #include PF_USER_FILEIO
126
127     #else
128         typedef FILE FileStream;
129
130         #define sdOpenFile      fopen
131         #define sdDeleteFile    remove
132         #define sdFlushFile     fflush
133         #define sdReadFile      fread
134         #define sdWriteFile     fwrite
135
136         /*
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.
143          */
144         #define sdSeekFile      fseek
145         #define sdTellFile      ftell
146
147         #define sdCloseFile     fclose
148         #define sdRenameFile    rename
149         #define sdInputChar     fgetc
150
151         #define PF_STDIN  ((FileStream *) stdin)
152         #define PF_STDOUT ((FileStream *) stdout)
153
154         #define  PF_SEEK_SET   (SEEK_SET)
155         #define  PF_SEEK_CUR   (SEEK_CUR)
156         #define  PF_SEEK_END   (SEEK_END)
157
158         /* TODO review the Size data type. */
159         ThrowCode sdResizeFile( FileStream *, uint64_t Size);
160
161         /*
162         ** printf() is only used for debugging purposes.
163         ** It is not required for normal operation.
164         */
165         #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
166     #endif
167
168 #endif  /* PF_NO_FILEIO */
169
170
171 #ifdef __cplusplus
172 extern "C" {
173 #endif
174
175 cell_t ioAccept( char *Target, cell_t n1 );
176 cell_t ioKey( void);
177 void ioEmit( char c );
178 void ioType( const char *s, cell_t n);
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif /* _pf_io_h */