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 markup

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.File Status?. *)   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 Read Char? (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 Read String? (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 Read Token? (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 Read Line? (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 Skip Line? (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 Write Char?(file : File; ch : CHAR);   (* Writes the char in 'ch' to the file fid. *)

PROCEDURE Write Ln? (fid: File);   (* Writes the implementation defined endOfLine to the output file fid. *)   PROCEDURE Write String? (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 File IO. *)

FROM File IO IMPORT File;

(* Read a line of text *)

PROCEDURE Read Line? ( 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 Skip Line? ( file : File ); (* Read and ignore all characters up to and including the first newline. *)

(* Write a line of text *)

PROCEDURE Write Line? ( 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 Write Ln? ( file : File ); (* Writes an empty line to <file>. The line is terminated by newline. *)