forked from ThomasDickey/vttest-snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvt320.c
1690 lines (1482 loc) · 43.7 KB
/
vt320.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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id: vt320.c,v 1.94 2023/12/30 01:25:54 tom Exp $ */
/*
* Reference: VT330/VT340 Programmer Reference Manual (EK-VT3XX-TP-001)
*/
#include <vttest.h>
#include <ttymodes.h>
#include <draw.h>
#include <esc.h>
static void
show_Locator_Status(char *report)
{
int pos = 0;
int code = scanto(report, &pos, 'n');
const char *show;
switch (code) {
case 53:
show = "No locator";
break;
case 50:
show = "Locator ready";
break;
case 58:
show = "Locator busy";
break;
default:
show = SHOW_FAILURE;
}
show_result("%s", show);
}
static void
show_Identify_Locator(char *report)
{
int pos = 0;
int Ps1 = scan_any(report, &pos, 'n');
int Ps2 = scanto(report, &pos, 'n');
const char *show = SHOW_FAILURE;
if (Ps1 == 57) {
switch (Ps2) {
case 0:
show = "Cannot identify locator";
break;
case 1:
show = "Locator is mouse";
break;
case 2:
show = "Locator is tablet";
break;
}
}
show_result("%s", show);
}
/*
* Though some people refer to the locator controls as "vt220", it appears in
* later terminals (documented in the vt330 manual, but introduced as in UWS).
*/
static int
tst_DSR_locator_status(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "?55n", show_Locator_Status);
}
static int
tst_DSR_identify_locator(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "?56n", show_Identify_Locator);
}
static void
show_ExtendedCursorPosition(char *report)
{
int pos = 0;
int Pl = scan_any(report, &pos, 'R');
int Pc = scan_any(report, &pos, 'R');
int Pp = scan_any(report, &pos, 'R');
if (Pl != 0 && Pc != 0) {
if (Pp != 0)
show_result("Line %d, Column %d, Page %d", Pl, Pc, Pp);
else
show_result("Line %d, Column %d (Page?)", Pl, Pc);
} else
show_result(SHOW_FAILURE);
}
/* vt340/vt420 & up */
int
tst_DSR_cursor(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "?6n", show_ExtendedCursorPosition);
}
/******************************************************************************/
int
tst_vt320_device_status(MENU_ARGS)
{
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Test VT220 features", tst_vt220_device_status },
{ "Test Keyboard Status", tst_DSR_keyboard },
{ "Test Printer Status", tst_DSR_printer },
{ "Test UDK Status", tst_DSR_userkeys },
{ "Test Locator Status", tst_DSR_locator_status },
{ "Identify Locator", tst_DSR_identify_locator },
{ "Test Extended Cursor-Position (DECXCPR)", tst_DSR_cursor },
{ "", 0 }
};
/* *INDENT-ON* */
do {
vt_clear(2);
__(title(0), printxx("VT320 Device Status Reports (DSR)"));
__(title(2), println("Choose test type:"));
} while (menu(my_menu));
return MENU_NOHOLD;
}
/******************************************************************************/
/*
* DECCIR returns single characters separated by semicolons. It's not clear
* (unless you test on a DEC terminal) from the documentation, which only cites
* their values. This function returns an equivalent-value, recovering from
* the bogus implementations that return a decimal number.
*/
static int
scan_chr(const char *str, int *pos, int toc)
{
int value = 0;
while (str[*pos] != '\0' && str[*pos] != toc) {
value = (value * 256) + (unsigned char) str[*pos];
*pos += 1;
}
if (str[*pos] == toc)
*pos += 1;
return value;
}
/*
* From Kermit 3.13 & VT220 pocket guide
*
* Request CSI 1 $ w cursor information report
* Response DCS 1 $ u Pr; Pc; Pp; Srend; Satt; Sflag; Pgl; Pgr; Scss; Sdesig ST
* where Pr is cursor row (counted from origin as 1,1)
* Pc is cursor column
* Pp is 1, video page, a constant for VT320s
* Srend = 40h + 8 (rev video on) + 4 (blinking on)
* + 2 (underline on) + 1 (bold on)
* Satt = 40h + 1 (selective erase on)
* Sflag = 40h + 8 (autowrap pending) + 4 (SS3 pending)
* + 2 (SS2 pending) + 1 (Origin mode on)
* Pgl = char set in GL (0 = G0, 1 = G1, 2 = G2, 3 = G3)
* Pgr = char set in GR (same as for Pgl)
* Scss = 40h + 8 (G3 is 96 char) + 4 (G2 is 96 char)
* + 2 (G1 is 96 char) + 1 (G0 is 96 char)
* Sdesig is string of character idents for sets G0...G3, with
* no separators between set idents.
* If NRCs are active the set idents (all 94 byte types) are:
* British A Italian Y
* Dutch 4 Norwegian/Danish ' (hex 60) or E or 6
* Finnish 5 or C Portuguese %6 or g or L
* French R or f Spanish Z
* French Canadian 9 or Q Swedish 7 or H
* German K Swiss =
* Hebrew %=
* (MS Kermit uses any choice when there are multiple)
*/
typedef struct {
/* position */
int row;
int col;
int page;
/* current rendition */
int Srend; /* raw rendition information */
int reverse;
int blinking;
int underline;
int bold;
/* attributes */
int Satt; /* raw attribute information */
int selective_erase;
/* flags */
int Sflag; /* raw flag-information */
int aw_pending;
int ss3_pending;
int ss2_pending;
int origin_mode;
/* character sets */
int gl;
int gr;
int Scss;
char cs_suffix[4][3];
int cs_sizes[4];
const char *cs_names[4];
} DECCIR_REPORT;
static int
parse_DECCIR(const char *input, DECCIR_REPORT * output)
{
int valid = 1;
int pos = 3; /* skip "1$u" */
int n;
memset(output, 0, sizeof(*output));
/* *INDENT-EQLS* */
output->row = scanto(input, &pos, ';');
output->col = scanto(input, &pos, ';');
output->page = scanto(input, &pos, ';');
output->Srend = scan_chr(input, &pos, ';');
if (output->Srend & 0x40) {
/* *INDENT-EQLS* */
output->reverse = ((output->Srend & 0x08) != 0);
output->blinking = ((output->Srend & 0x04) != 0);
output->underline = ((output->Srend & 0x02) != 0);
output->bold = ((output->Srend & 0x01) != 0);
}
output->Satt = scan_chr(input, &pos, ';');
if (output->Satt & 0x40) {
output->selective_erase = ((output->Satt & 1) != 0);
}
output->Sflag = scan_chr(input, &pos, ';');
if (output->Sflag & 0x40) {
/* *INDENT-EQLS* */
output->aw_pending = ((output->Sflag & 0x08) != 0);
output->ss3_pending = ((output->Sflag & 0x04) != 0);
output->ss2_pending = ((output->Sflag & 0x02) != 0);
output->origin_mode = ((output->Sflag & 0x01) != 0);
}
output->gl = scanto(input, &pos, ';');
output->gr = scanto(input, &pos, ';');
output->Scss = scan_chr(input, &pos, ';');
if (output->Scss & 0x40) {
output->cs_sizes[3] = (output->Scss & 0x08) ? 96 : 94;
output->cs_sizes[2] = (output->Scss & 0x04) ? 96 : 94;
output->cs_sizes[1] = (output->Scss & 0x02) ? 96 : 94;
output->cs_sizes[0] = (output->Scss & 0x01) ? 96 : 94;
}
n = 0;
while (input[pos] != '\0') {
strncpy(output->cs_suffix[n], input + pos, (size_t) 2)[2] = '\0';
if (output->cs_suffix[n][0] != '%') {
output->cs_suffix[n][1] = '\0';
}
output->cs_names[n++] = parse_Sdesig(input, &pos);
if (n >= 4)
break;
}
return valid;
}
static int
read_DECCIR(DECCIR_REPORT * output)
{
char *report;
int Ps = 1;
do_csi("%d$w", Ps);
report = get_reply();
if ((report = skip_dcs(report)) != 0
&& strip_terminator(report)
&& *report == Ps + '0'
&& !strncmp(report + 1, "$u", (size_t) 2)) {
return parse_DECCIR(report, output);
} else {
return 0;
}
}
#define show_DECCIR_flag(value, mask, string) \
if (value & mask) { value &= ~mask; show_result(string); }
static void
show_DECCIR(char *report)
{
int row;
int n;
DECCIR_REPORT data;
parse_DECCIR(report, &data);
vt_move(5, 10);
show_result("Cursor (%d,%d), page %d", data.row, data.col, data.page);
vt_move(6, 10);
if ((data.Srend & 0x4f) == data.Srend) {
printxx("Rendition:");
if (data.Srend == 0) {
show_result(" normal");
} else {
printxx("%s", data.reverse ? " reverse" : "");
printxx("%s", data.blinking ? " blinking" : "");
printxx("%s", data.underline ? " underline" : "");
printxx("%s", data.bold ? " bold" : "");
}
} else {
show_result(" -> unknown rendition (0x%x)", data.Srend);
}
vt_move(7, 10);
if ((data.Satt & 0x4f) == data.Satt) {
show_result("Selective erase: %s", data.selective_erase ? "ON" : "off");
} else {
show_result(" -> unknown attribute (0x%x)", data.Satt);
}
vt_move(8, 10);
if ((data.Sflag & 0x4f) == data.Sflag) {
printxx("Flags:");
printxx("%s", data.aw_pending ? " autowrap pending" : "");
printxx("%s", data.ss3_pending ? " SS3 pending" : "");
printxx("%s", data.ss2_pending ? " SS2 pending" : "");
printxx("%s", data.origin_mode ? " origin-mode on" : "");
} else {
show_result(" -> unknown flag (0x%x)", data.Sflag);
}
vt_move(9, 10);
show_result("Character set in GL: G%d", data.gl);
vt_move(10, 10);
show_result("Character set in GR: G%d", data.gr);
vt_move(11, 10);
if ((data.Scss & 0x4f) == data.Scss) {
printxx(" Character set sizes:");
for (n = 0; n <= 3; n++) {
printxx(" G%d(%d)", n, data.cs_sizes[n]);
}
} else {
show_result(" -> unknown char set size (0x%x)", data.Scss);
}
row = 12;
vt_move(row, 10);
show_result("Character set names for G0...G3: ");
println("");
for (n = 0; n < 4; ++n) {
show_result(" %s\n", (data.cs_names[n]
? data.cs_names[n]
: "?"));
println("");
}
}
/******************************************************************************/
static void
setup_charset(void)
{
int g;
for (g = 0; g <= 3; ++g) {
if (current_Gx[g] != sane_cs(g))
do_scs(g);
}
}
static void
restore_charset(void)
{
int g;
for (g = 0; g <= 3; ++g) {
if (current_Gx[g]) {
int save = current_Gx[g];
current_Gx[g] = sane_cs(g);
do_scs(g);
current_Gx[g] = save;
}
}
}
/******************************************************************************/
/*
* Request CSI 2 $ w tab stop report
* Response DCS 2 $ u Pc/Pc/...Pc ST
* Pc are column numbers (from 1) where tab stops occur. Note the
* separator "/" occurs in a real VT320 but should have been ";".
*/
static void
show_DECTABSR(char *report, int row)
{
int pos = 3; /* skip "2$u" */
int stop;
int *stops;
int n;
int len = 0;
int used = 0;
if ((stops = (int *) malloc(sizeof(int) * (strlen(report) + 1))) == NULL)
no_memory();
strcat(report, "/"); /* simplify scanning */
while ((stop = scanto(report, &pos, '/')) != 0) {
stops[len++] = stop;
}
println("");
printxx("Tab stops:");
row += 2;
ruler(row, min_cols);
for (n = 0; n < len; ++n) {
if (stops[n] <= min_cols && stops[n] > 0) {
cup(row, stops[n]);
print_chr('*');
}
}
cup(++row, 1);
for (n = used = 0; n < len; ++n) {
if (stops[n] <= min_cols && stops[n] > 0) {
if (used)
print_chr('\t');
print_chr('*');
++used;
}
}
free(stops);
}
/******************************************************************************/
int
any_decrqpsr(MENU_ARGS, int Ps)
{
char *report;
int row;
vt_move(1, 1);
printxx("Testing DECRQPSR: %s\n", the_title);
set_tty_raw(TRUE);
set_tty_echo(FALSE);
vt_move(row = 3, 10);
setup_charset();
do_csi("%d$w", Ps);
report = get_reply();
restore_charset();
row = chrprint2(report, row, 1);
if ((report = skip_dcs(report)) != 0) {
if (strip_terminator(report)
&& *report == Ps + '0'
&& !strncmp(report + 1, "$u", (size_t) 2)) {
show_result("%s (valid request)", SHOW_SUCCESS);
switch (Ps) {
case 1:
show_DECCIR(report);
break;
case 2:
show_DECTABSR(report, row);
break;
}
} else {
show_result(SHOW_FAILURE);
}
} else {
show_result(SHOW_FAILURE);
}
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/******************************************************************************/
static int
tst_DECCIR(MENU_ARGS)
{
return any_decrqpsr(PASS_ARGS, 1);
}
static int
tst_any_DECCIR(MENU_ARGS)
{
static char whatis_Gx[4][80];
static char nrc_mesg[80];
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Reset (G0 ASCII, G1 Latin-1, no NRC mode)", reset_charset },
{ nrc_mesg, toggle_nrc },
{ whatis_Gx[0], specify_G0 },
{ whatis_Gx[1], specify_G1 },
{ whatis_Gx[2], specify_G2 },
{ whatis_Gx[3], specify_G3 },
{ "Cursor Information Report (DECCIR)", tst_DECCIR },
{ "", 0 }
};
/* *INDENT-ON* */
dirty_charset(0);
reset_charset(PASS_ARGS); /* make the menu consistent */
if (get_level() > 2) {
int n;
do {
vt_clear(2);
__(title(0), printxx("Character-Set Tests"));
__(title(2), println("Choose test type:"));
sprintf(nrc_mesg, "%s National Replacement Character (NRC) mode",
STR_ENABLE(scs_national));
for (n = 0; n < 4; n++) {
sprintf(whatis_Gx[n], "Specify G%d (now %s)",
n, charset_name(n, current_Gx[n]));
}
} while (menu(my_menu));
dirty_charset(1);
/* tidy in case a "vt100" emulator does not ignore SCS */
vt_clear(1);
return reset_charset(PASS_ARGS);
} else {
vt_move(1, 1);
printxx("Sorry, terminal supports only VT%d", terminal_id());
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
}
/******************************************************************************/
static void
set_tabstops(int row, int stop)
{
int col;
tbc(3); /* clear existing tab-stops */
for (col = 0; col < min_cols; col += stop) {
cup(row, 1 + col);
hts();
}
}
static int test_tabstop;
static int
reset_tabstops(MENU_ARGS)
{
set_tabstops(1, test_tabstop = 8);
return MENU_NOHOLD;
}
static int
toggle_tabstop(MENU_ARGS)
{
if (--test_tabstop < 4)
test_tabstop = 10;
return MENU_NOHOLD;
}
static int
tst_DECTABSR(MENU_ARGS)
{
set_tabstops(1, test_tabstop);
return any_decrqpsr(PASS_ARGS, 2);
}
static int
tst_any_DECTABSR(MENU_ARGS)
{
static char msg_toggle_tabstop[80];
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Reset Tab Stops", reset_tabstops },
{ msg_toggle_tabstop, toggle_tabstop },
{ "Tab Stop Report (DECTABSR)", tst_DECTABSR },
{ "", 0 }
};
/* *INDENT-ON* */
int last_tabstop = 0;
reset_tabstops(PASS_ARGS); /* make the menu consistent */
do {
vt_clear(2);
__(title(0), printxx("Tab Stop Report (DECTABSR)"));
__(title(2), println("Choose test type:"));
if (last_tabstop != test_tabstop)
sprintf(msg_toggle_tabstop, "Set Tabs: %d", last_tabstop = test_tabstop);
} while (menu(my_menu));
vt_clear(1);
return reset_tabstops(PASS_ARGS);
}
/******************************************************************************/
/*
* The restore should move the cursor to 2,1; the relative move back to the
* test-grid demonstrates that.
*/
static void
tst_restore_cursor(const char *old_mode, int row, int col)
{
print_str(old_mode);
fflush(stdout); /* ensure terminal is updated */
if (row > 2)
cud(row - 2);
if (col > 1)
cuf(col - 1);
}
static int
tst_DECRSPS_cursor(MENU_ARGS)
{
char *old_mode;
char *s;
DECCIR_REPORT actual;
vt_move(1, 1);
printxx("Testing %s\n", the_title);
set_tty_raw(TRUE);
set_tty_echo(FALSE);
decrqpsr(1);
old_mode = strdup(get_reply());
if ((s = strchr(old_mode, 'u')) != 0) {
int item;
int row, col;
int len;
int j, k;
int tries, fails;
char temp[80];
println("");
println("Position/rendition:");
*s = 't';
for (item = 0; item < 16; ++item) {
cup(row = item + 4, col = 10);
sprintf(temp, "rendition[%2d]: ", item);
len = print_str(temp);
if (item == 0) {
len += print_str(" none");
} else {
if (item & 8) {
len += print_chr(' ');
sgr("7");
len += print_str("reverse");
}
if (item & 4) {
len += print_chr(' ');
sgr("5");
len += print_str("blinking");
}
if (item & 2) {
len += print_chr(' ');
sgr("4");
len += print_str("underline");
}
if (item & 1) {
len += print_chr(' ');
sgr("1");
len += print_str("bold");
}
}
if (read_DECCIR(&actual)) {
tst_restore_cursor(old_mode, row, col + len);
if (actual.Srend != (0x40 | item)) {
printxx(" (rendition?)");
} else if (actual.row != row) {
printxx(" (row?)");
} else if (actual.col != (col + len)) {
printxx(" (col?)");
} else {
printxx(" (OK)");
}
} else {
tst_restore_cursor(old_mode, row, col + len);
printxx(" (N/A)");
}
}
cup(max_lines - 1, 1);
restore_ttymodes();
holdit();
set_tty_raw(TRUE);
set_tty_echo(FALSE);
vt_move(1, 1);
printxx("Testing %s\n", the_title);
ed(0);
println("");
println("Flags:");
len = 42;
vt_move(row = 4, col = 10);
tprintf("%-*s", len, "Selective erase, should be blank:");
tst_restore_cursor(old_mode, row, col + len);
tprintf("XXXXXX");
vt_move(row, col + len);
decsel(0);
vt_move(++row, col);
tprintf("%-*s", len, "Selective erase, should not be blank:");
vt_move(row, col + len);
decsca(1);
tprintf("XXXXXX");
vt_move(row, col + len);
decsel(0);
fails = 0;
tries = 0;
for (j = ++row; j <= max_lines; ++j) {
cup(j, min_cols - 1);
for (k = 0; k < 3; k++) {
print_chr('0' + k);
fflush(stdout);
if (read_DECCIR(&actual)) {
tries++;
if (actual.aw_pending ^ (k == 1))
fails += 1;
}
if (j >= max_lines && k > 0)
break;
}
}
vt_move(row, 1);
ed(0);
println("");
println("Modes:");
vt_move(row += 2, col);
el(2);
if (fails) {
printxx("Autowrap-pending: failed %d of %d tries", fails, tries);
} else {
printxx("Autowrap-pending: OK");
}
println("");
fails = 1;
vt_move(++row, col);
print_str(ss2_output());
if (read_DECCIR(&actual) && actual.ss2_pending) {
print_chr(' ');
if (read_DECCIR(&actual) && !actual.ss2_pending) {
fails = 0;
}
}
el(2);
vt_move(row, col);
if (fails) {
println("SS2 pending: ERR");
} else {
println("SS2 pending: OK");
}
fails = 1;
vt_move(++row, col);
print_str(ss3_output());
if (read_DECCIR(&actual) && actual.ss3_pending) {
print_chr(' ');
if (read_DECCIR(&actual) && !actual.ss3_pending) {
fails = 0;
}
}
el(2);
vt_move(row, col);
if (fails) {
println("SS3 pending: ERR");
} else {
println("SS3 pending: OK");
}
fails = 1;
vt_move(++row, col);
decom(1);
if (read_DECCIR(&actual) && actual.origin_mode) {
fails = 0;
}
print_str(old_mode); /* restore original settings */
vt_move(row, col);
printxx("Origin mode: %s", fails ? "ERR" : "OK");
vt_move(++row, 1);
ed(0);
println("");
println("Character sets:");
esc("+A"); /* set G3 to British */
esc("o"); /* select that into GL */
esc("*0"); /* set G2 to DEC special graphics */
esc("}"); /* select that into GR */
esc("(<"); /* set G1 to DEC supplementary */
esc(")>"); /* set G0 to DEC technical */
read_DECCIR(&actual);
print_str(old_mode);
vt_move(row += 2, col);
printxx("Current GL: %s", (actual.gl == 3) ? "OK" : "ERR");
vt_move(++row, col);
printxx("Current GR: %s", (actual.gr == 2) ? "OK" : "ERR");
for (j = 0; j < 4; ++j) {
static const char *my_suffix = "<>0A";
vt_move(++row, col);
printxx("G%d suffix: '%.2s' %s (%s)", j,
actual.cs_suffix[j],
(actual.cs_suffix[j][0] == my_suffix[j]) ? "OK" : "ERR",
actual.cs_names[j]);
}
print_str(old_mode); /* restore original settings */
}
free(old_mode);
restore_ttymodes();
vt_move(max_lines - 1, 1);
ed(0);
return MENU_HOLD;
}
/******************************************************************************/
static void
tabstop_ruler(const char *tabsr, int row, int col)
{
int valid = 1;
int n;
int tabstops = 0;
char *expect;
const char *suffix;
const char *s;
if ((expect = malloc((size_t) min_cols + 1)) == NULL)
no_memory();
vt_move(row, col);
for (n = 0; n < min_cols; ++n) {
expect[n] = '-';
if (((n + 1) % 10) == 0) {
expect[n] = (char) ((((n + 1) / 10) % 10) + '0');
} else if (((n + 1) % 5) == 0) {
expect[n] = '+';
}
}
expect[min_cols] = '\0';
if (!strncmp(tabsr, "\033P", (size_t) 2)) {
suffix = "\033\\";
s = tabsr + 2;
} else if ((unsigned char) *tabsr == 0x90) {
suffix = "\234";
s = tabsr + 1;
} else {
suffix = 0;
s = 0;
}
if (s != 0 && !strncmp(s, "2$u", (size_t) 2)) {
int value = 0;
s += 2;
while (*++s != '\0') {
if (*s >= '0' && *s <= '9') {
value = (value * 10) + (*s - '0');
} else if (*s == '/' || !strcmp(s, suffix)) {
if (value-- > 0 && value < min_cols) {
if (expect[value] != '*') {
expect[value] = '*';
++tabstops;
value = 0;
} else {
valid = 0;
break;
}
}
if (!strcmp(s, suffix))
break;
} else {
if (strcmp(s, suffix))
valid = 0;
break;
}
}
} else {
valid = 0;
}
if (valid) {
println(expect);
print_chr('*');
for (n = 1; n < tabstops; ++n) {
print_chr('\t');
print_chr('*');
}
} else {
println("Invalid:");
chrprint2(tabsr, row, col);
}
free(expect);
}
static int
tst_DECRSPS_tabs(MENU_ARGS)
{
int row, stop;
char *old_tabs;
char *new_tabs;
char *s;
vt_move(1, 1);
printxx("Testing %s\n", the_title);
set_tty_raw(TRUE);
set_tty_echo(FALSE);
println("");
println("Original:");
decrqpsr(2);
old_tabs = strdup(get_reply());
tabstop_ruler(old_tabs, 4, 1);
vt_move(row = 7, 1);
println("Modified:");
++row;
for (stop = 7; stop >= 4; --stop) {
set_tabstops(row, stop);
decrqpsr(2);
new_tabs = get_reply();
tabstop_ruler(new_tabs, row, 1);
row += 2;
}
println("");
println("");
println("Restore:");
if ((s = strchr(old_tabs, 'u')) != 0)
*s = 't';
print_str(old_tabs); /* restore original tab-stops */
free(old_tabs);
decrqpsr(2);
new_tabs = get_reply();
tabstop_ruler(new_tabs, row + 2, 1);
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/* Test Window Report - VT340, VT420 */
static int
tst_DECRQDE(MENU_ARGS)
{
char *report;
char chr;
int Ph, Pw, Pml, Pmt, Pmp;
int row, col;
vt_move(1, 1);
println("Testing DECRQDE/DECRPDE Window Report");
set_tty_raw(TRUE);
set_tty_echo(FALSE);
do_csi("\"v");
report = get_reply();
vt_move(row = 3, col = 10);
chrprint2(report, row, col);
if ((report = skip_csi(report)) != 0
&& sscanf(report, "%d;%d;%d;%d;%d\"%c",
&Ph, &Pw, &Pml, &Pmt, &Pmp, &chr) == 6
&& chr == 'w') {
vt_move(5, 10);
show_result("lines:%d, cols:%d, left col:%d, top line:%d, page %d",
Ph, Pw, Pml, Pmt, Pmp);
} else {
show_result(SHOW_FAILURE);
}
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/* Request Terminal State Report */