InOut.def 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. DEFINITION MODULE InOut;
  2. (*
  3. Module: Wirth's Input/Output module
  4. From: "Programming in Modula-2", 3rd, corrected edition, by N. Wirth
  5. Version: $Id$
  6. *)
  7. CONST EOL = 12C;
  8. VAR Done : BOOLEAN;
  9. termCH : CHAR;
  10. PROCEDURE OpenInput(defext: ARRAY OF CHAR);
  11. (* Request a file name from the standard input stream and open
  12. this file for reading.
  13. If the filename ends with a '.', append the "defext" extension.
  14. Done := "file was successfully opened".
  15. If open, subsequent input is read from this file.
  16. *)
  17. PROCEDURE OpenOutput(defext : ARRAY OF CHAR);
  18. (* Request a file name from the standard input stream and open
  19. this file for writing.
  20. If the filename ends with a '.', append the "defext" extension.
  21. Done := "file was successfully opened".
  22. If open, subsequent output is written to this file.
  23. Files left open at program termination are automatically closed.
  24. *)
  25. PROCEDURE OpenInputFile(filename: ARRAY OF CHAR);
  26. (* Like OpenInput, but filename given as parameter.
  27. This procedure is not in Wirth's InOut.
  28. *)
  29. PROCEDURE OpenOutputFile(filename: ARRAY OF CHAR);
  30. (* Like OpenOutput, but filename given as parameter.
  31. This procedure is not in Wirth's InOut.
  32. *)
  33. PROCEDURE CloseInput;
  34. (* Close input file. Subsequent input is read from the standard input
  35. stream.
  36. *)
  37. PROCEDURE CloseOutput;
  38. (* Close output file. Subsequent output is written to the standard
  39. output stream.
  40. *)
  41. PROCEDURE Read(VAR ch : CHAR);
  42. (* Read a character from the current input stream and leave it in "ch".
  43. Done := NOT "end of file".
  44. *)
  45. PROCEDURE ReadString(VAR s : ARRAY OF CHAR);
  46. (* Read a string from the current input stream and leave it in "s".
  47. A string is any sequence of characters not containing blanks or
  48. control characters; leading blanks are ignored.
  49. Input is terminated by any character <= " ".
  50. This character is assigned to termCH.
  51. DEL or BACKSPACE is used for backspacing when input from terminal.
  52. *)
  53. PROCEDURE ReadInt(VAR x : INTEGER);
  54. (* Read a string and convert it to INTEGER.
  55. Syntax: integer = ['+'|'-'] digit {digit}.
  56. Leading blanks are ignored.
  57. Done := "integer was read".
  58. *)
  59. PROCEDURE ReadCard(VAR x : CARDINAL);
  60. (* Read a string and convert it to CARDINAL.
  61. Syntax: cardinal = digit {digit}.
  62. Leading blanks are ignored.
  63. Done := "cardinal was read".
  64. *)
  65. PROCEDURE Write(ch : CHAR);
  66. (* Write character "ch" to the current output stream.
  67. *)
  68. PROCEDURE WriteLn;
  69. (* Terminate line.
  70. *)
  71. PROCEDURE WriteString(s : ARRAY OF CHAR);
  72. (* Write string "s" to the current output stream
  73. *)
  74. PROCEDURE WriteInt(x : INTEGER; n : CARDINAL);
  75. (* Write integer x with (at least) n characters on the current output
  76. stream. If n is greater that the number of digits needed,
  77. blanks are added preceding the number.
  78. *)
  79. PROCEDURE WriteCard(x, n : CARDINAL);
  80. (* Write cardinal x with (at least) n characters on the current output
  81. stream. If n is greater that the number of digits needed,
  82. blanks are added preceding the number.
  83. *)
  84. PROCEDURE WriteOct(x, n : CARDINAL);
  85. (* Write cardinal x as an octal number with (at least) n characters
  86. on the current output stream.
  87. If n is greater that the number of digits needed,
  88. blanks are added preceding the number.
  89. *)
  90. PROCEDURE WriteHex(x, n : CARDINAL);
  91. (* Write cardinal x as a hexadecimal number with (at least)
  92. n characters on the current output stream.
  93. If n is greater that the number of digits needed,
  94. blanks are added preceding the number.
  95. *)
  96. END InOut.