mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-10-10 07:27:23 +00:00
ocat: fixing missing last line by flushing output after each file
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.
This commit is contained in:
parent
4dd3c395fe
commit
c985dcb3e4
1 changed files with 10 additions and 10 deletions
|
|
@ -2,16 +2,16 @@ 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 *)
|
(* looks at the OBERON search path and writes one or more Oberon or ascii texts to standard out *)
|
||||||
|
|
||||||
IMPORT Args, Console, Files, Texts;
|
IMPORT Args, Out, Files, Texts;
|
||||||
|
|
||||||
PROCEDURE Cat*;
|
PROCEDURE Cat*;
|
||||||
VAR path: ARRAY 128 OF CHAR; i: INTEGER; T: Texts.Text; R: Texts.Reader; ch: CHAR; tab: BOOLEAN;
|
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;
|
buf: ARRAY 1024 OF CHAR; bufpos: INTEGER;
|
||||||
|
|
||||||
PROCEDURE ConsoleChar(ch: CHAR); (* buffered write *)
|
PROCEDURE OutChar(ch: CHAR); (* buffered write *)
|
||||||
BEGIN buf[bufpos] := ch; INC(bufpos);
|
BEGIN buf[bufpos] := ch; INC(bufpos);
|
||||||
IF bufpos = LEN(buf) - 1 THEN buf[bufpos] := 0X; Console.String(buf); bufpos := 0 END
|
IF bufpos = LEN(buf) - 1 THEN buf[bufpos] := 0X; Out.String(buf); bufpos := 0 END
|
||||||
END ConsoleChar;
|
END OutChar;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
path := ""; NEW(T);
|
path := ""; NEW(T);
|
||||||
|
|
@ -24,16 +24,16 @@ MODULE OCatCmd; (* J. Templ, 13-Jan-96 *)
|
||||||
Texts.Open(T, path);
|
Texts.Open(T, path);
|
||||||
Texts.OpenReader(R, T, 0); Texts.Read(R, ch); bufpos := 0;
|
Texts.OpenReader(R, T, 0); Texts.Read(R, ch); bufpos := 0;
|
||||||
WHILE ~R.eot DO
|
WHILE ~R.eot DO
|
||||||
IF ch >= " " THEN ConsoleChar(ch)
|
IF ch >= " " THEN OutChar(ch)
|
||||||
ELSIF ch = 09X THEN
|
ELSIF ch = 09X THEN
|
||||||
IF tab THEN ConsoleChar(ch) ELSE ConsoleChar(" "); ConsoleChar(" ") END
|
IF tab THEN OutChar(ch) ELSE OutChar(" "); OutChar(" ") END
|
||||||
ELSIF ch = 0DX THEN ConsoleChar(0AX)
|
ELSIF ch = 0DX THEN OutChar(0AX)
|
||||||
END ;
|
END ;
|
||||||
Texts.Read(R, ch)
|
Texts.Read(R, ch)
|
||||||
END ;
|
END ;
|
||||||
buf[bufpos] := 0X; Console.String(buf) (* flush *)
|
buf[bufpos] := 0X; Out.String(buf); Out.Flush (* flush *)
|
||||||
ELSE
|
ELSE
|
||||||
Console.String("ocat: cannot open "); Console.String(path); Console.Ln
|
Out.String("ocat: cannot open "); Out.String(path); Out.Ln
|
||||||
END ;
|
END ;
|
||||||
INC(i); path := "";
|
INC(i); path := "";
|
||||||
Args.Get(i, path)
|
Args.Get(i, path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue