SEQFILE.DEF 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. DEFINITION MODULE SeqFile;
  2. (* Rewindable sequential files *)
  3. IMPORT IOLink;
  4. IMPORT ChanConsts;
  5. FROM ChanConsts IMPORT ChanFlags;
  6. TYPE
  7. ChanId = IOLink.ChanId;
  8. FlagSet = ChanConsts.FlagSet;
  9. OpenResults = ChanConsts.OpenResults;
  10. (* Accept singleton values of FlagSet *)
  11. CONST
  12. read = FlagSet{readFlag};
  13. (* input operations are requested/available *)
  14. write = FlagSet{writeFlag};
  15. (* output operations are requested/available *)
  16. old = FlagSet{oldFlag};
  17. (* a file may/must/did exist before the channel
  18. was opened *)
  19. text = FlagSet{textFlag};
  20. (* text operations are requested/available *)
  21. raw = FlagSet{rawFlag};
  22. (* raw operations are requested/available *)
  23. PROCEDURE OpenWrite (VAR cid : ChanId;
  24. name : ARRAY OF CHAR;
  25. flags : FlagSet;
  26. VAR res : OpenResults);
  27. (* The write flag is implied;
  28. without the binary flag, text is implied.
  29. If successful, assigns to the parameter cid the identity of a channel
  30. open to a stored file of the given name and assigns the value
  31. opened to the parameter res.
  32. The file is of zero length.
  33. Output mode is selected.
  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. PROCEDURE OpenAppend (VAR cid : ChanId;
  37. name : ARRAY OF CHAR;
  38. flags : FlagSet;
  39. VAR res : OpenResults);
  40. (* The write and old flags are implied;
  41. without the binary flag, text is implied.
  42. If successful, assigns to the parameter cid the identity of a channel
  43. open to a stored file of the given name and assigns the value
  44. opened to the parameter res.
  45. Output mode is selected and the write position corresponds to the
  46. length of the file.
  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 OpenRead (VAR cid : ChanId;
  50. name : ARRAY OF CHAR;
  51. flags : FlagSet;
  52. VAR res : OpenResults);
  53. (* The read and old flags are implied;
  54. without the binary flag, text is implied.
  55. If successful, assigns to the parameter cid the identity of a channel
  56. open to a stored file of the given name and assigns the value
  57. opened to the parameter res.
  58. Input mode is selected.
  59. If a channel cannot be opened as required, the value of the parameter
  60. res indicates the reason and cid identifies the bad channel. *)
  61. PROCEDURE IsSeqFile (cid : ChanId) : BOOLEAN;
  62. (* Tests if the channel is open to a rewindable sequential file *)
  63. PROCEDURE Reread (cid : ChanId);
  64. (* If the channel is not open to a rewindable file, the exception
  65. wrongDevice is raised. Otherwise, if successful, sets the read
  66. position to the start of the file and selects input mode.
  67. If the operation cannot be performed, perhaps because of
  68. insufficient permissions, neither input nor output mode is selected. *)
  69. PROCEDURE Rewrite (cid : ChanId);
  70. (* If the channel is not open to a rewindable file, the exception
  71. wrongDevice is raised. Otherwise, if successful, truncates the
  72. file to zero length and selects output mode.
  73. If the operation cannot be performed, perhaps because of
  74. insufficient permissions, neither input nor output mode is selected. *)
  75. PROCEDURE Close (VAR cid : ChanId);
  76. (* If the channel is not open to a rewindable file, the exception
  77. wrongDevice is raised. Otherwise, the channel is closed and the value
  78. identifying the bad channel is assigned to the parameter cid. *)
  79. END SeqFile.