TEXTINOU.DEF 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. (***********************************************************************)
  2. (* *)
  3. (* Modula_2 Compiler TextInOut Library Module *)
  4. (* *)
  5. (* High level input and output procedures for *)
  6. (* characters, strings, integers and cardinals *)
  7. (* *)
  8. (* THIS MODULE PROVIDES THE SAME PROCEDURES AS InOut *)
  9. (* BUT USES NAMED FILES AS SOURCE AND DESTINATION *)
  10. (* *)
  11. (* original module : N. Wirth, PIM-2, 1982 (InOut) *)
  12. (* modifications : *)
  13. (* *)
  14. (***********************************************************************)
  15. FOREIGN DEFINITION MODULE TextInOut;
  16. IMPORT IMPLEMENTATION FROM "textinout.obj & uxfiles.obj";
  17. FROM UxFiles IMPORT File;
  18. CONST
  19. EOL = 12C; (* End-of-line character *)
  20. VAR
  21. Done : BOOLEAN ; (* Status of some TextInOut procedure calls.
  22. TRUE if the operation was successful,
  23. FALSE otherwise. *)
  24. termCh : CHAR ; (* Terminating character of some input
  25. procedures. ReadString, ReadInt, ReadCard *)
  26. PROCEDURE Read(inFile : File; VAR c:CHAR);
  27. (* Precondition : TRUE
  28. Postcondition : Done = FALSE if and only if the end of the primary
  29. input stream is reached, otherwise c is the next
  30. character in the stream. *)
  31. PROCEDURE ReadString(inFile : File; VAR s: ARRAY OF CHAR);
  32. (* Precondition : TRUE
  33. Postcondition : Inputs a character string from the primary input
  34. stream until any character less than or equal to
  35. a blank is read. The variable termCh is set to the
  36. value of this terminating character.
  37. The NUL character (0C) or the end of the array is
  38. used to mark the end of the string.
  39. Leading blanks and/or tabs are ignored. Excess
  40. characters beyond the length of s are discarded. *)
  41. PROCEDURE ReadCard(inFile : File; VAR n: CARDINAL);
  42. (* Precondition : TRUE
  43. Postcondition : Done = TRUE if and only if the next sequence of
  44. characters on the input stream represents a
  45. CARDINAL value. The variable termCh is set to the
  46. value of the character that terminates this
  47. sequence. *)
  48. PROCEDURE ReadInt(inFile : File; VAR i : INTEGER);
  49. (* Precondition : TRUE
  50. Postcondition : Done = TRUE if and only if the next sequence of
  51. characters on the input stream represents a
  52. INTEGER value. The variable termCh is set to the
  53. value of the character that terminates this
  54. sequence. *)
  55. PROCEDURE Write(outFile : File; c:CHAR);
  56. (* Precondition : c is defined.
  57. Postcondition : The character representation corresponding to the
  58. value of c is written to the output stream. *)
  59. PROCEDURE WriteLn(outFile : File);
  60. (* Precondition : TRUE
  61. Postcondition : Equivalent to Write(EOL). *)
  62. PROCEDURE WriteString(outFile : File; s : ARRAY OF CHAR);
  63. (* Precondition : s is defined.
  64. Postcondition : Outputs a string of characters until a NUL character
  65. or the end of the array is encountered. *)
  66. PROCEDURE WriteCard(outFile : File; n: CARDINAL; w: CARDINAL);
  67. (* Precondition : n and w are defined.
  68. Postcondition : The value of n is written to the output stream
  69. occupying at least w character positions. Leading
  70. blanks fill out the space if it is not all required.
  71. The decimal number system is used. *)
  72. PROCEDURE WriteInt(outFile : File; i: INTEGER; w: CARDINAL);
  73. (* Precondition : i and w are defined.
  74. Postcondition : The value of i is written to the output stream
  75. occupying at least w character positions. Leading
  76. blanks fill out the space if it is not all required.
  77. The decimal number system is used and a sign is
  78. displayed only for negative numbers. *)
  79. PROCEDURE WriteOct(outFile : File; n: CARDINAL; w: CARDINAL);
  80. (* Precondition : n and w are defined.
  81. Postcondition : The value of n is written to the output stream
  82. occupying at least w character positions. Leading
  83. blanks fill out the space if it is not all required.
  84. The octal number system is used. *)
  85. PROCEDURE WriteHex(outFile : File; n: CARDINAL; w: CARDINAL);
  86. (* Precondition : n and w are defined.
  87. Postcondition : The value of n is written to the output stream
  88. occupying at least w character positions. Leading
  89. blanks fill out the space if it is not all required.
  90. The hexadecimal number system is used. *)
  91. END TextInOut.