RNDFILE.DEF 4.4 KB

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