home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / modu1096.zip / ISOsym / rndfile.def < prev    next >
Text File  |  1996-08-29  |  4KB  |  110 lines

  1. DEFINITION MODULE RndFile;
  2.  
  3.     (* Random access files *)
  4.  
  5. IMPORT IOChan, ChanConsts;
  6. FROM ChanConsts IMPORT ChanFlags;
  7.  
  8. TYPE
  9.   ChanId      = IOChan.ChanId;
  10.   FlagSet     = ChanConsts.FlagSet;
  11.   OpenResults = ChanConsts.OpenResults;
  12.  
  13.  
  14. (* Accept singleton values of FlagSet *)
  15. CONST
  16.   read  = FlagSet{readFlag}; (* input operations are requested/available *)
  17.   write = FlagSet{writeFlag};(* output operations are requested/available *)
  18.   old   = FlagSet{oldFlag};  (* file may/must/did exist before channel was opened *)
  19.   text  = FlagSet{textFlag}; (* text operations are requested/available *)
  20.   raw   = FlagSet{rawFlag};  (* raw operations are requested/available *)
  21.  
  22.  
  23. PROCEDURE OpenOld (VAR cid   : ChanId;
  24.                        name  : ARRAY OF CHAR;
  25.                        flags : FlagSet;
  26.                    VAR res   : OpenResults);
  27. (* Attempts to obtain and open a channel connected to a stored random access file
  28.    The old flag is implied; without the write flag, read is implied;
  29.    without the text flag, raw is implied.
  30.    If successful, assigns to the parameter cid the identity of a channel
  31.    open to a random access file of the given name and assigns the value
  32.    opened to the parameter res.
  33.    The read and/or write position is at the start of the file.
  34.    If a channel cannot be opened as required, the value of the parameter
  35.    res indicates the reason and cid identifies the bad channel. *)
  36.  
  37.  
  38. PROCEDURE OpenClean (VAR cid   : ChanId;
  39.                          name  : ARRAY OF CHAR;
  40.                          flags : FlagSet;
  41.                      VAR res   : OpenResults);
  42. (* Attempts to obtain and open a channel connected to a stored random access file
  43.    The write flag is implied; without the text flag, raw is implied.
  44.    If successful, assigns to the parameter cid the identity of a channel
  45.    open to a random access file of the given name and assigns the value
  46.    opened to the parameter res.
  47.    The file is of zero length.
  48.    If a channel cannot be opened as required, the value of the parameter
  49.    res indicates the reason and cid identifies the bad channel. *)
  50.  
  51.  
  52. PROCEDURE IsRndFile (cid : ChanId) : BOOLEAN;
  53. (* Tests if the channel is open to a random access file *)
  54.  
  55.  
  56. PROCEDURE IsRndFileException () : BOOLEAN;
  57. (* Returns TRUE if the current coroutine is in the exceptional execution state
  58.    because of the raising of a RndFile exception; otherwise returns FALSE. *)
  59.  
  60.  
  61. CONST
  62.   FilePosSize = SIZE(CARDINAL);
  63.  
  64. TYPE
  65.   FilePos = CARDINAL;  (* ARRAY [1..FilePosSize] OF LOC *)
  66.  
  67.  
  68. PROCEDURE StartPos (cid : ChanId) : FilePos;
  69. (* If the channel is not open to a random access file, the exception
  70.    wrongDevice is raised. Otherwise, returns the position of the
  71.    start of the file. *)
  72.  
  73.  
  74. PROCEDURE CurrentPos (cid : ChanId) : FilePos;
  75. (* If the channel is not open to a random access file, the exception
  76.    wrongDevice is raised. Otherwise, returns the current
  77.    read/write position. *)
  78.  
  79.  
  80. PROCEDURE EndPos (cid : ChanId) : FilePos;
  81. (* If the channel is not open to a random access file, the exception
  82.    wrongDevice is raised. Otherwise, returns the first position at
  83.    or after which there have been no writes. *)
  84.  
  85.  
  86. PROCEDURE NewPos (cid       : ChanId;
  87.                   chunks    : INTEGER;
  88.                   chunkSize : CARDINAL;
  89.                   from      : FilePos) : FilePos;
  90. (* If the channel is not open to a random access file, the exception
  91.    wrongDevice is raised. Otherwise, returns the position
  92.    chunks*chunkSize relative to the parameter from or raises the
  93.    exception posRange if the required position cannot be represented
  94.    as a value of type FilePos. *)
  95.  
  96.  
  97. PROCEDURE SetPos (cid : ChanId;
  98.                   pos : FilePos);
  99. (* If the channel is not open to a random access file, the exception
  100.    wrongDevice is raised. Otherwise, sets the read/write position to
  101.    the value given by the parameter pos. *)
  102.  
  103.  
  104. PROCEDURE Close (VAR cid : ChanId);
  105. (* If the channel is not open to a random access file, the exception
  106.    wrongDevice is raised. Otherwise, the channel is closed and the value
  107.    identifying the bad channel is assigned to the parameter cid. *)
  108.  
  109. END RndFile.
  110.