Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Text IO

Spec.TextIO History

Hide minor edits - Show changes to output

2010-05-24 12:32 by benjk -
Changed lines 3-43 from:
  (* Input and output of character and string types with specified files.
     The file status is of the type File.FileStatus. *)
 
IMPORT File;

  (* The following procedures read only until an endOfLine state is set. The file status is set
      to the value allRight, outOfRange, endOfLine, or endOfInput. *)
 
PROCEDURE ReadChar (file : File; VAR ch : CHAR
);
 (* Reads the next character from the file fid before an and of line mark and stores it in 'ch'. *)

PROCEDURE ReadString (fid: File; VAR s: ARRAY OF CHAR
);
 
(* Removes only those characters from the input file fid before the next line mark that can
      be accommodated in s as
a string value, and copies them to s. *)
 
PROCEDURE ReadToken (fid: File; VAR s:
ARRAY OF CHAR);
  (* Skips leading spaces, and then removes characters from the input file fid before the next
      space or line mark, copying to s as many as can be accommodated as a string value. *)

PROCEDURE ReadLine (fid: File; VAR s: ARRAY OF CHAR
);
  (* Removes any remaining characters from the input file fid before the next line mark,
      copying to s as many as can be accommodated as a string value.  *)
 
  (* The following procedure reads past the next line mark *)
 
PROCEDURE SkipLine (fid: File);
  (* Removes successive items from the input file fid up to and including the next endOfLine
      and clears that state, or until the end of input is reached. The file status is set to the
      value allRight or endOfInput.  *)
 
  (* Output procedures *)
 
PROCEDURE WriteChar(file : File; ch : CHAR);
  (* Writes the char in 'ch' to the file fid. *)

PROCEDURE WriteLn (fid: File);
  (* Writes the implementation defined endOfLine to the output file fid. *)
 
PROCEDURE WriteString (fid: File; s: ARRAY OF CHAR);
  (* Writes the characters in s to the output file fid. *)
 
to:
(* Driver for Line Oriented Text IO *)

(* This module interprets the contents of files as a sequence of lines of text
   delimited by newline. The module is implemented on top of module FileIO. *)

FROM FileIO IMPORT File;


(* Read a line of text *)

PROCEDURE ReadLine ( file : File; VAR str : ARRAY OF CHAR
);
(* Reads a line of text from <file> and passes it back in <str>. A runtime
  error is raised if the line exceeds the capacity of <str>. *
)


(* Skip a line of text *)

PROCEDURE SkipLine (
file : File );
(* Read and ignore all characters up to and including the first newline. *)


(* Write
a line of text *)

PROCEDURE WriteLine ( file : File; str : VARIADIC OF CONST
ARRAY OF CHAR );
(* Writes a sequence of character strings as a line to <file>. The line is
 
  terminated by newline. *)


(* Write an empty
line of text *)

PROCEDURE WriteLn ( file : File );
(* Writes an empty line to <file>. The line is terminated by newline. *
)