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