-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreports.c
653 lines (572 loc) · 17.3 KB
/
reports.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/* $Id: reports.c,v 1.57 2024/12/05 00:37:39 tom Exp $ */
#include <vttest.h>
#include <ttymodes.h>
#include <esc.h>
#include <ctype.h>
/* *INDENT-OFF* */
static
struct table {
int key;
const char *msg;
} paritytable[] = {
{ 1, "NONE" },
{ 4, "ODD" },
{ 5, "EVEN" },
{ -1, "" }
},nbitstable[] = {
{ 1, "8" },
{ 2, "7" },
{ -1,"" }
},speedtable[] = {
{ 0, "50" },
{ 8, "75" },
{ 16, "110" },
{ 24, "134.5"},
{ 32, "150" },
{ 40, "200" },
{ 48, "300" },
{ 56, "600" },
{ 64, "1200" },
{ 72, "1800" },
{ 80, "2000" },
{ 88, "2400" },
{ 96, "3600" },
{ 104, "4800" },
{ 112, "9600" },
{ 120, "19200" },
{ 128, "38400" },
{ -1, "" }
},operating_level[] = {
{ 6, "VT102" },
{ 12, "VT125" },
{ 61, "VT100 family" },
{ 62, "VT200 family" },
{ 63, "VT300 family" },
{ 64, "VT400 family" },
{ 65, "VT500 family" },
{ -1, "" }
},extensions[] = {
{ 1, "132 columns" }, /* vt400, vt382 */
{ 2, "printer port" }, /* vt400, vt382 */
{ 3, "ReGIS graphics" }, /* kermit */
{ 4, "Sixel graphics" }, /* vt382, kermit */
{ 5, "Katakana extension" }, /* vt382 */
{ 6, "selective erase" }, /* vt400, vt382 */
{ 7, "soft character set (DRCS)" }, /* vt400 */
{ 8, "user-defined keys (UDK)" }, /* vt400, vt382 */
{ 9, "national replacement character-sets" }, /* kermit */
{ 10, "Two-bytes Kanji" }, /* vt382 */
{ 11, "25th status line" }, /* ? */
{ 12, "Serbo-Croatian (SCS)" }, /* vt500 */
{ 13, "local editing mode" }, /* kermit */
{ 14, "8-bit architecture" }, /* ? */
{ 15, "DEC technical set" }, /* vt400, vt382 */
{ 16, "locator device port (ReGIS)" }, /* kermit */
{ 17, "terminal state reports" }, /* ? */
{ 18, "user windows" }, /* vt400 */
{ 19, "two sessions" }, /* vt400 */
{ 20, "APL" }, /* vt400? */
{ 21, "horizontal scrolling" }, /* vt400 */
{ 22, "color" }, /* vt500 */
{ 23, "Greek" }, /* vt500 */
{ 24, "Turkish" }, /* vt500 */
{ 25, "Arabic bilingual M1" }, /* vt400? */
{ 26, "Arabic bilingual M2" }, /* vt400? */
{ 27, "Arabic bilingual M3" }, /* vt400? */
{ 28, "rectangular editing" }, /* vt400 */
{ 29, "ANSI text locator" }, /* DXterm */
{ 30, "Hanzi" }, /* vt400? */
{ 32, "text macros" }, /* vt400? */
{ 33, "Hangul Hanja" }, /* vt400? */
{ 34, "Icelandic" }, /* vt400? */
{ 35, "Arabic bilingual TC" }, /* vt400? */
{ 36, "Arabic bilingual no TC" }, /* vt400? */
{ 36, "Arabic bilingual no TC" }, /* vt400? */
{ 37, "Thai" }, /* vt400? */
{ 38, "character outlining" }, /* vt400? */
{ 42, "ISO Latin-2" }, /* vt500 */
{ 44, "PC Term" }, /* vt500 */
{ 45, "soft key mapping" }, /* vt500 */
{ 46, "ASCII Terminal emulation (WYSE,TVI,...)" }, /* vt500 */
{ -1, "" }
};
/* *INDENT-ON* */
static int
legend(int n, const char *input, const char *word, const char *description)
{
int i;
size_t len = strlen(word);
char buf[BUF_SIZE];
for (i = 0; input[i] != 0; i++) {
if ((i == 0 || !isalpha(CharOf(input[i - 1])))
&& !strncmp(word, input + i, len)) {
sprintf(buf, "%-8s %-3s = %s", n ? "" : "Legend:", word, description);
show_result("%s", buf);
putchar('\n');
return n + 1;
}
}
return n;
}
static const char *
lookup(struct table t[], int k)
{
int i;
for (i = 0; t[i].key != -1; i++) {
if (t[i].key == k)
return (t[i].msg);
}
return ("BAD VALUE");
}
static void
report_is(const char *report, int row, int col)
{
const char *tag = "Report is:";
vt_move(row, col);
vt_el(0);
tprintf("%s", tag);
chrprint2(report, row, col + (int) strlen(tag));
}
/******************************************************************************/
static int
tst_DA(MENU_ARGS)
{
int found;
const char *report, *cmp;
/* *INDENT-OFF* */
static const char *attributes[][2] = { /* after CSI */
{ "?1;0c", "No options (vanilla VT100)" },
{ "?1;1c", "VT100 with STP" },
{ "?1;2c", "VT100 with AVO (could be a VT102)" },
{ "?1;3c", "VT100 with STP and AVO" },
{ "?1;4c", "VT100 with GPO" },
{ "?1;5c", "VT100 with STP and GPO" },
{ "?1;6c", "VT100 with AVO and GPO" },
{ "?1;7c", "VT100 with STP, AVO and GPO" },
{ "?1;11c", "VT100 with PP and AVO" },
{ "?1;15c", "VT100 with PP, GPO and AVO" },
{ "?2c", "VT102" },
{ "?4;2c", "VT132 with AVO" },
{ "?4;3c", "VT132 with AVO and STP" },
{ "?4;6c", "VT132 with GPO and AVO" },
{ "?4;7c", "VT132 with GPO, AVO, and STP" },
{ "?4;11c", "VT132 with PP and AVO" },
{ "?4;15c", "VT132 with PP, GPO and AVO" },
{ "?6c", "VT102" },
{ "?7c", "VT131" },
{ "?12;5c", "VT125" }, /* VT125 also has ROM version */
{ "?12;7c", "VT125 with AVO" }, /* number, so this won't work */
{ "?5;0c", "VK100 (GIGI)" },
{ "?5c", "VK100 (GIGI)" },
{ "?62;1;2;4;6;8;9;15c", "VT220" },
{ "?63;1;2;8;9c", "VT320" },
{ "?63;1;2;4;6;8;9;15c", "VT320" },
{ "?63;1;3;4;6;8;9;15;16;29c", "DXterm" },
{ "", "" }
};
/* *INDENT-ON* */
vt_move(1, 1);
println("Test of Device Attributes report (what are you)");
set_tty_raw(TRUE);
da();
report = get_reply();
report_is(report, 3, 1);
found = FALSE;
if ((cmp = skip_csi_2(report)) != NULL) {
int i;
for (i = 0; *attributes[i][0] != '\0'; i++) {
if (!strcmp(cmp, attributes[i][0])) {
int n = 0;
show_result(" -- means %s", attributes[i][1]);
putchar('\n');
n = legend(n, attributes[i][1], "STP", "Processor Option");
n = legend(n, attributes[i][1], "AVO", "Advanced Video Option");
n = legend(n, attributes[i][1], "GPO", "Graphics Processor Option");
(void) legend(n, attributes[i][1], "PP", "Printer Port");
found = TRUE;
break;
}
}
}
if (!found) { /* this could be a vt200+ with some options disabled */
if (cmp != NULL && *cmp == '?') {
int reportpos = 1;
int value = scan_DA(cmp, &reportpos);
show_result("%s\n", lookup(operating_level, value));
putchar('\n');
if (value == 12) {
if ((value = scan_DA(cmp, &reportpos)) >= 0) {
fputs(" ", stdout);
switch (value) {
case 2:
show_result("no STP, AVO, no GPO (ReGIS)");
break;
case 3:
show_result("no STP, AVO, GPO (ReGIS)");
break;
case 5:
show_result("no AVO");
break;
case 7:
show_result("with AVO");
break;
default:
printxx("unknown code %d", value);
break;
}
putchar('\n');
}
if ((value = scan_DA(cmp, &reportpos)) >= 0) {
fputs(" ", stdout);
switch (value) {
case 0:
show_result("no printer");
break;
case 1:
show_result("with printer");
break;
default:
printxx("unknown code %d", value);
break;
}
putchar('\n');
}
if ((value = scan_DA(cmp, &reportpos)) >= 0) {
tprintf(" ROM version %d", value);
putchar('\n');
}
} else {
while ((value = scan_DA(cmp, &reportpos)) >= 0) {
fputs(" ", stdout);
show_result("%d = %s\n", value, lookup(extensions, value));
putchar('\n');
}
}
found = TRUE;
}
}
if (!found)
show_result(" -- Unknown response, refer to the manual");
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/*
* Applies to VT220 & up (probably no VT100's).
* Expected reply (from VT420 manual):
* CSI > 4 1 ; Pv ; 0 c (Pv = firmware version)
* From kermit:
* CSI > 2 4 ; Pv ; 0 c (Pv = "0 ; 0 ; 0", for "0.0")
* I've seen also:
* CSI > 8 3 ; Pv ; 0 c (e.g., Pv = "3 0 7 0 1")
*/
static int
tst_DA_2(MENU_ARGS)
{
int row, col;
/* *INDENT-OFF* */
static const struct {
int Pp;
const char *name;
} tbl[] = {
{ 1, "VT220" },
{ 2, "VT240" },
{ 18, "VT330" },
{ 19, "VT340" },
{ 24, "VT320" },
{ 32, "VT382" }, /* EK-VT382-RM-001, page 11-5 */
{ 48, "VT382" }, /* EK-VT38T-UG-001, page C-40 */
{ 28, "DECterm" },
{ 41, "VT420" },
{ 61, "VT510" },
{ 64, "VT520" },
{ 65, "VT525" },
};
/* *INDENT-ON* */
char *report;
int Pp, Pv, Pc;
char ch;
const char *show = SHOW_FAILURE;
vt_move(1, 1);
println("Testing Secondary Device Attributes (Firmware version)");
set_tty_raw(TRUE);
do_csi(">c"); /* or "CSI > 0 c" */
report = get_reply();
vt_move(row = 3, col = 10);
chrprint2(report, row, col);
if ((report = skip_csi(report)) != NULL) {
if (sscanf(report, ">%d;%d;%d%c", &Pp, &Pv, &Pc, &ch) == 4
&& ch == 'c') {
const char *name = "unknown";
size_t n;
show = SHOW_SUCCESS;
for (n = 0; n < TABLESIZE(tbl); n++) {
if (Pp == tbl[n].Pp) {
name = tbl[n].name;
break;
}
}
vt_move(4, 10);
printxx("Pp=%d (%s)", Pp, name);
vt_move(5, 10);
printxx("Pv=%d, firmware version %d.%d", Pv, Pv / 10, Pv % 10);
vt_move(6, 10);
switch (Pp) {
case 64:
case 65:
printxx("Pc=%d, %s keyboard", Pc, Pc ? "PC" : "VT");
break;
default:
printxx("Pc=%d, ROM cartridge registration number", Pc);
break;
}
}
}
show_result("%s", show);
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/*
* VT400 (reply is a hexadecimal string)
*/
static int
tst_DA_3(MENU_ARGS)
{
int row, col;
char *report;
const char *show;
vt_move(1, 1);
println("Testing Tertiary Device Attributes (unit ID)");
set_tty_raw(TRUE);
do_csi("=c"); /* or "CSI = 0 c" */
report = get_reply();
vt_move(row = 3, col = 10);
chrprint2(report, row, col);
show = SHOW_FAILURE;
if (report == NULL || *report == '\0') {
if (get_level() < 4) /* vt420 and up support this */
show = "not supported";
} else {
char *content;
if ((content = skip_dcs(report)) != NULL
&& strip_terminator(content) != 0
&& *content++ == '!'
&& *content++ == '|'
&& strlen(content) != 0) {
char *check;
if (strlen(content) == 8) {
(void) strtol(content, &check, 16);
if (*check == '\0')
show = SHOW_SUCCESS;
}
}
}
show_result("%s", show);
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/* Not supported above VT320 */
static int
tst_DECREQTPARM(MENU_ARGS)
{
char *report, *report2, *cmp;
set_tty_raw(TRUE);
set_tty_echo(FALSE);
vt_move(2, 1);
println("Test of the \"Request Terminal Parameters\" feature, argument 0.");
vt_move(3, 1);
decreqtparm(0);
report = get_reply();
report_is(report, 5, 1);
if ((cmp = skip_csi(report)) != NULL)
report = cmp;
if (strlen(report) < 14
|| report[0] != '2'
|| report[1] != ';')
println(" -- Bad format");
else {
int reportpos = 2;
/* *INDENT-EQLS* */
int parity = scanto(report, &reportpos, ';');
int nbits = scanto(report, &reportpos, ';');
int xspeed = scanto(report, &reportpos, ';');
int rspeed = scanto(report, &reportpos, ';');
int clkmul = scanto(report, &reportpos, ';');
int flags = scanto(report, &reportpos, 'x');
if (parity <= 0 || nbits <= 0 || clkmul <= 0)
println(" -- Bad format");
else
println(" -- OK");
show_result(
"This means: Parity %s, %s bits, xmitspeed %s, recvspeed %s.\n",
lookup(paritytable, parity),
lookup(nbitstable, nbits),
lookup(speedtable, xspeed),
lookup(speedtable, rspeed));
show_result("(CLoCk MULtiplier = %d, STP option flags = %d)\n", clkmul, flags);
}
vt_move(10, 1);
println("Test of the \"Request Terminal Parameters\" feature, argument 1.");
vt_move(11, 1);
decreqtparm(1); /* Does the same as decreqtparm(0), reports "3" */
report2 = get_reply();
report_is(report2, 13, 1);
if ((cmp = skip_csi(report2)) != NULL)
report2 = cmp;
if (strlen(report2) < 1
|| report2[0] != '3')
println(" -- Bad format");
else {
report2[0] = '2';
if (!strcmp(report, report2))
println(" -- OK");
else
println(" -- Bad format");
}
vt_move(max_lines, 1);
restore_ttymodes();
return MENU_HOLD;
}
static int
tst_DSR(MENU_ARGS)
{
int found;
int origin;
int row, col;
char *report;
const char *cmp;
set_tty_raw(TRUE);
vt_move(1, 1);
printxx("Test of Device Status Report 5 (report terminal status).");
vt_move(row = 2, col = 1);
dsr(5);
report = get_reply();
report_is(report, row, col);
if ((cmp = skip_csi(report)) != NULL)
found = !strcmp(cmp, "0n") || !strcmp(cmp, "3n");
else
found = 0;
if (found)
show_result(" -- means \"TERMINAL OK\"");
else
show_result(" -- Unknown response!");
vt_move(4, 1);
println("Test of Device Status Report 6 (report cursor position).");
for (origin = 0; origin < 2; ++origin) {
if (origin) {
sm("?6");
decstbm(4, max_lines - 6);
}
vt_move(row = 5, col = 1);
dsr(6);
report = get_reply();
report_is(report, row, col);
if ((cmp = skip_csi(report)) != NULL) {
found = (!strcmp(cmp, "5;1R")
? 1
: ((!strcmp(cmp, "8;1R") && origin)
? 2
: 0));
} else {
found = 0;
}
switch (found) {
case 2:
show_result(" -- Ignores origin mode");
break;
case 1:
show_result(" -- OK");
break;
default:
show_result(" -- Unknown response!");
break;
}
}
rm("?6");
decstbm(0, 0);
vt_move(max_lines - 1, 1);
restore_ttymodes();
return MENU_HOLD;
}
static int
tst_ENQ(MENU_ARGS)
{
int row, col;
const char *report;
vt_move(5, 1);
println("This is a test of the ANSWERBACK MESSAGE. (To load the A.B.M.");
println("see the TEST KEYBOARD part of this program). Below here, the");
println("current answerback message in your terminal should be");
println("displayed. Finish this test with RETURN.");
vt_move(10, 1);
set_tty_raw(TRUE);
set_tty_echo(FALSE);
inflush();
tprintf("%c", 5); /* ENQ */
report = get_reply();
vt_move(row = 10, col = 1);
chrprint2(report, row, col);
vt_move(12, 1);
restore_ttymodes();
return MENU_HOLD;
}
static int
tst_NLM(MENU_ARGS)
{
int row, col;
const char *report;
vt_move(1, 1);
println("Test of LineFeed/NewLine mode.");
vt_move(3, 1);
sm("20");
set_tty_crmod(FALSE);
tprintf("NewLine mode set. Push the RETURN key: ");
report = instr();
vt_move(row = 4, col = 1);
vt_el(0);
chrprint2(report, row, col);
if (!strcmp(report, "\015\012"))
show_result(" -- OK");
else
show_result(" -- Not expected");
vt_move(6, 1);
rm("20");
tprintf("NewLine mode reset. Push the RETURN key: ");
report = instr();
vt_move(row = 7, col = 1);
vt_el(0);
chrprint2(report, row, col);
if (!strcmp(report, "\015"))
show_result(" -- OK");
else
show_result(" -- Not expected");
vt_move(9, 1);
restore_ttymodes();
return MENU_HOLD;
}
/******************************************************************************/
int
tst_reports(MENU_ARGS)
{
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", NULL },
{ "<ENQ> (AnswerBack Message)", tst_ENQ },
{ "Set/Reset Mode - LineFeed / Newline", tst_NLM },
{ "Device Status Report (DSR) VT100 & up", tst_DSR },
{ "Primary Device Attributes (DA) VT100 & up", tst_DA },
{ "Secondary Device Attributes (DA) VT220 & up", tst_DA_2 },
{ "Tertiary Device Attributes (DA) VT420", tst_DA_3 },
{ "Request Terminal Parameters (DECREQTPARM) VT100", tst_DECREQTPARM },
{ "", NULL }
};
/* *INDENT-ON* */
do {
vt_clear(2);
__(title(0), printxx("Terminal Reports/Responses"));
__(title(2), println("Choose test type:"));
} while (menu(my_menu));
return MENU_NOHOLD;
}