-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
2162 lines (1941 loc) · 51.5 KB
/
main.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: main.c,v 1.155 2024/12/05 00:37:39 tom Exp $ */
/*
VTTEST.C
Written November 1983 - July 1984 by Per Lindberg,
Stockholm University Computer Center (QZ), Sweden.
THE MAD PROGRAMMER STRIKES AGAIN!
Copyright (c) 1984, Per Lindberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. Neither the name of Per Lindberg nor the names of contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <vttest.h>
#include <ttymodes.h>
#include <esc.h>
#ifdef LOCALE
#include <locale.h>
#endif
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
/* *INDENT-EQLS* */
FILE *log_fp = NULL;
int allows_utf8 = FALSE;
int assume_utf8 = FALSE;
int brkrd = FALSE;
int debug_level = 0;
int decac_bg = -1;
int decac_fg = -1;
int input_8bits = FALSE;
int log_disabled = FALSE;
int max_cols = 132;
int max_lines = 24;
int min_cols = 80;
int output_8bits = FALSE;
int parse_7bits = FALSE;
int quick_reply = FALSE;
int reading = FALSE;
int slow_motion = FALSE;
int tty_speed = DEFAULT_SPEED; /* nominal speed, for padding */
int use_decac = FALSE;
int use_padding = FALSE;
jmp_buf intrenv;
static char *program;
static char empty[1];
static char *current_menu = empty;
GCC_NORETURN void
failed(const char *msg)
{
#ifdef HAVE_STRERROR
const char *why = strerror(errno);
fprintf(stderr, "%s: %s: %s\n", program, msg, why ? why : "?");
#elif defined(HAVE_SYS_NERR) && defined(HAVE_SYS_ERRLIST)
const char *why = (errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : "?";
fprintf(stderr, "%s: %s: %s\n", program, msg, why ? why : "?");
#else
perror(msg);
#endif
exit(EXIT_FAILURE);
}
GCC_NORETURN void
no_memory(void)
{
failed("no memory");
}
static void
usage(void)
{
static const char *msg[] =
{
"Usage: vttest [options] [24x80.132]"
,""
,"Options:"
," -V print the program version, and exit"
," -8 use 8-bit controls"
," -d debug (repeat for more detail)"
," -c cmdfile read commands from file"
," -f fontfile load DRCS data from file"
," -l logfile log test results to vttest.log"
," -p use padding"
," -q filter replies to show only the most recent"
," -s add time delay for scrolling"
," -u allow some tests to use UTF-8"
};
size_t n;
for (n = 0; n < TABLESIZE(msg); ++n)
fprintf(stderr, "%s\n", msg[n]);
exit(EXIT_FAILURE);
}
static int
version(void)
{
printxx("VT100 test program, version %d.%d", RELEASE, PATCHLEVEL);
#ifdef PATCH_DATE
if (PATCH_DATE)
printxx(" (%d)", PATCH_DATE);
#endif
return 1; /* used for indenting */
}
int
main(int argc, char *argv[])
{
/* *INDENT-OFF* */
static MENU mainmenu[] = {
{ "Exit", NULL },
{ "Test of cursor movements", tst_movements },
{ "Test of screen features", tst_screen },
{ "Test of character sets", tst_characters },
{ "Test of double-sized characters", tst_doublesize },
{ "Test of keyboard", tst_keyboard },
{ "Test of terminal reports", tst_reports },
{ "Test of VT52 mode", tst_vt52 },
{ "Test of VT102 features (Insert/Delete Char/Line)", tst_insdel },
{ "Test of known bugs", tst_bugs },
{ "Test of reset and self-test", tst_rst },
{ "Test non-VT100 (e.g., VT220, XTERM) terminals", tst_nonvt100 },
{ "Modify test-parameters", tst_setup },
{ "", NULL }
};
/* *INDENT-ON* */
char *opt_command = NULL;
char *opt_softchr = NULL;
char *opt_logging = NULL;
program = strrchr(argv[0], '/');
if (program != NULL)
++program;
else
program = argv[0];
#define OPT_ARG(value) \
do { \
if (!*++opt) { \
if (--argc < 1) \
usage(); \
value = *++argv; \
} \
opt = "?"; \
} while (0)
while (argc-- > 1) {
const char *opt = *++argv;
if (*opt == '-') {
while (*++opt != '\0') {
switch (*opt) {
case 'V':
version();
putchar('\n');
exit(EXIT_SUCCESS);
case 'c':
OPT_ARG(opt_command);
break;
case 'd':
debug_level++;
break;
case 'f':
OPT_ARG(opt_softchr);
break;
case 'l':
OPT_ARG(opt_logging);
break;
case 'p':
use_padding = TRUE;
break;
case 'q':
quick_reply = TRUE;
break;
case 's':
slow_motion = TRUE;
break;
case 'u':
allows_utf8 = TRUE;
break;
case '8':
output_8bits = TRUE;
break;
default:
usage();
}
}
} else {
/*
* Allow user to specify geometry of terminal to accommodate quasi-VT100
* terminals such as Linux console and xterm.
*/
char *p = argv[0];
char *q;
int values[3], n;
for (n = 0; n < 3; n++) {
int m;
if (!*p)
break;
if ((m = (int) strtol(p, &q, 10)) > 0) {
values[n] = m;
p = q;
if (*p)
p++;
} else {
break;
}
}
switch (n) {
case 3:
max_cols = values[2];
/* FALLTHRU */
case 2:
min_cols = values[1];
/* FALLTHRU */
case 1:
max_lines = values[0];
break;
}
if ((max_cols < min_cols) || (n == 0)) {
usage();
}
}
}
/* do this first, to capture results from other options */
if (opt_logging)
enable_logging(opt_logging);
if (opt_command)
setup_replay(opt_command);
if (opt_softchr)
setup_softchars(opt_softchr);
#ifdef UNIX
initterminal(setjmp(intrenv));
signal(SIGINT, onbrk);
signal(SIGTERM, onterm);
reading = FALSE;
#else
initterminal(0);
#endif
do {
vt_clear(2);
__(title(0), version());
title(1);
if (max_lines != 24
|| min_cols != 80
|| max_cols != 132)
printxx("Screen size %dx%d (%d max) ", max_lines, min_cols, max_cols);
if (tty_speed != DEFAULT_SPEED)
printxx("Line speed %dbd ", tty_speed);
if (use_padding)
printxx(" (padded)");
__(title(2), println("Choose test type:"));
} while (menu(mainmenu));
bye();
return EXIT_SUCCESS;
}
int
tst_movements(MENU_ARGS)
{
/* Test of:
CUF (Cursor Forward)
CUB (Cursor Backward)
CUD (Cursor Down) IND (Index) NEL (Next Line)
CUU (Cursor Up) RI (Reverse Index)
CUP (Cursor Position) HVP (Horizontal and Vertical Position)
ED (Erase in Display)
EL (Erase in Line)
DECALN (Screen Alignment Display)
DECAWM (Autowrap)
<CR> <BS>
Cursor control characters inside CSI sequences
*/
int i, row, col, pass, width;
const char *ctext = "This is a correct sentence";
set_tty_crmod(TRUE); /* want to disable tab/space conversion */
for (pass = 0; pass <= 1; pass++) {
int hlfxtra;
int inner_l, inner_r;
if (pass == 0) {
deccolm(FALSE);
width = min_cols;
} else {
deccolm(TRUE);
width = max_cols;
}
/* Compute left/right columns for a 60-column box centered in 'width' */
inner_l = (width - 60) / 2;
inner_r = 61 + inner_l;
hlfxtra = (width - 80) / 2;
if (LOG_ENABLED)
fprintf(log_fp, NOTE_STR "tst_movements box(%d cols)\n",
pass ? max_cols : min_cols);
decaln();
cup(9, inner_l);
ed(1);
cup(18, 60 + hlfxtra);
ed(0);
el(1);
cup(9, inner_r);
el(0);
/* 132: 36..97 */
/* 80: 10..71 */
for (row = 10; row <= 16; row++) {
cup(row, inner_l);
el(1);
cup(row, inner_r);
el(0);
}
cup(17, 30);
el(2);
for (col = 1; col <= width; col++) {
hvp(max_lines, col);
tprintf("*");
hvp(1, col);
tprintf("*");
}
cup(2, 2);
for (row = 2; row <= max_lines - 1; row++) {
tprintf("+");
cub(1);
ind();
}
cup(max_lines - 1, width - 1);
for (row = max_lines - 1; row >= 2; row--) {
tprintf("+");
cub(1);
ri();
}
cup(2, 1);
for (row = 2; row <= max_lines - 1; row++) {
tprintf("*");
cup(row, width);
tprintf("*");
cub(10);
if (row < 10)
nel();
else
tprintf("\n");
}
cup(2, 10);
cub(42 + hlfxtra);
cuf(2);
for (col = 3; col <= width - 2; col++) {
tprintf("+");
cuf(0);
cub(2);
cuf(1);
}
cup(max_lines - 1, inner_r - 1);
cuf(42 + hlfxtra);
cub(2);
for (col = width - 2; col >= 3; col--) {
tprintf("+");
cub(1);
cuf(1);
cub(0);
tprintf("%c", 8);
}
cup(1, 1);
cuu(10);
cuu(1);
cuu(0);
cup(max_lines, width);
cud(10);
cud(1);
cud(0);
cup(10, 2 + inner_l);
for (row = 10; row <= 15; row++) {
for (col = 2 + inner_l; col <= inner_r - 2; col++)
tprintf(" ");
cud(1);
cub(58);
}
cuu(5);
cuf(1);
printxx("The screen should be cleared, and have an unbroken bor-");
cup(12, inner_l + 3);
printxx("der of *'s and +'s around the edge, and exactly in the");
cup(13, inner_l + 3);
printxx("middle there should be a frame of E's around this text");
cup(14, inner_l + 3);
printxx("with one (1) free position around it. ");
holdit();
}
deccolm(FALSE);
/* DECAWM demo */
for (pass = 0; pass <= 1; pass++) {
static char on_left[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static char on_right[] = "abcdefghijklmnopqrstuvwxyz";
int height = sizeof(on_left) - 1;
int region = max_lines - 6;
if (LOG_ENABLED)
fprintf(log_fp, NOTE_STR "tst_movements wrap(%d cols)\n",
pass ? max_cols : min_cols);
/* note: DECCOLM clears the screen */
if (pass == 0) {
deccolm(FALSE);
width = min_cols;
} else {
deccolm(TRUE);
width = max_cols;
}
println("Test of autowrap, mixing control and print characters.");
println("The left/right margins should have letters in order:");
decstbm(3, region + 3);
decom(TRUE); /* this also homes the cursor */
for (i = 0; i < height; ++i) {
switch (i % 4) {
case 0:
/* draw characters as-is, for reference */
__(cup(region + 1, 1), tprintf("%c", on_left[i]));
__(cup(region + 1, width), tprintf("%c", on_right[i]));
tprintf("\n");
break;
case 1:
/* simple wrapping */
__(cup(region, width), tprintf("%c%c", on_right[i - 1], on_left[i]));
/* backspace at right margin */
__(cup(region + 1, width), tprintf("%c%c %c",
on_left[i], BS, on_right[i]));
tprintf("\n");
break;
case 2:
/* tab to right margin */
__(cup(region + 1, width), tprintf("%c%c%c%c%c%c",
on_left[i], BS, BS,
TAB, TAB, on_right[i]));
__(cup(region + 1, 2), tprintf("%c%c\n", BS, on_left[i]));
break;
default:
/* newline at right margin */
__(cup(region + 1, width), tprintf("\n"));
__(cup(region, 1), tprintf("%c", on_left[i]));
__(cup(region, width), tprintf("%c", on_right[i]));
break;
}
}
decom(FALSE);
decstbm(0, 0);
cup(max_lines - 2, 1);
holdit();
}
deccolm(FALSE); /* 80 cols */
if (LOG_ENABLED)
fprintf(log_fp,
NOTE_STR "tst_movements cursor-controls in ESC sequences\n");
vt_clear(2);
vt_move(1, 1);
println("Test of cursor-control characters inside ESC sequences.");
println("Below should be four identical lines:");
println("");
println("A B C D E F G H I");
for (i = 1; i < 10; i++) {
tprintf("%c", '@' + i);
do_csi("2%cC", BS); /* Two forward, one backspace */
}
println("");
/* Now put CR in CUF sequence. */
tprintf("A ");
for (i = 2; i < 10; i++) {
cprintf("%s%c%dC", csi_output(), CR, 2 * i - 2);
tprintf("%c", '@' + i);
}
println("");
/* Now put VT in CUU sequence. */
rm("20");
for (i = 1; i < 10; i++) {
tprintf("%c ", '@' + i);
do_csi("1\013A");
}
println("");
println("");
holdit();
if (LOG_ENABLED)
fprintf(log_fp,
NOTE_STR "tst_movements leading zeros in ESC sequences\n");
vt_clear(2);
vt_move(1, 1);
println("Test of leading zeros in ESC sequences.");
printxx("Two lines below you should see the sentence \"%s\".", ctext);
for (col = 1; *ctext; col++) {
cprintf("%s00000000004;00000000%dH", csi_output(), col);
tprintf("%c", *ctext++);
}
cup(20, 1);
restore_ttymodes();
return MENU_HOLD;
}
/* Scrolling test (used also in color-testing) */
void
do_scrolling(void)
{
int soft, first, last, down, i, pass;
ed(2);
decom(TRUE); /* Origin mode (relative) */
for (soft = -1; soft <= 0; soft++) {
if (soft)
decsclm(TRUE);
else
decsclm(FALSE);
for (pass = 0; pass < 2; ++pass) {
if (pass == 0) {
first = max_lines / 2;
last = first + 1;
} else {
first = 1;
last = max_lines;
}
decstbm(first, last);
ed(2);
for (down = 0; down >= -1; down--) {
if (down)
cuu(max_lines);
else
cud(max_lines);
for (i = 1; i <= max_lines + 5; i++) {
printxx("%s scroll %s region [%d..%d] size %d Line %d\n",
soft ? "Soft" : "Jump",
down ? "down" : "up",
first, last, last - first + 1, i);
if (down) {
ri();
ri();
} else if (soft)
extra_padding(10);
}
}
holdit();
}
}
}
int
tst_screen(MENU_ARGS)
{
/* Test of:
- DECSTBM (Set Top and Bottom Margins)
- TBC (Tabulation Clear)
- HTS (Horizontal Tabulation Set)
- SM RM (Set/Reset mode): - 80/132 chars
. - Origin: Relative/absolute
. - Scroll: Smooth/jump
. - Wraparound
- SGR (Select Graphic Rendition)
- SM RM (Set/Reset Mode) - Inverse
- DECSC (Save Cursor)
- DECRC (Restore Cursor)
*/
int i, j, cset, row, col, background;
static const char *tststr = "*qx`";
static const char *attr[5] =
{
";0", ";1", ";4", ";5", ";7"
};
set_tty_crmod(TRUE); /* want to disable tab/space conversion */
cup(1, 1);
decawm(TRUE); /* DECAWM: Wrap Around ON */
for (col = 1; col <= min_cols * 2; col++)
tprintf("*");
decawm(FALSE); /* DECAWM: Wrap Around OFF */
cup(3, 1);
for (col = 1; col <= min_cols * 2; col++)
tprintf("*");
decawm(TRUE); /* DECAWM: Wrap Around ON */
cup(5, 1);
println("This should be three identical lines of *'s completely filling");
println("the top of the screen without any empty lines between.");
println("(Test of WRAP AROUND mode setting.)");
holdit();
ed(2);
tbc(3);
cup(1, 1);
for (col = 1; col <= min_cols - 2; col += 3) {
cuf(3);
hts();
}
cup(1, 4);
for (col = 4; col <= min_cols - 2; col += 6) {
tbc(0);
cuf(6);
}
cup(1, 7);
tbc(1);
tbc(2); /* no-op */
cup(1, 1);
for (col = 1; col <= min_cols - 2; col += 6)
tprintf("%c*", TAB);
cup(2, 2);
for (col = 2; col <= min_cols - 2; col += 6)
tprintf(" *");
cup(4, 1);
println("Test of TAB setting/resetting. These two lines");
printxx("should look the same. ");
holdit();
for (background = 0; background <= 1; background++) {
if (background)
decscnm(FALSE);
else
decscnm(TRUE);
deccolm(TRUE); /* 132 cols */
ed(2); /* VT100 clears screen on SM3/RM3, but not obviously, so... */
cup(1, 1);
tbc(3);
for (col = 1; col <= max_cols; col += TABWIDTH) {
cuf(TABWIDTH);
hts();
}
cup(1, 1);
for (col = 1; col <= max_cols; col += 10)
tprintf("%.*s", (max_cols > col) ? (max_cols - col) : 10, "1234567890");
for (row = 3; row <= 20; row++) {
cup(row, row);
tprintf("This is %d column mode, %s background.", max_cols,
background ? "dark" : "light");
}
holdit();
deccolm(FALSE); /* 80 cols */
ed(2); /* VT100 clears screen on SM3/RM3, but not obviously, so... */
cup(1, 1);
for (col = 1; col <= min_cols; col += 10)
tprintf("%.*s", (min_cols > col) ? (min_cols - col) : 10, "1234567890");
for (row = 3; row <= 20; row++) {
cup(row, row);
tprintf("This is %d column mode, %s background.", min_cols,
background ? "dark" : "light");
}
holdit();
}
do_scrolling();
ed(2);
decstbm(max_lines - 1, max_lines);
printxx(
"\nOrigin mode test. This line should be at the bottom of the screen.");
cup(1, 1);
tprintf("%s",
"This line should be the one above the bottom of the screen. ");
holdit();
ed(2);
decom(FALSE); /* Origin mode (absolute) */
cup(max_lines, 1);
tprintf(
"Origin mode test. This line should be at the bottom of the screen.");
cup(1, 1);
tprintf("%s", "This line should be at the top of the screen. ");
holdit();
decstbm(1, max_lines);
ed(2);
/* *INDENT-OFF* */
cup( 1,20); tprintf("Graphic rendition test pattern:");
cup( 4, 1); sgr("0"); tprintf("vanilla");
cup( 4,40); sgr("0;1"); tprintf("bold");
cup( 6, 6); sgr(";4"); tprintf("underline");
cup( 6,45);sgr(";1");sgr("4");tprintf("bold underline");
cup( 8, 1); sgr("0;5"); tprintf("blink");
cup( 8,40); sgr("0;5;1"); tprintf("bold blink");
cup(10, 6); sgr("0;4;5"); tprintf("underline blink");
cup(10,45); sgr("0;1;4;5"); tprintf("bold underline blink");
cup(12, 1); sgr("1;4;5;0;7"); tprintf("negative");
cup(12,40); sgr("0;1;7"); tprintf("bold negative");
cup(14, 6); sgr("0;4;7"); tprintf("underline negative");
cup(14,45); sgr("0;1;4;7"); tprintf("bold underline negative");
cup(16, 1); sgr("1;4;;5;7"); tprintf("blink negative");
cup(16,40); sgr("0;1;5;7"); tprintf("bold blink negative");
cup(18, 6); sgr("0;4;5;7"); tprintf("underline blink negative");
cup(18,45); sgr("0;1;4;5;7"); tprintf("bold underline blink negative");
/* *INDENT-ON* */
sgr("");
decscnm(FALSE); /* Inverse video off */
cup(max_lines - 1, 1);
el(0);
tprintf("Dark background. ");
holdit();
decscnm(TRUE); /* Inverse video */
cup(max_lines - 1, 1);
el(0);
tprintf("Light background. ");
holdit();
decscnm(FALSE);
ed(2);
/* *INDENT-OFF* */
cup(8,12); tprintf("normal");
cup(8,24); tprintf("bold");
cup(8,36); tprintf("underscored");
cup(8,48); tprintf("blinking");
cup(8,60); tprintf("reversed");
cup(10,1); tprintf("stars:");
cup(12,1); tprintf("line:");
cup(14,1); tprintf("x'es:");
cup(16,1); tprintf("diamonds:");
/* *INDENT-ON* */
for (cset = 0; cset <= 3; cset++) {
for (i = 0; i <= 4; i++) {
cup(10 + 2 * cset, 12 + 12 * i);
sgr(attr[i]);
if (cset == 0 || cset == 2)
scs_normal();
else
scs_graphics();
for (j = 0; j <= 4; j++) {
tprintf("%c", tststr[cset]);
}
decsc();
cup(cset + 1, i + 1);
sgr("");
scs_normal();
tprintf("A");
decrc();
for (j = 0; j <= 4; j++) {
tprintf("%c", tststr[cset]);
}
}
}
sgr("0");
scs_normal();
cup(21, 1);
println("Test of the SAVE/RESTORE CURSOR feature. There should");
println("be ten characters of each flavour, and a rectangle");
println("of 5 x 4 A's filling the top left of the screen.");
restore_ttymodes();
return MENU_HOLD;
}
int
tst_doublesize(MENU_ARGS)
{
/* Test of:
DECSWL (Single Width Line)
DECDWL (Double Width Line)
DECDHL (Double Height Line) (also implicit double width)
*/
int col, i, w;
/* Print the test pattern in both 80 and 132 character width */
for (w = 0; w <= 1; w++) {
int w1 = 13 * w;
ed(2);
cup(1, 1);
if (w) {
deccolm(TRUE);
tprintf("%3d column mode", max_cols);
} else {
deccolm(FALSE);
tprintf("%3d column mode", min_cols);
}
cup(5, 3 + 2 * w1);
tprintf("v------- left margin");
cup(7, 3 + 2 * w1);
tprintf("This is a normal-sized line");
decdhl(0);
decdhl(1);
decdwl();
decswl();
cup(9, 2 + w1);
tprintf("This is a Double-width line");
decswl();
decdhl(0);
decdhl(1);
decdwl();
cup(11, 2 + w1);
decdwl();
decswl();
decdhl(1);
decdhl(0);
tprintf("This is a Double-width-and-height line");
cup(12, 2 + w1);
decdwl();
decswl();
decdhl(0);
decdhl(1);
tprintf("This is a Double-width-and-height line");
cup(14, 2 + w1);
decdwl();
decswl();
decdhl(1);
decdhl(0);
el(2);
tprintf("This is another such line");
cup(15, 2 + w1);
decdwl();
decswl();
decdhl(0);
decdhl(1);
tprintf("This is another such line");
cup(17, 3 + 2 * w1);
tprintf("^------- left margin");
cup(21, 1);
tprintf("This is not a double-width line");
for (i = 0; i <= 1; i++) {
cup(21, 6);
if (i) {
tprintf("**is**");
decdwl();
} else {
tprintf("is not");
decswl();
}
cup(max_lines - 1, 1);
holdit();
}
}
/* Set vanilla tabs for next test */
cup(1, 1);
tbc(3);
for (col = 1; col <= max_cols; col += TABWIDTH) {
cuf(TABWIDTH);
hts();
}
deccolm(FALSE);
ed(2);
/* *INDENT-OFF* */
scs_graphics();
cup( 8,1); decdhl(0); tprintf("lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
cup( 9,1); decdhl(1); tprintf("lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
cup(10,1); decdhl(0); tprintf("x%c%c%c%c%cx",9,9,9,9,9);
cup(11,1); decdhl(1); tprintf("x%c%c%c%c%cx",9,9,9,9,9);
cup(12,1); decdhl(0); tprintf("x%c%c%c%c%cx",9,9,9,9,9);
cup(13,1); decdhl(1); tprintf("x%c%c%c%c%cx",9,9,9,9,9);
scs(1, '0'); /* should look the same as scs_graphics() */
cup(14,1); decdhl(0); tprintf("x x");
cup(15,1); decdhl(1); tprintf("x x");
cup(16,1); decdhl(0); tprintf("mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj");
cup(17,1); decdhl(1); tprintf("mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj");
scs_normal();
/* *INDENT-ON* */
sgr("1;5");
cup(12, 3);
tprintf("* The mad programmer strikes again * ");
cup(13, 3);
tprintf("%c", 9);
cub(6);
tprintf("* The mad programmer strikes again *");
sgr("0");
cup(max_lines - 2, 1);
println("Another test pattern... a frame with blinking bold text,");
printxx("all in double-height double-width size. ");
holdit();
decstbm(8, max_lines); /* Absolute origin mode, so cursor is set at (1,1) */
cup(8, 1);
for (i = 1; i <= 12; i++)
ri();
decstbm(0, 0); /* No scroll region */
cup(1, 1);
printxx("%s", "Exactly half of the box should remain. ");
return MENU_HOLD;
}
int
tst_insdel(MENU_ARGS)
{
/* Test of:
SM/RM(4) (= IRM (Insertion/replacement mode))
ICH (Insert Character)
DCH (Delete character)
IL (Insert line)
DL (Delete line)
*/
int i, row, col, sw, dblchr, scr132;
for (scr132 = 0; scr132 <= 1; scr132++) {
if (scr132) {
deccolm(TRUE);
sw = max_cols;
} else {
deccolm(FALSE);
sw = min_cols;
}
ed(2);
cup(1, 1);
for (row = 1; row <= max_lines; row++) {
cup(row, 1);
for (col = 1; col <= sw; col++)
tprintf("%c", 'A' - 1 + row);
}
cup(4, 1);
printxx("Screen accordion test (Insert & Delete Line). ");
holdit();
ri();
el(2);
decstbm(2, max_lines - 1);
decom(TRUE);
cup(1, 1);
for (row = 1; row <= max_lines; row++) {
il(row);
dl(row);
}
decom(FALSE);
decstbm(0, 0);
cup(2, 1);
printxx("Top line: A's, bottom line: %c's, this line, nothing more. ",
'A' - 1 + max_lines);
holdit();
cup(2, 1);
ed(0);
cup(1, 2);
tprintf("B");
cub(1);
sm("4");
for (col = 2; col <= sw - 1; col++)
tprintf("*");
rm("4");
cup(4, 1);
printxx("Test of 'Insert Mode'. The top line should be 'A*** ... ***B'. ");
holdit();
ri();
el(2);