STDDEVIC.DEF 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. FOREIGN DEFINITION MODULE StdDevice;
  2. (* Procedures forming the interface to channels connected to
  3. the Standard device. *)
  4. IMPORT IMPLEMENTATION FROM "StdDevice.obj";
  5. IMPORT ChanConsts;
  6. IMPORT IOConsts;
  7. IMPORT IOLink;
  8. IMPORT RndFile;
  9. FROM SYSTEM IMPORT ADDRESS;
  10. CONST
  11. (* Device Errors - implementation dependent *)
  12. InvalidChannel = -1; (* channel not connected to this device *)
  13. NoError = 0;
  14. MaxSoftDevErr = 18; (* soft device errors in range 1..18 *)
  15. MinHardDevErr = 19; (* hard device errors >= 19 *)
  16. (* Codes for the Standard Channels connected to the StdDevice *)
  17. StdBad = -2;
  18. StdNull = -1;
  19. StdIn = 0;
  20. StdOut = 1;
  21. StdErr = 2;
  22. TYPE
  23. StdChanCode = [StdBad..StdErr];
  24. OpenResults = ChanConsts.OpenResults;
  25. ReadResults = IOConsts.ReadResults;
  26. DeviceTablePtr = IOLink.DeviceTablePtr;
  27. ChanId = IOLink.ChanId;
  28. DeviceData = IOLink.DeviceData;
  29. DeviceErrNum = IOLink.DeviceErrNum;
  30. FilePos = RndFile.FilePos;
  31. OpenMode = (ReadOnly, WriteOnly, ReadWrite);
  32. (* Text operations - these perform any required translation between
  33. the internal and external representation of text. *)
  34. PROCEDURE Look ( dtp : DeviceTablePtr;
  35. VAR ch : CHAR;
  36. VAR res : ReadResults);
  37. (* If there is a character as the next item in the given input stream,
  38. assigns its value to the parameter ch without removing it from the stream.
  39. Otherwise, the value of the parameter ch is not defined.
  40. The parameter res, and the stored read result, is set to the value
  41. allRight, endOfLine, or endOfInput. *)
  42. PROCEDURE Skip (dtp : DeviceTablePtr);
  43. (* If the input has ended, the exception skipAtEnd is raised,
  44. otherwise, the next character or line mark in the input is removed. *)
  45. PROCEDURE SkipLook ( dtp : DeviceTablePtr;
  46. VAR ch : CHAR;
  47. VAR res : ReadResults);
  48. (* If the stream has ended, the exception skipAtEnd is raised,
  49. otherwise, the next character or line mark is removed.
  50. If there is a character as the next item in the given input stream,
  51. assigned its value to the parameter ch without removing it from the stream.
  52. Otherwise, the value of the parameter ch is not defined.
  53. The parameter res, and the stored read result, is set to the value
  54. allRight, endOfLine or endOfInput. *)
  55. PROCEDURE TextRead ( dtp : DeviceTablePtr;
  56. to : ADDRESS;
  57. maxChars : CARDINAL;
  58. VAR charsRead : CARDINAL);
  59. (* Reads at most maxChars characters from the current line and assigns
  60. corresponding values to successive locations, starting at the address
  61. given by the parameter to, and continuing at increments corresponding
  62. to the address difference between successive components of an ARRAY OF
  63. CHAR. The number of characters read is assigned to the parameter
  64. charsRead. *)
  65. PROCEDURE TextWrite (dtp : DeviceTablePtr;
  66. from : ADDRESS;
  67. chars : CARDINAL);
  68. (* Writes a number of characters given by the value of the parameter chars,
  69. starting as the address given by the parameter from and continuing at
  70. increments corresponding to the address difference between successive
  71. components of an ARRAY OF CHAR. *)
  72. PROCEDURE WriteLn (dtp : DeviceTablePtr);
  73. (* Writes a line mark over the channel *)
  74. (* Binary operations *)
  75. PROCEDURE BinRead ( dtp : DeviceTablePtr;
  76. to : ADDRESS;
  77. maxLocs : CARDINAL;
  78. VAR locsRead : CARDINAL);
  79. (* Reads at most maxLocs items and assigns corresponding values to
  80. successive locations, starting at the address given by the parameter
  81. to.
  82. The number of items read is assigned to the parameter locsRead. *)
  83. PROCEDURE BinWrite (dtp : DeviceTablePtr;
  84. from : ADDRESS;
  85. locs : CARDINAL);
  86. (* Writes a number of items given by the value of the parameter locs from
  87. successive locations starting as the address given by the parameter
  88. from. *)
  89. (* Common operations *)
  90. PROCEDURE GetName ( dtp : DeviceTablePtr;
  91. VAR s : ARRAY OF CHAR);
  92. (* Copies to the parameter s a name associated with the channel,
  93. possibly truncated depending on the capacity of s. *)
  94. PROCEDURE Reset (dtp : DeviceTablePtr);
  95. (* Reset to a state defined by the device module *)
  96. PROCEDURE Flush (dtp : DeviceTablePtr);
  97. (* Flush any data buffered by the device module out to the destination *)
  98. PROCEDURE Free (dtp : DeviceTablePtr);
  99. (* Carries out the operations involved in closing the
  100. corresponding channel, including flushing buffers, but do
  101. not unmake the channel. *)
  102. (* Channel operations *)
  103. PROCEDURE MakeStdChanDeviceData (chanCode : StdChanCode) : DeviceData;
  104. (* Returns the device data to be held for all standard
  105. channels connected to the StdDevice. *)
  106. PROCEDURE OpenChannel ( dtp : DeviceTablePtr;
  107. oldFile : ARRAY OF CHAR;
  108. mode : OpenMode;
  109. VAR res : OpenResults);
  110. (* If a channel can be opened to the existing oldFile on the
  111. standard device, then creates dtp with the fields cd and errNum
  112. initialized, and res is set to opened.
  113. Otherwise, the value of the parameter res indicates
  114. the reason for the failure. *)
  115. PROCEDURE CreateChannel ( cd : DeviceData;
  116. newFile : ARRAY OF CHAR;
  117. mode : OpenMode;
  118. VAR res : OpenResults);
  119. (* If a channel can be opened to the newFile on the
  120. standard device, then creates dtp with the fields cd and errNum
  121. initialized, and res is set to opened.
  122. Otherwise, the value of the parameter res indicates
  123. the reason for the failure. *)
  124. PROCEDURE Delete ( name : ARRAY OF CHAR;
  125. VAR done : BOOLEAN);
  126. (* If done, the file called name has been deleted. *)
  127. PROCEDURE SetPos (cd : DeviceData;
  128. pos : FilePos);
  129. (* Sets the read/write position to the value given by the
  130. parameter pos. *)
  131. PROCEDURE GetPos (cd : DeviceData) : FilePos;
  132. (* Returns the current read/write position *)
  133. PROCEDURE StartPos (cd : DeviceData) : FilePos;
  134. (* Returns the first position of the file *)
  135. PROCEDURE EndPos (cd : DeviceData) : FilePos;
  136. (* Returns the first position at or after which there have been
  137. no writes *)
  138. PROCEDURE FileExists (fileName : ARRAY OF CHAR) : BOOLEAN;
  139. (* Does the file exist? *)
  140. END StdDevice.