diff --git a/lang/m2/libm2/Termcap.def b/lang/m2/libm2/Termcap.def index 8b4c59eaa..b999f4f57 100644 --- a/lang/m2/libm2/Termcap.def +++ b/lang/m2/libm2/Termcap.def @@ -14,19 +14,18 @@ that are explicit in the C-version, are hidden. These buffers are initialized by a call to Tgetent. The "ARRAY OF CHAR" parameters must be null-terminated. You can call them with a constant string argument, as these are always - null-terminated in our Modula-2 implementation. Also, the strings returned - by these routines are null-terminated. + null-terminated in our Modula-2 implementation. + Unlike the C version, this version takes care of UP, BC, and PC + automatically. Only ospeed must still be set by the user. *) DEFINITION MODULE Termcap; - TYPE STR = ARRAY[1..32] OF CHAR; - PTSTR = POINTER TO STR; + TYPE STRCAP; PUTPROC = PROCEDURE(CHAR); - VAR UP, BC: PTSTR; (* must be null-terminated *) + VAR ospeed: INTEGER; (* see termcap(3), tty(4) *) - PC: CHAR; (* is initially 0C *) PROCEDURE Tgetent(name: ARRAY OF CHAR) : INTEGER; @@ -34,12 +33,12 @@ DEFINITION MODULE Termcap; PROCEDURE Tgetflag(id: ARRAY OF CHAR): BOOLEAN; - PROCEDURE Tgoto(cm: PTSTR; col, line: INTEGER): PTSTR; + PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP; (* Result exists until next call to Tgoto *) - PROCEDURE Tgetstr(id: ARRAY OF CHAR): PTSTR; + PROCEDURE Tgetstr(id: ARRAY OF CHAR): STRCAP; (* Result exists until next call to Tgetent *) - PROCEDURE Tputs(cp: PTSTR; affcnt: INTEGER; p: PUTPROC); + PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC); END Termcap. diff --git a/lang/m2/libm2/Termcap.mod b/lang/m2/libm2/Termcap.mod index fd0751e20..d3d58bfb4 100644 --- a/lang/m2/libm2/Termcap.mod +++ b/lang/m2/libm2/Termcap.mod @@ -15,7 +15,12 @@ IMPLEMENTATION MODULE Termcap; IMPORT XXTermcap; FROM SYSTEM IMPORT ADR, ADDRESS; + TYPE STR = ARRAY[1..32] OF CHAR; + STRCAP = POINTER TO STR; + VAR Buf, Buf1 : ARRAY [1..1024] OF CHAR; + UP, BC: STRCAP; + PC: CHAR; Initialized: BOOLEAN; BufCnt : INTEGER; @@ -23,10 +28,17 @@ IMPLEMENTATION MODULE Termcap; VAR i: INTEGER; BEGIN i := XXTermcap.tgetent(ADR(Buf), ADR(name)); - IF i > 0 THEN - Initialized := TRUE - END; BufCnt := 1; + IF i > 0 THEN + Initialized := TRUE; + UP := Tgetstr("pc"); + IF UP # NIL THEN + PC := UP^[1]; + ELSE PC := 0C; + END; + UP := Tgetstr("up"); + BC := Tgetstr("bc"); + END; RETURN i; END Tgetent; @@ -46,14 +58,14 @@ IMPLEMENTATION MODULE Termcap; RETURN XXTermcap.tgetflag(ADR(id)) = 1; END Tgetflag; - PROCEDURE Tgoto(cm: PTSTR; col, line: INTEGER): PTSTR; + PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP; BEGIN XXTermcap.UP := UP; XXTermcap.BC := BC; RETURN XXTermcap.tgoto(cm, col, line); END Tgoto; - PROCEDURE Tgetstr(id: ARRAY OF CHAR): PTSTR; + PROCEDURE Tgetstr(id: ARRAY OF CHAR): STRCAP; VAR a, a2: ADDRESS; b: CARDINAL; BEGIN @@ -70,7 +82,7 @@ IMPLEMENTATION MODULE Termcap; RETURN a2; END Tgetstr; - PROCEDURE Tputs(cp: PTSTR; affcnt: INTEGER; p: PUTPROC); + PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC); BEGIN XXTermcap.PC := PC; XXTermcap.ospeed := ospeed; @@ -79,5 +91,4 @@ IMPLEMENTATION MODULE Termcap; BEGIN Initialized := FALSE; - PC := 0C; END Termcap.