1 #include <stdio.h>
2
3 char *CL, *CM, *CS, *SR;
4 int CO, LI, AM, XN;
5
6 char *tgetstr(), *getenv();
7 void PutStr(), CPutStr(), CCPutStr(), GotoPos(), RETURN();
8
main()9 main()
10 {
11 char *term, *s;
12 char tcbuf[1024];
13 char tcstr[1024], *tp;
14
15 if ((term = getenv("TERM")) == 0)
16 {
17 fprintf(stderr, "No $TERM set\n");
18 exit(1);
19 }
20 switch (tgetent(tcbuf, term))
21 {
22 case -1:
23 fprintf(stderr, "Could not open termcap file\n");
24 exit(1);
25 case 0:
26 fprintf(stderr, "I don't know what a '%s' terminal is.\n", term);
27 exit(1);
28 }
29 tp = tcstr;
30 if ((CL = tgetstr("cl", &tp)) == 0)
31 {
32 fprintf(stderr, "cl capability required\n");
33 exit(1);
34 }
35 if ((CM = tgetstr("cm", &tp)) == 0)
36 {
37 fprintf(stderr, "cm capability required\n");
38 exit(1);
39 }
40
41 if ((s = getenv("COLUMNS")))
42 CO = atoi(s);
43 if ((s = getenv("LINES")))
44 LI = atoi(s);
45 if (CO == 0)
46 CO = tgetnum("co");
47 if (LI == 0)
48 LI = tgetnum("li");
49 if (CO == 0)
50 CO = 80;
51 if (LI == 0)
52 LI = 24;
53 GotoPos(5, 1);
54 printf("******* cl capability does not work !!! *******");
55 GotoPos(5, 2);
56 PutStr(CL);
57 printf("******* cl capability does not home cursor *******");
58 GotoPos(0, 0);
59 printf(" ");
60 GotoPos(5, 4);
61 printf("******* cm capability does not work !!! *******");
62 GotoPos(5, 4);
63 printf(" ");
64 GotoPos(CO/2-12, LI/2);
65 printf("Your terminal size is");
66 GotoPos(CO/2-3, LI/2+1);
67 printf("%dx%d", CO, LI);
68 GotoPos(CO/2-2, 0);
69 printf("top");
70 GotoPos(CO/2-3, LI-1);
71 printf("bottom");
72 GotoPos(0, LI/2-2);printf("l");
73 GotoPos(0, LI/2-1);printf("e");
74 GotoPos(0, LI/2+0);printf("f");
75 GotoPos(0, LI/2+1);printf("t");
76 GotoPos(CO-1, LI/2-2);printf("r");
77 GotoPos(CO-1, LI/2-1);printf("i");
78 GotoPos(CO-1, LI/2+0);printf("g");
79 GotoPos(CO-1, LI/2+1);printf("h");
80 GotoPos(CO-1, LI/2+2);printf("t");
81 GotoPos(CO/2-15, LI/2+3);
82 RETURN();
83 AM = tgetflag("am");
84 printf("Termcap: terminal does %sauto-wrap", AM ? "" : "not ");
85 GotoPos(0, 5);
86 if (AM)
87 {
88 printf(" am capability set, but terminal does not wrap");
89 GotoPos(CO-1, 3);
90 }
91 else
92 {
93 printf(" am capability not set, but terminal does wrap");
94 GotoPos(CO-1, 4);
95 }
96 printf(" \n ");
97 GotoPos(0, 10);
98 RETURN();
99 if (AM)
100 {
101 XN = tgetflag("xn");
102 printf("Termcap: terminal has %smagic margins", XN ? "" : "no ");
103 GotoPos(0, 5);
104 if ((XN = tgetflag("xn")))
105 {
106 printf(" xn capability set, but terminal has no magic-margins");
107 GotoPos(CO-1, 4);
108 }
109 else
110 {
111 printf(" xn capability not set, but terminal has magic-margins");
112 GotoPos(CO-1, 3);
113 }
114 printf(" \n");
115 printf(" ");
116 GotoPos(0, 10);
117 RETURN();
118 if (XN)
119 {
120 GotoPos(0, 6);
121 printf(" last col in last row is not usable");
122 GotoPos(CO-1, LI-1);
123 printf(" ");
124 GotoPos(0, 6);
125 printf(" ");
126 GotoPos(0, 0);
127 printf("testing magic margins in last row");
128 GotoPos(0, 10);
129 RETURN();
130 }
131 }
132 if ((CS = tgetstr("cs", &tp)))
133 {
134 printf("Termcap: terminal has scrollregions");
135 GotoPos(0, 5);
136 printf(" cs capability set, but doesn't work");
137 CCPutStr(CS, 4, 5);
138 GotoPos(0, 5);
139 printf("\n\n");
140 CCPutStr(CS, 0, LI-1);
141 GotoPos(0, 10);
142 RETURN();
143 }
144 if ((SR = tgetstr("sr", &tp)))
145 {
146 GotoPos(0, 5);
147 printf(" sr capability set, but doesn't work");
148 GotoPos(0, 0);
149 PutStr(SR);
150 GotoPos(0, 6);
151 printf(" ");
152 GotoPos(0, 0);
153 printf("Termcap: terminal can scroll backwards");
154 GotoPos(0, 10);
155 RETURN();
156 }
157 }
158
159 void
putcha(c)160 putcha(c)
161 char c;
162 {
163 putchar(c);
164 }
165
166 void
PutStr(s)167 PutStr(s)
168 char *s;
169 {
170 tputs(s, 1, putcha);
171 fflush(stdout);
172 }
173
174 #ifndef __FreeBSD__
CPutStr(s,c)175 void CPutStr(s, c)
176 char *s;
177 int c;
178 {
179 tputs(tgoto(s, 0, c), 1, putcha);
180 fflush(stdout);
181 }
182 #endif /* __FreeBSD__ */
183
CCPutStr(s,x,y)184 void CCPutStr(s, x, y)
185 char *s;
186 int x, y;
187 {
188 tputs(tgoto(s, y, x), 1, putcha);
189 fflush(stdout);
190 }
191
GotoPos(x,y)192 void GotoPos(x,y)
193 int x,y;
194 {
195 tputs(tgoto(CM, x, y), 1, putcha);
196 fflush(stdout);
197 }
198
199 void
RETURN()200 RETURN()
201 {
202 printf("Press <RETURN> to continue");
203 fflush(stdout);
204 while(getchar() != '\n');
205 PutStr(CL);
206 }
207