mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-10-10 00:27:23 +00:00
console module only flushes its internal buffer on lf or when full. files without a trailing newline silently lost their last line on exit. switching to out module and calling out.flush after processing each file guarantees all buffered output is written.
50 lines
1.4 KiB
Modula-2
50 lines
1.4 KiB
Modula-2
MODULE OCatCmd; (* J. Templ, 13-Jan-96 *)
|
|
|
|
(* looks at the OBERON search path and writes one or more Oberon or ascii texts to standard out *)
|
|
|
|
IMPORT Args, Out, Files, Texts;
|
|
|
|
PROCEDURE Cat*;
|
|
VAR path: ARRAY 128 OF CHAR; i: INTEGER; T: Texts.Text; R: Texts.Reader; ch: CHAR; tab: BOOLEAN;
|
|
buf: ARRAY 1024 OF CHAR; bufpos: INTEGER;
|
|
|
|
PROCEDURE OutChar(ch: CHAR); (* buffered write *)
|
|
BEGIN buf[bufpos] := ch; INC(bufpos);
|
|
IF bufpos = LEN(buf) - 1 THEN buf[bufpos] := 0X; Out.String(buf); bufpos := 0 END
|
|
END OutChar;
|
|
|
|
BEGIN
|
|
path := ""; NEW(T);
|
|
Args.Get(1, path);
|
|
IF path = "-t" THEN tab := TRUE; i := 2; Args.Get(2, path)
|
|
ELSE tab := FALSE; i := 1
|
|
END ;
|
|
WHILE path # "" DO
|
|
IF Files.Old(path) # NIL THEN
|
|
Texts.Open(T, path);
|
|
Texts.OpenReader(R, T, 0); Texts.Read(R, ch); bufpos := 0;
|
|
WHILE ~R.eot DO
|
|
IF ch >= " " THEN OutChar(ch)
|
|
ELSIF ch = 09X THEN
|
|
IF tab THEN OutChar(ch) ELSE OutChar(" "); OutChar(" ") END
|
|
ELSIF ch = 0DX THEN OutChar(0AX)
|
|
END ;
|
|
Texts.Read(R, ch)
|
|
END ;
|
|
buf[bufpos] := 0X; Out.String(buf); Out.Flush (* flush *)
|
|
ELSE
|
|
Out.String("ocat: cannot open "); Out.String(path); Out.Ln
|
|
END ;
|
|
INC(i); path := "";
|
|
Args.Get(i, path)
|
|
END
|
|
END Cat;
|
|
|
|
BEGIN Cat
|
|
END OCatCmd.
|
|
|
|
|
|
|
|
ocat [-t] files...
|
|
|
|
-t no tab conversion
|