123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- DEFINITION MODULE InOut;
- (*
- Module: Wirth's Input/Output module
- From: "Programming in Modula-2", 3rd, corrected edition, by N. Wirth
- Version: $Id$
- *)
- CONST EOL = 12C;
- VAR Done : BOOLEAN;
- termCH : CHAR;
- PROCEDURE OpenInput(defext: ARRAY OF CHAR);
- (* Request a file name from the standard input stream and open
- this file for reading.
- If the filename ends with a '.', append the "defext" extension.
- Done := "file was successfully opened".
- If open, subsequent input is read from this file.
- *)
- PROCEDURE OpenOutput(defext : ARRAY OF CHAR);
- (* Request a file name from the standard input stream and open
- this file for writing.
- If the filename ends with a '.', append the "defext" extension.
- Done := "file was successfully opened".
- If open, subsequent output is written to this file.
- Files left open at program termination are automatically closed.
- *)
- PROCEDURE OpenInputFile(filename: ARRAY OF CHAR);
- (* Like OpenInput, but filename given as parameter.
- This procedure is not in Wirth's InOut.
- *)
- PROCEDURE OpenOutputFile(filename: ARRAY OF CHAR);
- (* Like OpenOutput, but filename given as parameter.
- This procedure is not in Wirth's InOut.
- *)
- PROCEDURE CloseInput;
- (* Close input file. Subsequent input is read from the standard input
- stream.
- *)
- PROCEDURE CloseOutput;
- (* Close output file. Subsequent output is written to the standard
- output stream.
- *)
- PROCEDURE Read(VAR ch : CHAR);
- (* Read a character from the current input stream and leave it in "ch".
- Done := NOT "end of file".
- *)
- PROCEDURE ReadString(VAR s : ARRAY OF CHAR);
- (* Read a string from the current input stream and leave it in "s".
- A string is any sequence of characters not containing blanks or
- control characters; leading blanks are ignored.
- Input is terminated by any character <= " ".
- This character is assigned to termCH.
- DEL or BACKSPACE is used for backspacing when input from terminal.
- *)
- PROCEDURE ReadInt(VAR x : INTEGER);
- (* Read a string and convert it to INTEGER.
- Syntax: integer = ['+'|'-'] digit {digit}.
- Leading blanks are ignored.
- Done := "integer was read".
- *)
- PROCEDURE ReadCard(VAR x : CARDINAL);
- (* Read a string and convert it to CARDINAL.
- Syntax: cardinal = digit {digit}.
- Leading blanks are ignored.
- Done := "cardinal was read".
- *)
- PROCEDURE Write(ch : CHAR);
- (* Write character "ch" to the current output stream.
- *)
- PROCEDURE WriteLn;
- (* Terminate line.
- *)
- PROCEDURE WriteString(s : ARRAY OF CHAR);
- (* Write string "s" to the current output stream
- *)
- PROCEDURE WriteInt(x : INTEGER; n : CARDINAL);
- (* Write integer x with (at least) n characters on the current output
- stream. If n is greater that the number of digits needed,
- blanks are added preceding the number.
- *)
- PROCEDURE WriteCard(x, n : CARDINAL);
- (* Write cardinal x with (at least) n characters on the current output
- stream. If n is greater that the number of digits needed,
- blanks are added preceding the number.
- *)
- PROCEDURE WriteOct(x, n : CARDINAL);
- (* Write cardinal x as an octal number with (at least) n characters
- on the current output stream.
- If n is greater that the number of digits needed,
- blanks are added preceding the number.
- *)
- PROCEDURE WriteHex(x, n : CARDINAL);
- (* Write cardinal x as a hexadecimal number with (at least)
- n characters on the current output stream.
- If n is greater that the number of digits needed,
- blanks are added preceding the number.
- *)
- END InOut.
|