Debian Codegraph @

vt52.c

raw
1 /* $Id: vt52.c,v 1.26 2024/12/06 09:29:28 tom Exp $ */
2
3 #include <vttest.h>
4 #include <ttymodes.h>
5 #include <esc.h>
6
7 static int
8 testing(const char *name, int row)
9 {
10 char buffer[1024];
11
12 sprintf(buffer,
13 "Testing %s. "
14 "A real VT%d will not recognize %s at this point",
15 name, terminal_id(), name);
16 println(buffer);
17 return row + 1;
18 }
19
20 static int
21 isreturn(const char *reply)
22 {
23 return (*reply == '\r' || *reply == '\n');
24 }
25
26 int
27 tst_vt52(MENU_ARGS)
28 {
29 /* *INDENT-OFF* */
30 static struct {
31 const char *rcode;
32 const char *rmsg;
33 } resptable[] = {
34 { "\033/A", " -- OK (VT50)" },
35 { "\033/C", " -- OK (VT55)" },
36 { "\033/H", " -- OK (VT50H without copier)" },
37 { "\033/J", " -- OK (VT50H with copier)" },
38 { "\033/K", " -- OK (means Standard VT52)" },
39 { "\033/L", " -- OK (VT52 with copier)" },
40 { "\033/Z", " -- OK (means VT100 emulating VT52)" },
41 { "", " -- Unknown response"}
42 };
43 /* *INDENT-ON* */
44
45 int i, j;
46 int box_r = 71;
47 char *response;
48 VTLEVEL save;
49
50 save_level(&save);
51 set_level(0); /* Reset ANSI (VT100) mode, Set VT52 mode */
52 vt52home(); /* Cursor home */
53 vt52ed(); /* Erase to end of screen */
54 vt52home(); /* Cursor home */
55 for (i = 0; i <= max_lines - 1; i++) {
56 for (j = 0; j <= 9; j++)
57 tprintf("%s", "FooBar ");
58 println("Bletch");
59 }
60 vt52home(); /* Cursor home */
61 vt52ed(); /* Erase to end of screen */
62
63 vt52cup(7, 47);
64 tprintf("nothing more.");
65 for (i = 1; i <= 10; i++)
66 tprintf("THIS SHOULD GO AWAY! ");
67 for (i = 1; i <= 5; i++) {
68 vt52cup(1, 1);
69 tprintf("%s", "Back scroll (this should go away)");
70 vt52ri(); /* Reverse LineFeed (with backscroll!) */
71 }
72 vt52cup(12, 60);
73 vt52ed(); /* Erase to end of screen */
74 for (i = 2; i <= 6; i++) {
75 vt52cup(i, 1);
76 vt52el(); /* Erase to end of line */
77 }
78 /*
79 * Draw some text that we do not want to display.
80 */
81 for (i = 2; i <= max_lines - 1; i++) {
82 vt52cup(i, 70);
83 tprintf("%s", "**Foobar");
84 }
85 /*
86 * Draw the left side of the box, going from bottom to top.
87 */
88 vt52cup(max_lines - 1, 10);
89 for (i = max_lines - 1; i >= 2; i--) {
90 tprintf("%s", "*");
91 tprintf("%c", 8); /* BS */
92 vt52ri(); /* Reverse LineFeed (LineStarve) */
93 }
94 /*
95 * Draw the top of the box, going from right to left.
96 * Make the movement a little more complicated by using cursor-addressing
97 * which is out of bounds vertically so that only the column is updated.
98 */
99 vt52cup(1, 70);
100 for (i = 70; i >= 10; i--) {
101 tprintf("%s", "*");
102 vt52cub1();
103 if (i % 2)
104 vt52cup(max_lines + 3, i - 1);
105 else
106 vt52cub1(); /* Cursor Left */
107 }
108 /*
109 * Draw the bottom of the box, going from left to right.
110 */
111 vt52cup(max_lines, 10);
112 for (i = 10; i <= 70; i++) {
113 tprintf("%s", "*");
114 tprintf("%c", 8); /* BS */
115 vt52cuf1(); /* Cursor Right */
116 }
117 /*
118 * Draw a column of "!" inside the left edge of the box.
119 */
120 vt52cup(2, 11);
121 for (i = 2; i <= max_lines - 1; i++) {
122 tprintf("%s", "!");
123 tprintf("%c", 8); /* BS */
124 vt52cud1(); /* Cursor Down */
125 }
126 /*
127 * Draw a column of "!" inside the right edge of the box.
128 */
129 vt52cup(max_lines - 1, 69);
130 for (i = max_lines - 1; i >= 2; i--) {
131 tprintf("%s", "!");
132 tprintf("%c", 8); /* BS */
133 vt52cuu1(); /* Cursor Up */
134 }
135 /*
136 * Erase the "*FooBar" on the right-side of the box, leaving just "*".
137 * A real VT52 would leave a ragged right-margin; VT100 emulating VT52 won't.
138 */
139 vt52cuf1(); /* Cursor Right */
140 vt52cuf1(); /* Cursor Right */
141 for (i = 2; i <= max_lines - 1; i++) {
142 int adj = i % 3;
143 if (adj) {
144 vt52cup(i, min_cols + 1 + adj); /* past right-margin of row i */
145 } else
146 vt52cup(i, box_r);
147 vt52el(); /* Erase to end of line */
148 }
149
150 vt52cup(10, 16);
151 printxx("%s", "The screen should be cleared, and have a centered");
152 vt52cup(11, 16);
153 printxx("%s", "rectangle of \"*\"s with \"!\"s on the inside to the");
154 vt52cup(12, 16);
155 printxx("%s", "left and right. Only this, and");
156 vt52cup(13, 16);
157 holdit();
158
159 vt52home(); /* Cursor home */
160 vt52ed(); /* Erase to end of screen */
161 printxx("%s", "This is the normal character set:");
162 for (j = 0; j <= 1; j++) {
163 vt52cup(3 + j, 16);
164 for (i = 0; i <= 47; i++)
165 tprintf("%c", 32 + i + 48 * j);
166 }
167 vt52cup(6, 1);
168 printxx("%s", "This is the special graphics character set:");
169 esc("F"); /* Select Special Graphics character set */
170 for (j = 0; j <= 1; j++) {
171 vt52cup(8 + j, 16);
172 for (i = 0; i <= 47; i++)
173 tprintf("%c", 32 + i + 48 * j);
174 }
175 esc("G"); /* Select ASCII character set */
176 vt52cup(12, 1);
177 holdit();
178
179 vt52home(); /* Cursor home */
180 vt52ed(); /* Erase to end of screen */
181 println("Test of terminal response to IDENTIFY command");
182
183 /*
184 * According to J.Altman, DECID isn't recognized by VT5xx terminals. Real
185 * DEC terminals through VT420 do, though it isn't recommended. VT420's
186 * emulation of VT52 does not recognize DA -- so we use DECID in this case.
187 */
188 set_tty_raw(TRUE);
189 decid(); /* Identify */
190 response = get_reply();
191 println("");
192
193 restore_level(&save);
194 restore_ttymodes();
195 padding(10); /* some terminals miss part of the response otherwise */
196
197 printxx("Response was ");
198 chrprint2(response, 2, 13);
199 for (i = 0; resptable[i].rcode[0] != '\0'; i++) {
200 if (!strcmp(response, resptable[i].rcode)) {
201 show_result("%s", resptable[i].rmsg);
202 break;
203 }
204 }
205 println("");
206 println("");
207
208 /*
209 * Verify whether returning to ANSI mode restores the previous operating
210 * level. If it was a VT220, we can check this by seeing if 8-bit controls
211 * work; if a VT420 we can check the value of DECSCL. A real VT420 goes to
212 * VT100 mode.
213 */
214 if (terminal_id() >= 200) {
215 int row, col;
216
217 row = 8;
218 set_level(0); /* Reset ANSI (VT100) mode, Set VT52 mode */
219 println("Verify operating level after restoring ANSI mode");
220 esc("<"); /* Enter ANSI mode (VT100 mode) */
221 set_tty_raw(TRUE);
222 if (save.cur_level >= 3) { /* VT340 implements DECRQSS */
223 vt_move(row, 1);
224 row = testing("DECSCL", row);
225 println("You should have to press return to continue:");
226 println("");
227 decrqss("\"p");
228 response = instr();
229 vt_move(++row, col = 10);
230 printxx("Response was");
231 chrprint2(response, row, col);
232 if (isreturn(response)) {
233 show_result(SHOW_SUCCESS);
234 } else {
235 if (parse_decrqss(response, "\"p") > 0)
236 printxx("DECSCL recognized --");
237 show_result(SHOW_FAILURE);
238 }
239 println("");
240 row++;
241 }
242
243 if (save.cur_level >= 2) {
244 const char *temp;
245
246 vt_move(++row, 1);
247 row = testing("S8C1T", row);
248 s8c1t(1);
249 cup(1, 1);
250 dsr(6);
251 response = instr();
252 vt_move(row, col = 10);
253 printxx("Response to CUP(1,1)/DSR(6)");
254 chrprint2(response, row, col);
255 if ((temp = skip_prefix(csi_input(), response)) != NULL) {
256 if (!strcmp("1;1R", temp)) {
257 printxx("S8C1T recognized --");
258 show_result(SHOW_FAILURE);
259 } else {
260 printxx("unknown response --");
261 show_result(SHOW_FAILURE);
262 }
263 } else {
264 input_8bits = FALSE; /* we expect this anyway */
265 if ((temp = skip_prefix(csi_input(), response)) != NULL
266 && !strcmp("1;1R", temp)) {
267 show_result(SHOW_SUCCESS);
268 } else {
269 printxx("unknown response --");
270 show_result(SHOW_FAILURE);
271 }
272 }
273 }
274 restore_level(&save);
275 restore_ttymodes();
276 println("");
277 println("");
278 }
279 return MENU_HOLD;
280 }