[mod.sources] v07i017: Test VT100 Features, Part02/02

sources-request@mirror.UUCP (09/03/86)

Submitted by: seismo!enea!suadb!lindberg (Per Lindberg QZ)
Mod.sources: Volume 7, Issue 17
Archive-name: vttest/Part02


#!/bin/sh
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".

# Exit status; set to 1 on "wc" errors or if would overwrite.
STATUS=0
# Contents:  main.c
 
echo x - main.c
if test -f main.c ; then
    echo main.c exists, putting output in $$main.c
    OUT=$$main.c
    STATUS=1
else
    OUT=main.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F main.c//'
XX/*
XX                               VTTEST.C

XX         Written Novemeber 1983 - July 1984 by Per Lindberg,
XX         Stockholm University Computer Center (QZ), Sweden.

XX                  THE MAD PROGRAMMER STRIKES AGAIN!

XX                   This software is (c) 1984 by QZ
XX               Non-commercial use and copying allowed.

XXIf you are developing a commercial product, and use this program to do
XXit, and that product is successful, please send a sum of money of your
XXchoice to the address below.

XX*/

XX#include "header.h"

XXchar inchar(), *instr(), *lookup();

XXstruct table {
XX    int key;
XX    char *msg;
XX} paritytable[] = {
XX    { 1, "NONE" },
XX    { 4, "ODD"  },
XX    { 5, "EVEN" },
XX    { -1, "" }
XX},nbitstable[] = {
XX    { 1, "8" },
XX    { 2, "7" },
XX    { -1,"" }
XX},speedtable[] = {
XX    {   0,    "50" },
XX    {   8,    "75" },
XX    {  16,   "110" },
XX    {  24,   "132.5"},
XX    {  32,   "150" },
XX    {  40,   "200" },
XX    {  48,   "300" },
XX    {  56,   "600" },
XX    {  64,  "1200" },
XX    {  72,  "1800" },
XX    {  80,  "2000" },
XX    {  88,  "2400" },
XX    {  96,  "3600" },
XX    { 104,  "4800" },
XX    { 112,  "9600" },
XX    { 120, "19200" },
XX    { -1, "" }
XX};

XXmain() {

XX  int menuchoice;

XX  static char *mainmenu[] = {
XX      "Exit",
XX      "Test of cursor movements",
XX      "Test of screen features",
XX      "Test of character sets",
XX      "Test of double-sized characters",
XX      "Test of keyboard",
XX      "Test of terminal reports",
XX      "Test of VT52 mode",
XX      "Test of VT102 features (Insert/Delete Char/Line)",
XX      "Test of known bugs",
XX      "Test of reset and self-test",
XX      ""
XX    };

XX#ifdef UNIX
XX  initterminal(setjmp(intrenv));
XX  signal(SIGINT, onbrk);
XX  signal(SIGTERM, onterm);
XX  reading = 0;
XX#else
XX  initterminal(0);
XX#endif
XX  do {
XX#ifdef SARG20
XX    ttybin(1);	/* set line to binary mode again. It's reset somehow!! */
XX#endif
XX    ed(2);
XX    cup(5,10); printf("VT100 test program, version %s", VERSION);
XX    cup(7,10); println("Choose test type:");
XX    menuchoice = menu(mainmenu);
XX    switch (menuchoice) {
XX      case 1:  tst_movements();   break;
XX      case 2:  tst_screen();      break;
XX      case 3:  tst_characters();  break;
XX      case 4:  tst_doublesize();  break;
XX      case 5:  tst_keyboard();    break;
XX      case 6:  tst_reports();     break;
XX      case 7:  tst_vt52();        break;
XX      case 8:  tst_insdel();      break;
XX      case 9:  tst_bugs();        break;
XX      case 10: tst_rst();         break;
XX    }
XX  } while (menuchoice);
XX  bye();
XX}

XXtst_movements() {

XX  /* Test of:
XX     CUF (Cursor Forward)
XX     CUB (Cursor Backward)
XX     CUD (Cursor Down)      IND (Index)  NEL (Next Line)
XX     CUU (Cursor Up)        RI  (Reverse Index)
XX     CUP (Cursor Position)  HVP (Horizontal and Vertical Position)
XX     ED  (Erase in Display)
XX     EL  (Erase in Line)
XX     DECALN (Screen Alignment Display)
XX     <CR> <BS>
XX     Cursor control characters inside CSI sequences
XX  */

XX  int i, row, col, pass, width, hlfxtra;
XX  char c, *ctext = "This is a correct sentence";

XX  for (pass = 0; pass <= 1; pass++) {
XX    if (pass == 0) { rm("?3"); width =  80; hlfxtra =  0; }
XX    else           { sm("?3"); width = 132; hlfxtra = 26; }

XX    decaln();
XX    cup( 9,10+hlfxtra); ed(1);
XX    cup(18,60+hlfxtra); ed(0); el(1);
XX    cup( 9,71+hlfxtra); el(0);
XX    for (row = 10; row <= 16; row++) {
XX      cup(row, 10+hlfxtra); el(1);
XX      cup(row, 71+hlfxtra); el(0);
XX    }
XX    cup(17,30); el(2);
XX    for (col = 1; col <= width; col++) {
XX      hvp(24, col); printf("*");
XX      hvp( 1, col); printf("*");
XX    }
XX    cup(2,2);
XX    for (row = 2; row <= 23; row++) {
XX      printf("+");
XX      cub(1);
XX      ind();
XX    }
XX    cup(23,width-1);
XX    for (row = 23; row >=2; row--) {
XX      printf("+");
XX      cub(1); ri();
XX    }
XX    cup(2,1);
XX    for (row = 2; row <= 23; row++) {
XX      printf("*");  cup(row, width);
XX      printf("*");
XX      cub(10);
XX      if (row < 10) nel();
XX      else          printf("\n");
XX    }
XX    cup(2,10);
XX    cub(42+hlfxtra); cuf(2);
XX    for (col = 3; col <= width-2; col++) {
XX      printf("+");
XX      cuf(0); cub(2); cuf(1);
XX    }
XX    cup(23,70+hlfxtra);
XX    cuf(42+hlfxtra); cub(2);
XX    for (col = width-2; col >= 3; col--) {
XX      printf("+");
XX      cub(1); cuf(1); cub(0); printf("%c", 8);
XX    }
XX    cup( 1, 1); cuu(10); cuu(1); cuu(0);
XX    cup(24,width); cud(10); cud(1); cud(0);

XX    cup(10,12+hlfxtra);
XX    for (row = 10; row <= 15; row++) {
XX      for (col = 12+hlfxtra; col <= 69+hlfxtra; col++) printf(" ");
XX      cud(1); cub(58);
XX    }
XX    cuu(5); cuf(1);
XX    printf("The screen should be cleared,  and have an unbroken bor-");
XX    cup(12,13+hlfxtra);
XX    printf("der of *'s and +'s around the edge,   and exactly in the");
XX    cup(13,13+hlfxtra);
XX    printf("middle  there should be a frame of E's around this  text");
XX    cup(14,13+hlfxtra);
XX    printf("with  one (1) free position around it.    ");
XX    holdit();
XX  }
XX  rm("?3");

XX  ed(2);
XX  cup(1,1);
XX  println("Test of cursor-control characters inside ESC sequences.");
XX  println("Below should be two identical lines:");
XX  println("");
XX  println("A B C D E F G H I J K L M N O P Q R S");
XX  for (i = 1; i < 20; i++) {
XX    printf("%c", 64 + i);
XX    brcstr("2\010", 'C');	/* Two forward, one backspace */
XX  }
XX  println("");
XX  println("");
XX  holdit();

XX  ed(2);
XX  cup(1,1);
XX  println("Test of leading zeros in ESC sequences.");
XX  printf("Two lines below you should see the sentence \"%s\".",ctext);
XX  for (col = 1; *ctext; col++)
XX   printf("\033[00000000004;00000000%dH%c",col,*ctext++);
XX  cup(20,1);
XX  holdit();
XX}

XXtst_screen() {

XX  /* Test of:
XX     - DECSTBM (Set Top and Bottom Margins)
XX     - TBC     (Tabulation Clear)
XX     - HTS     (Horizontal Tabulation Set)
XX     - SM RM   (Set/Reset mode): - 80/132 chars
XX                                 - Origin: Realtive/absolute
XX				 - Scroll: Smooth/jump
XX				 - Wraparound
XX     - SGR     (Select Graphic Rendition)
XX     - SM RM   (Set/Reset Mode) - Inverse
XX     - DECSC   (Save Cursor)
XX     - DECRC   (Restore Cursor)
XX  */

XX  int i, j, cset, row, col, down, soft, background;

XX  static char *tststr = "*qx`";
XX  static char *attr[5] = { ";0", ";1", ";4", ";5", ";7" };

XX  cup(1,1);
XX  sm("?7");  /* Wrap Around ON */
XX  for (col = 1; col <= 160; col++) printf("*");
XX  rm("?7");  /* Wrap Around OFF */
XX  cup(3,1);
XX  for (col = 1; col <= 160; col++) printf("*");
XX  sm("?7");  /* Wrap Around ON */
XX  cup(5,1);
XX  println("This should be three identical lines of *'s completely filling");
XX  println("the top of the screen without any empty lines between.");
XX  println("(Test of WRAP AROUND mode setting.)");
XX  holdit();

XX  ed(2);
XX  tbc(3);
XX  cup(1,1);
XX  for (col = 1; col <= 78; col += 3) {
XX    cuf(3); hts();
XX  }
XX  cup(1,4);
XX  for (col = 4; col <= 78; col += 6) {
XX    tbc(0); cuf(6);
XX  }
XX  cup(1,7); tbc(1); tbc(2); /* no-op */
XX  cup(1,1); for (col = 1; col <= 78; col += 6) printf("\t*");
XX  cup(2,2); for (col = 2; col <= 78; col += 6) printf("     *");
XX  cup(4,1);
XX  println("Test of TAB setting/resetting. These two lines");
XX  printf("should look the same. ");
XX  holdit();
XX  for (background = 0; background <= 1; background++) {
XX    if (background) rm("?5");
XX    else            sm("?5");
XX    sm("?3"); /* 132 cols */
XX    ed(2);    /* VT100 clears screen on SM3/RM3, but not obviously, so... */
XX    cup(1,1); tbc(3);
XX    for (col = 1; col <= 132; col += 8) {
XX      cuf(8); hts();
XX    }
XX    cup(1,1); for (col = 1; col <= 130; col += 10) printf("1234567890");
XX    printf("12");
XX    for (row = 3; row <= 20; row++) {
XX      cup(row,row);
XX      printf("This is 132 column mode, %s background.",
XX      background ? "dark" : "light");
XX    }
XX    holdit();
XX    rm("?3"); /* 80 cols */
XX    ed(2);    /* VT100 clears screen on SM3/RM3, but not obviously, so... */
XX    cup(1,1); for (col = 1; col <= 80; col += 10) printf("1234567890");
XX    for (row = 3; row <= 20; row++) {
XX      cup(row,row);
XX      printf("This is 80 column mode, %s background.",
XX      background ? "dark" : "light");
XX    }
XX    holdit();
XX  }
XX  ed(2);
XX  sm("?6"); /* Origin mode (relative) */
XX  for (soft = -1; soft <= 0; soft++) {
XX    if (soft) sm("?4");
XX    else      rm("?4");
XX    for (row = 12; row >= 1; row -= 11) {
XX      decstbm(row, 24-row+1);
XX      ed(2);
XX      for (down = 0; down >= -1; down--) {
XX        if (down) cuu(24);
XX	else      cud(24);
XX	for (i = 1; i <= 30; i++) {
XX	  printf("%s scroll %s region %d Line %d\n",
XX		 soft ? "Soft" : "Jump",
XX		 down ? "down" : "up",
XX		 2*(13-row), i);
XX	  if (down) { ri(); ri(); }
XX	}
XX      }
XX      holdit();
XX    }
XX  }
XX  ed(2);
XX  decstbm(23,24);
XX  printf(
XX  "\nOrigin mode test. This line should be at the bottom of the screen.");
XX  cup(1,1);
XX  printf("%s",
XX  "This line should be the one above the bottom of the screeen. ");
XX  holdit();
XX  ed(2);
XX  rm("?6"); /* Origin mode (absolute) */
XX  cup(24,1);
XX  printf(
XX  "Origin mode test. This line should be at the bottom of the screen.");
XX  cup(1,1);
XX  printf("%s", "This line should be at the top if the screen. ");
XX  holdit();
XX  decstbm(1,24);

XX  ed(2);
XX  cup( 1,20); printf("Graphic rendition test pattern:");
XX  cup( 4, 1); sgr("0");         printf("vanilla");
XX  cup( 4,40); sgr("0;1");       printf("bold");
XX  cup( 6, 6); sgr(";4");        printf("underline");
XX  cup( 6,45);sgr(";1");sgr("4");printf("bold underline");
XX  cup( 8, 1); sgr("0;5");       printf("blink");
XX  cup( 8,40); sgr("0;5;1");     printf("bold blink");
XX  cup(10, 6); sgr("0;4;5");     printf("underline blink");
XX  cup(10,45); sgr("0;1;4;5");   printf("bold underline blink");
XX  cup(12, 1); sgr("1;4;5;0;7"); printf("negative");
XX  cup(12,40); sgr("0;1;7");     printf("bold negative");
XX  cup(14, 6); sgr("0;4;7");     printf("underline negative");
XX  cup(14,45); sgr("0;1;4;7");   printf("bold underline negative");
XX  cup(16, 1); sgr("1;4;;5;7");  printf("blink negative");
XX  cup(16,40); sgr("0;1;5;7");   printf("bold blink negative");
XX  cup(18, 6); sgr("0;4;5;7");   printf("underline blink negative");
XX  cup(18,45); sgr("0;1;4;5;7"); printf("bold underline blink negative");
XX  sgr("");

XX  rm("?5"); /* Inverse video off */
XX  cup(23,1); el(0); printf("Dark background. "); holdit();
XX  sm("?5"); /* Inverse video */
XX  cup(23,1); el(0); printf("Light background. "); holdit();
XX  rm("?5");
XX  ed(2);
XX  cup(8,12); printf("normal");
XX  cup(8,24); printf("bold");
XX  cup(8,36); printf("underscored");
XX  cup(8,48); printf("blinking");
XX  cup(8,60); printf("reversed");
XX  cup(10,1); printf("stars:");
XX  cup(12,1); printf("line:");
XX  cup(14,1); printf("x'es:");
XX  cup(16,1); printf("diamonds:");
XX  for (cset = 0; cset <= 3; cset++) {
XX    for (i = 0; i <= 4; i++) {
XX    cup(10 + 2 * cset, 12 + 12 * i);
XX    sgr(attr[i]);
XX    if (cset == 0 || cset == 2) scs(0,'B');
XX    else                        scs(0,'0');
XX      for (j = 0; j <= 4; j++) {
XX        printf("%c", tststr[cset]);
XX      }
XX      decsc();
XX      cup(cset + 1, i + 1); sgr(""); scs(0,'B'); printf("A");
XX      decrc();
XX      for (j = 0; j <= 4; j++) {
XX        printf("%c", tststr[cset]);
XX      }
XX    }
XX  }
XX  sgr("0"); scs(0,'B'); cup(21,1);
XX  println("Test of the SAVE/RESTORE CURSOR feature. There should");
XX  println("be ten characters of each flavour, and a rectangle");
XX  println("of 5 x 4 A's filling the top left of the screen.");
XX  holdit();
XX}

XXtst_characters() {
XX  /* Test of:
XX     SCS    (Select character Set)
XX  */

XX  int i, j, g, cset;
XX  char chcode[5], *setmsg[5];

XX  chcode[0] = 'A';
XX  chcode[1] = 'B';
XX  chcode[2] = '0';
XX  chcode[3] = '1';
XX  chcode[4] = '2';
XX  setmsg[0] = "UK / national";
XX  setmsg[1] = "US ASCII";
XX  setmsg[2] = "Special graphics and line drawing";
XX  setmsg[3] = "Alternate character ROM standard characters";
XX  setmsg[4] = "Alternate character ROM special graphics";

XX  cup(1,10); printf("Selected as G0 (with SI)");
XX  cup(1,48); printf("Selected as G1 (with SO)");
XX  for (cset = 0; cset <= 4; cset++) {
XX    scs(1,'B');
XX    cup(3 + 4 * cset, 1);
XX    sgr("1");
XX    printf("Character set %c (%s)",chcode[cset], setmsg[cset]);
XX    sgr("0");
XX    for (g = 0; g <= 1; g++) {
XX      scs(g,chcode[cset]);
XX      for (i = 1; i <= 3; i++) {
XX        cup(3 + 4 * cset + i, 10 + 38 * g);
XX        for (j = 0; j <= 31; j++) {
XX	  printf("%c", i * 32 + j);
XX	}
XX      }
XX    }
XX  }
XX  scs(1,'B');
XX  cup(24,1); printf("These are the installed character sets. ");
XX  holdit();
XX}

XXtst_doublesize() {
XX  /* Test of:
XX     DECSWL  (Single Width Line)
XX     DECDWL  (Double Width Line)
XX     DECDHL  (Double Height Line) (also implicit double width)
XX  */

XX  int col, i, w, w1;

XX  /* Print the test pattern in both 80 and 132 character width  */

XX  for(w = 0; w <= 1; w++) {
XX    w1 = 13 * w;

XX    ed(2);
XX    cup(1, 1);
XX    if (w) { sm("?3"); printf("132 column mode"); }
XX    else   { rm("?3"); printf(" 80 column mode"); }

XX    cup( 5, 3 + 2 * w1);
XX    printf("v------- left margin");

XX    cup( 7, 3 + 2 * w1);
XX    printf("This is a normal-sized line");
XX    decdhl(0); decdhl(1); decdwl(); decswl();

XX    cup( 9, 2 + w1);
XX    printf("This is a Double-width line");
XX    decswl(); decdhl(0); decdhl(1); decdwl();

XX    cup(11, 2 + w1);
XX    decdwl(); decswl(); decdhl(1); decdhl(0);
XX    printf("This is a Double-width-and-height line");
XX    cup(12, 2 + w1);
XX    decdwl(); decswl(); decdhl(0); decdhl(1);
XX    printf("This is a Double-width-and-height line");

XX    cup(14, 2 + w1);
XX    decdwl(); decswl(); decdhl(1); decdhl(0); el(2);
XX    printf("This is another such line");
XX    cup(15, 2 + w1);
XX    decdwl(); decswl(); decdhl(0); decdhl(1);
XX    printf("This is another such line");

XX    cup(17, 3 + 2 * w1);
XX    printf("^------- left margin");

XX    cup(21, 1);
XX    printf("This is not a double-width line");
XX    for (i = 0; i <= 1; i++) {
XX      cup(21,6);
XX      if (i) { printf("**is**"); decdwl(); }
XX      else   { printf("is not"); decswl(); }
XX      cup(23,1); holdit();
XX    }
XX  }
XX  /* Set vanilla tabs for next test */
XX  cup(1,1); tbc(3); for (col = 1; col <= 132; col += 8) { cuf(8); hts(); }
XX  rm("?3");
XX  ed(2);
XX  scs(0,'0');

XX  cup( 8,1); decdhl(0); printf("lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
XX  cup( 9,1); decdhl(1); printf("lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
XX  cup(10,1); decdhl(0); printf("x%c%c%c%c%cx",9,9,9,9,9);
XX  cup(11,1); decdhl(1); printf("x%c%c%c%c%cx",9,9,9,9,9);
XX  cup(12,1); decdhl(0); printf("x%c%c%c%c%cx",9,9,9,9,9);
XX  cup(13,1); decdhl(1); printf("x%c%c%c%c%cx",9,9,9,9,9);
XX  cup(14,1); decdhl(0); printf("x                                      x");
XX  cup(15,1); decdhl(1); printf("x                                      x");
XX  cup(16,1); decdhl(0); printf("mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj");
XX  cup(17,1); decdhl(1); printf("mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj");
XX  scs(0,'B'); sgr("1;5");
XX  cup(12,3);
XX  printf("* The mad programmer strikes again * ");
XX  cup(13,3); printf("%c",9); cub(6);
XX  printf("* The mad programmer strikes again *");
XX  sgr("0");
XX  cup(22,1);
XX  println("Another test pattern...  a frame with blinking bold text,");
XX  printf("all in double-height double-width size. ");
XX  holdit();

XX  decstbm(8,24); /* Absolute origin mode, so cursor is set at (1,1) */
XX  cup(8,1);
XX  for (i = 1; i <= 12; i++)
XX    ri();
XX  decstbm(0,0);	/* No scroll region	*/
XX  cup(1,1);
XX  printf("%s", "Exactly half of the box should remain. ");
XX  holdit();
XX}

XXtst_keyboard() {

XX/* Test of:
XX     - DECLL   (Load LEDs)
XX     - Keyboard return messages
XX     - SM RM   (Set/Reset Mode) - Cursor Keys
XX                                - Auto repeat
XX     - DECKPAM (Keypad Application Mode)
XX     - DECKPNM (Keypad Numeric Mode)

XXThe standard VT100 keayboard layout:
XX 
XX                                                        UP   DN   LE  RI

XXESC   1!   2@   3#   4$   5%   6^   7&   8*   9(   0)   -_   =+   `~  BS

XXTAB*    qQ   wW   eE   rR   tT   yY   uU   iI   oO   pP   [{   ]}      DEL

XX**   **   aA   sS   dD   fF   gG   hH   jJ   kK   lL   ;:   ,"   RETN  \|

XX**   ****   zZ   xX   cC   vV   bB   nN   mM   ,<   .>   /?   ****   LF

XX             ****************SPACE BAR****************

XX                                                           PF1 PF2 PF3 PF4

XX                                                           *7* *8* *9* *-*

XX                                                           *4* *5* *6* *,*

XX                                                           *1* *2* *3*

XX                                                           ***0*** *.* ENT
XX*/

XX  char *ledmsg[6], *ledseq[6];

XX  int  i, j, okflag;
XX  int  kblayout;
XX  int  ckeymode;
XX  int  fkeymode;
XX  char kbdc;
XX  char *kbds = " ";
XX  char *curkeystr, *fnkeystr, *abmstr;
XX  char arptstring[500];

XX  static struct key {
XX      char c;
XX      int  row;
XX      int  col;
XX      char *symbol;
XX  } keytab [] = {
XX      { 27, 1,  0, "ESC" },
XX      { '1', 1,  6, "1" },    { '!', 1,  7, "!" },
XX      { '2', 1, 11, "2" },    { '@', 1, 12, "@" },
XX      { '3', 1, 16, "3" },    { '#', 1, 17, "#" },
XX      { '4', 1, 21, "4" },    { '$', 1, 22, "$" },
XX      { '5', 1, 26, "5" },    {'\%', 1, 27, "%" },
XX      { '6', 1, 31, "6" },    { '^', 1, 32, "^" },
XX      { '7', 1, 36, "7" },    { '&', 1, 37, "&" },
XX      { '8', 1, 41, "8" },    { '*', 1, 42, "*" },
XX      { '9', 1, 46, "9" },    { '(', 1, 47, "(" },
XX      { '0', 1, 51, "0" },    { ')', 1, 52, ")" },
XX      { '-', 1, 56, "-" },    { '_', 1, 57, "_" },
XX      { '=', 1, 61, "=" },    { '+', 1, 62, "+" },
XX      { '`', 1, 66, "`" },    { '~', 1, 67, "~" },
XX      {   8, 1, 70, "BS" },
XX      {   9, 2,  0, " TAB " },
XX      { 'q', 2,  8, "q" },    { 'Q', 2,  9, "Q" },
XX      { 'w', 2, 13, "w" },    { 'W', 2, 14, "W" },
XX      { 'e', 2, 18, "e" },    { 'E', 2, 19, "E" },
XX      { 'r', 2, 23, "r" },    { 'R', 2, 24, "R" },
XX      { 't', 2, 28, "t" },    { 'T', 2, 29, "T" },
XX      { 'y', 2, 33, "y" },    { 'Y', 2, 34, "Y" },
XX      { 'u', 2, 38, "u" },    { 'U', 2, 39, "U" },
XX      { 'i', 2, 43, "i" },    { 'I', 2, 44, "I" },
XX      { 'o', 2, 48, "o" },    { 'O', 2, 49, "O" },
XX      { 'p', 2, 53, "p" },    { 'P', 2, 54, "P" },
XX      { '[', 2, 58, "[" },    { '{', 2, 59, "{" },
XX      { ']', 2, 63, "]" },    { '}', 2, 64, "}" },
XX      { 127, 2, 71, "DEL" },
XX      { 'a', 3, 10, "a" },    { 'A', 3, 11, "A" },
XX      { 's', 3, 15, "s" },    { 'S', 3, 16, "S" },
XX      { 'd', 3, 20, "d" },    { 'D', 3, 21, "D" },
XX      { 'f', 3, 25, "f" },    { 'F', 3, 26, "F" },
XX      { 'g', 3, 30, "g" },    { 'G', 3, 31, "G" },
XX      { 'h', 3, 35, "h" },    { 'H', 3, 36, "H" },
XX      { 'j', 3, 40, "j" },    { 'J', 3, 41, "J" },
XX      { 'k', 3, 45, "k" },    { 'K', 3, 46, "K" },
XX      { 'l', 3, 50, "l" },    { 'L', 3, 51, "L" },
XX      { ';', 3, 55, ";" },    { ':', 3, 56, ":" },
XX      {'\'', 3, 60, "'" },    { '"', 3, 61,"\"" },
XX      {  13, 3, 65, "RETN"},
XX      {'\\', 3, 71,"\\" },    { '|', 3, 72, "|" },
XX      { 'z', 4, 12, "z" },    { 'Z', 4, 13, "Z" },
XX      { 'x', 4, 17, "x" },    { 'X', 4, 18, "X" },
XX      { 'c', 4, 22, "c" },    { 'C', 4, 23, "C" },
XX      { 'v', 4, 27, "v" },    { 'V', 4, 28, "V" },
XX      { 'b', 4, 32, "b" },    { 'B', 4, 33, "B" },
XX      { 'n', 4, 37, "n" },    { 'N', 4, 38, "N" },
XX      { 'm', 4, 42, "m" },    { 'M', 4, 43, "M" },
XX      { ',', 4, 47, "," },    { '<', 4, 48, "<" },
XX      { '.', 4, 52, "." },    { '>', 4, 53, ">" },
XX      { '/', 4, 57, "/" },    { '?', 4, 58, "?" },
XX      {  10, 4, 69, "LF" },
XX      { ' ', 5, 13, "                SPACE BAR                "},
XX      {'\0', 0,  0, ""  }
XX    };

XX  static struct natkey {
XX      char natc;
XX      int  natrow;
XX      int  natcol;
XX      char *natsymbol;
XX  } natkeytab [][29] = {
XX      {
XX        { '"', 1, 12, "\""},
XX        { '&', 1, 32, "&" },
XX        { '/', 1, 37, "/" },
XX        { '(', 1, 42, "(" },
XX        { ')', 1, 47, ")" },
XX        { '=', 1, 52, "=" },
XX        { '+', 1, 56, "+" },    { '?', 1, 57, "?" },
XX        { '`', 1, 61, "`" },    { '@', 1, 62, "@" },
XX        { '<', 1, 66, "<" },    { '>', 1, 67, ">" },
XX        { '}', 2, 58, "}" },    { ']', 2, 59, "]" },
XX        { '^', 2, 63, "^" },    { '~', 2, 64, "~" },
XX        { '|', 3, 55, "|" },    {'\\', 3, 56,"\\" },
XX        { '{', 3, 60, "{" },    { '[', 3, 61, "[" },
XX        {'\'', 3, 71, "'" },    { '*', 3, 72, "*" },
XX        { ',', 4, 47, "," },    { ';', 4, 48, ";" },
XX        { '.', 4, 52, "." },    { ':', 4, 53, ":" },
XX        { '-', 4, 57, "-" },    { '_', 4, 58, "_" },
XX        {'\0', 0,  0, ""  }
XX      },
XX      {
XX        { '"', 1, 12, "\""},
XX        { '&', 1, 32, "&" },
XX        { '/', 1, 37, "/" },
XX        { '(', 1, 42, "(" },
XX        { ')', 1, 47, ")" },
XX        { '=', 1, 52, "=" },
XX        { '+', 1, 56, "+" },    { '?', 1, 57, "?" },
XX        { '`', 1, 61, "`" },    { '@', 1, 62, "@" },
XX        { '<', 1, 66, "<" },    { '>', 1, 67, ">" },
XX        { '}', 2, 58, "}" },    { ']', 2, 59, "]" },
XX        { '~', 2, 63, "~" },    { '^', 2, 64, "^" },
XX        { '|', 3, 55, "|" },    {'\\', 3, 56,"\\" },
XX        { '{', 3, 60, "{" },    { '[', 3, 61, "[" },
XX        {'\'', 3, 71, "'" },    { '*', 3, 72, "*" },
XX        { ',', 4, 47, "," },    { ';', 4, 48, ";" },
XX        { '.', 4, 52, "." },    { ':', 4, 53, ":" },
XX        { '-', 4, 57, "-" },    { '_', 4, 58, "_" },
XX        {'\0', 0,  0, ""  }
XX      }
XX  };

XX  static struct curkey {
XX      char *curkeymsg[3];
XX      int  curkeyrow;
XX      int  curkeycol;
XX      char *curkeysymbol;
XX      char *curkeyname;
XX  } curkeytab [] = {

XX      /* A Reset, A Set,  VT52  */

XX      {{"\033[A","\033OA","\033A"}, 0, 56, "UP",  "Up arrow"   },
XX      {{"\033[B","\033OB","\033B"}, 0, 61, "DN",  "Down arrow" },
XX      {{"\033[D","\033OD","\033D"}, 0, 66, "LT",  "Left arrow" },
XX      {{"\033[C","\033OC","\033C"}, 0, 71, "RT",  "Right arrow"},
XX      {{"",      "",       ""     }, 0,  0, "",    "" }
XX  };

XX  static struct fnkey {
XX      char *fnkeymsg[4];
XX      int  fnkeyrow;
XX      int  fnkeycol;
XX      char *fnkeysymbol;
XX      char *fnkeyname;
XX  } fnkeytab [] = {

XX      /* ANSI-num,ANSI-app,VT52-nu,VT52-ap,  r, c,  symb   name         */

XX      {{"\033OP","\033OP","\033P","\033P" }, 6, 59, "PF1", "PF1"        },
XX      {{"\033OQ","\033OQ","\033Q","\033Q" }, 6, 63, "PF2", "PF2"        },
XX      {{"\033OR","\033OR","\033R","\033R" }, 6, 67, "PF3", "PF3"        },
XX      {{"\033OS","\033OS","\033S","\033S" }, 6, 71, "PF4", "PF4"        },
XX      {{"7",     "\033Ow","7",    "\033?w"}, 7, 59, " 7 ", "Numeric 7"  },
XX      {{"8",     "\033Ox","8",    "\033?x"}, 7, 63, " 8 ", "Numeric 8"  },
XX      {{"9",     "\033Oy","9",    "\033?y"}, 7, 67, " 9 ", "Numeric 9"  },
XX      {{"-",     "\033Om","-",    "\033?m"}, 7, 71, " - ", "Minus"      },
XX      {{"4",     "\033Ot","4",    "\033?t"}, 8, 59, " 4 ", "Numeric 4"  },
XX      {{"5",     "\033Ou","5",    "\033?u"}, 8, 63, " 5 ", "Numeric 5"  },
XX      {{"6",     "\033Ov","6",    "\033?v"}, 8, 67, " 6 ", "Numeric 6"  },
XX      {{",",     "\033Ol",",",    "\033?l"}, 8, 71, " , ", "Comma"      },
XX      {{"1",     "\033Oq","1",    "\033?q"}, 9, 59, " 1 ", "Numeric 1"  },
XX      {{"2",     "\033Or","2",    "\033?r"}, 9, 63, " 2 ", "Numeric 2"  },
XX      {{"3",     "\033Os","3",    "\033?s"}, 9, 67, " 3 ", "Numeric 3"  },
XX      {{"0",     "\033Op","0",    "\033?p"},10, 59,"   O   ","Numeric 0"},
XX      {{".",     "\033On",".",    "\033?n"},10, 67, " . ", "Point"      },
XX      {{"\015",  "\033OM","\015", "\033?M"},10, 71, "ENT", "ENTER"      },
XX      {{"","","",""},       0,  0, "",    ""           }
XX    };

XX  static struct ckey {
XX      int  ccount;
XX      char *csymbol;
XX  } ckeytab [] = {
XX      { 0, "NUL (CTRL-@ or CTRL-Space)" },
XX      { 0, "SOH (CTRL-A)" },
XX      { 0, "STX (CTRL-B)" },
XX      { 0, "ETX (CTRL-C)" },
XX      { 0, "EOT (CTRL-D)" },
XX      { 0, "ENQ (CTRL-E)" },
XX      { 0, "ACK (CTRL-F)" },
XX      { 0, "BEL (CTRL-G)" },
XX      { 0, "BS  (CTRL-H) (BACK SPACE)" },
XX      { 0, "HT  (CTRL-I) (TAB)" },
XX      { 0, "LF  (CTRL-J) (LINE FEED)" },
XX      { 0, "VT  (CTRL-K)" },
XX      { 0, "FF  (CTRL-L)" },
XX      { 0, "CR  (CTRL-M) (RETURN)" },
XX      { 0, "SO  (CTRL-N)" },
XX      { 0, "SI  (CTRL-O)" },
XX      { 0, "DLE (CTRL-P)" },
XX      { 0, "DC1 (CTRL-Q) (X-On)" },
XX      { 0, "DC2 (CTRL-R)" },
XX      { 0, "DC3 (CTRL-S) (X-Off)" },
XX      { 0, "DC4 (CTRL-T)" },
XX      { 0, "NAK (CTRL-U)" },
XX      { 0, "SYN (CTRL-V)" },
XX      { 0, "ETB (CTRL-W)" },
XX      { 0, "CAN (CTRL-X)" },
XX      { 0, "EM  (CTRL-Y)" },
XX      { 0, "SUB (CTRL-Z)" },
XX      { 0, "ESC (CTRL-[) (ESCAPE)" },
XX      { 0, "FS  (CTRL-\\ or CTRL-? or CTRL-_)" },
XX      { 0, "GS  (CTRL-])" },
XX      { 0, "RS  (CTRL-^ or CTRL-~ or CTRL-`)" },
XX      { 0, "US  (CTRL-_ or CTRL-?)" }
XX  };

XX  static char *keyboardmenu[] = {
XX      "Standard American ASCII layout",
XX      "Swedish national layout D47",
XX      "Swedish national layout E47",
XX      /* add new keyboard layouts here */
XX      ""
XX    };

XX  static char *curkeymodes[3] = {
XX      "ANSI / Cursor key mode RESET",
XX      "ANSI / Cursor key mode SET",
XX      "VT52 Mode"
XX  };

XX  static char *fnkeymodes[4] = {
XX      "ANSI Numeric mode",
XX      "ANSI Application mode",
XX      "VT52 Numeric mode",
XX      "VT52 Application mode"
XX  };

XX  ledmsg[0] = "L1 L2 L3 L4"; ledseq[0] = "1;2;3;4";
XX  ledmsg[1] = "   L2 L3 L4"; ledseq[1] = "1;0;4;3;2";
XX  ledmsg[2] = "   L2 L3";    ledseq[2] = "1;4;;2;3";
XX  ledmsg[3] = "L1 L2";       ledseq[3] = ";;2;1";
XX  ledmsg[4] = "L1";          ledseq[4] = "1";
XX  ledmsg[5] = "";            ledseq[5] = "";

XX#ifdef UNIX
XX  fflush(stdout);
XX#endif
XX  ed(2);
XX  cup(10,1);
XX  println("These LEDs (\"lamps\") on the keyboard should be on:");
XX  for (i = 0; i <= 5; i++) {
XX    cup(10,52); el(0); printf("%s", ledmsg[i]);
XX    decll("0");
XX    decll(ledseq[i]);
XX    cup(12,1); holdit();
XX  }

XX  ed(2);
XX  cup(10,1);
XX  println("Test of the AUTO REPEAT feature");
XX  println("");
XX  println("Hold down an alphanumeric key for a while, then push RETURN.");
XX  printf("%s", "Auto Repeat OFF: ");
XX  rm("?8");
XX  inputline(arptstring);
XX  if (strlen(arptstring) == 0)      println("No characters read!??");
XX  else if (strlen(arptstring) == 1) println("OK.");
XX  else                              println("Too many characters read.");
XX  println("");
XX  println("Hold down an alphanumeric key for a while, then push RETURN.");
XX  printf("%s", "Auto Repeat ON: ");
XX  sm("?8");
XX  inputline(arptstring);
XX  if (strlen(arptstring) == 0)      println("No characters read!??");
XX  else if (strlen(arptstring) == 1) println("Not enough characters read.");
XX  else                              println("OK.");
XX  println("");
XX  holdit();

XX  ed(2);
XX  cup(5,10);
XX  println("Choose keyboard layout:");
XX  kblayout = menu(keyboardmenu);
XX  if (kblayout) {
XX    kblayout--;
XX    for (j = 0; natkeytab[kblayout][j].natc != '\0'; j++) {
XX      for (i = 0; keytab[i].c != '\0'; i++) {
XX	if (keytab[i].row == natkeytab[kblayout][j].natrow &&
XX	    keytab[i].col == natkeytab[kblayout][j].natcol) {
XX	  keytab[i].c = natkeytab[kblayout][j].natc;
XX	  keytab[i].symbol = natkeytab[kblayout][j].natsymbol;
XX	  break;
XX	}
XX      }
XX    }
XX  }

XX  ed(2);
XX  for (i = 0; keytab[i].c != '\0'; i++) {
XX    cup(1 + 2 * keytab[i].row, 1 + keytab[i].col);
XX    sgr("7");
XX    printf("%s", keytab[i].symbol);
XX    sgr("");
XX  }
XX  cup(22,1);
XX#ifdef UNIX
XX  sgttyNew.sg_flags &= ~CRMOD;
XX  sgttyNew.sg_flags &= ~ECHO;
XX  stty(0, &sgttyNew);
XX#endif
XX  inflush();
XX  printf("Press each key, both shifted and unshifted. Finish with RETURN:");
XX  do { /* while (kbdc != 13) */
XX    cup(23,1); kbdc = inchar();
XX    cup(23,1); el(0);
XX    sprintf(kbds, "%c", kbdc);
XX    chrprint(kbds);
XX    for (i = 0; keytab[i].c != '\0'; i++) {
XX      if (keytab[i].c == kbdc) {
XX        cup(1 + 2 * keytab[i].row, 1 + keytab[i].col);
XX	printf("%s", keytab[i].symbol);
XX	break;
XX      }
XX    }
XX  } while (kbdc != 13);
XX#ifdef SARG10
XX  inchar();  /* Local hack: Read LF that TOPS-10 adds to CR */
XX#endif
XX  cup(23,1); el(0);

XX  for (ckeymode = 0; ckeymode <= 2; ckeymode++) {
XX    if (ckeymode) sm("?1");
XX    else            rm("?1");
XX    for (i = 0; curkeytab[i].curkeysymbol[0] != '\0'; i++) {
XX      cup(1 + 2 * curkeytab[i].curkeyrow, 1 + curkeytab[i].curkeycol);
XX      sgr("7");
XX      printf("%s", curkeytab[i].curkeysymbol);
XX      sgr("");
XX    }
XX    cup(20,1); printf("<%s>%20s", curkeymodes[ckeymode], "");
XX    cup(22,1); el(0);
XX    cup(22,1); printf("%s", "Press each cursor key. Finish with TAB.");
XX    for(;;) {
XX      cup(23,1);
XX      if (ckeymode == 2) rm("?2"); /* VT52 mode */
XX      curkeystr = instr();
XX      esc("<");                      /* ANSI mode */
XX      cup(23,1); el(0);
XX      cup(23,1); chrprint(curkeystr);
XX      if (!strcmp(curkeystr,"\t")) break;
XX      for (i = 0; curkeytab[i].curkeysymbol[0] != '\0'; i++) {
XX	if (!strcmp(curkeystr,curkeytab[i].curkeymsg[ckeymode])) {
XX	  sgr("7");
XX	  printf(" (%s key) ", curkeytab[i].curkeyname);
XX	  sgr("");
XX	  cup(1 + 2 * curkeytab[i].curkeyrow,
XX	      1 + curkeytab[i].curkeycol);
XX	  printf("%s", curkeytab[i].curkeysymbol);
XX	  break;
XX	}
XX      }
XX      if (i == sizeof(curkeytab) / sizeof(struct curkey) - 1) {
XX	sgr("7");
XX	printf("%s", " (Unknown cursor key) ");
XX	sgr("");
XX      }
XX    }
XX  }

XX  for (fkeymode = 0; fkeymode <= 3; fkeymode++) {
XX    for (i = 0; fnkeytab[i].fnkeysymbol[0] != '\0'; i++) {
XX      cup(1 + 2 * fnkeytab[i].fnkeyrow, 1 + fnkeytab[i].fnkeycol);
XX      sgr("7");
XX      printf("%s", fnkeytab[i].fnkeysymbol);
XX      sgr("");
XX    }
XX    cup(20,1); printf("<%s>%20s", fnkeymodes[fkeymode], "");
XX    cup(22,1); el(0);
XX    cup(22,1); printf("%s", "Press each function key. Finish with TAB.");
XX    for(;;) {
XX      cup(23,1);
XX      if (fkeymode >= 2)  rm("?2");    /* VT52 mode */
XX      if (fkeymode % 2)   deckpam();   /* Application mode */
XX      else                 deckpnm();	/* Numeric mode     */
XX      fnkeystr = instr();
XX      esc("<");				/* ANSI mode */
XX      cup(23,1); el(0);
XX      cup(23,1); chrprint(fnkeystr);
XX      if (!strcmp(fnkeystr,"\t")) break;
XX      for (i = 0; fnkeytab[i].fnkeysymbol[0] != '\0'; i++) {
XX	if (!strcmp(fnkeystr,fnkeytab[i].fnkeymsg[fkeymode])) {
XX	  sgr("7");
XX	  printf(" (%s key) ", fnkeytab[i].fnkeyname);
XX	  sgr("");
XX	  cup(1 + 2 * fnkeytab[i].fnkeyrow, 1 + fnkeytab[i].fnkeycol);
XX	  printf("%s", fnkeytab[i].fnkeysymbol);
XX	  break;
XX	}
XX      }
XX      if (i == sizeof(fnkeytab) / sizeof(struct fnkey) - 1) {
XX	sgr("7");
XX	printf("%s", " (Unknown function key) ");
XX	sgr("");
XX      }
XX    }
XX  }

XX#ifdef UNIX
XX  sgttyNew.sg_flags |= CRMOD;
XX  stty(0, &sgttyNew);
XX#endif
XX  ed(2);
XX  cup(5,1);
XX  println("Finally, a check of the ANSWERBACK MESSAGE, which can be sent");
XX  println("by pressing CTRL-BREAK. The answerback message can be loaded");
XX  println("in SET-UP B by pressing SHIFT-A and typing e.g.");
XX  println("");
XX  println("         \" H e l l o , w o r l d Return \"");
XX  println("");
XX  println("(the double-quote characters included).  Do that, and then try");
XX  println("to send an answerback message with CTRL-BREAK.  If it works,");
XX  println("the answerback message should be displayed in reverse mode.");
XX  println("Finish with a single RETURN.");

XX#ifdef UNIX
XX  sgttyNew.sg_flags &= ~CRMOD;
XX  stty(0, &sgttyNew);
XX#endif
XX  do {
XX    cup(17,1);
XX    inflush();
XX    abmstr = instr();
XX    cup(17,1);
XX    el(0);
XX    chrprint(abmstr);
XX  } while (strcmp(abmstr,"\r"));

XX  ed(2);
XX  for (i = 0; i < 32; i++) {
XX    cup(1 + (i % 16), 1 + 40 * (i / 16));
XX    sgr("7");
XX    printf("%s", ckeytab[i].csymbol);
XX    sgr("0");
XX  }
XX  cup(19,1);
XX#ifdef UNIX
XX  sgttyNew.sg_flags |= CRMOD;
XX  stty(0, &sgttyNew);
XX#endif
XX  println(
XX  "Push each CTRL-key TWICE. Note that you should be able to send *all*");
XX  println(
XX  "CTRL-codes twice, including CTRL-S (X-Off) and CTRL-Q (X-Off)!");
XX  println(
XX  "Finish with DEL (also called DELETE or RUB OUT), or wait 1 minute.");
XX#ifdef UNIX
XX#ifdef SIII
XX  sgttyNew.sg_flags &= ~CBREAK;
XX  stty(0, &sgttyNew);
XX#endif
XX  sgttyNew.sg_flags |= RAW;
XX  stty(0, &sgttyNew);
XX#endif
XX  ttybin(1);
XX#ifdef SARG20
XX  page(0);	/* Turn off all character processing at input */
XX  superbin(1);	/* Turn off ^C (among others). Keep your fingers crossed!! */
XX#endif
XX  do {
XX    cup(23,1); kbdc = inchar();
XX    cup(23,1); el(0);
XX    if (kbdc < 32) printf("  %s", ckeytab[kbdc].csymbol);
XX    else {
XX      sprintf(kbds, "%c", kbdc);
XX      chrprint(kbds);
XX      printf("%s", " -- not a CTRL key");
XX    }
XX    if (kbdc < 32) ckeytab[kbdc].ccount++;
XX    if (ckeytab[kbdc].ccount == 2) {
XX      cup(1 + (kbdc % 16), 1 + 40 * (kbdc / 16));
XX      printf("%s", ckeytab[kbdc].csymbol);
XX    }
XX  } while (kbdc != '\177');
XX#ifdef UNIX
XX  sgttyNew.sg_flags &= ~RAW;
XX  sgttyNew.sg_flags |= ECHO;
XX  stty(0, &sgttyNew);
XX#ifdef SIII
XX  sgttyNew.sg_flags |= CBREAK;
XX  stty(0, &sgttyNew);
XX#endif
XX#endif
XX  ttybin(0);
XX#ifdef SARG20
XX  superbin(0);	/* Puuuh! We made it!? */
XX  page(1);	/* Back to normal input processing */
XX  ttybin(1);	/* This must be the mode for DEC20 */
XX#endif
XX  cup(24,1);
XX  okflag = 1;
XX  for (i = 0; i < 32; i++) if (ckeytab[i].ccount < 2) okflag = 0;
XX  if (okflag) printf("%s", "OK. ");
XX  else        printf("%s", "You have not been able to send all CTRL keys! ");
XX  holdit();
XX}

XXtst_reports() {
XX  /* Test of:
XX       <ENQ>       (AnswerBack Message)
XX       SM RM       (Set/Reset Mode) - LineFeed / Newline
XX       DSR         (Device Status Report)
XX       DA          (Device Attributes)
XX       DECREQTPARM (Request Terminal Parameters)
XX  */

XX  int parity, nbits, xspeed, rspeed, clkmul, flags;
XX  int i, reportpos;
XX  char *report, *report2;
XX  static char *attributes[][2] = {
XX    { "\033[?1;0c",   "No options (vanilla VT100)" },
XX    { "\033[?1;1c",   "VT100 with STP" },
XX    { "\033[?1;2c",   "VT100 with AVO (could be a VT102)" },
XX    { "\033[?1;3c",   "VT100 with STP and AVO" },
XX    { "\033[?1;4c",   "VT100 with GPO" },
XX    { "\033[?1;5c",   "VT100 with STP and GPO" },
XX    { "\033[?1;6c",   "VT100 with AVO and GPO" },
XX    { "\033[?1;7c",   "VT100 with STP, AVO and GPO" },
XX    { "\033[?1;11c",  "VT100 with PP and AVO" },
XX    { "\033[?1;15c",  "VT100 with PP, GPO and AVO" },
XX    { "\033[?4;2c",   "VT132 with AVO" },
XX    { "\033[?4;3c",   "VT132 with AVO and STP" },
XX    { "\033[?4;6c",   "VT132 with GPO and AVO" },
XX    { "\033[?4;7c",   "VT132 with GPO, AVO, and STP" },
XX    { "\033[?4;11c",  "VT132 with PP and AVO" },
XX    { "\033[?4;15c",  "VT132 with PP, GPO and AVO" },
XX    { "\033[?7c",     "VT131" },
XX    { "\033[?12;5c",  "VT125" },           /* VT125 also has ROM version */
XX    { "\033[?12;7c",  "VT125 with AVO" },  /* number, so this won't work */
XX    { "\033[?5;0c",   "VK100 (GIGI)" },
XX    { "\033[?5c",     "VK100 (GIGI)" },
XX    { "", "" }
XX  };

XX#ifdef UNIX
XX  sgttyNew.sg_flags &= ~ECHO;
XX  stty(0, &sgttyNew);
XX#endif
XX  cup(5,1);
XX  println("This is a test of the ANSWERBACK MESSAGE. (To load the A.B.M.");
XX  println("see the TEST KEYBOARD part of this program). Below here, the");
XX  println("current answerback message in your terminal should be");
XX  println("displayed. Finish this test with RETURN.");
XX  cup(10,1);
XX  inflush();
XX  printf("%c", 5); /* ENQ */
XX  report = instr();
XX  cup(10,1);
XX  chrprint(report);
XX  cup(12,1);
XX  holdit();

XX  ed(2);
XX  cup(1,1);
XX  println("Test of LineFeed/NewLine mode.");
XX  cup(3,1);
XX  sm("20");
XX#ifdef UNIX
XX  sgttyNew.sg_flags &= ~CRMOD;
XX  stty(0, &sgttyNew);
XX#endif
XX  printf("NewLine mode set. Push the RETURN key: ");
XX  report = instr();
XX  cup(4,1);
XX  el(0);
XX  chrprint(report);
XX  if (!strcmp(report, "\015\012")) printf(" -- OK");
XX  else                             printf(" -- Not expected");
XX  cup(6,1);
XX  rm("20");
XX  printf("NewLine mode reset. Push the RETURN key: ");
XX  report = instr();
XX  cup(7,1);
XX  el(0);
XX  chrprint(report);
XX  if (!strcmp(report, "\015")) printf(" -- OK");
XX  else                         printf(" -- Not expected");
XX  cup(9,1);
XX#ifdef UNIX
XX  sgttyNew.sg_flags |= CRMOD;
XX  stty(0, &sgttyNew);
XX#endif
XX  holdit();

XX  ed(2);
XX  cup(1,1);
XX  printf("Test of Device Status Report 5 (report terminal status).");
XX  cup(2,1);
XX  dsr(5);
XX  report = instr();
XX  cup(2,1);
XX  el(0);
XX  printf("Report is: ");
XX  chrprint(report);
XX  if      (!strcmp(report,"\033[0n")) printf(" -- means \"TERMINAL OK\"");
XX  else if (!strcmp(report,"\033[3n")) printf(" -- means \"TERMINAL OK\"");
XX  else                                printf(" -- Unknown response!");

XX  cup(4,1);
XX  println("Test of Device Status Report 6 (report cursor position).");
XX  cup(5,1);
XX  dsr(6);
XX  report = instr();
XX  cup(5,1);
XX  el(0);
XX  printf("Report is: ");
XX  chrprint(report);
XX  if (!strcmp(report,"\033[5;1R")) printf(" -- OK");
XX  else                             printf(" -- Unknown response!");

XX  cup(7,1);
XX  println("Test of Device Attributes report (what are you)");
XX  cup(8,1);
XX  da(0);
XX  report = instr();
XX  cup(8,1);
XX  el(0);
XX  printf("Report is: ");
XX  chrprint(report);
XX  for (i = 0; *attributes[i][0] != '\0'; i++) {
XX    if (!strcmp(report,attributes[i][0])) break;
XX  }
XX  if (*attributes[i][0] == '\0')
XX  printf(" -- Unknown response, refer to the manual");
XX  else {
XX    printf(" -- means %s", attributes[i][1]);
XX    if (i) {
XX      cup(9,1);
XX      println("Legend: STP = Processor Option");
XX      println("        AVO = Advanced Video Option");
XX      println("        GPO = Graphics Processor Option");
XX      println("        PP  = Printer Port");
XX    }
XX  }

XX  cup(14,1);
XX  println("Test of the \"Request Terminal Parameters\" feature, argument 0.");
XX  cup(15,1);
XX  decreqtparm(0);
XX  report = instr();
XX  cup(15,1);
XX  el(0);
XX  printf("Report is: ");
XX  chrprint(report);
XX  if (strlen(report) < 16
XX   || report[0] != '\033'
XX   || report[1] != '['
XX   || report[2] != '2'
XX   || report[3] != ';')
XX  println(" -- Bad format");
XX  else {
XX    reportpos = 4;
XX    parity = scanto(report, &reportpos, ';');
XX    nbits  = scanto(report, &reportpos, ';');
XX    xspeed = scanto(report, &reportpos, ';');
XX    rspeed = scanto(report, &reportpos, ';');
XX    clkmul = scanto(report, &reportpos, ';');
XX    flags  = scanto(report, &reportpos, 'x');
XX    if (parity == 0 || nbits == 0 || clkmul == 0) println(" -- Bad format");
XX    else                                          println(" -- OK");
XX    printf(
XX    "This means: Parity %s, %s bits, xmitspeed %s, recvspeed %s.\n",
XX    lookup(paritytable, parity),
XX    lookup(nbitstable, nbits),
XX    lookup(speedtable, xspeed),
XX    lookup(speedtable, rspeed));
XX    printf("(CLoCk MULtiplier = %d, STP option flags = %d)\n", clkmul, flags);
XX  }

XX  cup(19,1);
XX  println("Test of the \"Request Terminal Parameters\" feature, argument 1.");
XX  cup(20,1);
XX  decreqtparm(1);	/* Does the same as decreqtparm(0), reports "3" */
XX  report2 = instr();
XX  cup(20,1);
XX  el(0);
XX  printf("Report is: ");
XX  chrprint(report2);
XX  if (strlen(report2) < 3
XX   || report2[2] != '3')
XX  println(" -- Bad format");
XX  else {
XX    report2[2] = '2';
XX    if (!strcmp(report,report2)) println(" -- OK");
XX    else                         println(" -- Bad format");
XX  }
XX  cup(24,1);
XX  holdit();
XX#ifdef UNIX
XX  sgttyNew.sg_flags |= ECHO;
XX  stty(0, &sgttyNew);
XX#endif
XX}

XXtst_vt52() {

XX  static struct rtabl {
XX      char *rcode;
XX      char *rmsg;
XX  } resptable[] = {
XX      { "\033/K", " -- OK (means Standard VT52)" },
XX      { "\033/Z", " -- OK (means VT100 emulating VT52)" },
XX      { "",       " -- Unknown response"}
XX  };

XX  int i,j;
XX  char *response;

XX  rm("?2");  /* Reset ANSI (VT100) mode, Set VT52 mode	*/
XX  esc("H");  /* Cursor home	*/
XX  esc("J");  /* Erase to end of screen	*/
XX  esc("H");  /* Cursor home	*/
XX  for (i = 0; i <= 23; i++) {
XX    for (j = 0; j <= 9; j++)
XX    printf("%s", "FooBar ");
XX    println("Bletch");
XX  }
XX  esc("H");  /* Cursor home	*/
XX  esc("J");  /* Erase to end of screen	*/

XX  vt52cup(7,47);
XX  printf("nothing more.");
XX  for (i = 1; i <= 10; i++) printf("THIS SHOULD GO AWAY! ");
XX  for (i = 1; i <= 5; i++) {
XX    vt52cup(1,1);
XX    printf("%s", "Back scroll (this should go away)");
XX    esc("I"); 		/* Reverse LineFeed (with backscroll!)	*/
XX  }
XX  vt52cup(12,60);
XX  esc("J");  /* Erase to end of screen	*/
XX  for (i = 2; i <= 6; i++) {
XX    vt52cup(i,1);
XX    esc("K");		/* Erase to end of line	*/
XX  }

XX  for (i = 2; i <= 23; i++) {
XX    vt52cup(i,70); printf("%s", "**Foobar");
XX  }
XX  vt52cup(23,10); 
XX  for (i = 23; i >= 2; i--) {
XX    printf("%s", "*");
XX    printf("%c", 8);	/* BS */
XX    esc("I");		/* Reverse LineFeed (LineStarve)	*/
XX  }
XX  vt52cup(1,70);
XX  for (i = 70; i >= 10; i--) {
XX    printf("%s", "*");
XX    esc("D"); esc("D");	/* Cursor Left */
XX  }
XX  vt52cup(24,10);
XX  for (i = 10; i <= 70; i++) {
XX    printf("%s", "*");
XX    printf("%c", 8);	/* BS */
XX    esc("C");		/* Cursor Right	*/
XX  }
XX  vt52cup(2,11);
XX  for (i = 2; i <= 23; i++) {
XX    printf("%s", "!");
XX    printf("%c", 8);	/* BS */
XX    esc("B");		/* Cursor Down	*/
XX  }
XX  vt52cup(23,69);
XX  for (i = 23; i >= 2; i--) {
XX    printf("%s", "!");
XX    printf("%c", 8);	/* BS */
XX    esc("A");		/* Cursor Up	*/
XX  }
XX  for (i = 2; i <= 23; i++) {
XX    vt52cup(i,71);
XX    esc("K");		/* Erase to end of line	*/
XX  }

XX  vt52cup(10,16);
XX  printf("%s", "The screen should be cleared, and have a centered");
XX  vt52cup(11,16);
XX  printf("%s", "rectangle of \"*\"s with \"!\"s on the inside to the");
XX  vt52cup(12,16);
XX  printf("%s", "left and right. Only this, and");
XX  vt52cup(13,16);
XX  holdit();

XX  esc("H");  /* Cursor home	*/
XX  esc("J");  /* Erase to end of screen	*/
XX  printf("%s", "This is the normal character set:");
XX  for (j =  0; j <=  1; j++) {
XX    vt52cup(3 + j, 16);
XX    for (i = 0; i <= 47; i++)
XX    printf("%c", 32 + i + 48 * j);
XX  }
XX  vt52cup(6,1);
XX  printf("%s", "This is the special graphics character set:");
XX  esc("F");	/* Select Special Graphics character set	*/
XX  for (j =  0; j <=  1; j++) {
XX    vt52cup(8 + j, 16);
XX    for (i = 0; i <= 47; i++)
XX    printf("%c", 32 + i + 48 * j);
XX  }
XX  esc("G");	/* Select ASCII character set	*/
XX  vt52cup(12,1);
XX  holdit();

XX  esc("H");  /* Cursor home	*/
XX  esc("J");  /* Erase to end of screen	*/
XX  println("Test of terminal response to IDENTIFY command");
XX  esc("Z");	/* Identify	*/
XX  response = instr();
XX  println("");
XX  printf("Response was");
XX  esc("<");  /* Enter ANSI mode (VT100 mode) */
XX  chrprint(response);
XX  for(i = 0; resptable[i].rcode[0] != '\0'; i++)
XX    if (!strcmp(response, resptable[i].rcode))
XX      break;
XX  printf("%s", resptable[i].rmsg);
XX  println("");
XX  println("");
XX  holdit();
XX}

XXtst_insdel() {

XX    /* Test of:
XX       SM/RM(4) (= IRM (Insertion/replacement mode))
XX       ICH (Insert Character)
XX       DCH (Delete character)
XX       IL  (Insert line)
XX       DL  (Delete line)
XX    */

XX  int i, row, col, sw, dblchr, scr132;

XX  for(scr132 = 0; scr132 <= 1; scr132++) {
XX    if (scr132) { sm("?3"); sw = 132; }
XX    else        { rm("?3"); sw =  80; }
XX    ed(2);
XX    cup(1,1);
XX    for (row=1; row<=24; row++) {
XX	cup(row,1);
XX	for (col=1; col<=sw; col++)
XX	    printf("%c", 'A'-1+row);
XX    }
XX    cup(4,1);
XX    printf("Screen accordion test (Insert & Delete Line). "); holdit();
XX    ri(); el(2);
XX    decstbm( 2,23);
XX    sm("?6");
XX    cup(1,1);
XX    for (row=1; row<=24; row++) {
XX      il(row);
XX      dl(row);
XX    }
XX    rm("?6");
XX    decstbm( 0, 0);
XX    cup(2,1);
XX    printf(
XX    "Top line: A's, bottom line: X's, this line, nothing more. ");
XX    holdit();
XX    cup(2,1); ed(0);
XX    cup(1,2);
XX    printf("B");
XX    cub(1);
XX    sm("4");
XX    for (col=2; col<=sw-1; col++)
XX      printf("*");
XX    rm("4");
XX    cup(4,1);
XX    printf("Test of 'Insert Mode'. The top line should be 'A*** ... ***B'. ");
XX    holdit(); ri(); el(2);
XX    cup(1,2);
XX    dch(sw-2);
XX    cup(4,1);
XX    printf("Test of 'Delete Character'. The top line should be 'AB'. ");
XX    holdit();

XX    for(dblchr = 1; dblchr <= 2; dblchr++) {
XX      ed(2);
XX      for (row=1; row<=24; row++) {
XX	cup(row,1);
XX	if (dblchr == 2) decdwl();
XX	for (col=1; col<=sw/dblchr; col++)
XX	  printf("%c", 'A'-1+row);
XX	cup(row,sw/dblchr-row);
XX	dch(row);
XX      }
XX      cup(4,1);
XX      println("The right column should be staggered ");
XX      printf("by one.  ");
XX      holdit();
XX    }
XX    ed(2);
XX    cup(1,1);
XX    println("If your terminal has the ANSI 'Insert Character' function");
XX    println("(the VT102 does not), then you should see a line like this");
XX    println("  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");
XX    println("below:");
XX    println("");
XX    for (i = 'Z'; i >= 'A'; i--) {
XX      printf("%c\010",i);
XX      ich(2);
XX    }
XX    cup(10,1);
XX    holdit();

XX    if (sw == 132) rm("?3");
XX  }
XX}

XXdch(pn) int pn; { brc(pn, 'P'); }  /* Delete character */
XXich(pn) int pn; { brc(pn, '@'); }  /* Insert character -- not in VT102 */
XXdl(pn)  int pn; { brc(pn, 'M'); }  /* Delete line */
XXil(pn)  int pn; { brc(pn, 'L'); }  /* Insert line */

XX/*  Test of some known VT100 bugs and misfeatures  */

XXtst_bugs() {

XX  int i, menuchoice;

XX  static char *menutable[] = {
XX    "Exit to main menu",
XX    "Bug A: Smooth scroll to jump scroll",
XX    "Bug B: Scrolling region",
XX    "Bug C: Wide to narrow screen",
XX    "Bug D: Narrow to wide screen",
XX    "Bug E: Cursor move from double- to single-wide line",
XX    "Bug F: Column mode escape sequence",
XX    "Wrap around with cursor addressing",
XX    "Erase right half of double width lines",
XX    "Funny scroll regions",
XX    /* Add more here */
XX    ""
XX  };

XX  static char *hmsg[] = {
XX  "Test of known bugs in the DEC VT100 series. The numbering of some of",
XX  "the bugs (A-F) refers to the article 'VT100 MAGIC' by Sami Tabih in",
XX  "the 'Proceedings of the DEC Users Society' at St. Louis, Missouri, May",
XX  "1983. To understand some of the tests, you have to look at the source",
XX  "code or the article. Of course, a good VT100-compatible terminal",
XX  "should not have these bugs (or have some means of disabling them)! If",
XX  "a bug appears, you might want to RESET the terminal before continuing",
XX  "the test. There is a test of the RESET function in the main menu.",
XX  "" };

XX  do {
XX    ed(2); cup(1,1);
XX    for (i = 0; *hmsg[i]; i++) println(hmsg[i]);
XX    println("");
XX    println("          Choose bug test number:");
XX    menuchoice = menu(menutable);
XX    switch (menuchoice) {
XX      case  1:  bug_a();  break;
XX      case  2:  bug_b();  break;
XX      case  3:  bug_c();  break;
XX      case  4:  bug_d();  break;
XX      case  5:  bug_e();  break;
XX      case  6:  bug_f();  break;
XX      case  7:  bug_w();  break;
XX      case  8:  bug_l();  break;
XX      case  9:  bug_s();  break;
XX    }
XX  } while (menuchoice);
XX}

XX/* Bug A: Smooth scroll to jump scroll */

XXbug_a() {
XX  int i;

XX  cup (10, 1);
XX  println("This is a test of the VT100 'Scroll while toggle softscroll'");
XX  println("bug.  The cursor may disappear, or move UP the screen, or");
XX  println("multiple copies of some lines may appear.");
XX  holdit();

XX  /*  Invoke the bug  */

XX  esc ("[24H");				/* Simplified cursor movement	*/
XX  rm("?4"); for (i = 1; i <= 20; i++) printf("\n");
XX  sm("?4"); for (i = 1; i <= 10; i++) printf("\n");
XX  rm("?4"); for (i = 1; i <=  5; i++) printf("\n");

XX  /* That should be enough to show the bug. But we'll try another way:	*/
XX  sm ("?4");				/* Set soft scroll		*/
XX  nel ();				/* "NextLine", move down	*/
XX  rm ("?4");				/* Reset soft scroll		*/
XX  nel ();				/* "NextLine", move down	*/
XX  for (i = 1; i <= 10; i++) {		/* Show the bug			*/
XX      printf ("Softscroll bug test, line %d.  ", i);
XX      holdit();
XX  }
XX  println("That should have been enough to show the bug, if present.");
XX  holdit();
XX}

XX/*  Bug B: Scrolling region  */

XXbug_b() {
XX  char c;

XX  decaln();
XX  cup( 1,1); el(0);
XX  printf("Line 11 should be double-wide, line 12 should be cleared.");
XX  cup( 2,1); el(0);
XX  printf("Then, the letters A-P should be written at the beginning");
XX  cup( 3,1); el(0);
XX  printf("of lines 12-24, and the empty line and A-E are scrolled away.");
XX  cup( 4,1); el(0);
XX  printf("If the bug is present, some lines are confused, look at K-P.");
XX  cup(11,1); decdwl();
XX  decstbm(12,24);
XX  cup(12,1); el(0); printf("Here we go... "); holdit();
XX  cup(12,1); ri();					/* Bug comes here */
XX  for (c = 'A'; c <= 'P'; c++) printf("%c\n",c);	/* Bug shows here */
XX  holdit();
XX  decstbm(0,0);						/* No scr. region */
XX}

XX/*  Bug C: Wide to narrow screen  */

XXbug_c() {
XX  sm("?3");						/* 132 column mode */
XX  cup(1,81);
XX  rm("?3");						/*  80 column mode */
XX  cup(12,5);
XX  printf("Except for this line, the screen should be blank. ");
XX  holdit();
XX}

XX/*  Bug D: Narrow to wide screen  */

XXbug_d() {
XX  int i;
XX  char result;
XX  /* Make the bug appear */
XX  do {
XX    cup(14,1);

XX    /* The original code in the article says
XX     * PRINT ESC$; "[13;1H"; CHR$(10%);
XX     * but I guess a cup(14,1); would do.
XX     * (To output a pure LF might be tricky).
XX     */

XX    sm("?3");		      /* Make the bug visible */
XX    cup(1,9); decdwl();
XX    println("You should see blinking text at the bottom line.");
XX    cup(3,9); decdwl();
XX    println("Enter 0 to exit, 1 to try to invoke the bug again.");
XX    cup(24,9); decdwl(); sgr("1;5;7");
XX    printf("If you can see this then the bug did not appear."); sgr("");
XX    cup(4,9); decdwl();
XX    result = inchar(); readnl();
XX    rm("?3");
XX  } while (result == '1');
XX  sm("?4");	/* Syrup scroll */
XX  cup(23,1);
XX  for (i = 1; i <= 5; i++)
XX  println("If the bug is present, this should make things much worse!");
XX  holdit();
XX  rm("?4");	/* Jump scroll */
XX}

XX/*  Bug E: Cursor move from double- to single-wide line  */

XXbug_e() {
XX  int i;
XX  static char *rend[2] = { "\033[m", "\033[7m" };
XX  sm("?3");
XX  cup(1,1); decdwl();
XX  println("This test should put an 'X' at line 3 column 100.");
XX  for (i = 1; i <= 12; i++) printf("1234567890%s",rend[i & 1]);
XX  cup(1,1);	/* The bug appears when we jump from a dobule-wide line */
XX  cup(3,100);	/* to a single-wide line, column > 66.                  */
XX  printf("X");
XX  cup(4, 66); printf("!                                 !");
XX  cup(5,1);
XX  printf("--------------------------- The 'X' should NOT be above here -");
XX  printf("---+------------ but above here -----+");
XX  cup(10,1); decdwl(); holdit();
XX  rm("?3");
XX}

XX/*  Bug F: Column mode escape sequence  */

XXbug_f() {
XX  int i, row, col;

XX /*
XX  *  VT100 "toggle origin mode, forget rest" bug.  If you try to set
XX  *	(or clear) parameters and one of them is the "origin mode"
XX  *	("?6") parameter, parameters that appear after the "?6"
XX  *	remain unaffected.  This is also true on CIT-101 terminals.
XX  */
XX  sm ("?5");				/* Set reverse mode		*/
XX  sm ("?3");				/* Set 132 column mode		*/
XX  println("Test VT100 'Toggle origin mode, forget rest' bug, part 1.");
XX  println("The screen should be in reverse, 132 column mode.");
XX  holdit();
XX  ed (2);
XX  rm ("?6;5;3");		/* Reset (origin, reverse, 132 col)	*/
XX  println("Test VT100 'Toggle origin mode, forget rest' bug, part 2.\n");
XX  println("The screen should be in non-reverse, 80 column mode.");
XX  holdit();
XX}

XX  /*	Bug W:
XX   *	The dreaded "wraparound" bug!  You CUP to col 80, write a char,
XX   *	CUP to another line in col 80, write a char. And the brain-damaged
XX   *	terminal thinks that "Hokay, so he's written a char in col 80, so
XX   *	I stay in col 80 and wait for next character. Let's see now, here
XX   *	comes another character, and I'm still in col 80, so I must make
XX   *	a NewLine first." -- It doesn't clear that "still in col 80" flag
XX   *	on a CUP. Argh!
XX   */

XXbug_w() {
XX  int row, col;

XX  cup (16,1);
XX  println("   This illustrates the \"wrap around bug\" which exists on a");
XX  println("   standard VT100. At the top of the screen there should be");
XX  println("   a row of +'s, and the rightmost column should be filled");
XX  println("   with *'s. But if the bug is present, some of the *'s may");
XX  println("   be placed in other places, e.g. in the leftmost column,");
XX  println("   and the top line of +'s may be scrolled away.");

XX  cup(1,1);
XX  for (col = 1; col <= 79; col++)
XX      printf ("+");
XX  for (row = 1; row <= 24; row++) {
XX      hvp (row, 80);
XX      printf ("*");
XX  }
XX  cup(24,1);
XX  holdit();
XX}

XX  /*	Bug L:
XX   *	Check if the right half of double-width lines comes back
XX   *	when a line is first set to single-width, filled with stuff,
XX   *	set to double-width, and finally reset to single-width.
XX   *
XX   *	A VT100 has this misfeature, and many others. Foo!
XX   */

XXbug_l() {
XX  cup(15, 1);
XX  printf("This-is-a-long-line-This-is-a-long-line-");
XX  printf("This-is-a-long-line-This-is-a-long-line-");
XX  cup(1, 1);
XX  printf("This is a test of what happens to the right half of double-width");
XX  println(" lines.");
XX  printf("A common misfeature is that the right half does not come back");
XX  println(" when a long");
XX  printf("single-width line is set to double-width and then reset to");
XX  println(" single-width.");

XX  cup(5, 1);
XX  println("Now the line below should contain 80 characters in single width.");
XX  holdit();
XX  cup(15, 1); decdwl();
XX  cup(8, 1);
XX  println("Now the line below should contain 40 characters in double width.");
XX  holdit();
XX  cup(15, 1); decswl();
XX  cup(11, 1);
XX  println("Now the line below should contain 80 characters in single width.");
XX  holdit();

XX  /* ...and in 132 column mode  */

XX  sm("?3");
XX  ed(2);
XX  cup(15, 1);
XX  printf("This-is-a-long-line-This-is-a-long-line-");
XX  printf("This-is-a-long-line-This-is-a-long-line-");
XX  printf("This-is-a-long-line-This-is-a-long-line-");
XX  printf("ending-here-");

XX  cup(1, 1);
XX  printf("This is the same test in 132 column mode.");

XX  cup(5, 1);
XX  println("Now the line below should contain 132 characters in single width.");
XX  holdit();
XX  cup(15, 1); decdwl();
XX  cup(8, 1);
XX  println("Now the line below should contain 66 characters in double width.");
XX  holdit();
XX  cup(15, 1); decswl();
XX  cup(11, 1);
XX  println("Now the line below should contain 132 characters in single width.");
XX  holdit();
XX  rm("?3");
XX}

XXbug_s() {
XX  int i;
XX  decstbm(20,10);	/* 20-10=-10, < 2, so no scroll region. */
XX  cup(1,1);
XX  for (i=1; i<=20; i++)
XX    printf("This is 20 lines of text (line %d), no scroll region.\n", i);
XX  holdit();
XX  ed(2);
XX  decstbm(0,1);		/* Should be interpreted as decstbm(1,1) = none */
XX  cup(1,1);
XX  for (i=1; i<=20; i++)
XX    printf("This is 20 lines of text (line %d), no scroll region.\n", i);
XX  holdit();
XX  decstbm(0,0);		/* No scroll region (just in case...)	*/
XX}

XXtst_rst() {

XX  /*
XX   * Test of
XX   *	- RIS    (Reset to Initial State)
XX   *	- DECTST (invoke terminal test)
XX   */

XX  cup(10,1);
XX  printf ("The terminal will now be RESET. ");
XX  holdit();
XX  ris();
XX#ifdef UNIX
XX  fflush(stdout);
XX#endif
XX  zleep(5000);		/* Wait 5.0 seconds */
XX  cup(10,1);
XX  println("The terminal is now RESET. Next, the built-in confidence test");
XX  printf("%s", "will be invoked. ");
XX  holdit();
XX  ed(2);
XX  dectst(1);
XX#ifdef UNIX
XX  fflush(stdout);
XX#endif
XX  zleep(5000);		/* Wait 5.0 seconds */
XX  cup(10,1);
XX  println("If the built-in confidence test found any errors, a code");
XX  printf("%s", "is visible above. ");
XX  holdit();
XX}

XXinitterminal(pn) int pn; {

XX#ifdef UNIX
XX  if (pn==0) {
XX    fflush(stdout);
XX    gtty(0,&sgttyOrg);
XX    gtty(0,&sgttyNew);
XX    sgttyNew.sg_flags |= CBREAK;
XX    }
XX  else  {
XX    fflush(stdout);
XX    inflush();
XX    sleep(2);
XX    sgttyNew.sg_flags = sgttyOrg.sg_flags | CBREAK;
XX    }
XX  stty(0,&sgttyNew);
XX#ifdef SIII
XX  close(2);
XX  open("/dev/tty",O_RDWR|O_NDELAY);
XX#endif
XX#endif
XX#ifdef SARG10
XX  /* Set up neccesary TOPS-10 terminal parameters	*/

XX  trmop(02041, `VT100`);	/* tty type vt100	*/
XX  trmop(02002, 0);	/* tty no tape	*/
XX  trmop(02003, 0);	/* tty lc	*/
XX  trmop(02005, 1);	/* tty tab	*/
XX  trmop(02010, 1);	/* tty no crlf	*/
XX  trmop(02020, 0);	/* tty no tape	*/
XX  trmop(02021, 1);	/* tty page	*/
XX  trmop(02025, 0);	/* tty blanks	*/
XX  trmop(02026, 1);	/* tty no alt	*/
XX  trmop(02040, 1);	/* tty defer	*/
XX#endif
XX#ifdef SARG20
XX  ttybin(1);	/* set line to binary mode */
XX#endif
XX  /* Set up my personal prejudices	*/

XX  esc("<");	/* Enter ANSI mode (if in VT52 mode)	*/
XX  rm("?1");     /* cursor keys normal   */
XX  rm("?3");	/* 80 col mode		*/
XX  rm("?4");     /* Jump scroll          */
XX  rm("?5");     /* Normal screen        */
XX  rm("?6");	/* Absolute origin mode	*/
XX  sm("?7");	/* Wrap around on	*/
XX  rm("?8");	/* Auto repeat off	*/
XX  decstbm(0,0);	/* No scroll region	*/
XX  sgr("0");     /* Normal character attributes  */

XX}

XXbye () {
XX  /* Force my personal prejudices upon the poor luser	*/

XX  esc("<");	/* Enter ANSI mode (if in VT52 mode)	*/
XX  rm("?1");     /* cursor keys normal   */
XX  rm("?3");	/* 80 col mode		*/
XX  rm("?5");     /* Normal screen        */
XX  rm("?6");	/* Absolute origin mode	*/
XX  sm("?7");	/* Wrap around on	*/
XX  sm("?8");	/* Auto repeat on	*/
XX  decstbm(0,0);	/* No scroll region	*/
XX  sgr("0");     /* Normal character attributes  */

XX  /* Say goodbye */

XX  ed(2);
XX  cup(12,30);
XX  printf("That's all, folks!\n");
XX  printf("\n\n\n");
XX  inflush();
XX#ifdef SARG20
XX  ttybin(0);	/* reset line to normal mode */
XX#endif
XX#ifdef UNIX
XX  stty(0,&sgttyOrg);
XX#endif
XX  exit();
XX}

XX#ifdef UNIX
XXonbrk() {
XX  signal(SIGINT, onbrk);
XX  if (reading)
XX    brkrd = 1;
XX  else
XX    longjmp(intrenv, 1);
XX}

XXonterm() {
XX  signal(SIGTERM, onterm);
XX  longjmp(intrenv, 1);
XX}
XX#endif

XXholdit() {
XX  inflush();
XX  printf("Push <RETURN>");
XX  readnl();
XX}

XXreadnl() {
XX#ifdef UNIX
XX  char ch;
XX  fflush(stdout);
XX  brkrd = 0;
XX  reading = 1;
XX  do { read(0,&ch,1); } while(ch != '\n' && !brkrd);
XX  if (brkrd)
XX    kill(getpid(), SIGTERM);
XX  reading = 0;
XX#endif
XX#ifdef SARG10
XX while (getchar() != '\n')
XX ;
XX#endif
XX#ifdef SARG20
XX while (getchar() != '\n')
XX   ;
XX#endif
XX}

XXscanto(str, pos, toc) char *str; int *pos; char toc; {
XX  char c;
XX  int result = 0;

XX  while (toc != (c = str[(*pos)++])) {
XX    if (isdigit(c)) result = result * 10 + c - '0';
XX    else break;
XX  }
XX  if (c == toc) return(result);
XX  else          return(0);
XX}

XXchar *lookup(t, k) struct table t[]; int k; {

XX  int i;
XX  for (i = 0; t[i].key != -1; i++) {
XX    if (t[i].key == k) return(t[i].msg);
XX  }
XX  return("BAD VALUE");
XX}

XXmenu(table) char *table[]; {

XX  int i, tablesize, choice;
XX  char c;
XX  char storage[80];
XX  char *s = storage;
XX  println("");
XX  tablesize = 0;
XX  for (i = 0; *table[i] != '\0'; i++) {
XX    printf("          %d. %s\n", i, table[i]);
XX    tablesize++;
XX  }
XX  tablesize--;

XX  printf("\n          Enter choice number (0 - %d): ", tablesize);
XX  for(;;) {
XX    inputline(s);
XX    choice = 0;
XX    while (c = *s++) choice = 10 * choice + c - '0';
XX    if (choice >= 0 && choice <= tablesize) {
XX      ed(2);
XX      return (choice);
XX    }
XX    printf("          Bad choice, try again: ");
XX  }
XX}

XXchrprint (s) char *s; {

XX  int i;

XX  printf("  ");
XX  sgr("7");
XX  printf(" ");
XX  for (i = 0; s[i] != '\0'; i++) {
XX    if (s[i] <= ' ' || s[i] == '\177')
XX    printf("<%d> ", s[i]);
XX    else printf("%c ", s[i]);
XX  }
XX  sgr("");
XX}
@//E*O*F main.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo Inspecting for damage in transit...
temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
    1993    8253   57759 main.c
!!!
wc  main.c | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if test -s $dtemp ; then
    echo "Ouch [diff of wc output]:"
    cat $dtemp
    STATUS=1
elif test $STATUS = 0 ; then
    echo "No problems found."
else
    echo "WARNING -- PROBLEMS WERE FOUND..."
fi
exit $STATUS