improved interface
This commit is contained in:
parent
9eb1f7a67b
commit
da11deeece
|
@ -15,8 +15,10 @@
|
||||||
by a call to Tgetent. The "ARRAY OF CHAR" parameters must be null-terminated.
|
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
|
You can call them with a constant string argument, as these are always
|
||||||
null-terminated in our Modula-2 implementation.
|
null-terminated in our Modula-2 implementation.
|
||||||
Unlike the C version, this version takes care of UP, BC, and PC
|
Unlike the C version, this version takes care of UP, BC, PC, and ospeed
|
||||||
automatically. Only ospeed must still be set by the user.
|
automatically.
|
||||||
|
If Tgetent is not called by the user, it is called by the module itself,
|
||||||
|
using the TERM environment variable, or "dumb" if TERM does not exist.
|
||||||
*)
|
*)
|
||||||
|
|
||||||
DEFINITION MODULE Termcap;
|
DEFINITION MODULE Termcap;
|
||||||
|
@ -24,9 +26,6 @@ DEFINITION MODULE Termcap;
|
||||||
TYPE STRCAP;
|
TYPE STRCAP;
|
||||||
PUTPROC = PROCEDURE(CHAR);
|
PUTPROC = PROCEDURE(CHAR);
|
||||||
|
|
||||||
VAR
|
|
||||||
ospeed: INTEGER; (* see termcap(3), tty(4) *)
|
|
||||||
|
|
||||||
PROCEDURE Tgetent(name: ARRAY OF CHAR) : INTEGER;
|
PROCEDURE Tgetent(name: ARRAY OF CHAR) : INTEGER;
|
||||||
|
|
||||||
PROCEDURE Tgetnum(id: ARRAY OF CHAR): INTEGER;
|
PROCEDURE Tgetnum(id: ARRAY OF CHAR): INTEGER;
|
||||||
|
@ -36,8 +35,10 @@ DEFINITION MODULE Termcap;
|
||||||
PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP;
|
PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP;
|
||||||
(* Result exists until next call to Tgoto *)
|
(* Result exists until next call to Tgoto *)
|
||||||
|
|
||||||
PROCEDURE Tgetstr(id: ARRAY OF CHAR): STRCAP;
|
PROCEDURE Tgetstr(id: ARRAY OF CHAR; VAR res: STRCAP) : BOOLEAN;
|
||||||
(* Result exists until next call to Tgetent *)
|
(* Returns FALSE if capability does not exist;
|
||||||
|
Result exists until next call to Tgetent.
|
||||||
|
*)
|
||||||
|
|
||||||
PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC);
|
PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC);
|
||||||
|
|
||||||
|
|
|
@ -14,81 +14,82 @@ IMPLEMENTATION MODULE Termcap;
|
||||||
|
|
||||||
IMPORT XXTermcap;
|
IMPORT XXTermcap;
|
||||||
FROM SYSTEM IMPORT ADR, ADDRESS;
|
FROM SYSTEM IMPORT ADR, ADDRESS;
|
||||||
|
FROM Unix IMPORT gtty;
|
||||||
|
FROM Arguments IMPORT GetEnv;
|
||||||
|
|
||||||
TYPE STR = ARRAY[1..32] OF CHAR;
|
TYPE STR = ARRAY[1..32] OF CHAR;
|
||||||
STRCAP = POINTER TO STR;
|
STRCAP = POINTER TO STR;
|
||||||
|
|
||||||
VAR Buf, Buf1 : ARRAY [1..1024] OF CHAR;
|
VAR Buf, Buf1 : ARRAY [1..1024] OF CHAR;
|
||||||
UP, BC: STRCAP;
|
|
||||||
PC: CHAR;
|
|
||||||
Initialized: BOOLEAN;
|
|
||||||
BufCnt : INTEGER;
|
BufCnt : INTEGER;
|
||||||
|
|
||||||
PROCEDURE Tgetent(name: ARRAY OF CHAR) : INTEGER;
|
PROCEDURE Tgetent(name: ARRAY OF CHAR) : INTEGER;
|
||||||
VAR i: INTEGER;
|
VAR i: INTEGER;
|
||||||
|
x: STRCAP;
|
||||||
|
sp: STR;
|
||||||
BEGIN
|
BEGIN
|
||||||
i := XXTermcap.tgetent(ADR(Buf), ADR(name));
|
i := XXTermcap.tgetent(ADR(Buf), ADR(name));
|
||||||
BufCnt := 1;
|
BufCnt := 1;
|
||||||
|
IF gtty(1, ADR(sp)) < 0 THEN
|
||||||
|
ELSE
|
||||||
|
XXTermcap.ospeed := ORD(sp[2]);
|
||||||
|
END;
|
||||||
IF i > 0 THEN
|
IF i > 0 THEN
|
||||||
Initialized := TRUE;
|
IF Tgetstr("pc", x) THEN
|
||||||
UP := Tgetstr("pc");
|
XXTermcap.PC := x^[1];
|
||||||
IF UP # NIL THEN
|
ELSE XXTermcap.PC := 0C;
|
||||||
PC := UP^[1];
|
|
||||||
ELSE PC := 0C;
|
|
||||||
END;
|
END;
|
||||||
UP := Tgetstr("up");
|
IF Tgetstr("up", x) THEN ; END; XXTermcap.UP := x;
|
||||||
BC := Tgetstr("bc");
|
IF Tgetstr("bc", x) THEN ; END; XXTermcap.BC := x;
|
||||||
END;
|
END;
|
||||||
RETURN i;
|
RETURN i;
|
||||||
END Tgetent;
|
END Tgetent;
|
||||||
|
|
||||||
PROCEDURE Tgetnum(id: ARRAY OF CHAR): INTEGER;
|
PROCEDURE Tgetnum(id: ARRAY OF CHAR): INTEGER;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NOT Initialized THEN
|
|
||||||
RETURN -1;
|
|
||||||
END;
|
|
||||||
RETURN XXTermcap.tgetnum(ADR(id));
|
RETURN XXTermcap.tgetnum(ADR(id));
|
||||||
END Tgetnum;
|
END Tgetnum;
|
||||||
|
|
||||||
PROCEDURE Tgetflag(id: ARRAY OF CHAR): BOOLEAN;
|
PROCEDURE Tgetflag(id: ARRAY OF CHAR): BOOLEAN;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NOT Initialized THEN
|
|
||||||
RETURN FALSE;
|
|
||||||
END;
|
|
||||||
RETURN XXTermcap.tgetflag(ADR(id)) = 1;
|
RETURN XXTermcap.tgetflag(ADR(id)) = 1;
|
||||||
END Tgetflag;
|
END Tgetflag;
|
||||||
|
|
||||||
PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP;
|
PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP;
|
||||||
BEGIN
|
BEGIN
|
||||||
XXTermcap.UP := UP;
|
|
||||||
XXTermcap.BC := BC;
|
|
||||||
RETURN XXTermcap.tgoto(cm, col, line);
|
RETURN XXTermcap.tgoto(cm, col, line);
|
||||||
END Tgoto;
|
END Tgoto;
|
||||||
|
|
||||||
PROCEDURE Tgetstr(id: ARRAY OF CHAR): STRCAP;
|
PROCEDURE Tgetstr(id: ARRAY OF CHAR; VAR res: STRCAP) : BOOLEAN;
|
||||||
VAR a, a2: ADDRESS;
|
VAR a, a2: ADDRESS;
|
||||||
b: CARDINAL;
|
b: CARDINAL;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NOT Initialized THEN
|
|
||||||
RETURN NIL;
|
|
||||||
END;
|
|
||||||
a := ADR(Buf1[BufCnt]);
|
a := ADR(Buf1[BufCnt]);
|
||||||
a2 := XXTermcap.tgetstr(ADR(id), ADR(a));
|
a2 := XXTermcap.tgetstr(ADR(id), ADR(a));
|
||||||
|
res := a2;
|
||||||
IF a2 = NIL THEN
|
IF a2 = NIL THEN
|
||||||
RETURN NIL;
|
RETURN FALSE;
|
||||||
END;
|
END;
|
||||||
b := a - a2;
|
b := a - a2;
|
||||||
INC(BufCnt, b);
|
INC(BufCnt, b);
|
||||||
RETURN a2;
|
RETURN TRUE;
|
||||||
END Tgetstr;
|
END Tgetstr;
|
||||||
|
|
||||||
PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC);
|
PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC);
|
||||||
BEGIN
|
BEGIN
|
||||||
XXTermcap.PC := PC;
|
|
||||||
XXTermcap.ospeed := ospeed;
|
|
||||||
XXTermcap.tputs(cp, affcnt, XXTermcap.PUTPROC(p));
|
XXTermcap.tputs(cp, affcnt, XXTermcap.PUTPROC(p));
|
||||||
END Tputs;
|
END Tputs;
|
||||||
|
|
||||||
|
PROCEDURE InitTermcap;
|
||||||
|
VAR Bf: STR;
|
||||||
|
BEGIN
|
||||||
|
IF GetEnv("TERM", Bf) = 0 THEN
|
||||||
|
Bf := "dumb";
|
||||||
|
END;
|
||||||
|
IF Tgetent(Bf) <= 0 THEN
|
||||||
|
END;
|
||||||
|
END InitTermcap;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
Initialized := FALSE;
|
InitTermcap;
|
||||||
END Termcap.
|
END Termcap.
|
||||||
|
|
Loading…
Reference in a new issue