Skip to content

Instantly share code, notes, and snippets.

@be9
Created October 7, 2008 12:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save be9/15282 to your computer and use it in GitHub Desktop.
Save be9/15282 to your computer and use it in GitHub Desktop.
Modula-2 Files
MODULE cat;
IMPORT StreamFile, ChanConsts, STextIO, TextIO, IOConsts, IOChan;
VAR
fi : StreamFile.ChanId;
fname : ARRAY [0..255] OF CHAR;
res : ChanConsts.OpenResults;
ch : CHAR;
BEGIN
fname := "test.txt";
StreamFile.Open(fi,fname,StreamFile.text+StreamFile.old+StreamFile.read,res);
IF res <> StreamFile.opened THEN
STextIO.WriteString("Open error");
STextIO.WriteLn;
RETURN;
END;
LOOP
TextIO.ReadChar(fi, ch);
CASE IOChan.ReadResult(fi) OF
| IOConsts.endOfInput: EXIT;
| IOConsts.endOfLine: TextIO.SkipLine(fi); STextIO.WriteLn;
ELSE
STextIO.WriteChar(ch);
END;
END;
StreamFile.Close(fi);
END cat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment