pforth: use long for off_t
[pforth] / csrc / pf_io.h
index 8c145a0..db8fd92 100644 (file)
-/* @(#) pf_io.h 98/01/26 1.2 */\r
-#ifndef _pf_io_h\r
-#define _pf_io_h\r
-\r
-/***************************************************************\r
-** Include file for PForth IO\r
-**\r
-** Author: Phil Burk\r
-** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom\r
-**\r
-** The pForth software code is dedicated to the public domain,\r
-** and any third party may reproduce, distribute and modify\r
-** the pForth software code or any derivative works thereof\r
-** without any compensation or license.  The pForth software\r
-** code is provided on an "as is" basis without any warranty\r
-** of any kind, including, without limitation, the implied\r
-** warranties of merchantability and fitness for a particular\r
-** purpose and their equivalents under the laws of any jurisdiction.\r
-**\r
-***************************************************************/\r
-\r
-#define PF_CHAR_XON    (0x11)\r
-#define PF_CHAR_XOFF   (0x13)   \r
-\r
-int  sdTerminalOut( char c );\r
-int  sdTerminalEcho( char c );\r
-int  sdTerminalFlush( void );\r
-int  sdTerminalIn( void );\r
-int  sdQueryTerminal( void );\r
-void sdTerminalInit( void );\r
-void sdTerminalTerm( void );\r
-\r
-void ioInit( void );\r
-void ioTerm( void );\r
-\r
-\r
-#ifdef PF_NO_CHARIO\r
-       void sdEnableInput( void );\r
-       void sdDisableInput( void );\r
-\r
-#else   /* PF_NO_CHARIO */\r
-       #ifdef PF_USER_CHARIO\r
-/* Get user prototypes or macros from include file.\r
-** API must match that defined above for the stubs.\r
-*/\r
-/* If your sdTerminalIn echos, define PF_KEY_ECHOS. */\r
-               #include PF_USER_CHARIO\r
-       #else\r
-               #define sdEnableInput()     /* sdTerminalOut( PF_CHAR_XON ) */\r
-               #define sdDisableInput()    /* sdTerminalOut( PF_CHAR_XOFF ) */\r
-               \r
-       #endif\r
-#endif   /* PF_NO_CHARIO */\r
-\r
-/* Define file access modes. */\r
-/* User can #undef and re#define using PF_USER_FILEIO if needed. */\r
-#define PF_FAM_READ_ONLY   (0)\r
-#define PF_FAM_READ_WRITE  (1)\r
-#define PF_FAM_WRITE_ONLY  (2)\r
-#define PF_FAM_BINARY_FLAG (8)\r
-\r
-#define PF_FAM_CREATE_WO      ("w")\r
-#define PF_FAM_CREATE_RW      ("w+")\r
-#define PF_FAM_OPEN_RO        ("r")\r
-#define PF_FAM_OPEN_RW        ("r+")\r
-#define PF_FAM_BIN_CREATE_WO  ("wb")\r
-#define PF_FAM_BIN_CREATE_RW  ("wb+")\r
-#define PF_FAM_BIN_OPEN_RO    ("rb")\r
-#define PF_FAM_BIN_OPEN_RW    ("rb+")\r
-\r
-#ifdef PF_NO_FILEIO\r
-\r
-       typedef void FileStream;\r
-\r
-       extern FileStream *PF_STDIN;\r
-       extern FileStream *PF_STDOUT;\r
-\r
-       #ifdef __cplusplus\r
-       extern "C" {\r
-       #endif\r
-       \r
-       /* Prototypes for stubs. */\r
-       FileStream *sdOpenFile( const char *FileName, const char *Mode );\r
-       cell_t sdFlushFile( FileStream * Stream  );\r
-       cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream  );\r
-       cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream  );\r
-       cell_t sdSeekFile( FileStream * Stream, cell_t Position, int32_t Mode );\r
-       cell_t sdTellFile( FileStream * Stream );\r
-       cell_t sdCloseFile( FileStream * Stream );\r
-       cell_t sdInputChar( FileStream *stream );\r
-       \r
-       #ifdef __cplusplus\r
-       }   \r
-       #endif\r
-       \r
-       #define  PF_SEEK_SET   (0)\r
-       #define  PF_SEEK_CUR   (1)\r
-       #define  PF_SEEK_END   (2)\r
-       /*\r
-       ** printf() is only used for debugging purposes.\r
-       ** It is not required for normal operation.\r
-       */\r
-       #define PRT(x) /* No printf(). */\r
-\r
-#else\r
-\r
-       #ifdef PF_USER_FILEIO\r
-/* Get user prototypes or macros from include file.\r
-** API must match that defined above for the stubs.\r
-*/\r
-               #include PF_USER_FILEIO\r
-               \r
-       #else\r
-               typedef FILE FileStream;\r
-\r
-               #define sdOpenFile      fopen\r
-               #define sdFlushFile     fflush\r
-               #define sdReadFile      fread\r
-               #define sdWriteFile     fwrite\r
-               #define sdSeekFile      fseek\r
-               #define sdTellFile      ftell\r
-               #define sdCloseFile     fclose\r
-               #define sdInputChar     fgetc\r
-               \r
-               #define PF_STDIN  ((FileStream *) stdin)\r
-               #define PF_STDOUT ((FileStream *) stdout)\r
-               \r
-               #define  PF_SEEK_SET   (0)\r
-               #define  PF_SEEK_CUR   (1)\r
-               #define  PF_SEEK_END   (2)\r
-               \r
-               /*\r
-               ** printf() is only used for debugging purposes.\r
-               ** It is not required for normal operation.\r
-               */\r
-               #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }\r
-       #endif\r
-\r
-#endif  /* PF_NO_FILEIO */\r
-\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-cell_t ioAccept( char *Target, cell_t n1 );\r
-cell_t ioKey( void);\r
-void ioEmit( char c );\r
-void ioType( const char *s, cell_t n);\r
-\r
-#ifdef __cplusplus\r
-}   \r
-#endif\r
-\r
-#endif /* _pf_io_h */\r
+/* @(#) pf_io.h 98/01/26 1.2 */
+#ifndef _pf_io_h
+#define _pf_io_h
+
+/***************************************************************
+** Include file for PForth IO
+**
+** Author: Phil Burk
+** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
+**
+** The pForth software code is dedicated to the public domain,
+** and any third party may reproduce, distribute and modify
+** the pForth software code or any derivative works thereof
+** without any compensation or license.  The pForth software
+** code is provided on an "as is" basis without any warranty
+** of any kind, including, without limitation, the implied
+** warranties of merchantability and fitness for a particular
+** purpose and their equivalents under the laws of any jurisdiction.
+**
+***************************************************************/
+
+#include "pf_types.h"
+
+#define PF_CHAR_XON    (0x11)
+#define PF_CHAR_XOFF   (0x13)
+
+int  sdTerminalOut( char c );
+int  sdTerminalEcho( char c );
+int  sdTerminalFlush( void );
+int  sdTerminalIn( void );
+int  sdQueryTerminal( void );
+void sdTerminalInit( void );
+void sdTerminalTerm( void );
+
+void ioInit( void );
+void ioTerm( void );
+
+#ifdef PF_NO_CHARIO
+    void sdEnableInput( void );
+    void sdDisableInput( void );
+
+#else   /* PF_NO_CHARIO */
+    #ifdef PF_USER_CHARIO
+/* Get user prototypes or macros from include file.
+** API must match that defined above for the stubs.
+*/
+/* If your sdTerminalIn echos, define PF_KEY_ECHOS. */
+        #include PF_USER_CHARIO
+    #else
+        #define sdEnableInput()     /* sdTerminalOut( PF_CHAR_XON ) */
+        #define sdDisableInput()    /* sdTerminalOut( PF_CHAR_XOFF ) */
+
+    #endif
+#endif   /* PF_NO_CHARIO */
+
+/* Define file access modes. */
+/* User can #undef and re#define using PF_USER_FILEIO if needed. */
+#define PF_FAM_READ_ONLY   (0)
+#define PF_FAM_READ_WRITE  (1)
+#define PF_FAM_WRITE_ONLY  (2)
+#define PF_FAM_BINARY_FLAG (8)
+
+#define PF_FAM_CREATE_WO      ("w")
+#define PF_FAM_CREATE_RW      ("w+")
+#define PF_FAM_OPEN_RO        ("r")
+#define PF_FAM_OPEN_RW        ("r+")
+#define PF_FAM_BIN_CREATE_WO  ("wb")
+#define PF_FAM_BIN_CREATE_RW  ("wb+")
+#define PF_FAM_BIN_OPEN_RO    ("rb")
+#define PF_FAM_BIN_OPEN_RW    ("rb+")
+
+#ifdef PF_NO_FILEIO
+
+    typedef void FileStream;
+
+    extern FileStream *PF_STDIN;
+    extern FileStream *PF_STDOUT;
+
+    #ifdef __cplusplus
+    extern "C" {
+    #endif
+
+    /* Prototypes for stubs. */
+    FileStream *sdOpenFile( const char *FileName, const char *Mode );
+    cell_t sdFlushFile( FileStream * Stream  );
+    cell_t sdReadFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream  );
+    cell_t sdWriteFile( void *ptr, cell_t Size, int32_t nItems, FileStream * Stream  );
+    cell_t sdSeekFile( FileStream * Stream, file_offset_t Position, int32_t Mode );
+    cell_t sdRenameFile( const char *OldName, const char *NewName );
+    cell_t sdDeleteFile( const char *FileName );
+    ThrowCode sdResizeFile( FileStream *, uint64_t Size);
+    file_offset_t sdTellFile( FileStream * Stream );
+    cell_t sdCloseFile( FileStream * Stream );
+    cell_t sdInputChar( FileStream *stream );
+
+    #ifdef __cplusplus
+    }
+    #endif
+
+    #define  PF_SEEK_SET   (0)
+    #define  PF_SEEK_CUR   (1)
+    #define  PF_SEEK_END   (2)
+    /*
+    ** printf() is only used for debugging purposes.
+    ** It is not required for normal operation.
+    */
+    #define PRT(x) /* No printf(). */
+
+#else
+
+    #ifdef PF_USER_FILEIO
+/* Get user prototypes or macros from include file.
+** API must match that defined above for the stubs.
+*/
+        #include PF_USER_FILEIO
+
+    #else
+        typedef FILE FileStream;
+
+        #define sdOpenFile      fopen
+        #define sdDeleteFile    remove
+        #define sdFlushFile     fflush
+        #define sdReadFile      fread
+        #define sdWriteFile     fwrite
+
+        /*
+         * Note that fseek() and ftell() only support a long file offset.
+         * So 64-bit offsets may not be supported on some platforms.
+         * At one point we supported fseeko() and ftello() but they require
+         * the off_t data type, which is not very portable.
+         * So we decided to sacrifice vary large file support in
+         * favor of portability.
+         */
+        #define sdSeekFile      fseek
+        #define sdTellFile      ftell
+
+        #define sdCloseFile     fclose
+        #define sdRenameFile    rename
+        #define sdInputChar     fgetc
+
+        #define PF_STDIN  ((FileStream *) stdin)
+        #define PF_STDOUT ((FileStream *) stdout)
+
+        #define  PF_SEEK_SET   (SEEK_SET)
+        #define  PF_SEEK_CUR   (SEEK_CUR)
+        #define  PF_SEEK_END   (SEEK_END)
+
+        /* TODO review the Size data type. */
+        ThrowCode sdResizeFile( FileStream *, uint64_t Size);
+
+        /*
+        ** printf() is only used for debugging purposes.
+        ** It is not required for normal operation.
+        */
+        #define PRT(x) { printf x; sdFlushFile(PF_STDOUT); }
+    #endif
+
+#endif  /* PF_NO_FILEIO */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+cell_t ioAccept( char *Target, cell_t n1 );
+cell_t ioKey( void);
+void ioEmit( char c );
+void ioType( const char *s, cell_t n);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _pf_io_h */