home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xc212os2.zip / ISODEF / rndfile.def < prev    next >
Text File  |  1996-01-09  |  4KB  |  105 lines

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