IOCHAN.DEF 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. DEFINITION MODULE IOChan;
  2. (* Types and procedures forming the interface to channels for
  3. device-independent data transfer modules *)
  4. FROM IOConsts IMPORT ReadResults;
  5. IMPORT IOLink;
  6. FROM ChanConsts IMPORT FlagSet;
  7. FROM SYSTEM IMPORT ADDRESS;
  8. TYPE
  9. ChanId = IOLink.ChanId;
  10. ChanExceptions = IOLink.ChanExceptions;
  11. DeviceErrNum = IOLink.DeviceErrNum;
  12. (* There is one pre-defined value identifying a bad channel on which no
  13. data transfer operations are available. It is used to initialize
  14. variables of type ChanId: *)
  15. PROCEDURE InvalidChan () : ChanId;
  16. (* Returns the value identifying the bad channel *)
  17. (* For each of the following operations, if the device supports the
  18. operation on the channel, the behaviour of the procedure conforms with the
  19. description below. The full behaviour is defined for each device module.
  20. If the device does not support the operation on the channel, the behaviour
  21. of the procedure is to raise the exception notAvailable. *)
  22. (* Text operations - these perform any required translation between
  23. the internal and external representation of text. *)
  24. PROCEDURE Look ( cid : ChanId;
  25. VAR ch : CHAR;
  26. VAR res : ReadResults);
  27. (* If there is a character as the next item in the given input stream,
  28. assigns its value to the parameter ch without removing it from the stream.
  29. Otherwise, the value of the parameter ch is not defined.
  30. The parameter res, and the stored read result, is set to the value
  31. allRight, endOfLine, or endOfInput. *)
  32. PROCEDURE Skip (cid : ChanId);
  33. (* If the input has ended, the exception skipAtEnd is raised,
  34. otherwise, the next character or line mark in the input is removed
  35. and the stored read result is set to the value allRight. *)
  36. PROCEDURE SkipLook ( cid : ChanId;
  37. VAR ch : CHAR;
  38. VAR res : ReadResults);
  39. (* If the stream has ended, the exception skipAtEnd is raised,
  40. otherwise, the next character or line mark is removed.
  41. If there is a character as the next item in the given input stream,
  42. assignsd its value to the parameter ch without removing it from the stream.
  43. Otherwise, the value of the parameter ch is not defined.
  44. The parameter res, and the stored read result, is set to the value
  45. allRight, endOfLine or endOfInput. *)
  46. PROCEDURE TextRead ( cid : ChanId;
  47. to : ADDRESS;
  48. maxChars : CARDINAL;
  49. VAR charsRead : CARDINAL);
  50. (* Reads at most maxChars characters from the current line and assigns
  51. corresponding values to successive locations, starting at the address
  52. given by the parameter to, and continuing at increments corresponding
  53. to the address difference between successive components of an ARRAY OF
  54. CHAR. The number of characters read is assigned to the parameter charsRead.
  55. The read result is set to the value allRight, endOfLine, or endOfInput. *)
  56. PROCEDURE TextWrite (cid : ChanId;
  57. from : ADDRESS;
  58. charsToWrite : CARDINAL);
  59. (* Writes a number of characters given by the value of the parameter
  60. charsToWrite,
  61. starting as the address given by the parameter from and continuing at
  62. increments corresponding to the address difference between successive
  63. components of an ARRAY OF CHAR. *)
  64. PROCEDURE WriteLn (cid : ChanId);
  65. (* Writes a line mark over the channel *)
  66. (* Raw operations *)
  67. PROCEDURE RawRead ( cid : ChanId;
  68. to : ADDRESS;
  69. maxLocs : CARDINAL;
  70. VAR locsRead : CARDINAL);
  71. (* Reads at most maxLocs items and assigns corresponding values to
  72. successive locations, starting at the address given by the parameter
  73. to.
  74. The number of items read is assigned to the parameter locsRead.
  75. The read result is set to the value allRight or endOfInput. *)
  76. PROCEDURE RawWrite (cid : ChanId;
  77. from : ADDRESS;
  78. locsToWrite : CARDINAL);
  79. (* Writes a number of items given by the value of the parameter locsToWrite from
  80. successive locations starting as the address given by the parameter
  81. from. *)
  82. (* Common operations *)
  83. PROCEDURE GetName ( cid : ChanId;
  84. VAR s : ARRAY OF CHAR);
  85. (* Copies to the parameter s a name associated with the channel,
  86. possibly truncated depending on the capacity of s. *)
  87. PROCEDURE Reset (cid : ChanId);
  88. (* Reset to a state defined by the device module *)
  89. PROCEDURE Flush (cid : ChanId);
  90. (* Flush any data buffered by the device module out to the destination *)
  91. (* Access to read results *)
  92. PROCEDURE SetReadResult (cid : ChanId;
  93. res : ReadResults);
  94. (* Sets the read result value for the channel to the value res *)
  95. PROCEDURE ReadResult (cid : ChanId) : ReadResults;
  96. (* Returns the stored read result value for the channel *)
  97. (* (This is initially the value notKnown) *)
  98. (* Users can discover which flags actually apply to a channel *)
  99. PROCEDURE CurrentFlags (cid : ChanId) : FlagSet;
  100. (* Returns the set of flags that apply to the given channel *)
  101. PROCEDURE ChanException () : ChanExceptions;
  102. (* returns the ChanException value for the current context *)
  103. END IOChan.