Set title bas on the output found on the screen.
[screen-lua.git] / src / terminfo / checktc.c
blobccc9485c6b895137dd15ce2a3aecb8b85aeef92f
1 #include <stdio.h>
3 char *CL, *CM, *CS, *SR;
4 int CO, LI, AM, XN;
6 char *tgetstr(), *getenv();
7 void PutStr(), CPutStr(), CCPutStr(), GotoPos(), RETURN();
9 main()
11 char *term, *s;
12 char tcbuf[1024];
13 char tcstr[1024], *tp;
15 if ((term = getenv("TERM")) == 0)
17 fprintf(stderr, "No $TERM set\n");
18 exit(1);
20 switch (tgetent(tcbuf, term))
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);
29 tp = tcstr;
30 if ((CL = tgetstr("cl", &tp)) == 0)
32 fprintf(stderr, "cl capability required\n");
33 exit(1);
35 if ((CM = tgetstr("cm", &tp)) == 0)
37 fprintf(stderr, "cm capability required\n");
38 exit(1);
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)
88 printf(" am capability set, but terminal does not wrap");
89 GotoPos(CO-1, 3);
91 else
93 printf(" am capability not set, but terminal does wrap");
94 GotoPos(CO-1, 4);
96 printf(" \n ");
97 GotoPos(0, 10);
98 RETURN();
99 if (AM)
101 XN = tgetflag("xn");
102 printf("Termcap: terminal has %smagic margins", XN ? "" : "no ");
103 GotoPos(0, 5);
104 if ((XN = tgetflag("xn")))
106 printf(" xn capability set, but terminal has no magic-margins");
107 GotoPos(CO-1, 4);
109 else
111 printf(" xn capability not set, but terminal has magic-margins");
112 GotoPos(CO-1, 3);
114 printf(" \n");
115 printf(" ");
116 GotoPos(0, 10);
117 RETURN();
118 if (XN)
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();
132 if ((CS = tgetstr("cs", &tp)))
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();
144 if ((SR = tgetstr("sr", &tp)))
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();
159 void
160 putcha(c)
161 char c;
163 putchar(c);
166 void
167 PutStr(s)
168 char *s;
170 tputs(s, 1, putcha);
171 fflush(stdout);
174 void CPutStr(s, c)
175 char *s;
176 int c;
178 tputs(tgoto(s, 0, c), 1, putcha);
179 fflush(stdout);
182 void CCPutStr(s, x, y)
183 char *s;
184 int x, y;
186 tputs(tgoto(s, y, x), 1, putcha);
187 fflush(stdout);
190 void GotoPos(x,y)
191 int x,y;
193 tputs(tgoto(CM, x, y), 1, putcha);
194 fflush(stdout);
197 void
198 RETURN()
200 printf("Press <RETURN> to continue");
201 fflush(stdout);
202 while(getchar() != '\n');
203 PutStr(CL);