995
|
1 #include <stdio.h>
|
|
2 #include "ueed.h"
|
|
3
|
|
4 #ifdef TERMCAP
|
|
5
|
|
6 #define NROW 24
|
|
7 #define NCOL 80
|
|
8 #define BEL 0x07
|
|
9 #define ESC 0x1B
|
|
10
|
|
11
|
|
12 extern int ttopen();
|
|
13 extern int ttgetc();
|
|
14 extern int ttputc();
|
|
15 extern int ttflush();
|
|
16 extern int ttclose();
|
|
17 extern int tcapmove();
|
|
18 extern int tcapeeol();
|
|
19 extern int tcapeeop();
|
|
20 extern int tcapbeep();
|
|
21 extern int tcapopen();
|
|
22 extern int tput();
|
|
23 extern char *tgoto();
|
|
24
|
|
25 #define TCAPSLEN 315
|
|
26
|
|
27 char tcapbuf[TCAPSLEN];
|
|
28 char PC,
|
|
29 *CM,
|
|
30 *CL,
|
|
31 *CE,
|
|
32 *UP,
|
|
33 *CD;
|
|
34
|
|
35
|
|
36 TERM term = {
|
|
37 NROW-1,
|
|
38 NCOL,
|
|
39 &tcapopen,
|
|
40 &ttclose,
|
|
41 &ttgetc,
|
|
42 &ttputc,
|
|
43 &ttflush,
|
|
44 &tcapmove,
|
|
45 &tcapeeol,
|
|
46 &tcapeeop,
|
|
47 &tcapbeep
|
|
48 };
|
|
49
|
|
50 tcapopen()
|
|
51
|
|
52 {
|
|
53 char *getenv();
|
|
54 char *t, *p, *tgetstr();
|
|
55 char tcbuf[1024];
|
|
56 char *tv_stype;
|
|
57 char err_str[72];
|
|
58
|
|
59 if ((tv_stype = getenv("TERM")) == NULL)
|
|
60 {
|
|
61 puts("Environment variable TERM not defined!");
|
|
62 exit(1);
|
|
63 }
|
|
64
|
|
65 if((tgetent(tcbuf, tv_stype)) != 1)
|
|
66 {
|
|
67 sprintf(err_str, "Unknown terminal type %s!", tv_stype);
|
|
68 puts(err_str);
|
|
69 exit(1);
|
|
70 }
|
|
71
|
|
72 p = tcapbuf;
|
|
73 t = tgetstr("pc", &p);
|
|
74 if(t)
|
|
75 PC = *t;
|
|
76
|
|
77 CD = tgetstr("cd", &p);
|
|
78 CM = tgetstr("cm", &p);
|
|
79 CE = tgetstr("ce", &p);
|
|
80 UP = tgetstr("up", &p);
|
|
81
|
|
82 if(CD == NULL || CM == NULL || CE == NULL || UP == NULL)
|
|
83 {
|
|
84 puts("Incomplete termcap entry\n");
|
|
85 exit(1);
|
|
86 }
|
|
87
|
|
88 if (p >= &tcapbuf[TCAPSLEN])
|
|
89 {
|
|
90 puts("Terminal description too big!\n");
|
|
91 exit(1);
|
|
92 }
|
|
93 ttopen();
|
|
94 }
|
|
95 tcapmove(row, col)
|
|
96 register int row, col;
|
|
97 {
|
|
98 putpad(tgoto(CM, col, row));
|
|
99 }
|
|
100
|
|
101 tcapeeol()
|
|
102 {
|
|
103 putpad(CE);
|
|
104 }
|
|
105
|
|
106 tcapeeop()
|
|
107 {
|
|
108 putpad(CD);
|
|
109
|
|
110 }
|
|
111
|
|
112 tcapbeep()
|
|
113 {
|
|
114 ttputc(BEL);
|
|
115 }
|
|
116
|
|
117 putpad(str)
|
|
118 char *str;
|
|
119 {
|
|
120 tputs(str, 1, ttputc);
|
|
121 }
|
|
122
|
|
123 putnpad(str, n)
|
|
124 char *str;
|
|
125 {
|
|
126 tputs(str, n, ttputc);
|
|
127 }
|
|
128 #endif TERMCAP
|
|
129
|
|
130
|