[9] | 1 | (*
|
---|
| 2 | (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
---|
| 3 | See the copyright notice in the ACK home directory, in the file "Copyright".
|
---|
| 4 | *)
|
---|
| 5 |
|
---|
| 6 | (*
|
---|
| 7 | Module: Interface to termcap database
|
---|
| 8 | From: Unix manual chapter 3
|
---|
| 9 | Version: $Header: /cvsup/minix/src/lib/ack/libm2/Termcap.mod,v 1.1 2005/10/10 15:27:46 beng Exp $
|
---|
| 10 | *)
|
---|
| 11 |
|
---|
| 12 | (*$R-*)
|
---|
| 13 | IMPLEMENTATION MODULE Termcap;
|
---|
| 14 |
|
---|
| 15 | IMPORT XXTermcap;
|
---|
| 16 | FROM SYSTEM IMPORT ADR, ADDRESS;
|
---|
| 17 | FROM Unix IMPORT isatty;
|
---|
| 18 | FROM Arguments IMPORT
|
---|
| 19 | GetEnv;
|
---|
| 20 |
|
---|
| 21 | TYPE STR = ARRAY[1..32] OF CHAR;
|
---|
| 22 | STRCAP = POINTER TO STR;
|
---|
| 23 |
|
---|
| 24 | VAR Buf, Buf1 : ARRAY [1..1024] OF CHAR;
|
---|
| 25 | BufCnt : INTEGER;
|
---|
| 26 |
|
---|
| 27 | PROCEDURE Tgetent(name: ARRAY OF CHAR) : INTEGER;
|
---|
| 28 | VAR i: INTEGER;
|
---|
| 29 | x: STRCAP;
|
---|
| 30 | BEGIN
|
---|
| 31 | i := XXTermcap.tgetent(ADR(Buf), ADR(name));
|
---|
| 32 | BufCnt := 1;
|
---|
| 33 | IF isatty(1) THEN
|
---|
| 34 | ELSE
|
---|
| 35 | (* This used to be something returned by gtty(). To increase
|
---|
| 36 | * portability we forget about old terminals needing delays.
|
---|
| 37 | * (kjb)
|
---|
| 38 | *)
|
---|
| 39 | XXTermcap.ospeed := 0;
|
---|
| 40 | END;
|
---|
| 41 | IF i > 0 THEN
|
---|
| 42 | IF Tgetstr("pc", x) THEN
|
---|
| 43 | XXTermcap.PC := x^[1];
|
---|
| 44 | ELSE XXTermcap.PC := 0C;
|
---|
| 45 | END;
|
---|
| 46 | IF Tgetstr("up", x) THEN ; END; XXTermcap.UP := x;
|
---|
| 47 | IF Tgetstr("bc", x) THEN ; END; XXTermcap.BC := x;
|
---|
| 48 | END;
|
---|
| 49 | RETURN i;
|
---|
| 50 | END Tgetent;
|
---|
| 51 |
|
---|
| 52 | PROCEDURE Tgetnum(id: ARRAY OF CHAR): INTEGER;
|
---|
| 53 | BEGIN
|
---|
| 54 | RETURN XXTermcap.tgetnum(ADR(id));
|
---|
| 55 | END Tgetnum;
|
---|
| 56 |
|
---|
| 57 | PROCEDURE Tgetflag(id: ARRAY OF CHAR): BOOLEAN;
|
---|
| 58 | BEGIN
|
---|
| 59 | RETURN XXTermcap.tgetflag(ADR(id)) = 1;
|
---|
| 60 | END Tgetflag;
|
---|
| 61 |
|
---|
| 62 | PROCEDURE Tgoto(cm: STRCAP; col, line: INTEGER): STRCAP;
|
---|
| 63 | BEGIN
|
---|
| 64 | RETURN XXTermcap.tgoto(cm, col, line);
|
---|
| 65 | END Tgoto;
|
---|
| 66 |
|
---|
| 67 | PROCEDURE Tgetstr(id: ARRAY OF CHAR; VAR res: STRCAP) : BOOLEAN;
|
---|
| 68 | VAR a, a2: ADDRESS;
|
---|
| 69 | b: CARDINAL;
|
---|
| 70 | BEGIN
|
---|
| 71 | a := ADR(Buf1[BufCnt]);
|
---|
| 72 | a2 := XXTermcap.tgetstr(ADR(id), ADR(a));
|
---|
| 73 | res := a2;
|
---|
| 74 | IF a2 = NIL THEN
|
---|
| 75 | RETURN FALSE;
|
---|
| 76 | END;
|
---|
| 77 | b := a - a2;
|
---|
| 78 | INC(BufCnt, b);
|
---|
| 79 | RETURN TRUE;
|
---|
| 80 | END Tgetstr;
|
---|
| 81 |
|
---|
| 82 | PROCEDURE Tputs(cp: STRCAP; affcnt: INTEGER; p: PUTPROC);
|
---|
| 83 | BEGIN
|
---|
| 84 | XXTermcap.tputs(cp, affcnt, XXTermcap.PUTPROC(p));
|
---|
| 85 | END Tputs;
|
---|
| 86 |
|
---|
| 87 | PROCEDURE InitTermcap;
|
---|
| 88 | VAR Bf: STR;
|
---|
| 89 | BEGIN
|
---|
| 90 | IF GetEnv("TERM", Bf) = 0 THEN
|
---|
| 91 | Bf := "dumb";
|
---|
| 92 | END;
|
---|
| 93 | IF Tgetent(Bf) <= 0 THEN
|
---|
| 94 | END;
|
---|
| 95 | END InitTermcap;
|
---|
| 96 |
|
---|
| 97 | BEGIN
|
---|
| 98 | InitTermcap;
|
---|
| 99 | END Termcap.
|
---|