[comp.lang.modula2] Encore Modula2 : Comments

kumard@sunybcs (Deepak Kumar) (02/10/88)

This is about I/O on the Modula2 version 2.0 running under UMAX

I noticed that I/O is supported by SITerminal and m5un.

If one uses the Read from SITerminal, first of all, it is a
parameterless function procedure, secondly, it does not support
umax/unix command level input redirection (i.e. a.out < infile ...)
However, the Write procedure can redirect output to a file
(i.e. a.out > outfile...)

On the other hand, the Read procedure in m5un does redirection on
input, however, Write doesn't!!

Now, there is SINumberIO for doing I/O on INTEGER, CARDINAL, and
REAL. Looking through the code one notices that all I/O is
ultimately implemented through the Read/Write in SITerminal
(i.e. Convert number to a string using SIConversions, then do
  a WriteString, which uses Write for output
  and
  ReadString, convert it to the required number. readString uses
  read)

Also, the Read from m5un does not echo what you type in...

And similarly there are problems with explicit file I/O.
But there is SIStreams .....

SOLUTION:

I have managed without much difficulty and a lot of juggling
to put together my own modules InOut and FileInOut.

InOut works exactly as described by Wirth 3rd ed. It can be used
for all I/O (i.e. Read, Write, ReadInt/Card/Real and the Writes,
and WriteLn) and will redirect both input and Output as you like.

InOut has OpenInput/CloseInput missing....

FileInOut provides a file I/O interface with

OpenFile(VAR f: File; filename: ARRAY OF CHAR; mode: CHAR);
mode can be 'r' for read and 'w' for write.

and

CloseFile(f: File);

and it has all the procedures as InOut (i.e. Read, ReadInt/Card/Real
etc and the Writes). They all take an extra argument which is the
File specifier. One can have multiple files open simultaneously
for input as well as output.

I'm not sure if I can give away the code to everyone because it
uses some code from the compiler source. But I will discuss the
details with anyone who desires.

One question: About interfacing C functions.

What are the numebers in SIIUnix that are listed against all the
UNIXCALLS. Are those the only callable C functions? Can they be
extended? How?

Deepak.


kumard@gort.cs.buffalo.EDU
kumard@sunybcs.BITNET
kumard@sunybcs.UUCP
Deepak Kumar, Dept. of CS, 226 Bell Hall, SUNY@Buffalo, NY 14260.