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