INOUT.DEF 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. (***********************************************************************)
  2. (* *)
  3. (* Modula_2 Compiler InOut Library Module *)
  4. (* *)
  5. (* High level input and output procedures for *)
  6. (* characters, strings, integers and cardinals *)
  7. (* and allows redirection of I/O to/from files *)
  8. (* *)
  9. (* original module : N. Wirth, PIM-2, 1982 *)
  10. (* modifications : 29-JUN-89 import from UxFiles *)
  11. (* *)
  12. (* *)
  13. (***********************************************************************)
  14. FOREIGN DEFINITION MODULE InOut;
  15. IMPORT IMPLEMENTATION FROM "inout.obj";
  16. CONST
  17. EOL = 12C; (* End-of-line character *)
  18. VAR
  19. Done : BOOLEAN ; (* Status of some InOut procedure calls.
  20. TRUE if the operation was successful,
  21. FALSE otherwise. *)
  22. termCh : CHAR ; (* Terminating character of some input
  23. procedures. ReadString, ReadInt, ReadCard *)
  24. PROCEDURE OpenInput(Extension : ARRAY OF CHAR);
  25. (* Precondition : TRUE
  26. Postcondition : The primary input stream is redefined to be the
  27. external file name whose names has been supplied
  28. by the user. If the name ends with a "." the string
  29. Extension is appended to the end of it.
  30. Done = TRUE if and only if the file is opened
  31. successfully *)
  32. PROCEDURE OpenOutput(Extension : ARRAY OF CHAR);
  33. (* Precondition : TRUE
  34. Postcondition : The primary output stream is redefined to be the
  35. external file name whose names has been supplied
  36. by the user. If the name ends with a "." the string
  37. Extension is appended to the end of it.
  38. Done = TRUE if and only if the file is opened
  39. successfully *)
  40. PROCEDURE CloseInput;
  41. (* Precondition : TRUE
  42. Postcondition : The primary input stream is redefined to be the
  43. terminal keyboard and the previously used input
  44. stream is closed *)
  45. PROCEDURE CloseOutput;
  46. (* Precondition : TRUE
  47. Postcondition : The primary output stream is redefined to be the
  48. terminal keyboard and the previously used output
  49. stream is closed *)
  50. PROCEDURE Read(VAR c:CHAR);
  51. (* Precondition : TRUE
  52. Postcondition : Done = FALSE if and only if the end of the primary
  53. input stream is reached, otherwise c is the next
  54. character in the stream. *)
  55. PROCEDURE ReadLn();
  56. (* Precondition : TRUE
  57. Postcondition : Done = FALSE if and only if the end of the primary
  58. input stream is reached. Characters up to and
  59. including the EOLN mark are read and consumed *)
  60. PROCEDURE ReadString(VAR s: ARRAY OF CHAR);
  61. (* Precondition : TRUE
  62. Postcondition : Inputs a character string from the primary input
  63. stream until any character less than or equal to
  64. a blank is read. The variable termCh is set to the
  65. value of this terminating character.
  66. The NUL character (0C) or the end of the array is
  67. used to mark the end of the string.
  68. Leading blanks and/or tabs are ignored. Excess
  69. characters beyond the length of s are discarded. *)
  70. PROCEDURE ReadCard(VAR n: CARDINAL);
  71. (* Precondition : TRUE
  72. Postcondition : Done = TRUE if and only if the next sequence of
  73. characters on the input stream represents a
  74. CARDINAL value. The variable termCh is set to the
  75. value of the character that terminates this
  76. sequence. *)
  77. PROCEDURE ReadInt(VAR i : INTEGER);
  78. (* Precondition : TRUE
  79. Postcondition : Done = TRUE if and only if the next sequence of
  80. characters on the input stream represents a
  81. INTEGER value. The variable termCh is set to the
  82. value of the character that terminates this
  83. sequence. *)
  84. PROCEDURE Write(c:CHAR);
  85. (* Precondition : c is defined.
  86. Postcondition : The character representation corresponding to the
  87. value of c is written to the output stream. *)
  88. PROCEDURE WriteLn;
  89. (* Precondition : TRUE
  90. Postcondition : Equivalent to Write(EOL). *)
  91. PROCEDURE WriteString(s : ARRAY OF CHAR);
  92. (* Precondition : s is defined.
  93. Postcondition : Outputs a string of characters until a NUL character
  94. or the end of the array is encountered. *)
  95. PROCEDURE WriteCard(n: CARDINAL; w: CARDINAL);
  96. (* Precondition : n and w are defined.
  97. Postcondition : The value of n is written to the output stream
  98. occupying at least w character positions. Leading
  99. blanks fill out the space if it is not all required.
  100. The decimal number system is used. *)
  101. PROCEDURE WriteInt(i: INTEGER; w: CARDINAL);
  102. (* Precondition : i and w are defined.
  103. Postcondition : The value of i is written to the output stream
  104. occupying at least w character positions. Leading
  105. blanks fill out the space if it is not all required.
  106. The decimal number system is used and a sign is
  107. displayed only for negative numbers. *)
  108. PROCEDURE WriteOct(n: CARDINAL; w: CARDINAL);
  109. (* Precondition : n and w are defined.
  110. Postcondition : The value of n is written to the output stream
  111. occupying at least w character positions. Leading
  112. blanks fill out the space if it is not all required.
  113. The octal number system is used. *)
  114. PROCEDURE WriteHex(n: CARDINAL; w: CARDINAL);
  115. (* Precondition : n and w are defined.
  116. Postcondition : The value of n is written to the output stream
  117. occupying at least w character positions. Leading
  118. blanks fill out the space if it is not all required.
  119. The hexadecimal number system is used. *)
  120. END InOut.
  121.