home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d536 / chemesthetics.lha / Chemesthetics / Source / Source.LZH / gio.h < prev    next >
C/C++ Source or Header  |  1991-06-12  |  6KB  |  152 lines

  1. #ifndef GIO_H
  2. #define GIO_H
  3. /*----------------------------------------------------------------------*/
  4. /* GIO.H  defs for Generic I/O Speed Up Package.               1/23/86 */
  5. /* See GIOCall.C for an example of usage.                */
  6. /* Read not speeded-up yet.  Only one Write file buffered at a time.    */
  7. /*                                    */
  8. /* Note: The speed-up provided is ONLY significant for code such as IFF */
  9. /* which does numerous small Writes and Seeks.                */
  10. /*                                    */
  11. /* WARNING: If gio reports an error to you and you care what specific    */
  12. /* Dos error was, you must call IoErr() BEFORE calling any other gio    */
  13. /* functions.                                */
  14. /*                                                                      */ 
  15. /* By Jerry Morrison and Steve Shaw, Electronic Arts.                   */ 
  16. /* This software is in the public domain.                               */ 
  17. /*                                                                      */ 
  18. /* This version for the Commodore-Amiga computer.                       */
  19. /*                                                                      */ 
  20. /*----------------------------------------------------------------------*/
  21.  
  22. /* Use this file interface in place of ALL Open,Close,Read,Write,Seek DOS
  23.  * calls for an optional i/o speed-up via buffering.  You must use ONLY
  24.  * these G routines for a file that is being buffered; e.g., call GClose
  25.  * to Close the file, etc.
  26.  * It is harmless though not necessary to use G routines for a file that
  27.  * is not being buffered; e.g., GClose and Close are equivalent in that
  28.  * case.
  29.  * This Version only buffers one file at a time, and only for writing.
  30.  * If you call GWriteDeclare for a second file before the first file
  31.  * is GClosed, the first file becomes unbuffered.  This is harmless, no
  32.  * data is lost, the first file is simply no longer speeded-up.
  33.  */
  34.  
  35. /* Before compiling any modules that make G calls, or compiling gio.c,
  36.  * you must set the GIO_ACTIVE flag below.
  37.  *
  38.  * To omit the speed-up code,
  39.  *    #define GIO_ACTIVE 0
  40.  *
  41.  * To make the speed-up happen:
  42.  * 1. #define GIO_ACTIVE 1
  43.  * 2. link gio.o into your progrm
  44.  * 3. GWriteDeclare(file, buffer, size)
  45.  *    after GOpening the file and before doing
  46.  *    any writing.
  47.  * 4. ONLY use GRead, GWrite, GSeek, GClose -- do not use the DOS i/o
  48.  *    routines directly.
  49.  * 5. When done, do GClose.  Or to stop buffering without closing the
  50.  *    file, do GWriteUndeclare(file).
  51.  */
  52. #define GIO_ACTIVE 0
  53.  
  54. #ifndef COMPILER_H
  55. #include "iff/compiler.h"
  56. #endif
  57.  
  58. #ifndef LIBRARIES_DOS_H
  59. #include "libraries/dos.h"
  60. #endif
  61.  
  62. #ifndef OFFSET_BEGINNING
  63. #define OFFSET_BEGINNING OFFSET_BEGINING
  64. #endif
  65.  
  66. #if GIO_ACTIVE
  67.  
  68. #ifdef FDwAT  /* Compiler handles Function Declaration with Argument Types */
  69.  
  70. /* Present for completeness in the interface.
  71.  * "openmode" is either MODE_OLDFILE to read/write an existing file, or
  72.  * MODE_NEWFILE to write a new file.
  73.  * RETURNs a "file" pointer to a system-supplied structure that describes
  74.  * the open file.  This pointer is passed in to the other routines below.*/
  75. extern BPTR GOpen(char * /*filename*/, LONG /*openmode*/);
  76.  
  77. /* NOTE: Flushes & Frees the write buffer.
  78.  * Returns -1 on error from Write.*/
  79. extern LONG GClose(BPTR /*file*/);
  80.  
  81. /* Read not speeded-up yet.
  82.  * GOpen the file, then do GReads to get successive chunks of data in
  83.  * the file.  Assumes the system can handle any number of bytes in each
  84.  * call, regardless of any block-structure of the device being read from.
  85.  * When done, GClose to free any system resources associated with an
  86.  * open file.*/
  87. extern LONG GRead(BPTR /*file*/, BYTE * /*buffer*/, LONG /*nBytes*/);
  88.  
  89. /* Writes out any data in write buffer for file.
  90.  * NOTE WHEN have Seeked into middle of buffer:
  91.  * GWriteFlush causes current position to be the end of the data written.
  92.  * -1 on error from Write.*/
  93. extern LONG GWriteFlush(BPTR /*file*/);
  94.  
  95. /* Sets up variables to describe a write buffer for the file.*/
  96. /* If the buffer already has data in it from an outstanding GWriteDeclare,
  97.  * then that buffer must first be flushed.
  98.  * RETURN -1 on error from Write for that previous buffer flush.
  99.  * See also "GWriteUndeclare".*/
  100. extern LONG GWriteDeclare(BPTR /*file*/, BYTE * /*buffer*/, LONG /*nBytes*/);
  101.  
  102. /* ANY PROGRAM WHICH USES "GWrite" MUST USE "GSeek" rather than "Seek"
  103.  * TO SEEK ON A FILE BEING WRITTEN WITH "GWrite".
  104.  * "Write" with Generic speed-up.
  105.  * -1 on error from Write.  else returns # bytes written to disk.
  106.  * Call GOpen, then do successive GWrites with GSeeks if required,
  107.  * then GClose when done.  (IFF does require GSeek.)*/
  108. extern LONG GWrite(BPTR /*file*/, BYTE * /*buffer*/, LONG /*nBytes*/);
  109.  
  110. /* "Seek" with Generic speed-up, for a file being written with GWrite.*/
  111. /* Returns what Seek returns, which appears to be the position BEFORE
  112.  * seeking, though the documentation says it returns the NEW position.
  113.  * In fact, the code now explicitly returns the OLD position when
  114.  * seeking within the buffer.
  115.  * Eventually, will support two independent files, one being read, the
  116.  * other being written.  Or could support even more.  Designed so is safe
  117.  * to call even for files which aren't being buffered.*/
  118. extern LONG GSeek(BPTR /*file*/, LONG /*position*/, LONG /*mode*/);
  119.  
  120. #else /*not FDwAT*/
  121.  
  122. extern BPTR GOpen();
  123. extern LONG GClose();
  124. extern LONG GRead();
  125. extern LONG GWriteFlush();
  126. extern LONG GWriteDeclare();
  127. extern LONG GWrite();
  128. extern LONG GSeek();
  129.  
  130. #endif FDwAT
  131.  
  132. #else /* not GIO_ACTIVE */
  133.  
  134. #define GOpen(filename, openmode)            Open(filename, openmode)
  135. #define GClose(file)                  Close(file)
  136. #define GRead(file, buffer, nBytes)        Read(file, buffer, nBytes)
  137. #define GWriteFlush(file)            (0)
  138. #define GWriteDeclare(file, buffer, nBytes) (0)
  139. #define GWrite(file, buffer, nBytes)        Write(file, buffer, nBytes)
  140. #define GSeek(file, position, mode)        Seek(file, position, mode)
  141.  
  142. #endif GIO_ACTIVE
  143.  
  144.  
  145. /* Release the buffer for that file, flushing it to disk if it has any
  146.  * contents.  GWriteUndeclare(NULL) to release ALL buffers.
  147.  * Currently, only one file can be buffered at a time anyway.*/
  148. #define GWriteUndeclare(file)  GWriteDeclare(file, NULL, 0)
  149.  
  150.  
  151. #endif
  152.