| 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 | #define PF_CHAR_XON (0x11) |
| 23 | #define PF_CHAR_XOFF (0x13) |
| 24 | |
| 25 | int sdTerminalOut( char c ); |
| 26 | int sdTerminalEcho( char c ); |
| 27 | int sdTerminalFlush( void ); |
| 28 | int sdTerminalIn( void ); |
| 29 | int sdQueryTerminal( void ); |
| 30 | void sdTerminalInit( void ); |
| 31 | void sdTerminalTerm( void ); |
| 32 | |
| 33 | void ioInit( void ); |
| 34 | void ioTerm( void ); |
| 35 | |
| 36 | |
| 37 | #ifdef PF_NO_CHARIO |
| 38 | void sdEnableInput( void ); |
| 39 | void sdDisableInput( void ); |
| 40 | |
| 41 | #else /* PF_NO_CHARIO */ |
| 42 | #ifdef PF_USER_CHARIO |
| 43 | /* Get user prototypes or macros from include file. |
| 44 | ** API must match that defined above for the stubs. |
| 45 | */ |
| 46 | /* If your sdTerminalIn echos, define PF_KEY_ECHOS. */ |
| 47 | #include PF_USER_CHARIO |
| 48 | #else |
| 49 | #define sdEnableInput() /* sdTerminalOut( PF_CHAR_XON ) */ |
| 50 | #define sdDisableInput() /* sdTerminalOut( PF_CHAR_XOFF ) */ |
| 51 | |
| 52 | #endif |
| 53 | #endif /* PF_NO_CHARIO */ |
| 54 | |
| 55 | /* Define file access modes. */ |
| 56 | /* User can #undef and re#define using PF_USER_FILEIO if needed. */ |
| 57 | #define PF_FAM_READ_ONLY (0) |
| 58 | #define PF_FAM_READ_WRITE (1) |
| 59 | #define PF_FAM_WRITE_ONLY (2) |
| 60 | #define PF_FAM_BINARY_FLAG (8) |
| 61 | |
| 62 | #define PF_FAM_CREATE_WO ("w") |
| 63 | #define PF_FAM_CREATE_RW ("w+") |
| 64 | #define PF_FAM_OPEN_RO ("r") |
| 65 | #define PF_FAM_OPEN_RW ("r+") |
| 66 | #define PF_FAM_BIN_CREATE_WO ("wb") |
| 67 | #define PF_FAM_BIN_CREATE_RW ("wb+") |
| 68 | #define PF_FAM_BIN_OPEN_RO ("rb") |
| 69 | #define PF_FAM_BIN_OPEN_RW ("rb+") |
| 70 | |
| 71 | #ifdef PF_NO_FILEIO |
| 72 | |
| 73 | typedef void FileStream; |
| 74 | |
| 75 | extern FileStream *PF_STDIN; |
| 76 | extern FileStream *PF_STDOUT; |
| 77 | |
| 78 | #ifdef __cplusplus |
| 79 | extern "C" { |
| 80 | #endif |
| 81 | |
| 82 | /* Prototypes for stubs. */ |
| 83 | FileStream *sdOpenFile( const char *FileName, const char *Mode ); |
| 84 | cell_t sdFlushFile( FileStream * Stream ); |
| 85 | cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream ); |
| 86 | cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream ); |
| 87 | cell_t sdSeekFile( FileStream * Stream, off_t Position, int32_t Mode ); |
| 88 | off_t sdTellFile( FileStream * Stream ); |
| 89 | cell_t sdCloseFile( FileStream * Stream ); |
| 90 | cell_t sdInputChar( FileStream *stream ); |
| 91 | |
| 92 | #ifdef __cplusplus |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | #define PF_SEEK_SET (0) |
| 97 | #define PF_SEEK_CUR (1) |
| 98 | #define PF_SEEK_END (2) |
| 99 | /* |
| 100 | ** printf() is only used for debugging purposes. |
| 101 | ** It is not required for normal operation. |
| 102 | */ |
| 103 | #define PRT(x) /* No printf(). */ |
| 104 | |
| 105 | #else |
| 106 | |
| 107 | #ifdef PF_USER_FILEIO |
| 108 | /* Get user prototypes or macros from include file. |
| 109 | ** API must match that defined above for the stubs. |
| 110 | */ |
| 111 | #include PF_USER_FILEIO |
| 112 | |
| 113 | #else |
| 114 | typedef FILE FileStream; |
| 115 | |
| 116 | #define sdOpenFile fopen |
| 117 | #define sdDeleteFile remove |
| 118 | #define sdFlushFile fflush |
| 119 | #define sdReadFile fread |
| 120 | #define sdWriteFile fwrite |
| 121 | #if defined(WIN32) || defined(__NT__) || defined(AMIGA) |
| 122 | /* TODO To support 64-bit file offset we probably need fseeki64(). */ |
| 123 | #define sdSeekFile fseek |
| 124 | #define sdTellFile ftell |
| 125 | #else |
| 126 | #define sdSeekFile fseeko |
| 127 | #define sdTellFile ftello |
| 128 | #endif |
| 129 | #define sdCloseFile fclose |
| 130 | #define sdInputChar fgetc |
| 131 | |
| 132 | #define PF_STDIN ((FileStream *) stdin) |
| 133 | #define PF_STDOUT ((FileStream *) stdout) |
| 134 | |
| 135 | #define PF_SEEK_SET (SEEK_SET) |
| 136 | #define PF_SEEK_CUR (SEEK_CUR) |
| 137 | #define PF_SEEK_END (SEEK_END) |
| 138 | |
| 139 | /* |
| 140 | ** printf() is only used for debugging purposes. |
| 141 | ** It is not required for normal operation. |
| 142 | */ |
| 143 | #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); } |
| 144 | #endif |
| 145 | |
| 146 | #endif /* PF_NO_FILEIO */ |
| 147 | |
| 148 | |
| 149 | #ifdef __cplusplus |
| 150 | extern "C" { |
| 151 | #endif |
| 152 | |
| 153 | cell_t ioAccept( char *Target, cell_t n1 ); |
| 154 | cell_t ioKey( void); |
| 155 | void ioEmit( char c ); |
| 156 | void ioType( const char *s, cell_t n); |
| 157 | |
| 158 | #ifdef __cplusplus |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | #endif /* _pf_io_h */ |