home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckoco3.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  767KB  |  19,832 lines

  1. /* C K O C O 3 . C */
  2.  
  3. /*
  4.   Authors: Frank da Cruz (fdc@columbia.edu),
  5.              Columbia University Academic Information Systems, New York City.
  6.            Jeffrey E Altman (jaltman@secure-endpoints.com)
  7.              Secure Endpoints Inc., New York City
  8.  
  9.   Copyright (C) 1985, 2004, Trustees of Columbia University in the City of
  10.   New York.  All rights reserved.  This copyright notice must not be removed,
  11.   altered, or obscured.
  12. */
  13.  
  14. #include "ckcdeb.h"             /* Typedefs, debug formats, etc */
  15. #include "ckcker.h"             /* Kermit definitions */
  16. #include "ckcasc.h"             /* ASCII character symbols */
  17. #include "ckcnet.h"             /* Network support */
  18. #include "ckuusr.h"             /* For terminal type definitions, etc. */
  19. #include "ckcxla.h"             /* Character set translation */
  20. #include "ckcuni.h"             /* Unicode Character Set Translations */
  21. #ifndef NOLOCAL
  22. #include "ckowys.h"
  23. #include "ckodg.h"
  24. #include "ckoava.h"
  25. #include "ckotvi.h"
  26. #include "ckohzl.h"
  27. #include "ckohp.h"
  28. #include "ckovc.h"
  29. #include "ckoi31.h"
  30. #include "ckoqnx.h"
  31. #include "ckoadm.h"
  32. #endif /* NOLOCAL */
  33.  
  34. #include <ctype.h>              /* Character types */
  35. #include <io.h>                 /* File io function declarations */
  36. #include <process.h>            /* Process-control function declarations */
  37. #include <stdlib.h>             /* Standard library declarations */
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <assert.h>
  43.  
  44. #define DECLED
  45.  
  46. #ifdef NT
  47. #include <windows.h>
  48. #else /* NT */
  49.  
  50. #ifdef OS2MOUSE
  51. #define INCL_MOU
  52. #endif /* OS2MOUSE */
  53.  
  54. #define INCL_NOPM
  55. #define INCL_VIO
  56. #define INCL_ERRORS
  57. #define INCL_DOSPROCESS
  58. #define INCL_DOSSEMAPHORES
  59. #define INCL_DOSDEVIOCTL
  60. #define INCL_WINCLIPBOARD
  61. #include <os2.h>
  62. #undef COMMENT                /* COMMENT is defined in os2.h */
  63. #endif /* NT */
  64. #include "ckocon.h"             /* definitions common to console routines */
  65.  
  66. #ifndef NOLOCAL
  67. #include "ckokey.h"
  68. #include "ckotek.h"
  69. #include "ckowin.h"
  70.  
  71. #ifdef CK_NETBIOS
  72. #include "ckonbi.h"
  73. extern UCHAR NetBiosRemote[] ;
  74. #endif /* CK_NETBIOS */
  75.  
  76. #ifdef KUI
  77. #include "ikui.h"
  78. #endif /* KUI */
  79.  
  80. #ifdef NETCONN
  81. #ifdef TCPSOCKET
  82. #ifdef CK_NAWS
  83. _PROTOTYP( int tn_snaws, (void) );
  84. #ifdef RLOGCODE
  85. _PROTOTYP( int rlog_naws, (void) ) ;
  86. #endif /* RLOGCODE */
  87. #ifdef SSHBUILTIN
  88. _PROTOTYP( int ssh_snaws, (void));
  89. #endif /* SSHBUILTIN */
  90. extern int me_naws;
  91. #endif /* CK_NAWS */
  92.  
  93. extern int tn_rem_echo;
  94. extern int tcp_incoming;
  95. #endif /* TCPSOCKET */
  96. #endif /* NETCONN */
  97.  
  98. _PROTOTYP(void vtescape, (void));
  99. _PROTOTYP(void vt100, (unsigned short vtch));
  100. #endif /* NOLOCAL */
  101.  
  102. /*
  103.  *
  104.  * =============================externals=====================================
  105.  */
  106. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR);  /* Character set xlate */
  107. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);  /* functions. */
  108. extern char     *printername;
  109. extern int      printpipe;
  110. #ifdef BPRINT
  111. extern int  printbidi;                  /* SET BPRINTER (bidirectional) */
  112. #endif /* BPRINT */
  113. bool winprint = FALSE;
  114. FILE *lst=NULL;                 /* List (print) device */
  115. #ifdef NT
  116. _PROTOTYP(int Win32PrtOpen, (char *));
  117. _PROTOTYP(int Win32PrtWrite, (char *, int));
  118. _PROTOTYP(int Win32PrtClose, (void));
  119. #endif /* NT */
  120. static time_t printerclose_t=0;
  121. bool     printon        = FALSE; /* Printer is on */
  122.  
  123. #ifdef NT
  124. _PROTOTYP( FILE * win95popen, (const char *cmd, const char *mode) );
  125. _PROTOTYP( int win95pclose, (FILE *pipe) );
  126. #define popen _popen
  127. #define pclose _pclose
  128. #endif /* NT */
  129.  
  130. #ifdef COMMENT
  131. _PROTOTYP( FILE * popen, (const char *cmd, const char *mode));
  132. _PROTOTYP( int pclose, (FILE *pipe));
  133. #endif /* COMMENT */
  134.  
  135. #ifndef NOLOCAL
  136. extern struct csinfo fcsinfo[]; /* File character set info */
  137. extern int tcsr, tcsl;          /* Terminal character sets, remote & local. */
  138. extern int prncs;               /* Printer Character Set */
  139. extern int tcs_transp;
  140.  
  141. extern int ttmdm;
  142. extern int tnlm, tn_nlm;        /* Terminal newline mode, ditto for TELNET */
  143. extern int tn_b_nlm ;           /* TELNET BINARY newline mode */
  144. extern int tt_crd;              /* Carriage-return display mode */
  145. extern int tt_lfd;              /* Line-feed display mode */
  146. extern int tt_bell;             /* How to handle incoming Ctrl-G characters */
  147. extern int tt_type, tt_type_mode ;
  148. extern int tt_status[VNUM];           /* Terminal status line displayed */
  149. extern int tt_status_usr[VNUM];
  150. extern int tt_modechg;          /* Terminal Video-Change (80 or 132 cols) */
  151. extern int tt_senddata;         /* May data be sent to the host */
  152. extern int tt_hidattr;          /* Attributes do not occupy a space */
  153. #ifdef PCTERM
  154. extern int tt_pcterm;
  155. #endif /* PCTERM */
  156. extern int ttyfd, Shutdown ;
  157. #ifdef CK_TAPI
  158. extern int tttapi;
  159. #endif /* CK_TAPI */
  160. #ifdef KUI
  161. extern CKFLOAT  tt_linespacing[VNUM];
  162. #endif /* KUI */
  163. extern long     speed, vernum;
  164. extern int      local, escape, duplex, parity, flow, seslog, pmask,
  165.                 cmdmsk, cmask, sosi, xitsta, debses, mdmtyp, carrier, what;
  166. extern int      cflg, cnflg, stayflg, tt_escape, tt_scroll;
  167. extern int      network, nettype, ttnproto, protocol, inautodl;
  168. extern int cmdlvl,tlevel, ckxech;
  169. extern int ttnum;                               /* from ckcnet.c */
  170. extern int tt_async;
  171. #ifndef NOXFER
  172. extern int      autodl, adl_ask;
  173. int adl_kc0 = TRUE,
  174.     adl_zc0 = TRUE;     /* Process autodownload C0 chars by emulation */
  175. extern int adl_err, xferstat;
  176. extern CHAR stchr;
  177. #endif /* NOXFER */
  178. int duplex_sav = -1 ;
  179.  
  180. #ifndef NOSPL
  181. extern struct mtab *mactab;             /* Main macro table */
  182. extern int nmac;                        /* Number of macros */
  183. #endif /* NOSPL */
  184. #ifdef TNCODE
  185. extern int tn_deb;
  186. #endif /* TNCODE */
  187.  
  188. extern KEY      *keymap;
  189. extern MACRO    *macrotab;
  190. extern char     ttname[], sesfil[];
  191. #ifndef NODIAL
  192. extern char     * d_name;
  193. #endif /* NODIAL */
  194.  
  195. extern int  scrninitialized[] ;
  196. extern bool scrollflag[] ;
  197. extern bool viewonly ;           /* View Only Terminal mode */
  198. extern int  updmode ;            /* Fast/Smooth scrolling */
  199. extern int priority ;
  200. extern TID  tidRdComWrtScr ;
  201.  
  202. #ifdef CK_XYZ
  203. extern int p_avail ;
  204. #endif /* CK_XYZ */
  205.  
  206. extern int beepfreq, beeptime ;
  207. extern int pwidth, pheight;
  208. extern int win95lucida, win95hsl;
  209.  
  210. /*
  211.  * =============================variables==============================
  212.  */
  213.  
  214. /*
  215.   These are RGB bits for the fore- and background colors in the PC's video
  216.   adapter, 3 bits for each color.  These default values can be changed by the
  217.   SET TERMINAL COLOR command (in ckuus7.c) or by CSI3x;4xm escape sequences
  218.   from the host.
  219. */
  220. unsigned char     colornormal     = 0x17;
  221. unsigned char     colorunderline  = 0x47;
  222. unsigned char     colordebug      = 0x47;
  223. unsigned char     colorreverse    = 0x71;
  224. unsigned char     colorgraphic    = 0x17;
  225. #ifdef COMMENT
  226. unsigned char     colorstatus     = 0x37;
  227. unsigned char     colorhelp       = 0x37;
  228. #else /* COMMENT */
  229. unsigned char     colorstatus     = 0x71;
  230. unsigned char     colorhelp       = 0x71;
  231. #endif /* COMMENT */
  232. unsigned char     colorselect     = 0xe0;
  233. unsigned char     colorborder     = 0x01;
  234. unsigned char     coloritalic     = 0x27;
  235.  
  236. int bgi = FALSE, fgi = FALSE ;
  237. unsigned char     colorcmd        = 0x07;
  238. int colorreset    = TRUE ;  /* reset on CSI 0 m - use normal colors */
  239. int erasemode     = FALSE ; /* Use current colors when erasing characters */
  240. int user_erasemode= FALSE ; /* Use current colors when erasing characters */
  241. int trueblink     = TRUE ;
  242. int truereverse   = TRUE ;
  243. int trueunderline = TRUE ;
  244. int truedim       = TRUE ;
  245. #ifdef KUI
  246. int trueitalic    = TRUE ;
  247. #else /* KUI */
  248. int trueitalic    = FALSE ;
  249. #endif /* KUI */
  250.  
  251. extern enum markmodes markmodeflag[VNUM] = {notmarking, notmarking,
  252.                                                 notmarking, notmarking} ;
  253.  
  254. extern int tn_bold;                     /* TELNET negotiation bold */
  255. extern int esc_exit;                    /* Escape back = exit */
  256. extern char * esc_msg;
  257. extern int interm ;                     /* INPUT echo state */
  258. extern BYTE vmode ;
  259.  
  260. long waittime;                  /* Timeout on CTS during CONNECT */
  261. #define INTERVAL 100L
  262.  
  263. char termessage[MAXTERMCOL];
  264.  
  265. #ifdef CK_APC
  266. extern int apcactive;                   /* Application Program Command (APC) */
  267. int apcrecv = 0;
  268. int dcsrecv = 0;                        /* Device Control String (DCS) */
  269. int oscrecv = 0;                        /* Operating System Command (OSC) */
  270. int pmrecv  = 0;                        /* Private Message (PM) */
  271. int pu1recv = 0;                        /* 97801-5xx Private Use One (PU1) */
  272. int pu2recv = 0;                        /* 97801-5xx Private Use Two (PU2) */
  273. int c1strrecv = 0;                      /* Other generic C1 strings */
  274. extern int apcstatus;                   /* items ... */
  275. #ifdef DCMDBUF
  276. extern char *apcbuf;
  277. #else
  278. extern char apcbuf[];
  279. #endif /* DCMDBUF */
  280. int apclength = 0;
  281. int apcbuflen = APCBUFLEN - 2;
  282. #endif /* CK_APC */
  283.  
  284. extern char * keydefptr;
  285. extern int keymac;
  286. extern int keymacx ;
  287.  
  288. bool scrollstatus[VNUM] = {FALSE,FALSE,FALSE,FALSE} ;
  289. bool escapestatus[VNUM] = {FALSE,FALSE,FALSE,FALSE} ;
  290. extern int tt_idlelimit;                /* Auto-exit Connect when idle */
  291. extern int tt_timelimit;                /* Auto-exit Connect after time */
  292. extern bool flipscrnflag[] ;
  293.  
  294.  
  295. extern videobuffer vscrn[];
  296.  
  297. ascreen                                 /* For saving screens: */
  298.   vt100screen,                          /* terminal screen */
  299.   commandscreen ;                       /* OS/2 screen */
  300.  
  301. extern ascreen mousescreen; /* Screen during mouse actions */
  302.  
  303. extern unsigned char                    /* Video attribute bytes */
  304.     attribute=NUL,                      /* Current video attribute byte */
  305.     underlineattribute=NUL,
  306.     savedattribute[VNUM]={0,0,0,0},       /* Saved video attribute byte */
  307.     saveddefaultattribute[VNUM]={0,0,0,0},/* Saved video attribute byte */
  308.     savedunderlineattribute[VNUM]={0,0,0,0},/* Saved video attribute byte */
  309.     defaultattribute=NUL,               /* Default video attribute byte */
  310.     italicattribute=NUL,                /* Default video attribute byte */
  311.     saveditalicattribute[VNUM]={0,0,0,0},
  312.     reverseattribute=NUL,
  313.     savedreverseattribute[VNUM]={0,0,0,0},
  314.     graphicattribute=NUL,
  315.     savedgraphicattribute[VNUM]={0,0,0,0},
  316.     borderattribute=NUL,
  317.     savedborderattribute[VNUM]={0,0,0,0};
  318.  
  319. vtattrib attrib={0,0,0,0,0,0,0,0,0,0},
  320.          savedattrib[VNUM]={{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},
  321.                             {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
  322.          cmdattrib={0,0,0,0,0,0,0,0,0,0};
  323.  
  324. int wherex[];                           /* Screen column, 1-based */
  325. int wherey[];                           /* Screen row, 1-based */
  326. int margintop = 1 ;                     /* Top of scrolling region, 1-based */
  327. int marginbot = 24 ;                    /* Bottom of same, 1-based */
  328. int marginleft = 1;
  329. int marginright = 80;
  330.  
  331. int quitnow, hangnow, outshift, tcs, langsv;
  332.  
  333. int term_io = TRUE;                     /* Terminal emulator performs I/O */
  334.  
  335. int prevchar = 0;                       /* Last char written to terminal screen */
  336.  
  337. extern char answerback[81];             /* answerback */
  338. char usertext[(MAXTERMCOL) + 1];        /* Status line and its parts */
  339. char statusline[MAXTERMCOL + 1];
  340. char hoststatusline[MAXTERMCOL + 1];
  341. char exittext[(20) + 1];
  342. #define HLPTXTLEN 41
  343. char helptext[HLPTXTLEN];
  344. char filetext[(20) + 1];
  345. char savefiletext[(20) + 1] = { NUL };
  346. #define HSTNAMLEN 41
  347. char hostname[HSTNAMLEN];
  348.  
  349. #define DEFTABS \
  350. "0\
  351. T0000000T0000000T0000000T0000000T0000000T0000000T0000000T0000000T0000000\
  352. T0000000T0000000T0000000T0000000T0000000T0000000T0000000T0000000T0000000\
  353. T00000";
  354.  
  355. char htab[MAXTERMCOL+2] = DEFTABS       /* Default tab settings */
  356.  
  357. static int achar;                       /* Global - current character */
  358. int tt_utf8 = 0;                        /* Is UTF8 mode active ? */
  359.  
  360. struct _vtG G[4] = {
  361.     TX_ASCII,   TX_ASCII,  cs94, cs94, TRUE,  TRUE, TRUE, NULL, NULL, NULL, NULL, TRUE,
  362.     TX_8859_1,  TX_8859_1, cs96, cs96, FALSE, TRUE, TRUE, NULL, NULL, NULL, NULL, TRUE,
  363.     TX_8859_1,  TX_8859_1, cs96, cs96, FALSE, TRUE, TRUE, NULL, NULL, NULL, NULL, TRUE,
  364.     TX_8859_1,  TX_8859_1, cs96, cs96, FALSE, TRUE, TRUE, NULL, NULL, NULL, NULL, TRUE
  365.     };
  366. struct _vtG *GL = &G[0], *SSGL = NULL;   /* GL and single shift GL */
  367. struct _vtG *GR = &G[2];                 /* GR */
  368. struct _vtG *GNOW = &G[0];
  369. struct _vtG savedG[VNUM][4];
  370. struct _vtG *savedGL[VNUM] = {NULL,NULL,NULL,NULL},
  371.             *savedGR[VNUM] = {NULL,NULL,NULL,NULL},
  372.             *savedSSGL[VNUM] = {NULL,NULL,NULL,NULL} ;
  373. static int  Qsaved = FALSE;              /* QANSI charset shifts */
  374. struct _vtG QsavedG[4],
  375.             *QsavedGL = NULL,
  376.             *QsavedGR = NULL,
  377.             *QsavedSSGL = NULL;
  378.  
  379. bool     printregion    = FALSE; /* Print extent = full screen */
  380. bool     xprintff       = FALSE; /* Print formfeed */
  381. bool     turnonprinter  = FALSE; /* Time to turn on printer */
  382. bool     xprint         = FALSE; /* Controller print in progress */
  383. bool     aprint         = FALSE; /* Auto-print in progress */
  384. bool     cprint         = FALSE; /* Copy-print in progress (for debug) */
  385. bool     uprint         = FALSE; /* Transparent print */
  386. bool     turnoffprinter = FALSE; /* Time to turn it off */
  387.  
  388. bool     wrapit    = FALSE;
  389. bool     literal_ch= FALSE;
  390. bool     screenon  = TRUE;
  391. extern bool     cursorena[];       /* Cursor enabled / disabled */
  392. extern bool     cursoron[] ;       /* Cursor state on/off       */
  393. bool     relcursor = FALSE;
  394. bool     keylock   = FALSE;
  395. bool     vt52graphics = FALSE;
  396.  
  397. bool     saverelcursor[VNUM]={FALSE,FALSE,FALSE,FALSE},
  398.          saved[VNUM]={FALSE,FALSE,FALSE,FALSE};
  399. int      savedwrap[VNUM]={FALSE,FALSE,FALSE,FALSE} ;
  400. int      savedrow[VNUM] = {0,0,0,0};
  401. int      savedcol[VNUM] = {0,0,0,0};
  402.  
  403. bool     deccolm = FALSE;               /* 80/132-column mode */
  404. bool     decscnm = FALSE;               /* Normal/reverse screen mode */
  405. int      decscnm_usr = FALSE;           /* User default for decscnm */
  406. bool     decnrcm = FALSE ;              /* National Replacement Charset mode */
  407. int      decnrcm_usr = FALSE;           /* NRC mode - user default */
  408. bool     decsasd = SASD_TERMINAL ;      /* Active Status Display */
  409. int      decssdt = SSDT_INDICATOR ;     /* Status Display Type */
  410. bool     deckbum = FALSE ;              /* Keyboard (Typewriter/DP) */
  411. bool     decsace = FALSE;               /* DECSACE */
  412. int      savdecbkm = 0 ;                /* User default Backspace Mode */
  413. bool     erm = FALSE ;                  /* Erasure Mode  VT300 */
  414. bool     crm = FALSE ;                  /* Control Mode  VT300 */
  415. bool     decled[4] = {FALSE,FALSE,FALSE,FALSE} ; /* DEC LEDs */
  416. bool     insertmode = FALSE;            /* Insert/replace mode */
  417. bool     sco8bit = FALSE;               /* SCO ANSI 8th bit quoting */
  418. bool     scoBCS2 = FALSE;               /* SCO ANSI BCS2 */
  419. bool     scocompat = FALSE;             /* SCO ANSI Backward Compatibility Mode */
  420. extern int wyse8bit;                    /* WYSE ASCII 8th bit quoting */
  421. bool     keyclick  = FALSE ;
  422. int      dec_upss = TX_8859_1 ;
  423. int      dec_lang = VTL_NORTH_AM;       /* DEC VT Language = North American */
  424. int      dec_nrc  = TX_ASCII;           /* DEC NRC for use during NRC Mode  */
  425. int      dec_kbd  = TX_8859_1;          /* DEC Keyboard character set       */
  426.  
  427. /*
  428.   Terminal parameters that can also be set externally by SET commands.
  429.   Formerly they were declared and initialized here, and had different
  430.   names, as shown in the comments.  Now they are declared and
  431.   initialized in ckuus7.c.  - fdc
  432. */
  433. int tt_kb_mode = KBM_EN ;               /* Keyboard is in English mode */
  434. int tt_kb_glgr = FALSE;                 /* Kbd Follows GL/GR charset */
  435. bool send_c1 = FALSE;                   /* Flag for sending C1 controls */
  436. extern int send_c1_usr ;                /* User default for send_c1 */
  437.  
  438. /*
  439.   VT220 and higher Pn's for terminal ID string are (* = Not supported):
  440.      1 - 132 columns
  441.      2 - Printer port
  442.   *  3 - ReGIS graphics
  443.   *  4 - Sixel graphics
  444.      6 - DECSED - Selective erase
  445.   *  7 - DRCS - Soft character sets
  446.      8 - UDK - User-defined keys
  447.      9 - National Replacement Character Sets can be designated by host
  448.   * 12 - Serbo-Croation (SCS)
  449.   * 13 - Local editing
  450.     15 - Technical character set
  451.   * 16 - Locator device port
  452.   * 18 - Windowing Capability
  453.   * 19 - Dual sessions
  454.   * 21 - Horizontal Scrolling
  455.     22 - Color
  456.     23 - Greek
  457.   * 24 - Turkish
  458.     42 - ISO Latin-2
  459.     44 - PC Term
  460.     45 - Soft-key mapping
  461.     46 - ASCII Terminal emulation
  462. */
  463. struct tt_info_rec tt_info[] = {        /* Indexed by terminal type */
  464.     "TTY", {NULL},                              "",                    /* Teletype */
  465.     "D200", {"DG200","DATA-GENERAL-200",NULL},  "o#!J ",               /* Data General 200 */
  466.     "D210", {"DG210","DATA-GENERAL-210",NULL},  "o#(HY",               /* Data General 210 */
  467.     "D217", {"DG217","DATA-GENERAL-217",NULL},  "o#(HY",               /* Data General 217 */
  468.     "HP2621", {"HP2621P","HP2621A","HP-2621",NULL},"2621A",            /* HP 2621A */
  469.     "HPTERM", {"HP-TERM","X-HPTERM",NULL},      "X-hpterm",            /* HP TERM */
  470.     "H1500", {"HZ1500","HAZELTINE-1500",NULL},  "",                    /* Hazeltine 1500 */
  471.     "VC404", {"VOLKER-CRAIG-404",NULL},         "",                    /* Volker Craig VC4404/404 */
  472.     "WY30", {"WYSE-30","WYSE30",NULL},          "30\r",                /* WYSE-30 */
  473.     "WY50", {"WYSE-50","WYSE50",NULL},          "50\r",                /* WYSE-50 */
  474.     "WY60", {"WYSE-60","WYSE60",NULL},          "60\r",                /* WYSE-60 */
  475.     "WY160", {"WYSE-160","WYSE160",NULL},       "160\r",               /* WYSE-160 */
  476.     "QNX",  {"QNX4",NULL},                      "",                    /* QNX */
  477.     "QANSI", {NULL},                            "",                    /* QNX ANSI */
  478.     "VT52",{"DEC-VT52",NULL},                   "/Z",                  /* DEC VT52 */
  479.     "H19", {"HEATH","ZENITH","Z19",NULL},       "/K",                  /* Heath-19 */
  480.     "IBM3151", {"I3151",NULL},                   "",                   /* IBM 3151 */
  481.     "SCOANSI", {"SCO-ANSI","ANSI-850","ANSI-8859",NULL},    "",        /* SCO ANSI */
  482.     "AT386",  {"386AT","ATT6386",NULL},         "",                    /* AT-386 */
  483.     "ANSI",   {"DOSANSI","ANSI.SYS","PCANSI",NULL},"",                 /* "ANSI"  */
  484.     "VIP7809", {NULL},                          "7813  P GC  A\003",   /* Honeywell MOD400 4.0 */
  485.     "LINUX",  {NULL},                           "",                    /* Linux */
  486.     "HFT", {"IBM8512","IBM8513",NULL},          "[?1;2c",              /* IBM HFT */
  487.     "AIXTERM", {"AIXTERM-M",NULL},              "[?1;2c",              /* IBM AIXTERM */
  488.     "SUN", {"SUN-COLOR",NULL},                  "",                    /* SUN Console */
  489.     "BA80-08", {"BA80",NULL},                   "",                    /* Nixdorf BA80 */
  490.     "BETERM",  {NULL},                          "",                    /* BEOS ANSI */
  491.     "VT100", {"DEC-VT100","VT100-AM",NULL},     "[?1;2c",              /* DEC VT100 */
  492.     "VT102", {"DEC-VT102",NULL},                "[?6c",                /* DEC VT102 */
  493.     "VT220", {"DEC-VT220","DEC-VT200","VT200",NULL}, "[?62;1;2;6;8;9;15;44c",  /* DEC VT220 */
  494.     "VT220PC", {"DEC-VT220-PC","DEC-VT200-PC","VT200PC",NULL}, "[?62;1;2;6;8;9;15;44c",  /* DEC VT220 w/ PC keyboard */
  495.     "VT320", {"DEC-VT320","DEC-VT300","VT300",NULL}, "[?63;1;2;6;8;9;15;44c",  /* DEC VT320 */
  496.     "VT320PC", {"DEC-VT320-PC","DEC-VT300-PC","VT300PC",NULL}, "[?63;1;2;6;8;9;15;44c",  /* DEC VT320 w/ PC keyboard */
  497.     "WY370", {"WYSE-370","WYSE370","WY350",NULL},"[?63;1;2;6;8;9;15;44c",  /* WYSE 370 (same as VT320) */
  498.     "97801", {"SNI-97801",NULL},                "[?62;1;2;6;8;9;15;44c",  /* Sinix 97801 */
  499.     "AAA", { "ANNARBOR", "AMBASSADOR",NULL}, "11;00;00", /* Ann Arbor Ambassador */
  500. #ifdef COMMENT
  501.     "VT420", {"DEC-VT420","DEC-VT400","VT400",NULL},    "[?64;1;2;6;8;9;15;22;23;42;44;45;46c",       /* DEC VT420 */
  502.     "VT525", {"DEC-VT525","DEC-VT500","VT500",NULL},    "[?65;1;2;6;8;9;15;22;23;42;44;45;46c",       /* DEC VT520 */
  503. #endif /* COMMENT */
  504.     "TVI910", {"TELEVIDEO-910","TVI910+""910",NULL},    "TVS 910 REV.I\r",        /* TVI 910+ */
  505.     "TVI925", {"TELEVIDEO-925","925",NULL},     "TVS 925 REV.I\r",        /* TVI 925  */
  506.     "TVI950", {"TELEVIDEO-950","950",NULL},     "1.0,0\r",                /* TVI 950  */
  507.     "ADM3A",  {NULL}, "", /* LSI ADM 3A */
  508.     "ADM5",   {NULL}, "", /* LSI ADM 5 */
  509.     "VTNT",   {NULL},                           "",                       /* Microsoft NT VT */
  510.     "IBM3101",{"I3101",NULL},   ""                       /* IBM 31xx */
  511. };
  512. int max_tt = TT_MAX;                    /* Highest terminal type */
  513.  
  514. /* SET TERMINAL values ... */
  515.  
  516. extern int tt_arrow;                    /* Arrow-key mode */
  517. extern int tt_keypad;                   /* Keypad mode */
  518. extern int tt_shift_keypad;             /* Keypad Shift mode */
  519. extern int tt_wrap;                     /* Autowrap */
  520. extern int tt_type;                     /* Terminal type */
  521. extern int tt_cursor_usr;               /* Cursor type */
  522. extern int tt_cursorena_usr;            /* Cursor enabled by user */
  523. extern int tt_cursor;                   /* Active cursor mode */
  524. extern int tt_answer;                   /* Answerback enabled/disabled */
  525. extern int tt_scrsize[];                /* Scrollback buffer size */
  526. extern int tt_roll[];                   /* Scrollback style */
  527. extern int tt_rows[];                   /* Screen rows */
  528. extern int tt_cols[];                   /* Screen columns */
  529.        int tt_cols_usr = 80;            /* User default screen width */
  530. int tt_szchng[VNUM] = {1,1,1,0}; /* Screen Size Changed */
  531. extern int cmd_rows;                    /* Screen rows */
  532. extern int cmd_cols;                    /* Screen columns */
  533. extern int tt_ctstmo;                   /* CTS timeout */
  534. extern int tt_pacing;                   /* Output-pacing */
  535. extern int tt_mouse;                    /* Mouse */
  536. extern int tt_updmode;                  /* Terminal Screen Update Mode */
  537. extern int tt_url_hilite;
  538. extern int tt_url_hilite_attr;
  539. int tt_type_vt52 = TT_VT52 ;            /* Terminal Type Mode before entering VT52 mode */
  540. int      holdscreen = FALSE ;
  541.  
  542. int      escstate = ES_NORMAL;
  543. int      escnext = 1;
  544. int      esclast = 0;
  545.  
  546. int marginbell = FALSE, marginbellcol = 72 ;
  547.  
  548. extern int autoscroll ;                 /* WYSE ASCII Term AutoScroll Mode */
  549. extern int writeprotect ;               /* WYSE ASCII WriteProtect Mode */
  550. extern int protect ;                    /* WYSE ASCII Protect Mode */
  551. extern int wysegraphics ;               /* WYSE ASCII Graphics Mode */
  552. extern vtattrib WPattrib ;              /* WYSE ASCII WriteProtect Mode Attrib */
  553. extern vtattrib defWPattrib ;           /* WYSE ASCII default WP Mode Attrib */
  554. extern int attrmode ;                   /* WYSE ASCII Attribute Mode */
  555. extern int wy_keymode ;                 /* WYSE ASCII Key Appl Mode */
  556. extern int wy_enhanced ;                /* WYSE ASCII Enhanced Mode */
  557. extern int wy_widthclr ;                /* WYSE ASCII Width Clear Mode */
  558. extern int wy_autopage ;                /* WYSE ASCII Auto Page Mode */
  559. extern int wy_monitor ;                 /* WYSE ASCII Monitor Mode */
  560. extern int wy_nullsuppress;             /* WYSE ASCII Null Suppression */
  561. extern int tvi_ic ;                     /* TVI insert character */
  562. extern int wy_block;                    /* TVI block mode (FALSE = Conversation mode) */
  563. extern int hzgraphics;                  /* Hazeltine graphics mode */
  564.  
  565. int tt_sac = SP;                        /* Spacing Attribute Character */
  566. int sni_pagemode = FALSE;               /* 97801 Page Mode */
  567. int sni_pagemode_usr = FALSE;           /* 97801 Page Mode (User Default) */
  568. int sni_scroll_mode = FALSE;            /* 97801 Roll (power-on) or Scroll */
  569. int sni_scroll_mode_usr = FALSE;        /* 97801 Roll or Scroll (User Default) */
  570. int sni_chcode = TRUE;                  /* 97801 CH.CODE mode */
  571. int sni_chcode_usr = TRUE;              /* 97801 CH.CODE mode */
  572. int sni_chcode_7 = TRUE;                /* 97801 CH.CODE key enabled 7-bit mode */
  573. int sni_chcode_8 = TRUE;                /* 97801 CH.CODE key enabled 8-bit mode */
  574. int sni_bitmode = 8;                    /* 97801 CH.CODE 8-bit mode */
  575. CHAR sni_kbd_firmware[7]="920031";      /* 97801 Keyboard Firmware Version */
  576. CHAR sni_term_firmware[7]="830851";     /* 97801 Terminal Firmware Version */
  577.  
  578. /* Escape-sequence processing buffer */
  579.  
  580. unsigned short escbuffer[ESCBUFLEN+1];
  581.  
  582. /*
  583.    For pushing back input characters,
  584.    e.g. converting 8-bit controls to 7-bit escape sequences.
  585. */
  586. static int f_pushed = 0, c_pushed = 0, f_popped = 0;
  587.  
  588. int sgrcolors = TRUE;                   /* Process SGR Color Commands */
  589.  
  590. static
  591. unsigned char sgrcols[8] = {
  592. /* Black   */ 0,
  593. /* Red     */ 4,
  594. /* Green   */ 2,
  595. /* Brown   */ 6,
  596. /* Blue    */ 1,
  597. /* Magenta */ 5,
  598. /* Cyan    */ 3,
  599. /* White   */ 7
  600. };
  601.  
  602. static
  603. unsigned char isocols[8] = {
  604. /* Black   */ 0,
  605. /* Blue    */ 1,
  606. /* Green   */ 2,
  607. /* Cyan    */ 3,
  608. /* Red     */ 4,
  609. /* Magenta */ 5,
  610. /* Yellow  */ 6,
  611. /* White   */ 7
  612. };
  613.  
  614. /* Function prototypes */
  615. #ifndef NOTTOCI
  616. int ttoci(char c);
  617. #endif /* NOTTOCI */
  618.  
  619. int status_saved = -1;
  620.  
  621. extern int os2_outesc ;                     /* Esc seq recognizer for keys... */
  622.  
  623. /* BA80 Function Key Label Reader */
  624. static char ba80_fkey_buf[256]="", *ba80_fkey_ptr=NULL;
  625. static int  ba80_fkey_read = 0;
  626.  
  627. /* VTNT variables */
  628.  
  629. #define VTNT_BUFSZ      36864
  630. #define VTNT_MIN_READ   42
  631. static char vtnt_buf[VTNT_BUFSZ]="";
  632. static unsigned long  vtnt_index = 0;
  633. static unsigned long  vtnt_read  = VTNT_MIN_READ;
  634.  
  635. /* DEC F-key strings */
  636. char * fkeys[] = {
  637.  "[11~","[12~","[13~","[14~","[15~",    /* F1  - F5 PC Keyboard */
  638.  "[17~","[18~","[19~","[20~","[21~",    /* F6  - F10 */
  639.  "[23~","[24~","[25~","[26~","[28~",    /* F11 - F15 */
  640.  "[29~","[31~","[32~","[33~","[34~"     /* F16 - F20 */
  641. };
  642.  
  643. /* DEC Editing key strings */
  644. char * ekeys[] = {
  645.     "[1~",      /* Find */
  646.     "[2~",      /* Insert */
  647.     "[3~",      /* Remove */
  648.     "[4~",      /* Select */
  649.     "[5~",      /* Previous Screen */
  650.     "[6~",      /* Next Screen */
  651.     "[H"        /* PC Home */
  652. };
  653.  
  654. /* DEC User Defined Key strings */
  655. /* Also used for SCO ANSI UDK strings */
  656. /* There are 15 DEC strings, and 60 AT386 strings */
  657. /* And 65 Wyse characters */
  658. /* And close to 108 DG keys (regular and unix modes) */
  659. /* 153 SNI 97801 keys */
  660. char * udkfkeys[200];  /* let udkreset() initialize them */
  661. int udklock = 0 ;      /* Are User Defined Keys locked? */
  662.  
  663. #ifndef NOKVERBS
  664. extern struct keytab kverbs[] ;         /* Kverbs table  */
  665. extern int nkverbs ;                    /* Num of Kverbs */
  666.  
  667. /* Compose-key support structures and tables */
  668.  
  669. struct compose_key_tab {
  670.     CHAR c1;                            /* First char of compose sequence */
  671.     CHAR c2;                            /* Second char of compose sequence */
  672.     CHAR c3;                            /* Character that it maps to */
  673. };
  674.  
  675. struct compose_key_tab l1ktab[] = {     /* The Latin-1 Compose Key Table */
  676.     'N', 'B', (CHAR) 0xA0,        /* No-Break Space */
  677.     'n', 'b', (CHAR) 0xA0,        /* No-Break Space */
  678.     'A', '`', (CHAR) 0xC0,              /* A grave */
  679.     '`', 'A', (CHAR) 0xC0,              /* A grave */
  680.     'A', (CHAR) 0x27, (CHAR) 0xC1,      /* A acute */
  681.     (CHAR) 0x27, 'A', (CHAR) 0xC1,      /* A acute */
  682.     'A', '^', (CHAR) 0xC2,              /* A circumflex */
  683.     '^', 'A', (CHAR) 0xC2,              /* A circumflex */
  684.     'A', '~', (CHAR) 0xC3,              /* A tilde */
  685.     '~', 'A', (CHAR) 0xC3,              /* A tilde */
  686.     'A', '"', (CHAR) 0xC4,              /* A diaeresis */
  687.     '"', 'A', (CHAR) 0xC4,              /* A diaeresis */
  688.     'A', '*', (CHAR) 0xC5,              /* A ring above */
  689.     '*', 'A', (CHAR) 0xC5,              /* A ring above */
  690.     'A', 'E', (CHAR) 0xC6,              /* A with E */
  691.     'C', ',', (CHAR) 0xC7,              /* C Cedilla */
  692.     ',', 'C', (CHAR) 0xC7,              /* C Cedilla */
  693.     'E', '`', (CHAR) 0xC8,              /* E grave */
  694.     '`', 'E', (CHAR) 0xC8,              /* E grave */
  695.     'E', (CHAR) 0x27, (CHAR) 0xC9,      /* E acute */
  696.     (CHAR) 0x27, 'E', (CHAR) 0xC9,      /* E acute */
  697.     'E', '^', (CHAR) 0xCA,              /* E circumflex */
  698.     '^', 'E', (CHAR) 0xCA,              /* E circumflex */
  699.     'E', '"', (CHAR) 0xCB,              /* E diaeresis */
  700.     '"', 'E', (CHAR) 0xCB,              /* E diaeresis */
  701.     'I', '`', (CHAR) 0xCC,              /* I grave */
  702.     '`', 'I', (CHAR) 0xCC,              /* I grave */
  703.     'I', (CHAR) 0x27, (CHAR) 0xCD,      /* I acute */
  704.     (CHAR) 0x27, 'I', (CHAR) 0xCD,      /* I acute */
  705.     'I', '^', (CHAR) 0xCE,              /* I circumflex */
  706.     '^', 'I', (CHAR) 0xCE,              /* I circumflex */
  707.     'I', '"', (CHAR) 0xCF,              /* I diaeresis */
  708.     '"', 'I', (CHAR) 0xCF,              /* I diaeresis */
  709.     '-', 'D', (CHAR) 0xD0,              /* Icelandic Eth */
  710.     'D', '-', (CHAR) 0xD0,              /* Icelandic Eth */
  711.     'N', '~', (CHAR) 0xD1,              /* N tilde */
  712.     '~', 'N', (CHAR) 0xD1,              /* N tilde */
  713.     'O', 'E', (CHAR) 0xD7,      /* OE digraph (not really in Latin-1) */
  714.     'O', '`', (CHAR) 0xD2,              /* O grave */
  715.     '`', 'O', (CHAR) 0xD2,              /* O grave */
  716.     'O', (CHAR) 0x27, (CHAR) 0xD3,      /* O acute */
  717.     (CHAR) 0x27, 'O', (CHAR) 0xD3,      /* O acute */
  718.     'O', '^', (CHAR) 0xD4,              /* O circumflex */
  719.     '^', 'O', (CHAR) 0xD4,              /* O circumflex */
  720.     'O', '~', (CHAR) 0xD5,              /* O tilde */
  721.     '~', 'O', (CHAR) 0xD5,              /* O tilde */
  722.     'O', '"', (CHAR) 0xD6,              /* O diaeresis */
  723.     '"', 'O', (CHAR) 0xD6,              /* O diaeresis */
  724.     'O', '/', (CHAR) 0xD8,              /* O oblique stroke */
  725.     '/', 'O', (CHAR) 0xD8,              /* O oblique stroke */
  726.     'U', '`', (CHAR) 0xD9,              /* U grave */
  727.     '`', 'U', (CHAR) 0xD9,              /* U grave */
  728.     'U', (CHAR) 0x27, (CHAR) 0xDA,      /* U acute */
  729.     (CHAR) 0x27, 'U', (CHAR) 0xDA,      /* U acute */
  730.     'U', '^', (CHAR) 0xDB,              /* U circumflex */
  731.     '^', 'U', (CHAR) 0xDB,              /* U circumflex */
  732.     'U', '"', (CHAR) 0xDC,              /* U diaeresis */
  733.     '"', 'U', (CHAR) 0xDC,              /* U diaeresis */
  734.     'Y', (CHAR) 0x27, (CHAR) 0xDD,      /* Y acute */
  735.     (CHAR) 0x27, 'Y', (CHAR) 0xDD,      /* Y acute */
  736.     'H', 'T', (CHAR) 0xDE,              /* Icelandic Thorn */
  737.     'T', 'H', (CHAR) 0xDE,              /* Icelandic Thorn */
  738.     's', 's', (CHAR) 0xDF,              /* German scharfes s */
  739.     'a', '`', (CHAR) 0xE0,              /* a grave */
  740.     '`', 'a', (CHAR) 0xE0,              /* a grave */
  741.     'a', (CHAR) 0x27, (CHAR) 0xE1,      /* a acute */
  742.     (CHAR) 0x27, 'a', (CHAR) 0xE1,      /* a acute */
  743.     'a', '^', (CHAR) 0xE2,              /* a circumflex */
  744.     '^', 'a', (CHAR) 0xE2,              /* a circumflex */
  745.     'a', '~', (CHAR) 0xE3,              /* a tilde */
  746.     '~', 'a', (CHAR) 0xE3,              /* a tilde */
  747.     'a', '"', (CHAR) 0xE4,              /* a diaeresis */
  748.     '"', 'a', (CHAR) 0xE4,              /* a diaeresis */
  749.     'a', '*', (CHAR) 0xE5,              /* a ring above */
  750.     '*', 'a', (CHAR) 0xE5,              /* a ring above */
  751.     'a', 'e', (CHAR) 0xE6,              /* a with e */
  752.     'c', ',', (CHAR) 0xE7,              /* c cedilla */
  753.     ',', 'c', (CHAR) 0xE7,              /* c cedilla */
  754.     'e', '`', (CHAR) 0xE8,              /* e grave */
  755.     '`', 'e', (CHAR) 0xE8,              /* e grave */
  756.     'e', (CHAR) 0x27, (CHAR) 0xE9,      /* e acute */
  757.     (CHAR) 0x27, 'e', (CHAR) 0xE9,      /* e acute */
  758.     'e', '^', (CHAR) 0xEA,              /* e circumflex */
  759.     '^', 'e', (CHAR) 0xEA,              /* e circumflex */
  760.     'e', '"', (CHAR) 0xEB,              /* e diaeresis */
  761.     '"', 'e', (CHAR) 0xEB,              /* e diaeresis */
  762.     'i', '`', (CHAR) 0xEC,              /* i grave */
  763.     '`', 'i', (CHAR) 0xEC,              /* i grave */
  764.     'i', (CHAR) 0x27, (CHAR) 0xED,      /* i acute */
  765.     (CHAR) 0x27, 'i', (CHAR) 0xED,      /* i acute */
  766.     'i', '^', (CHAR) 0xEE,              /* i circumflex */
  767.     '^', 'i', (CHAR) 0xEE,              /* i circumflex */
  768.     'i', '"', (CHAR) 0xEF,              /* i diaeresis */
  769.     '"', 'i', (CHAR) 0xEF,              /* i diaeresis */
  770.     '-', 'd', (CHAR) 0xF0,              /* Icelandic eth */
  771.     'd', '-', (CHAR) 0xF0,              /* Icelandic eth */
  772.     'n', '~', (CHAR) 0xF1,              /* n tilde */
  773.     '~', 'n', (CHAR) 0xF1,              /* n tilde */
  774.     'o', 'e', (CHAR) 0xF7,      /* oe digraph (not really in Latin-1) */
  775.     'o', '`', (CHAR) 0xF2,              /* o grave */
  776.     '`', 'o', (CHAR) 0xF2,              /* o grave */
  777.     'o', (CHAR) 0x27, (CHAR) 0xF3,      /* o acute */
  778.     (CHAR) 0x27, 'o', (CHAR) 0xF3,      /* o acute */
  779.     'o', '^', (CHAR) 0xF4,              /* o circumflex */
  780.     '^', 'o', (CHAR) 0xF4,              /* o circumflex */
  781.     'o', '~', (CHAR) 0xF5,              /* o tilde */
  782.     '~', 'o', (CHAR) 0xF5,              /* o tilde */
  783.     'o', '"', (CHAR) 0xF6,              /* o diaeresis */
  784.     '"', 'o', (CHAR) 0xF6,              /* o diaeresis */
  785.     '-', ':', (CHAR) 0xF7,              /* Division sign */
  786.     'o', '/', (CHAR) 0xF8,              /* o oblique stroke */
  787.     '/', 'o', (CHAR) 0xF8,              /* o oblique stroke */
  788.     'u', '`', (CHAR) 0xF9,              /* u grave */
  789.     '`', 'u', (CHAR) 0xF9,              /* u grave */
  790.     'u', (CHAR) 0x27, (CHAR) 0xFA,      /* u acute */
  791.     (CHAR) 0x27, 'u', (CHAR) 0xFA,      /* u acute */
  792.     'u', '^', (CHAR) 0xFB,              /* u circumflex */
  793.     '^', 'u', (CHAR) 0xFB,              /* u circumflex */
  794.     'u', '"', (CHAR) 0xFC,              /* u diaeresis */
  795.     '"', 'u', (CHAR) 0xFC,              /* u diaeresis */
  796.     'y', (CHAR) 0x27, (CHAR) 0xFD,      /* y acute */
  797.     (CHAR) 0x27, 'y', (CHAR) 0xFD,      /* y acute */
  798.     'h', 't', (CHAR) 0xFE,              /* Icelandic thorn */
  799.     't', 'h', (CHAR) 0xFE,              /* Icelandic thorn */
  800.     'y', '"', (CHAR) 0xFF,              /* y diaeresis */
  801.     '"', 'y', (CHAR) 0xFF,              /* y diaeresis */
  802.     '+', '+', '#',                      /* Number sign */
  803.     'A', 'A', '@',                      /* At sign */
  804.     'a', 'a', '@',                      /* At sign */
  805.     '(', '(', '[',                      /* Left bracket */
  806.     '/', '/', '\\',                     /* Backslash */
  807.     '/', '<', '\\',                     /* Backslash */
  808.     ')', ')', ']',                      /* Right bracket */
  809.     '(', '-', '{',                      /* Left brace */
  810.     '/', '^', '|',                      /* Vertical bar */
  811.     ')', '-', '}',                      /* Right brace */
  812.     '!', '!', (CHAR) 0xA1,              /* Inverted exclamation */
  813.     'C', '/', (CHAR) 0xA2,              /* Cent sign */
  814.     'c', '/', (CHAR) 0xA2,              /* Cent sign */
  815.     'L', '-', (CHAR) 0xA3,              /* Pound sterling sign */
  816.     'l', '-', (CHAR) 0xA3,              /* Pound sterling sign */
  817.     'Y', '-', (CHAR) 0xA5,              /* Yen sign */
  818.     'y', '-', (CHAR) 0xA5,              /* Yen sign */
  819.     '|', '|', (CHAR) 0xA6,              /* Broken bar */
  820.     'S', 'O', (CHAR) 0xA7,              /* Paragraph sign */
  821.     'S', '!', (CHAR) 0xA7,              /* Paragraph sign */
  822.     'S', '0', (CHAR) 0xA7,              /* Paragraph sign */
  823.     's', 'o', (CHAR) 0xA7,              /* Paragraph sign */
  824.     's', '!', (CHAR) 0xA7,              /* Paragraph sign */
  825.     's', '0', (CHAR) 0xA7,              /* Paragraph sign */
  826.     'X', 'O', (CHAR) 0xA4,              /* Currency sign */
  827.     'X', '0', (CHAR) 0xA4,              /* Currency sign */
  828.     'x', 'o', (CHAR) 0xA4,              /* Currency sign */
  829.     'x', '0', (CHAR) 0xA4,              /* Currency sign */
  830.     'C', 'O', (CHAR) 0xA9,              /* Copyright sign */
  831.     'C', '0', (CHAR) 0xA9,              /* Copyright sign */
  832.     'c', 'o', (CHAR) 0xA9,              /* Copyright sign */
  833.     'c', '0', (CHAR) 0xA9,              /* Copyright sign */
  834.     'A', '_', (CHAR) 0xAA,              /* Feminine ordinal */
  835.     'a', '_', (CHAR) 0xAA,              /* Feminine ordinal */
  836.     '<', '<', (CHAR) 0xAB,              /* Left angle quotation */
  837.     '-', ',', (CHAR) 0xAC,              /* Not sign */
  838.     '-', '-', (CHAR) 0xAD,              /* Soft hyphen */
  839.     'R', 'O', (CHAR) 0xAE,              /* Registered Trademark */
  840.     'r', 'o', (CHAR) 0xAE,              /* Registered Trademark */
  841.     '-', '^', (CHAR) 0xAF,              /* Macron */
  842.     '0', '^', (CHAR) 0xB0,              /* Degree sign */
  843.     '+', '-', (CHAR) 0xB1,              /* Plus or minus sign */
  844.     '2', '^', (CHAR) 0xB2,              /* Superscript 2 */
  845.     '3', '^', (CHAR) 0xB3,              /* Superscript 3 */
  846.     (CHAR) 0x27, (CHAR) 0x27, (CHAR) 0xB4, /* Acute accent */
  847.     '/', 'U', (CHAR) 0xB5,              /* Micro sign */
  848.     'U', '/', (CHAR) 0xB5,              /* Micro sign */
  849.     '/', 'u', (CHAR) 0xB5,              /* Micro sign */
  850.     'u', '/', (CHAR) 0xB5,              /* Micro sign */
  851.     'P', '!', (CHAR) 0xB6,              /* Pilcrow sign */
  852.     'p', '!', (CHAR) 0xB6,              /* Pilcrow sign */
  853.     '.', '^', (CHAR) 0xB7,              /* Middle dot */
  854.     ',', ',', (CHAR) 0xB8,              /* Cedilla */
  855.     '1', '^', (CHAR) 0xB9,              /* Superscript 1 */
  856.     'O', '_', (CHAR) 0xBA,              /* Masculine ordinal */
  857.     'o', '_', (CHAR) 0xBA,              /* Masculine ordinal */
  858.     '>', '>', (CHAR) 0xBB,              /* Right angle quotation */
  859.     '1', '4', (CHAR) 0xBC,              /* Fraction one quarter */
  860.     '1', '2', (CHAR) 0xBD,              /* Fraction one half */
  861.     '?', '?', (CHAR) 0xBF,              /* Inverted question mark */
  862.     'x', 'x', (CHAR) 0xD7,              /* Multiplication sign */
  863.     'X', 'X', (CHAR) 0xD7,              /* Multiplication sign */
  864.     /*
  865.     The following group is for entering ASCII characters that are otherwise
  866.     impossible to enter, e.g. because they are dead-key combinations.
  867.     */
  868.     (CHAR)0x27, '.' ,(CHAR) 0x27,       /* Apostrophe */
  869.     '.', (CHAR)0x27, (CHAR) 0x27,       /* Apostrophe */
  870.     '^', '^', '^',                      /* Circumflex or caret */
  871.     '`', '`', '`',                      /* Grave accent or backquote */
  872.     '~', '~', '~',                      /* Tilde */
  873.     ',', '.', ',',                      /* Comma */
  874.     '.', ',', ',',                      /* Comma */
  875.     '"', '"', '"',                      /* Doublequote */
  876.     ':', ':', (CHAR) 0xA8               /* Diaeresis */
  877.  
  878. };
  879. int nl1ktab = (sizeof(l1ktab) / sizeof(struct compose_key_tab));
  880.  
  881. struct compose_key_tab l2ktab[] = {     /* The Latin-2 Compose Key Table */
  882.     'N', 'B', (CHAR) 0xA0,        /* No-Break Space */
  883.     'A', C_OGONEK, (CHAR) 0xA1,         /* A ogonek */
  884.     C_OGONEK, 'A', (CHAR) 0xA1,         /* A ogonek */
  885.     C_BREVE, C_BREVE, (CHAR) 0xF4,      /* Breve */
  886.     'L', '/', (CHAR) 0xA3,              /* L with stroke */
  887.     '/', 'L', (CHAR) 0xA3,              /* L with stroke */
  888.     'X', 'O', (CHAR) 0xA4,              /* Currency sign */
  889.     'X', '0', (CHAR) 0xA4,              /* Currency sign */
  890.     'x', 'o', (CHAR) 0xA4,              /* Currency sign */
  891.     'x', '0', (CHAR) 0xA4,              /* Currency sign */
  892.     'L', C_CARON, 0xA5,                 /* L caron */
  893.     C_CARON, 'L', 0xA5,                 /* L caron */
  894.     'S', C_ACUTE, (CHAR) 0xA6,          /* S acute */
  895.     C_ACUTE, 'S', (CHAR) 0xA6,          /* S acute */
  896.     'S', 'O', (CHAR) 0xA7,              /* Paragraph sign */
  897.     'S', '!', (CHAR) 0xA7,              /* Paragraph sign */
  898.     'S', '0', (CHAR) 0xA7,              /* Paragraph sign */
  899.     's', 'o', (CHAR) 0xA7,              /* Paragraph sign */
  900.     's', '!', (CHAR) 0xA7,              /* Paragraph sign */
  901.     's', '0', (CHAR) 0xA7,              /* Paragraph sign */
  902.     ':', ':', (CHAR) 0xA8,              /* Diaeresis */
  903.     'S', C_CARON, (CHAR) 0xA9,          /* S caron */
  904.     C_CARON, 'S', (CHAR) 0xA9,          /* S caron */
  905.     'S', C_CEDILLA, (CHAR) 0xAA,        /* S cedilla */
  906.     C_CEDILLA, 'S', (CHAR) 0xAA,        /* S cedilla */
  907.     'T', C_CARON, (CHAR) 0xAB,          /* T caron */
  908.     C_CARON, 'T', (CHAR) 0xAB,          /* T caron */
  909.     'Z', C_ACUTE, (CHAR) 0xAC,          /* Z acute */
  910.     C_ACUTE, 'Z', (CHAR) 0xAC,          /* Z acute */
  911.     '-', '-', (CHAR) 0xAD,              /* Soft hyphen */
  912.     'Z', C_CARON, (CHAR) 0xAE,          /* Z caron */
  913.     C_CARON, 'Z', (CHAR) 0xAE,          /* Z caron */
  914.     'Z', C_DOT, (CHAR) 0xAF,            /* Z dot above */
  915.     C_DOT, 'Z', (CHAR) 0xAF,            /* Z dot above */
  916.     '0', '^', (CHAR) 0xB0,              /* Degree sign */
  917.     'a', C_OGONEK, (CHAR) 0xB1,         /* a ogonek */
  918.     C_OGONEK, 'a', (CHAR) 0xB1,         /* a ogonek */
  919.     C_OGONEK, C_OGONEK, (CHAR) 0xB2,    /* Ogonek */
  920.     'l', '/', (CHAR) 0xB3,              /* l with stroke */
  921.     '/', 'l',(CHAR) 0xB3,               /* l with stroke */
  922.     C_ACUTE, C_ACUTE, (CHAR) 0xB4,      /* Acute accent */
  923.     'l', C_CARON, (CHAR) 0xB5,          /* l caron */
  924.     C_CARON, 'l', (CHAR) 0xB5,          /* l caron */
  925.     's', C_ACUTE, (CHAR) 0xB6,          /* s acute */
  926.     C_ACUTE, 's', (CHAR) 0xB6,          /* s acute */
  927.     C_CARON, C_CARON, (CHAR) 0xB7,      /* Caron */
  928.     C_CEDILLA, C_CEDILLA, (CHAR) 0xB8,  /* Cedilla */
  929.     's', C_CARON, (CHAR) 0xB9,          /* s caron */
  930.     C_CARON, 's', (CHAR) 0xB9,          /* s caron */
  931.     's', C_CEDILLA, (CHAR) 0xBA,        /* s cedilla */
  932.     C_CEDILLA, 's', (CHAR) 0xBA,        /* s cedilla */
  933.     't', C_CARON, (CHAR) 0xBB,          /* t caron */
  934.     C_CARON, 't', (CHAR) 0xBB,          /* t caron */
  935.     'z', C_ACUTE, (CHAR) 0xBC,          /* z acute */
  936.     C_ACUTE, 'z', (CHAR) 0xBC,          /* z acute */
  937.     C_DACUTE, C_DACUTE, (CHAR) 0xBD,    /* Double acute */
  938.     'z', C_CARON, (CHAR) 0xBE,          /* z caron */
  939.     C_CARON, 'z', (CHAR) 0xBE,          /* z caron */
  940.     'z', C_DOT, (CHAR) 0xBF,            /* z dot above */
  941.     C_DOT, 'z', (CHAR) 0xBF,            /* z dot above */
  942.     'R', C_ACUTE, (CHAR) 0xC0,          /* R acute */
  943.     C_ACUTE, 'R', (CHAR) 0xC0,          /* R acute */
  944.     'A', C_ACUTE, (CHAR) 0xC1,          /* A acute */
  945.     C_ACUTE, 'A', (CHAR) 0xC1,          /* A acute */
  946.     'A', '^', (CHAR) 0xC2,              /* A circumflex */
  947.     '^', 'A', (CHAR) 0xC2,              /* A circumflex */
  948.     'A', C_BREVE, (CHAR) 0xC3,          /* A breve */
  949.     C_BREVE, 'A', (CHAR) 0xC3,          /* A breve */
  950.     'A', '"', (CHAR) 0xC4,              /* A diaeresis */
  951.     '"', 'A', (CHAR) 0xC4,              /* A diaeresis */
  952.     'L', C_ACUTE, (CHAR) 0xC5,          /* L acute */
  953.     C_ACUTE, 'L', (CHAR) 0xC5,          /* L acute */
  954.     'C', C_ACUTE, (CHAR) 0xC6,          /* C acute */
  955.     C_ACUTE, 'C', (CHAR) 0xC6,          /* C acute */
  956.     'C', ',', (CHAR) 0xC7,              /* C cedilla */
  957.     ',', 'C', (CHAR) 0xC7,              /* C cedilla */
  958.     'C', C_CARON, (CHAR) 0xC8,          /* C caron */
  959.     C_CARON, 'C', (CHAR) 0xC8,          /* C caron */
  960.     'E', C_ACUTE, (CHAR) 0xC9,          /* E acute */
  961.     C_ACUTE, 'E', (CHAR) 0xC9,          /* E acute */
  962.     'E', C_OGONEK, (CHAR) 0xCA,         /* E ogonek */
  963.     C_OGONEK, 'E', (CHAR) 0xCA,         /* E ogonek */
  964.     'E', '"', (CHAR) 0xCB,              /* E diaeresis */
  965.     '"', 'E', (CHAR) 0xCB,              /* E diaeresis */
  966.     'E', C_CARON, (CHAR) 0xCC,          /* E caron */
  967.     C_CARON, 'E', (CHAR) 0xCC,          /* E caron */
  968.     'I', C_ACUTE, (CHAR) 0xCD,          /* I acute */
  969.     C_ACUTE, 'I', (CHAR) 0xCD,          /* I acute */
  970.     'I', '^', (CHAR) 0xCE,              /* I circumflex */
  971.     '^', 'I', (CHAR) 0xCE,              /* I circumflex */
  972.     C_CARON, 'D', (CHAR) 0xCF,          /* D caron */
  973.     'D', C_CARON, (CHAR) 0xCF,          /* D caron */
  974.     '-', 'D', (CHAR) 0xD0,              /* D stroke */
  975.     'D', '-', (CHAR) 0xD0,              /* D stroke */
  976.     'N', C_ACUTE, (CHAR) 0xD1,          /* N acute */
  977.     C_ACUTE, 'N', (CHAR) 0xD1,          /* N acute */
  978.     'N', C_CARON, (CHAR) 0xD2,          /* N caron */
  979.     C_CARON, 'N', (CHAR) 0xD2,          /* N caron */
  980.     'O', C_ACUTE, (CHAR) 0xD3,          /* O acute */
  981.     C_ACUTE, 'O', (CHAR) 0xD3,          /* O acute */
  982.     'O', '^', (CHAR) 0xD4,              /* O circumflex */
  983.     '^', 'O', (CHAR) 0xD4,              /* O circumflex */
  984.     'O', C_DACUTE, (CHAR) 0xD5,         /* O double acute */
  985.     C_DACUTE, 'O', (CHAR) 0xD5,         /* O double acute */
  986.     'O', '"', (CHAR) 0xD6,              /* O diaeresis */
  987.     '"', 'O', (CHAR) 0xD6,              /* O diaeresis */
  988.     'x', 'x', (CHAR) 0xD7,              /* Multiplication sign */
  989.     'X', 'X', (CHAR) 0xD7,              /* Multiplication sign */
  990.     'R', C_CARON, (CHAR) 0xD8,          /* R caron */
  991.     C_CARON, 'R', (CHAR) 0xD8,          /* R caron */
  992.     'U', C_RING, (CHAR) 0xD9,           /* U ring */
  993.     C_RING, 'U', (CHAR) 0xD9,           /* U ring */
  994.     'U', C_ACUTE, (CHAR) 0xDA,          /* U acute */
  995.     C_ACUTE, 'U', (CHAR) 0xDA,          /* U acute */
  996.     'U', C_DACUTE, (CHAR) 0xDB,         /* U double acute */
  997.     C_DACUTE, 'U', (CHAR) 0xDB,         /* U double acute */
  998.     'U', '"', (CHAR) 0xDC,              /* U diaeresis */
  999.     '"', 'U', (CHAR) 0xDC,              /* U diaeresis */
  1000.     'Y', C_ACUTE, (CHAR) 0xDD,          /* Y acute */
  1001.     C_ACUTE, 'Y', (CHAR) 0xDD,          /* Y acute */
  1002.     'T', ',', (CHAR) 0xDE,              /* T cedilla */
  1003.     ',', 'T', (CHAR) 0xDE,              /* T cedilla */
  1004.     's', 's', (CHAR) 0xDF,              /* German sharp s */
  1005.     'r', C_ACUTE, (CHAR) 0xE0,          /* r acute */
  1006.     C_ACUTE, 'r', (CHAR) 0xE0,          /* r acute */
  1007.     'a', C_ACUTE, (CHAR) 0xE1,          /* a acute */
  1008.     C_ACUTE, 'a', (CHAR) 0xE1,          /* a acute */
  1009.     'a', '^', (CHAR) 0xE1,              /* a circumflex */
  1010.     '^', 'a', (CHAR) 0xE1,              /* a circumflex */
  1011.     'a', C_BREVE, (CHAR) 0xE3,          /* a breve */
  1012.     C_BREVE, 'a', (CHAR) 0xE3,          /* a breve */
  1013.     'a', '"', (CHAR) 0xE4,              /* a diaeresis */
  1014.     '"', 'a', (CHAR) 0xE4,              /* a diaeresis */
  1015.     'l', C_ACUTE, (CHAR) 0xE5,          /* l acute */
  1016.     C_ACUTE, 'l', (CHAR) 0xE5,          /* l acute */
  1017.     'c', C_ACUTE, (CHAR) 0xE6,          /* c acute */
  1018.     C_ACUTE, 'c', (CHAR) 0xE6,          /* c acute */
  1019.     'c', ',', (CHAR) 0xE7,              /* c cedilla */
  1020.     ',', 'c', (CHAR) 0xE7,              /* c cedilla */
  1021.     'c', C_CARON, (CHAR) 0xE8,          /* c caron */
  1022.     C_CARON, 'c', (CHAR) 0xE8,          /* c caron */
  1023.     'e', C_ACUTE, (CHAR) 0xE9,          /* e acute */
  1024.     C_ACUTE, 'e', (CHAR) 0xE9,          /* e acute */
  1025.     'e', C_OGONEK, (CHAR) 0xEA,         /* e ogonek */
  1026.     C_OGONEK, 'e', (CHAR) 0xEA,         /* e ogonek */
  1027.     'e', '"', (CHAR) 0xEB,              /* e diaeresis */
  1028.     '"', 'e', (CHAR) 0xEB,              /* e diaeresis */
  1029.     'e', C_CARON, (CHAR) 0xEC,          /* e caron */
  1030.     C_CARON, 'e', (CHAR) 0xEC,          /* e caron */
  1031.     'i', C_ACUTE, (CHAR) 0xED,          /* i acute */
  1032.     C_ACUTE, 'i', (CHAR) 0xED,          /* i acute */
  1033.     'i', '^', (CHAR) 0xEE,              /* i circumflex */
  1034.     '^', 'i', (CHAR) 0xEE,              /* i circumflex */
  1035.     'd', C_CARON, (CHAR) 0xEF,          /* d caron */
  1036.     C_CARON, 'd', (CHAR) 0xEF,          /* d caron */
  1037.     '-', 'd', (CHAR) 0xF0,              /* d stroke */
  1038.     'd', '-', (CHAR) 0xF0,              /* d stroke */
  1039.     'n', C_ACUTE, (CHAR) 0xF1,          /* n acute */
  1040.     C_ACUTE, 'n', (CHAR) 0xF1,          /* n acute */
  1041.     'n', C_CARON, (CHAR) 0xF2,          /* n caron */
  1042.     C_CARON, 'n', (CHAR) 0xF2,          /* n caron */
  1043.     'o', C_ACUTE, (CHAR) 0xF3,          /* o acute */
  1044.     C_ACUTE, 'o', (CHAR) 0xF3,          /* o acute */
  1045.     'o', '^', (CHAR) 0xF4,              /* o circumflex */
  1046.     '^', 'o', (CHAR) 0xF4,              /* o circumflex */
  1047.     'o', C_DACUTE, (CHAR) 0xF5,         /* o double acute */
  1048.     C_DACUTE, 'o', (CHAR) 0xF5,         /* o double acute */
  1049.     'o', '"', (CHAR) 0xF6,              /* o diaeresis */
  1050.     '"', 'o', (CHAR) 0xF6,              /* o diaeresis */
  1051.     '-', ':', (CHAR) 0xF7,              /* Division sign */
  1052.     'r', C_CARON, (CHAR) 0xF8,          /* r caron */
  1053.     C_CARON, 'r', (CHAR) 0xF8,          /* r caron */
  1054.     'u', C_RING, (CHAR) 0xF9,           /* u ring */
  1055.     C_RING, 'u', (CHAR) 0xF9,           /* u ring */
  1056.     'u', C_ACUTE, (CHAR) 0xFA,          /* u acute */
  1057.     C_ACUTE, 'u', (CHAR) 0xFA,          /* u acute */
  1058.     'u', C_DACUTE, (CHAR) 0xFB,         /* u double acute */
  1059.     C_DACUTE, 'u', (CHAR) 0xFB,         /* u double acute */
  1060.     'u', '"', (CHAR) 0xFC,              /* u diaeresis */
  1061.     '"', 'u', (CHAR) 0xFC,              /* u diaeresis */
  1062.     'y', C_ACUTE, (CHAR) 0xFD,          /* y acute */
  1063.     C_ACUTE, 'y', (CHAR) 0xFD,          /* y acute */
  1064.     't', ',', (CHAR) 0xFE,              /* t cedilla */
  1065.     ',', 't', (CHAR) 0xFE,              /* t cedilla */
  1066.     C_DOT, C_DOT, (CHAR) 0xFF,          /* Dot above */
  1067.     /*
  1068.     The following group is for entering ASCII characters that are otherwise
  1069.     impossible to enter, e.g. because they are dead-key combinations.
  1070.     */
  1071.     '+', '+', '#',                      /* Number sign */
  1072.     'A', 'A', '@',                      /* At sign */
  1073.     'a', 'a', '@',                      /* At sign */
  1074.     '(', '(', '[',                      /* Left bracket */
  1075.     '/', '/', '\\',                     /* Backslash */
  1076.     '/', '<', '\\',                     /* Backslash */
  1077.     ')', ')', ']',                      /* Right bracket */
  1078.     '(', '-', '{',                      /* Left brace */
  1079.     '/', '^', '|',                      /* Vertical bar */
  1080.     ')', '-', '}',                      /* Right brace */
  1081.     (CHAR)0x27, '.', C_ACUTE,           /* Apostrophe */
  1082.     '.', (CHAR)0x27, C_ACUTE,           /* Apostrophe */
  1083.     '^', '^', '^',                      /* Circumflex or caret */
  1084.     '`', '`', '`',                      /* Grave accent or backquote */
  1085.     '~', '~', '~',                      /* Tilde */
  1086.     ',', '.', ',',                      /* Comma */
  1087.     '.', ',', ',',                      /* Comma */
  1088.     '"', '"', '"',                      /* Doublequote */
  1089.     ':', ':', (CHAR) 0xA8               /* Diaeresis */
  1090. };
  1091. int nl2ktab = (sizeof(l2ktab) / sizeof(struct compose_key_tab));
  1092.  
  1093. vik_rec vik;
  1094. #endif /* NOKVERBS */
  1095.  
  1096.  
  1097. USHORT
  1098. xldecgrph( CHAR c ) {
  1099. #ifdef COMMENT
  1100.     if ( isunicode() ) {
  1101.         return(c);
  1102.     }
  1103.     else {
  1104.         static unsigned char graphicset[32] = { /* VT100/200 graphic characters */
  1105.             0x20,
  1106.             0x04, 0xB0, 0x1A, 0x17, 0x1B, 0x19, 0xF8, 0xF1,
  1107.             0x15, 0x12, 0xD9, 0xBF, 0xDA, 0xC0, 0xC5, 0xC4,
  1108.             0xC4, 0xC4, 0xC4, 0xC4, 0xC3, 0xB4, 0xC1, 0xC2,
  1109.             0xB3, 0xF3, 0xF2, 0xE3, 0x9D, 0x9C, 0xFA
  1110.         };
  1111.         return graphicset[c>127 ? c-222 : c-95] ;
  1112.     }
  1113. #else /* COMMENT */
  1114.     USHORT cx = 0;
  1115.     if ( isunicode() ) {
  1116.         cx = (*xl_u[TX_DECSPEC])(c);
  1117.         if ( win95hsl && cx >= 0x23BA && cx <= 0x23BD )
  1118.             cx = tx_hslsub(cx);
  1119.         else if ( cx >= 0xE000 && cx <= 0xF8FF )
  1120.             cx = tx_usub(cx);
  1121.         if (win95lucida && cx > 0x017f)
  1122.             cx = tx_lucidasub(cx);
  1123.     }
  1124.     else {
  1125.         cx = (*xl_u[TX_DECSPEC])(c);
  1126.         if ( GNOW->itol )
  1127.             cx = (*GNOW->itol)(cx);
  1128.     }
  1129.     return(cx);
  1130. #endif /* COMMENT */
  1131. }
  1132.  
  1133. USHORT
  1134. xldectech( CHAR c ) {
  1135.     USHORT cx = 0;
  1136.     if ( isunicode() ) {
  1137.         cx = (*xl_u[TX_DECTECH])(c);
  1138.         if ( win95hsl && cx >= 0x23BA && cx <= 0x23BD )
  1139.             cx = tx_hslsub(cx);
  1140.         else if ( cx >= 0xE000 && cx <= 0xF8FF )
  1141.             cx = tx_usub(cx);
  1142.         if (win95lucida && cx > 0x017f)
  1143.             cx = tx_lucidasub(cx);
  1144.     }
  1145.     else {
  1146. #ifdef COMMENT
  1147.     static unsigned char graphicset[94] = { /* VT200 technical characters */
  1148.              '?', '?', '?', '?', '?', '?', '?',
  1149.         '?', '?', '?', '?', '?', '?', '?', '?',
  1150.         '?', '?', '?', '?', '?', '?', '?', '?',
  1151.         '?', ' ', ' ', ' ', '?', '?', '?', '?',
  1152.         '?', '?', '?', '?', '?', '?', '?', '?',
  1153.         '?', '?', '?', '?', '?', '?', '?', '?',
  1154.         '?', '?', ' ', '?', ' ', ' ', '?', '?',
  1155.         '?', '?', '?', '?', '?', '?', '?', '?',
  1156.         '?', '?', '?', '?', '?', '?', '?', '?',
  1157.         '?', '?', '?', '?', '?', '?', '?', '?',
  1158.         '?', '?', '?', '?', '?', '?', '?', '?',
  1159.         '?', '?', '?', '?', '?', '?', '?'
  1160.     };
  1161.         cx = graphicset[c>127 ? c-160 : c-33] ;
  1162. #else /* COMMENT */
  1163.         cx = (*xl_u[TX_DECTECH])(c);
  1164.         if ( GNOW->itol )
  1165.             cx = (*GNOW->itol)(cx);
  1166. #endif /* COMMENT */
  1167.     }
  1168.     return(cx);
  1169. }
  1170.  
  1171. USHORT
  1172. xlh19grph( CHAR c ) {
  1173.     USHORT cx=0;
  1174.     if ( isunicode() ) {
  1175.         cx = (*xl_u[TX_H19GRAPH])(c);
  1176.         if ( win95hsl && cx >= 0x23BA && cx <= 0x23BD )
  1177.             cx = tx_hslsub(cx);
  1178.         else if ( cx >= 0xE000 && cx <= 0xF8FF )
  1179.             cx = tx_usub(cx);
  1180.         if (win95lucida && cx > 0x017f)
  1181.             cx = tx_lucidasub(cx);
  1182.     }
  1183.     else {
  1184. #ifdef COMMENT
  1185.     static unsigned char graphicset[33] = { /* Heath-19 graphic characters */
  1186.         0xFA, 0xDD, 0x5C/*0xB3*/, 0xC4, 0xC5,
  1187.         0xBF, 0xD9, 0xC0, 0xDA, 0xF1,
  1188.         0x1A, 0xDB, 0xFE, 0x19, 0xDC,
  1189.         0xDC, 0xDF, 0xDF, 0xDF, 0xDE,
  1190.         0x2F/*0xDE*/, 0xC2, 0xB4, 0xC1, 0xC3,
  1191.         0x58, 0x2F, 0x5C, 0x16, 0x5F,
  1192.         0xB3, 0xB3, 0X14
  1193.     };
  1194.         cx =  graphicset[c>127 ? c-211 : c-94] ;
  1195. #else
  1196.         cx = (*xl_u[TX_H19GRAPH])(c);
  1197.         if ( GNOW->itol )
  1198.             cx = (*GNOW->itol)(cx);
  1199. #endif /* COMMENT */
  1200.     }
  1201.     return(cx);
  1202. }
  1203.  
  1204. #ifdef CKLEARN
  1205. ULONG learnt1;
  1206. char learnbuf[LEARNBUFSIZ] = { NUL, NUL };
  1207. int  learnbc = 0;
  1208. int  learnbp = 0;
  1209. int  learnst = 0;
  1210.  
  1211. VOID
  1212. learnreset()
  1213. {
  1214.     learnbuf[0] = NUL;
  1215.     learnbc = 0;
  1216.     learnbp = 0;
  1217.     learnst = 0;
  1218. }
  1219.  
  1220. VOID
  1221. learnnet(int c)
  1222. {
  1223.     if (learning && learnst != LEARN_KEYBOARD) {
  1224.         learnbuf[learnbp++] = c;
  1225.         if ( learnbp >= LEARNBUFSIZ )
  1226.             learnbp = 0;
  1227.         learnbc++;
  1228.         learnst = LEARN_NET;
  1229.     }
  1230. }
  1231.  
  1232. VOID
  1233. learnkeyb(con_event evt, int state) {   /* Learned script keyboard character */
  1234.     char buf[64];
  1235.     char * ptr=NULL;
  1236.     int cc;
  1237.  
  1238.     if (!learning || !learnfp)
  1239.       return;
  1240.  
  1241.     switch (evt.type) {
  1242.     case key:
  1243.         cc = evt.key.scancode;
  1244.         if (cc == 0) {
  1245.             ptr = "\\N";
  1246.         } else if (cc < SP || cc > 126 && cc < 160) {
  1247.             ckmakmsg(buf,64,"\\{",ckitoa((int)cc),"}",NULL);
  1248.             ptr = buf;
  1249.         } else {
  1250.             buf[0] = evt.key.scancode ;
  1251.             buf[1] = '\0';
  1252.             ptr = buf;
  1253.         }
  1254.         break;
  1255.  
  1256. #ifndef NOKVERBS
  1257.     case kverb: {
  1258.         extern struct keytab kverbs[];
  1259.         extern int nkverbs;
  1260.         int i;
  1261.  
  1262.         for ( i=0; i<nkverbs; i++ ) {
  1263.             if ( kverbs[i].kwval == evt.kverb.id ) {
  1264.                 ckmakmsg(buf,64,"\\K{",kverbs[i].kwd,"}",NULL);
  1265.                 ptr = buf;
  1266.             }
  1267.         }
  1268.         break;
  1269.     }
  1270. #endif /* NOKVERBS */
  1271.     case macro:
  1272.         ptr = evt.macro.string;
  1273.         break;
  1274.  
  1275.     case literal:
  1276.         ptr = evt.literal.string;
  1277.         break;
  1278.  
  1279.     case esc:
  1280.         buf[0] = ESC;
  1281.         buf[1] = evt.esc.key & ~F_ESC ;
  1282.         buf[2] = '\0' ;
  1283.         ptr = buf;
  1284.         break;
  1285.  
  1286.     case csi:
  1287.         buf[0] = ESC;
  1288.         buf[1] = '[' ;
  1289.         buf[2] = evt.csi.key & ~F_CSI ;
  1290.         buf[3] = '\0' ;
  1291.         ptr = buf;
  1292.         break;
  1293.     }
  1294.  
  1295.     switch (learnst) {                  /* Learn state... */
  1296.       case LEARN_NEUTRAL:
  1297.       case LEARN_NET:
  1298.         if (learnbc > 0) {              /* Have net characters? */
  1299.             char nbuf[LEARNBUFSIZ];
  1300.             int i, j, n;
  1301.             ULONG t;
  1302.  
  1303.             t = (ULONG) time(0);        /* Calculate INPUT timeout */
  1304.             j = t - learnt1;
  1305.             j += (j / 4) > 0 ? (j / 4) : 1; /* Add some slop */
  1306.             if (j < 2) j = 2;               /* 2 seconds minimum */
  1307.  
  1308.             fputs("\r\nINPUT ",learnfp);/* Give INPUT command for them */
  1309.             fputs(ckitoa(j),learnfp);
  1310.             fputs(" {",learnfp);
  1311.             learnt1 = t;
  1312.  
  1313.             n = LEARNBUFSIZ;
  1314.             if (learnbc < LEARNBUFSIZ) {  /* Circular buffer */
  1315.                 n = learnbc;              /*  hasn't wrapped yet. */
  1316.                 learnbp = 0;
  1317.             }
  1318.             j = 0;                      /* Copy to linear buffer */
  1319.             for (i = 0; i < n; i++) {   /* Number of chars in circular buf */
  1320.  
  1321.                 cc = learnbuf[(learnbp + i) % LEARNBUFSIZ];
  1322.  
  1323.                 /* Later account for prompts that end with a newline? */
  1324.  
  1325.                 if (cc == CR && j > 0) {
  1326.                     if (nbuf[j-1] != LF)
  1327.                       j = 0;
  1328.                 }
  1329.                 nbuf[j++] = cc;
  1330.             }
  1331.             for (i = 0; i < j; i++) {   /* Now copy out the buffer */
  1332.                 cc = nbuf[i];           /* interpreting control chars */
  1333.                 if (cc == 0) {          /* We don't INPUT NULs */
  1334.                     continue;
  1335.                 } else if (cc < SP ||   /* Controls need quoting */
  1336.                            cc > 126 && cc < 160) {
  1337.                     ckmakmsg(buf,64,"\\{",ckitoa((int)cc),"}",NULL);
  1338.                     fputs(buf,learnfp);
  1339.                 } else {                /* Plain character */
  1340.                     putc(cc,learnfp);
  1341.                 }
  1342.             }
  1343.             fputs("}\nIF FAIL STOP 1 INPUT timeout",learnfp);
  1344.             learnbc = 0;
  1345.         }
  1346.         learnbp = 0;
  1347.         fputs("\nPAUSE 1\nOUTPUT ",learnfp); /* Emit OUTPUT and fall thru */
  1348.  
  1349.       case LEARN_KEYBOARD:
  1350.         if ( ptr )
  1351.             fputs(ptr,learnfp);
  1352.     }
  1353.     learnst = state;
  1354. }
  1355. #endif /* CKLEARN */
  1356. #endif /* NOLOCAL */
  1357.  
  1358. /* ------------------------------------------------------------------ */
  1359. /* Printer functions                                                  */
  1360. /* ------------------------------------------------------------------ */
  1361.  
  1362. /* Text2PS */
  1363.  
  1364. /*
  1365.   Postscript Prolog, to be inserted at the beginning of the output file.
  1366.   The %% Comments are to make the file conformant with Adobe's "Postscript
  1367.   File Structuring Conventions", which allow page-oriented operations in
  1368.   Postscript previewers, page pickers, etc.
  1369. */
  1370. char *prolog[] = {                      /* Standard prolog */
  1371.     "%!PS-Adobe-1.0",                   /* Works with Postscript 1.0 */
  1372.     "%%Title: oofa",
  1373.     "%%DocumentFonts: Courier CourierLatin1",
  1374.     "%%Creator: K95",
  1375.     "%%Pages: (atend)",
  1376.     "%%EndComments",
  1377. /*
  1378.   Postscript font reencoding.  The standard encoding does not have the
  1379.   characters needed for Latin-1.
  1380.  
  1381.   Unfortunately, the font reencoding methods listed in the Postscript
  1382.   Cookbook simply do not work with the Apple Laserwriter (even though they
  1383.   did work with other Postscript devices).  The method described in the
  1384.   Adobe PostScript Language Reference Manual (2nd Ed) to change from the
  1385.   StandardEncoding vector to the ISOLatin1Encoding vector works only with
  1386.   the LaserWriter-II, but not older LaserWriters.
  1387.  
  1388.   This method, suggested by Bur Davis at Adobe, works around the fact that
  1389.   Courier was a "stroke font" in pre-version-47.0 Postscript, in which many of
  1390.   the accented characters are composed from other characters (e.g. i-grave =
  1391.   dotless i + grave).  It is probably not the most efficient possible solution
  1392.   (an iterative method might be better), but it works.
  1393. */
  1394.     "/CourierLatin1 /Courier findfont dup dup maxlength dict begin",
  1395.     "{",
  1396.     "    1 index /FID ne { def } { pop pop } ifelse",
  1397.     "} forall",
  1398.     "/Encoding exch 1 index get 256 array copy def",
  1399. /*
  1400.   The following characters are added at the C1 positions 128-153, for printing
  1401.   non-Latin1 character sets such as IBM code pages, DEC MCS, NeXT, etc.  Note
  1402.   that we cannot use characters from the Symbol font.  Characters from
  1403.   different fonts cannot be mixed.  Anyway, the Symbol font is not fixed-width.
  1404. */
  1405.     "Encoding 128 /quotesingle put",
  1406.     "Encoding 129 /quotedblleft put",
  1407.     "Encoding 131 /fi put",
  1408.     "Encoding 132 /endash put",
  1409.     "Encoding 133 /dagger put",
  1410.     "Encoding 134 /periodcentered put",
  1411.     "Encoding 135 /bullet put",
  1412.     "Encoding 136 /quotesinglbase put",
  1413.     "Encoding 137 /quotedblbase put",
  1414.     "Encoding 138 /quotedblright put",
  1415.     "Encoding 139 /ellipsis put",
  1416.     "Encoding 140 /perthousand put",
  1417.     "Encoding 141 /dotaccent put",
  1418.     "Encoding 142 /hungarumlaut put",
  1419.     "Encoding 143 /ogonek put",
  1420.     "Encoding 144 /caron put",
  1421.     "Encoding 145 /fl put",
  1422.     "Encoding 146 /emdash put",
  1423.     "Encoding 147 /Lslash put",
  1424.     "Encoding 148 /OE put",
  1425.     "Encoding 149 /lslash put",
  1426.     "Encoding 150 /oe put",
  1427.     "Encoding 151 /florin put",
  1428.     "Encoding 152 /fraction put",
  1429.     "Encoding 153 /daggerdbl put",
  1430. /*
  1431.   The following six characters are required for pre-47.0 PostScript versions,
  1432.   which compose accented Courier characters by putting together the base
  1433.   character and the accent.
  1434. */
  1435.     "Encoding 154 /dotlessi put",
  1436.     "Encoding 155 /grave put",
  1437.     "Encoding 156 /circumflex put",
  1438.     "Encoding 157 /tilde put",
  1439.     "Encoding 158 /breve put",
  1440.     "Encoding 159 /ring put",
  1441. /*
  1442.   The remainder follow the normal ISO 8859-1 encoding.
  1443. */
  1444.     "Encoding 160 /space put",
  1445.     "Encoding 161 /exclamdown put",
  1446.     "Encoding 162 /cent put",
  1447.     "Encoding 163 /sterling put",
  1448.     "Encoding 164 /currency put",
  1449.     "Encoding 165 /yen put",
  1450.     "Encoding 166 /brokenbar put",
  1451.     "Encoding 167 /section put",
  1452.     "Encoding 168 /dieresis put",
  1453.     "Encoding 169 /copyright put",
  1454.     "Encoding 170 /ordfeminine put",
  1455.     "Encoding 171 /guillemotleft put",
  1456.     "Encoding 172 /logicalnot put",
  1457.     "Encoding 173 /hyphen put",
  1458.     "Encoding 174 /registered put",
  1459.     "Encoding 175 /macron put",
  1460.     "Encoding 176 /degree put",
  1461.     "Encoding 177 /plusminus put",
  1462.     "Encoding 178 /twosuperior put",
  1463.     "Encoding 179 /threesuperior put",
  1464.     "Encoding 180 /acute put",
  1465.     "Encoding 181 /mu put",
  1466.     "Encoding 182 /paragraph put",
  1467.     "Encoding 183 /bullet put",
  1468.     "Encoding 184 /cedilla put",
  1469.     "Encoding 185 /onesuperior put",
  1470.     "Encoding 186 /ordmasculine put",
  1471.     "Encoding 187 /guillemotright put",
  1472.     "Encoding 188 /onequarter put",
  1473.     "Encoding 189 /onehalf put",
  1474.     "Encoding 190 /threequarters put",
  1475.     "Encoding 191 /questiondown put",
  1476.     "Encoding 192 /Agrave put",
  1477.     "Encoding 193 /Aacute put",
  1478.     "Encoding 194 /Acircumflex put",
  1479.     "Encoding 195 /Atilde put",
  1480.     "Encoding 196 /Adieresis put",
  1481.     "Encoding 197 /Aring put",
  1482.     "Encoding 198 /AE put",
  1483.     "Encoding 199 /Ccedilla put",
  1484.     "Encoding 200 /Egrave put",
  1485.     "Encoding 201 /Eacute put",
  1486.     "Encoding 202 /Ecircumflex put",
  1487.     "Encoding 203 /Edieresis put",
  1488.     "Encoding 204 /Igrave put",
  1489.     "Encoding 205 /Iacute put",
  1490.     "Encoding 206 /Icircumflex put",
  1491.     "Encoding 207 /Idieresis put",
  1492.     "Encoding 208 /Eth put",
  1493.     "Encoding 209 /Ntilde put",
  1494.     "Encoding 210 /Ograve put",
  1495.     "Encoding 211 /Oacute put",
  1496.     "Encoding 212 /Ocircumflex put",
  1497.     "Encoding 213 /Otilde put",
  1498.     "Encoding 214 /Odieresis put",
  1499.     "Encoding 215 /multiply put",
  1500.     "Encoding 216 /Oslash put",
  1501.     "Encoding 217 /Ugrave put",
  1502.     "Encoding 218 /Uacute put",
  1503.     "Encoding 219 /Ucircumflex put",
  1504.     "Encoding 220 /Udieresis put",
  1505.     "Encoding 221 /Yacute put",
  1506.     "Encoding 222 /Thorn put",
  1507.     "Encoding 223 /germandbls put",
  1508.     "Encoding 224 /agrave put",
  1509.     "Encoding 225 /aacute put",
  1510.     "Encoding 226 /acircumflex put",
  1511.     "Encoding 227 /atilde put",
  1512.     "Encoding 228 /adieresis put",
  1513.     "Encoding 229 /aring put",
  1514.     "Encoding 230 /ae put",
  1515.     "Encoding 231 /ccedilla put",
  1516.     "Encoding 232 /egrave put",
  1517.     "Encoding 233 /eacute put",
  1518.     "Encoding 234 /ecircumflex put",
  1519.     "Encoding 235 /edieresis put",
  1520.     "Encoding 236 /igrave put",
  1521.     "Encoding 237 /iacute put",
  1522.     "Encoding 238 /icircumflex put",
  1523.     "Encoding 239 /idieresis put",
  1524.     "Encoding 240 /eth put",
  1525.     "Encoding 241 /ntilde put",
  1526.     "Encoding 242 /ograve put",
  1527.     "Encoding 243 /oacute put",
  1528.     "Encoding 244 /ocircumflex put",
  1529.     "Encoding 245 /otilde put",
  1530.     "Encoding 246 /odieresis put",
  1531.     "Encoding 247 /divide put",
  1532.     "Encoding 248 /oslash put",
  1533.     "Encoding 249 /ugrave put",
  1534.     "Encoding 250 /uacute put",
  1535.     "Encoding 251 /ucircumflex put",
  1536.     "Encoding 252 /udieresis put",
  1537.     "Encoding 253 /yacute put",
  1538.     "Encoding 254 /thorn put",
  1539.     "Encoding 255 /ydieresis put",
  1540.     "currentdict end definefont",
  1541. /*
  1542.   Set the font and define functions for adding lines and printing pages.
  1543. */
  1544.     "/CourierLatin1 findfont 11 scalefont setfont",
  1545.     "/StartPage{/sv save def 48 765 moveto}def",
  1546.     "/ld -11.4 def",                    /* Line spacing */
  1547.     "/yline 765 def",                   /* Position of top line */
  1548.     "/U{show",                          /* Show line, don't advance */
  1549.     "  48 yline moveto}def",
  1550.     "/S{show",                          /* Show line, move to next line */
  1551.     "  /yline yline ld add def",
  1552.     "  48 yline moveto}def",
  1553.     "/L{ld mul yline add /yline exch def", /* Move down n lines  */
  1554.     "  48 yline moveto}def",
  1555.     "/EndPage{showpage sv restore}def",
  1556.     "%%EndProlog",                      /* End of prolog. */
  1557.     "%%Page: 1 1",                      /* Number the first page. */
  1558.     "StartPage",                        /* And start it. */
  1559.     ""                                  /* Empty string = end of array. */
  1560. };                                      /* End PS Prolog */
  1561.  
  1562. #define NOESCSEQ        /* We don't support this, should be no need. */
  1563. #ifndef NOESCSEQ        /* Swallow ANSI escape and control sequences */
  1564. #define ESCSEQ          /* unless -DNOESCSEQ given on cc command line. */
  1565. #endif /* NOESCSEQ */
  1566.  
  1567. #define PS_WIDTH 80     /* Portrait printer line width, characters */
  1568. #define PS_LENGTH 66    /* Portrait printer page length, lines */
  1569. #define MAXPSLENGTH 256
  1570.  
  1571. /* TextPS Globals */
  1572.  
  1573. static int hpos = 0,                    /* Character number in line buffer */
  1574.   maxhpos = 0,                          /* Longest line in buffer */
  1575.   page = 0,                             /* Page number */
  1576.   line = 0,                             /* Line number */
  1577.   blank = 0,                            /* Blank line count */
  1578.   pagefull = 0,                         /* Flag for page overflow */
  1579.   psflag = 0,                           /* Flag for file already postscript */
  1580.   proflg = 0,                           /* Prolog done */
  1581.   shift = 0,                            /* Shift state */
  1582.   ps_escape = 0;
  1583.  
  1584. int ps_width = PS_WIDTH;                /* Paper width, characters */
  1585. int ps_length = PS_LENGTH;              /* Paper length, characters */
  1586.  
  1587. int txt2ps = 0;                         /* Flag set if we convert to PS */
  1588.  
  1589. /* Data structures */
  1590.  
  1591. /*
  1592.   buf is the line buffer.  columns (indexed by hpos) are the characters
  1593.   in the line, rows are overstruck lines.  At display time (see addline),
  1594.   buf is treated as a 3-dimensional array, with the extra dimension being
  1595.   for wraparound.  The total size of the buffer is 80 chars per line times
  1596.   66 lines per page times 10 levels of overstriking = 52,800.  This allows
  1597.   files that contain absolutely no linefeeds to still print correctly.
  1598. */
  1599. #define BUFNUM 10                       /* Number of overstrike buffers */
  1600. #define BUFWID 5280                     /* Max characters per line */
  1601.  
  1602. unsigned char buf[BUFNUM][BUFWID];      /* Line buffers */
  1603. unsigned char outbuf[400];              /* Output buffer */
  1604. int linesize[BUFNUM];                   /* Size of each line in buffer */
  1605. int bufs[MAXPSLENGTH];                  /* # overstrike buffers per line */
  1606.  
  1607. /* Line and page display routines */
  1608.  
  1609. /* Forward declarations */
  1610.  
  1611. void addline();                         /* Add line to page */
  1612. void addchar();                         /* Add character to line */
  1613. void newpage();                         /* New page */
  1614.  
  1615. void
  1616. clearbuf() {                            /* Clear line buffer */
  1617.     int i;
  1618. /*
  1619.   Note: if a loop is used instead of memset, this program runs
  1620.   veeeery slooooooowly.
  1621. */
  1622.     memset(buf,SP,BUFNUM * BUFWID);     /* Clear buffers and counts */
  1623.     for (i = 0; i < BUFNUM; linesize[i++] = -1) ;
  1624.     for (i = 0; i < ps_length; bufs[i++] = 0) ;
  1625.     hpos = 0;                           /* Reset line buffer pointer */
  1626.     maxhpos = 0;                        /* And maximum line ps_length */
  1627. }
  1628.  
  1629. void
  1630. doprolog() {                            /* Output the PostScript prolog */
  1631.     int i;
  1632.     CHAR crlf[2] = { CR, LF };
  1633.  
  1634.     for (i = 0; *prolog[i]; i++) {
  1635. #ifdef NT
  1636.         if ( winprint ) {
  1637.             int rc;
  1638.             rc = Win32PrtWrite( prolog[i], strlen(prolog[i]) );
  1639.             debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1640.             rc = Win32PrtWrite( crlf, 2 );
  1641.         }
  1642.         else
  1643. #endif /* NT */
  1644.         if ( lst ) {
  1645.             int rc;
  1646.             rc = fwrite( prolog[i], 1, strlen(prolog[i]), lst );
  1647.             debug(F111,"txt2ps_char","fwrite rc",rc);
  1648.             rc = fwrite( crlf, 1, 2, lst );
  1649.         }
  1650.         proflg++;
  1651.     }
  1652. }
  1653.  
  1654. void
  1655. addchar(c) unsigned char c; {           /* Add character to line buffer */
  1656.     int i, m;
  1657.     int * bp;
  1658.  
  1659.     if (c < SP || c == DEL) c = SP;     /* ASCII controls become spaces. */
  1660.  
  1661.     for (i = 0; i < BUFNUM; i++) {      /* Find first */
  1662.         if (hpos > linesize[i]) {       /* available overstrike buffer */
  1663.             buf[i][hpos] = c;           /* Deposit character */
  1664.             linesize[i] = hpos;         /* Remember size of this buffer. */
  1665.             m = hpos / ps_width;        /* Line-wrap segment number. */
  1666.             if (bufs[m] < i) {          /* Highest overstrike buffer used */
  1667. #ifdef OS2ONLY
  1668.                 bp = &bufs[m];          /*   (os2 compiler bug)           */
  1669.                 *bp = i;                /*   for this line-wrap segment.  */
  1670. #else /* OS2ONLY */
  1671.                 bufs[m] = i;            /*   for this line-wrap segment   */
  1672. #endif /* OS2ONLY */
  1673.             }
  1674.             break;
  1675.         }
  1676.     }
  1677.     if (hpos > maxhpos) maxhpos = hpos; /* Remember maximum line position. */
  1678.     if (++hpos >= BUFWID)               /* Increment line position. */
  1679.       addline();                        /* If buffer full, dump it. */
  1680. }
  1681.  
  1682. void
  1683. addline() {                             /* Add a line to the current page */
  1684.     int i, j, k, m, n, y, wraps;
  1685.     unsigned char *p, *q, c;
  1686.     CHAR lf = LF;
  1687.  
  1688.     if (line == 0 && page == 1) {       /* First line of file? */
  1689.         if (!strncmp(buf[0],"%!",2)) {  /* Already Postscript? */
  1690.             psflag++;                   /* Yes, set this flag & just copy */
  1691.             buf[0][hpos] = '\0';        /* Trim trailing blanks */
  1692. #ifdef NT
  1693.             if ( winprint ) {               /* Print this line */
  1694.                 int rc;
  1695.                 rc = Win32PrtWrite( buf[0], strlen(buf[0]) );
  1696.                 debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1697.                 rc = Win32PrtWrite( &lf, 1 );
  1698.             }
  1699.             else
  1700. #endif /* NT */
  1701.             if ( lst ) {
  1702.                 int rc;
  1703.                 rc = fwrite( buf[0], 1, strlen(buf[0]), lst );
  1704.                 debug(F111,"txt2ps_char","fwrite rc",rc);
  1705.                 rc = fwrite( &lf, 1, 1, lst );
  1706.             }
  1707.             return;
  1708.         } else if (!proflg) {           /* Not Postscript, print prolog. */
  1709.             doprolog();
  1710.         }
  1711.     }
  1712.     if (linesize[0] < 0) {              /* If line is empty, */
  1713.         blank++;                        /* just count it. */
  1714.         return;
  1715.     }
  1716.     if (blank > 0) {                    /* Any previous blank lines? */
  1717.         if (blank == 1) {               /* One */
  1718. #ifdef NT
  1719.         if ( winprint ) {
  1720.             int rc;
  1721.             rc = Win32PrtWrite( "()S\n", 4 );
  1722.             debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1723.         }
  1724.         else
  1725. #endif /* NT */
  1726.         if ( lst ) {
  1727.             int rc;
  1728.             rc = fwrite( "()S\n", 1, 4, lst );
  1729.             debug(F111,"txt2ps_char","fwrite rc",rc);
  1730.         }
  1731.         }
  1732.         else {                          /* Many */
  1733.             CHAR buf[16];
  1734.             sprintf(buf,"%d L\n",blank);        /* safe */
  1735. #ifdef NT
  1736.         if ( winprint ) {
  1737.             int rc;
  1738.             rc = Win32PrtWrite( buf, strlen(buf) );
  1739.             debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1740.         }
  1741.         else
  1742. #endif /* NT */
  1743.         if ( lst ) {
  1744.             int rc;
  1745.             rc = fwrite( buf, 1, strlen(buf), lst );
  1746.             debug(F111,"txt2ps_char","fwrite rc",rc);
  1747.         }
  1748.         }
  1749.     }
  1750.     line += blank;                      /* Count the blank lines */
  1751.     blank = 0;                          /* Reset blank line counter */
  1752.  
  1753.     wraps = maxhpos / ps_width;         /* Number of times line will wrap */
  1754.     if (wraps > ps_length) wraps = ps_length;   /* (within reason) */
  1755.  
  1756.     for (k = 0; k <= wraps; k++) {      /* For each wrapped line */
  1757.         m = k * ps_width;                       /* Starting position in buffer */
  1758.         for (i = 0; i <= bufs[k]; i++) { /* For each overstrike buffer */
  1759.             y = linesize[i] + 1;        /* Actual character count */
  1760.             if (y <= m)                 /* Nothing there, next buffer. */
  1761.               continue;
  1762.             /* Ending position of this wrap region in buffer. */
  1763.             n = (y < m + ps_width) ? y : m + ps_width;
  1764.             q = outbuf;
  1765.             *q++ = '(';                 /* Start text arg */
  1766.             for (j = m, p = buf[i]+m; j < n; j++) { /* For each character */
  1767.                 c = *p++;
  1768.                 if (c == '(' || c == ')' || c =='\\') /* Quote specials */
  1769.                   *q++ = '\\';          /*  with backslash. */
  1770.                 if ((int) c < 128)      /* Insert 7-bit character literally */
  1771.                   *q++ = c;
  1772.                 else {                  /* Insert 8-bit character */
  1773.                     *q++ = '\\';        /* as octal backslash ps_escape */
  1774.                     *q++ = (c >> 6) + '0'; /* (this avoids call to sprintf) */
  1775.                     *q++ = ((c >> 3) & 07) + '0';
  1776.                     *q++ = (c & 07) + '0';
  1777.                 }
  1778.             }
  1779.             *q = '\0';
  1780. #ifdef NT
  1781.             if ( winprint ) {
  1782.                 int rc;
  1783.                 rc = Win32PrtWrite( outbuf, strlen(outbuf) );
  1784.                 if ( i == bufs[k] )
  1785.                     rc = Win32PrtWrite( ")S\n", 3 );
  1786.                 else
  1787.                     rc = Win32PrtWrite( ")U\n", 3 );
  1788.                 debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1789.             }
  1790.             else
  1791. #endif /* NT */
  1792.             if ( lst ) {
  1793.                 int rc;
  1794.                 rc = fwrite( outbuf, 1, strlen(outbuf), lst );
  1795.                 if ( i == bufs[k] )
  1796.                     rc = fwrite( ")S\n", 1, 3, lst );
  1797.                 else
  1798.                     rc = fwrite( ")U\n", 1, 3, lst );
  1799.                 debug(F111,"txt2ps_char","fwrite rc",rc);
  1800.             }
  1801.         }
  1802.     }
  1803.     clearbuf();                         /* Clear line buffer */
  1804.     line += wraps + 1;                  /* Increment line number */
  1805.     if (line > (ps_length - 1)) {               /* If page is full */
  1806.         newpage();                      /* print it and start new one */
  1807.         pagefull = 1;
  1808.     }
  1809. }
  1810.  
  1811. void
  1812. newpage() {                             /* Print current page, start new one */
  1813.     CHAR buf[80];
  1814.     if (pagefull) {                     /* If we just overflowed onto a */
  1815.         pagefull = 0;                   /* new page, but then got a formfeed */
  1816.         return;                         /* immediately after... */
  1817.     }
  1818.     if (!proflg)                        /* Do prolog if not done already */
  1819.       doprolog();                       /*  (in case file starts with ^L) */
  1820.     if (hpos)                           /* Add any partial line */
  1821.       addline();
  1822.     line = hpos = 0;                    /* Reset line, advance page */
  1823.     page++;
  1824.     sprintf(buf,"EndPage\n%%%%Page: %d %d\nStartPage\n",page,page); /* safe */
  1825. #ifdef NT
  1826.     if ( winprint ) {
  1827.         int rc;
  1828.         rc = Win32PrtWrite( buf, strlen(buf) );
  1829.         debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1830.     }
  1831.     else
  1832. #endif /* NT */
  1833.     if ( lst ) {
  1834.         int rc;
  1835.         rc = fwrite( buf, 1, strlen(buf), lst );
  1836.         debug(F111,"txt2ps_char","fwrite rc",rc);
  1837.     }
  1838.     blank = 0;
  1839. }
  1840.  
  1841. VOID
  1842. txt2ps_begin()
  1843. {
  1844.     hpos = line = psflag = 0;           /* Initialize these... */
  1845.     maxhpos = 0, pagefull = 0, proflg = 0, shift = 0;
  1846.     ps_escape = blank = 0;
  1847.     page = 1;
  1848.  
  1849.     clearbuf();                         /* Clear line buffer. */
  1850. }
  1851.  
  1852. VOID
  1853. txt2ps_end()
  1854. {
  1855.     CHAR buf[80];
  1856.     if (!psflag) {                      /* Done. If not postscript already, */
  1857.         if (hpos)                       /* if last line was not empty, */
  1858.           addline();                    /* add it to the page. */
  1859.         if (page != 1 || line != 0) {   /* Add trailer. */
  1860.             sprintf(buf,"EndPage\n%%%%Trailer\n%%%%Pages: %d\n",page); /* safe */
  1861. #ifdef NT
  1862.             if ( winprint ) {
  1863.                 int rc;
  1864.                 rc = Win32PrtWrite( buf, strlen(buf) );
  1865.                 debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1866.             }
  1867.             else
  1868. #endif /* NT */
  1869.             if ( lst ) {
  1870.                 int rc;
  1871.                 rc = fwrite( buf, 1, strlen(buf), lst );
  1872.                 debug(F111,"txt2ps_char","fwrite rc",rc);
  1873.             }
  1874.         }
  1875.     }
  1876. }
  1877.  
  1878. VOID
  1879. txt2ps_char(CHAR c)
  1880. {
  1881.     if (psflag) {                       /* File already postscript? */
  1882. #ifdef NT
  1883.         if ( winprint ) {
  1884.             int rc;
  1885.             rc = Win32PrtWrite( &c, 1 );
  1886.             debug(F111,"txt2ps_char","Win32PrtWrite rc",rc);
  1887.         }
  1888.         else
  1889. #endif /* NT */
  1890.         if ( lst ) {
  1891.             int rc;
  1892.             rc = fwrite( &c, 1, 1, lst );
  1893.             debug(F111,"txt2ps_char","fwrite rc",rc);
  1894.         }
  1895.         return;
  1896.     }
  1897.  
  1898. #ifdef ESCSEQ
  1899.     if (ps_escape) {                       /* Swallow ANSI ps_escape sequences */
  1900.         switch (ps_escape) {
  1901.         case 1:                 /* ESC */
  1902.             if (c < 040 || c > 057) /* Not intermediate character */
  1903.                 ps_escape = 0;
  1904.             continue;
  1905.         case 2:                 /* CSI */
  1906.             if (c < 040 || c > 077)     /* Not parameter or intermediate */
  1907.                 ps_escape = 0;
  1908.             continue;
  1909.         default:                        /* Bad ps_escape value, */
  1910.             ps_escape = 0;         /* shouldn't happen. */
  1911.             break;
  1912.         }
  1913.     }
  1914. #endif /* ESCSEQ */
  1915.  
  1916.     if (shift && c > 31 && c < 127)
  1917.         c |= 0200;                      /* Handle shift state. */
  1918.  
  1919.     if (pagefull && c != 014)   /* Spurious blank page suppression */
  1920.         pagefull = 0;
  1921.  
  1922.     switch (c) {                        /* Handle the input character */
  1923.     case 010:                   /* Backspace */
  1924.         hpos--;
  1925.         if (hpos < 0) hpos = 0;
  1926.         return;
  1927.  
  1928.     case 011:                   /* Tab */
  1929.         hpos = (hpos | 7) + 1;
  1930.         return;
  1931.  
  1932.     case 012:                   /* Linefeed */
  1933.         addline();                      /* Add the line to the page */
  1934.         return;
  1935.  
  1936.     case 014:                   /* Formfeed */
  1937.         newpage();                      /* Print current page */
  1938.         return;
  1939.  
  1940.     case 015:                   /* Carriage return */
  1941.         hpos = 0;                       /* Back to left margin */
  1942.         return;
  1943.  
  1944.     case 016:                   /* Shift-Out */
  1945.         shift = 1;                      /* Set shift state */
  1946.         return;
  1947.  
  1948.     case 017:                   /* Shift-In */
  1949.         shift = 0;                      /* Reset shift state */
  1950.         return;
  1951.  
  1952. #ifdef ESCSEQ                           /* Swallow ANSI ps_escape sequences */
  1953. /*
  1954.   1 = ANSI ps_escape sequence
  1955.   2 = ANSI control sequence
  1956. */
  1957.     case 033:                   /* ESC or 7-bit CSI */
  1958.         ps_escape = ((c = getchar()) == 0133) ? 2 : 1;
  1959.         if (c != 033 && c != 0133 && c != 233) /* Not ANSI after all */
  1960.             ungetc(c,stdin);            /* put it back, avoid loops */
  1961.         return;
  1962.  
  1963.     case 0233:                  /* 8-bit CSI */
  1964.         if (charset == LATIN1) {
  1965.             ps_escape = 2;         /* 0233 is graphic char on PC, etc */
  1966.             return;
  1967.         }                               /* Otherwise fall thru & print it */
  1968. #endif /* ESCSEQ */
  1969.  
  1970.     default:
  1971.         addchar(c);
  1972.     }
  1973. }
  1974.  
  1975.  
  1976. void
  1977. printeron() {
  1978.     extern int noprinter, printertype;
  1979.     extern char * printsep;
  1980.  
  1981.     debug(F111,"printeron()","printon",printon);
  1982.     debug(F111,"printeron()","noprinter",noprinter);
  1983.     debug(F111,"printeron()","printertype",printertype);
  1984.     debug(F110,"printeron() printsep",printsep,0);
  1985.  
  1986.     printerclose_t = 0;
  1987.  
  1988.     if (printon || noprinter || printertype == PRT_NON)
  1989.         /* It's already on or should be ignored */
  1990.         return;
  1991.  
  1992.     if (printeropen()) {                /* Open OK? */
  1993.  
  1994. #ifndef NOLOCAL
  1995.         if ( !savefiletext[0] )
  1996.           ckstrncpy(savefiletext,filetext,sizeof(filetext));
  1997.         if ( is_xprint() )
  1998.           ckstrncpy(filetext,"CTRL PRINT",sizeof(filetext));
  1999.         else if ( is_cprint() )
  2000.             ckstrncpy( filetext, "COPY PRINT",sizeof(filetext));
  2001.         else if ( is_aprint() )
  2002.           ckstrncpy(filetext,"AUTO PRINT",sizeof(filetext));
  2003.         else if ( is_uprint() )
  2004.           ckstrncpy(filetext,"USER PRINT",sizeof(filetext));
  2005.         else
  2006.             ckstrncpy(filetext, "PRINTER ON",sizeof(filetext));
  2007.  
  2008.         VscrnIsDirty(VTERM);  /* status line needs to be updated */
  2009. #endif /* NOLOCAL */
  2010.         printon = TRUE;                 /* and printer is on. */
  2011.     }
  2012. #ifndef NOLOCAL
  2013.     else {
  2014.         char errormsg[MAXTERMCOL];
  2015.         debug(F100,"printeron() failed","",0);
  2016.         ckmakmsg(errormsg,sizeof(errormsg),
  2017.                  " ERROR: Unable to open device \"",
  2018.                  printername?printername:"prn","\"",NULL );
  2019.         popuperror(vmode,errormsg);
  2020.     }
  2021. #endif /* NOLOCAL */
  2022.  
  2023.     /* if there is a separator page, print it */
  2024.     if ( printsep ) {
  2025.         FILE * file = fopen(printsep,"rb");
  2026.         char   buf[512];
  2027.         int    count=0;
  2028.  
  2029.         if ( file ) {
  2030.             while ((count = fread(buf,sizeof(char),512,file)) > 0)
  2031.                 prtstr(buf,count);
  2032.             fclose(file);
  2033.         }
  2034.     }
  2035. }
  2036.  
  2037. void
  2038. printeroff() {                          /* Turn off printer */
  2039.     extern char * printterm;
  2040.     extern int    printtimo;
  2041.     debug(F111,"printeroff()","printon",printon);
  2042.     debug(F110,"printeroff() printterm",printterm,0);
  2043.     debug(F111,"printeroff()","printtimo",printtimo);
  2044.  
  2045.     if (!printon)                       /* It's already off. */
  2046.       return;
  2047.  
  2048.     if ( printterm ) {
  2049.         prtstr( printterm, strlen(printterm) );
  2050.     }
  2051.  
  2052. #ifdef BPRINT
  2053.     if ( !printbidi ) {
  2054. #endif /* BPRINT */
  2055.         if ( printtimo ) {
  2056.             printerclose_t = time(NULL) + printtimo;
  2057.         }
  2058.         else if ( !printerclose() )
  2059.             return;
  2060. #ifdef BPRINT
  2061.     }
  2062. #endif /* BPRINT */
  2063.  
  2064.  
  2065.     printon = FALSE;
  2066.  
  2067. #ifndef NOLOCAL
  2068.     if ( is_xprint() )
  2069.         ckstrncpy(filetext,"CTRL PRINT",sizeof(filetext));
  2070.     else if ( is_cprint() )
  2071.         ckstrncpy( filetext, "COPY PRINT",sizeof(filetext));
  2072.     else if ( is_aprint() )
  2073.         ckstrncpy(filetext,"AUTO PRINT",sizeof(filetext));
  2074.     else if ( is_uprint() )
  2075.         ckstrncpy(filetext,"USER PRINT",sizeof(filetext));
  2076.     else if (savefiletext[0]) {         /* Fix status line */
  2077.         ckstrncpy(filetext,savefiletext,sizeof(filetext));
  2078.         savefiletext[0] = NUL;
  2079.     }
  2080.  
  2081.     VscrnIsDirty(VTERM);  /* status line needs to be updated */
  2082. #endif /* NOLOCAL */
  2083. }
  2084.  
  2085. #ifndef NOLOCAL
  2086. int
  2087. is_noprint()
  2088. {
  2089.     if ( cprint )
  2090.         return(0);
  2091.     if ( xprint )
  2092.         return(0);
  2093.     if ( aprint )
  2094.         return(0);
  2095.     if ( uprint )
  2096.         return(0);
  2097.     return(1);
  2098. }
  2099.  
  2100. int
  2101. is_uprint()
  2102. {
  2103.     if ( cprint )
  2104.         return(0);
  2105.     if ( xprint )
  2106.         return(0);
  2107.     if ( aprint )
  2108.         return(0);
  2109.     if ( uprint )
  2110.         return(1);
  2111.     return(0);
  2112. }
  2113.  
  2114. int
  2115. is_aprint()
  2116. {
  2117.     if ( cprint )
  2118.         return(0);
  2119.     if ( xprint )
  2120.         return(0);
  2121.     if ( aprint )
  2122.         return(1);
  2123.     return(0);
  2124. }
  2125.  
  2126. int
  2127. is_cprint()
  2128. {
  2129.     if ( cprint )
  2130.         return(1);
  2131.     return(0);
  2132. }
  2133.  
  2134. int
  2135. is_xprint()
  2136. {
  2137.     if ( cprint )
  2138.         return(0);
  2139.     if ( xprint )
  2140.         return(1);
  2141.     return(0);
  2142. }
  2143. #endif /* NOLOCAL */
  2144.  
  2145. int
  2146. printeropen()
  2147. {
  2148.     extern int printertype;
  2149. #ifdef BPRINT
  2150.     if ( printbidi )
  2151.         return TRUE;
  2152. #endif /* BPRINT */
  2153.  
  2154.     if ( winprint || lst )              /* Already open? */
  2155.         return TRUE;
  2156.  
  2157.     if ( printertype == PRT_NON )
  2158.         return FALSE;
  2159.  
  2160.     if (!printername)                   /* If printer not redirected */
  2161.         lst = fopen("prn", "wb");       /* open the PRN device */
  2162.     else if ( printpipe || printertype == PRT_PIP ) {
  2163.         if ( !printpipe )
  2164.             printpipe = 1;
  2165.         lst = (FILE *) popen(printername, "wb" ) ;/* open the piped command */
  2166.     }
  2167. #ifdef NT
  2168.     else if (printertype == PRT_WIN) {
  2169.         if ( Win32PrtOpen( printername ) ) {
  2170.             debug(F111,"Win32PrtOpen",printername,1);
  2171.             winprint = TRUE;
  2172.             lst = (FILE *)-1;
  2173.         }
  2174.     }
  2175. #endif /* NT */
  2176.     else if ( printertype == PRT_DOS ) {
  2177. #ifdef NT
  2178.         HANDLE hPrt;
  2179.         lst = fopen(printername, "ab"); /* open the file in append mode. */
  2180.         if ( lst ) {
  2181.             hPrt = (HANDLE)_get_osfhandle(_fileno(lst));
  2182.             if ( hPrt != INVALID_HANDLE_VALUE ) {
  2183.                 prtcfg(hPrt);
  2184.             }
  2185.         }
  2186. #else /* NT */
  2187.         lst = fopen(printername, "ab"); /* open the file in append mode. */
  2188. #endif /* NT */
  2189.     } else if ( printertype == PRT_FIL ) {
  2190.         lst = fopen(printername, "ab"); /* open the file in append mode. */
  2191.     }
  2192.  
  2193.     if ( txt2ps )                       /* Init Txt2PS conversions */
  2194.         txt2ps_begin();
  2195.  
  2196.     return (lst || winprint);
  2197. }
  2198.  
  2199. int
  2200. printerclose()
  2201. {
  2202.     extern int printertype;
  2203.  
  2204.     printerclose_t = 0;   /* printerclose no longer needs to be called */
  2205.  
  2206.     if ( txt2ps )
  2207.         txt2ps_end();                   /* Complete Txt2PS conversions */
  2208.  
  2209. #ifdef BPRINT
  2210.     if ( printbidi )
  2211.         return FALSE;
  2212. #endif /* BPRINT */
  2213.  
  2214.     if ( !(winprint || lst) )           /* Printer Closed? */
  2215.         return TRUE;
  2216.  
  2217. #ifdef NT
  2218.     if ( printertype == PRT_WIN && winprint ) {
  2219.         int rc = Win32PrtClose();
  2220.         debug(F111,"Win32PrtClose",printername,rc);
  2221.         winprint = FALSE;
  2222.         lst = NULL;
  2223.     }
  2224.     else
  2225. #endif
  2226.     if (lst)
  2227.     {
  2228.         if ( printpipe && printertype == PRT_PIP )
  2229.         {
  2230.             pclose(lst);
  2231.         }
  2232.         else if ( printertype == PRT_DOS || printertype == PRT_FIL )
  2233.             fclose(lst);
  2234.         lst = NULL;
  2235.     }
  2236.     return !(winprint || lst);
  2237. }
  2238.  
  2239. void
  2240. prtchar( char c )
  2241. {
  2242.     int turnoffprinter = FALSE ;
  2243.     int rc = 0;
  2244.  
  2245.     debug(F101,"prtchar","",c);
  2246. #ifdef BPRINT
  2247.     if ( printbidi ) {
  2248.         rc = bprtwrite( &c, 1 );
  2249.         debug(F111,"prtchar","bprtwrite rc",rc);
  2250.         return;
  2251.     }
  2252. #endif /* BPRINT */
  2253.  
  2254.     if (printon == FALSE)           /* Printer already on? */
  2255.     {
  2256.         printeron() ;               /* Turn on printer */
  2257.         turnoffprinter = TRUE ;     /* Remember to turn it off */
  2258.     }
  2259.  
  2260.     if ( txt2ps ) {
  2261.         txt2ps_char(c);
  2262.     } else
  2263. #ifdef NT
  2264.     if ( winprint ) {
  2265.         rc = Win32PrtWrite( &c, 1 );
  2266.         debug(F111,"prtchar","Win32PrtWrite rc",rc);
  2267.     }
  2268.     else
  2269. #endif /* NT */
  2270.     if ( lst ) {
  2271.         rc = fwrite( &c, 1, 1, lst );
  2272.         debug(F111,"prtchar","fwrite rc",rc);
  2273.     }
  2274.  
  2275.     if ( turnoffprinter )
  2276.         printeroff();
  2277. }
  2278.  
  2279. void
  2280. prtstr( char * s, int len )
  2281. {
  2282.     int turnoffprinter = FALSE ;
  2283.     int rc = 0;
  2284.  
  2285.     debug(F111,"prtstr",s,len);
  2286.  
  2287. #ifdef BPRINT
  2288.     if ( printbidi ) {
  2289.         rc = bprtwrite( s, len );
  2290.         debug(F111,"prtstr","bprtwrite rc",rc);
  2291.         return;
  2292.     }
  2293. #endif /* BPRINT */
  2294.  
  2295.     if (printon == FALSE)                       /* Printer already on? */
  2296.     {
  2297.         printeron() ;               /* Turn on printer */
  2298.         turnoffprinter = TRUE ;     /* Remember to turn it off */
  2299.     }
  2300.  
  2301.     if ( txt2ps ) {
  2302.         int i = 0;
  2303.         for ( ;i<len;i++ )
  2304.             txt2ps_char(s[i]);
  2305.     } else
  2306. #ifdef NT
  2307.     if ( winprint ) {
  2308.         rc = Win32PrtWrite( s, len );
  2309.         debug(F111,"prtstr","Win32PrtWrite rc",rc);
  2310.     }
  2311.     else
  2312. #endif /* NT */
  2313.     if ( lst ) {
  2314.         rc = fwrite( s, 1, len, lst );
  2315.         debug(F111,"prtstr","fwrite rc",rc);
  2316.     }
  2317.  
  2318.     if ( turnoffprinter )
  2319.         printeroff();
  2320. }
  2321.  
  2322. void
  2323. prtfile( char * filename )
  2324. {
  2325.     FILE * file=NULL;
  2326.     char   buf[512];
  2327.     int    count=0;
  2328.     int turnoffprinter = FALSE ;
  2329.     int rc = 0;
  2330.  
  2331.     debug(F110,"prtfile",filename,0);
  2332.  
  2333.     if (printon == FALSE)           /* Printer already on? */
  2334.     {
  2335.         printeron() ;               /* Turn on printer */
  2336.         turnoffprinter = TRUE ;     /* Remember to turn it off */
  2337.     }
  2338.  
  2339.     file = fopen(filename,"rb");
  2340.     if ( file ) {
  2341.         while ((count = fread(buf,sizeof(char),512,file)) > 0) {
  2342.             if ( txt2ps ) {
  2343.                 int i = 0;
  2344.                 extern int fcharset;
  2345.                 USHORT uch;
  2346.                 int charset;
  2347.  
  2348.                 charset = fc2tx( fcharset );
  2349.  
  2350.                 for ( ;i<count;i++ ) {
  2351.                     if ( charset >= 0 ) {
  2352.                         uch = xl_u[charset](buf[i]);
  2353.                         txt2ps_char(xl_tx[TX_8859_1](uch));
  2354.                     } else
  2355.                         txt2ps_char(buf[i]);
  2356.                 }
  2357.             } else
  2358.                 prtstr(buf,count);
  2359.         }
  2360.         fclose(file);
  2361.     }
  2362.  
  2363.     if ( turnoffprinter )
  2364.         printeroff();
  2365. }
  2366.  
  2367. #ifndef NOLOCAL
  2368. /* ----------------------------------------------------------------- */
  2369. /* PrtLine - Copy the specified line on screen to printer.           */
  2370. /* parameters = Line to print 1-based, terminating character.        */
  2371. /* ----------------------------------------------------------------- */
  2372. void
  2373. prtline(int line, unsigned short achar) {
  2374.     int    j;
  2375.     USHORT n;
  2376.     viocell cells[MAXTERMCOL];
  2377.     char    outbuf[MAXTERMCOL + 1];
  2378.     int     turnoffprinter = FALSE ;
  2379.  
  2380.     if (printon == FALSE)                       /* Printer already on? */
  2381.     {
  2382.         printeron() ;               /* Turn on printer */
  2383.         turnoffprinter = TRUE ;     /* Remember to turn it off */
  2384.     }
  2385.  
  2386.     if (printon) {                              /* If printer on */
  2387.         n = VscrnGetWidth(VTERM) * sizeof(viocell);     /* Line width, incl attributes */
  2388.         /* Internally, screen lines are 0-based, so "i-1". */
  2389.         memcpy(cells,VscrnGetCells(VTERM,line-1),n);
  2390.  
  2391.         for (j = 0; j < VscrnGetWidth(VTERM); j++) {    /* Strip away the attribute bytes */
  2392.             if ( isunicode() )
  2393.             {
  2394.                 if (GNOW->itol )
  2395.                     outbuf[j] = (*GNOW->itol)(cells[j].c);
  2396.             }
  2397.             else {
  2398.                 outbuf[j] =(cells[j].c & 0xFF);
  2399.             }
  2400.         }
  2401.  
  2402.         for (j = VscrnGetWidth(VTERM) - 1; j >= 0; j--) /* Strip trailing blanks */
  2403.           if (outbuf[j] != SP)
  2404.             break;
  2405.         outbuf[j+1] = '\r';
  2406.         outbuf[j+2] = achar;
  2407.         outbuf[j+3] = NUL;              /* Terminate string with NUL */
  2408.         if ( ISTVI(tt_type_mode) || ISWYSE(tt_type_mode) )
  2409.             prtstr(outbuf,strlen(outbuf)+1);        /* Print the NUL */
  2410.         else
  2411.             prtstr(outbuf,strlen(outbuf));
  2412.     }
  2413.  
  2414.     if ( turnoffprinter )
  2415.         printeroff();
  2416. }
  2417.  
  2418. /* ----------------------------------------------------------------- */
  2419. /* PrtScreen - Copy lines on screen to printer.                      */
  2420. /* parameters = Top line to print, bottom line to print, 1-based.    */
  2421. /* ----------------------------------------------------------------- */
  2422. void
  2423. prtscreen(BYTE vmode, int top, int bot) {
  2424.     int    i, j, first, last, ch;
  2425.     USHORT n;
  2426.     viocell cells[MAXTERMCOL];
  2427.     char    outbuf[MAXTERMCOL + 1];
  2428.     int     turnoffprinter = FALSE ;
  2429.  
  2430.     if (top < 1 || bot > VscrnGetHeight(vmode)-(tt_status[vmode]?1:0))         /* Args out of bounds? */
  2431.       return;
  2432.  
  2433.     if (printon == FALSE)                       /* Printer already on? */
  2434.     {
  2435.         printeron() ;               /* Turn on printer */
  2436.         turnoffprinter = TRUE ;     /* Remember to turn it off */
  2437.     }
  2438.  
  2439.     if (printon) {                              /* If printer on */
  2440.         n = VscrnGetWidth(vmode) * sizeof(viocell);     /* Line width, incl attributes */
  2441.         for (i = top-1; i < bot; i++) {  /* For each screen line, i... */
  2442.             /* Internally, screen lines are 0-based, so "i-1". */
  2443.  
  2444.             if (scrollflag[vmode]&& tt_roll[vmode])
  2445.               memcpy(cells,VscrnGetCells(vmode,VscrnGetScrollTop(vmode)
  2446.                                           -VscrnGetTop(vmode)+i),n) ;
  2447.             else
  2448.               memcpy(cells,VscrnGetCells(vmode,i),n);
  2449.  
  2450.             for (j = 0; j < VscrnGetWidth(vmode); j++) { /* Strip away the attribute bytes */
  2451.                 if ( isunicode() )
  2452.                 {
  2453.                     ch = (xl_tx[prncs])(cells[j].c);
  2454.                 }
  2455.                 else {
  2456. #ifndef COMMENT
  2457.                     ch = (xl_tx[prncs])((xl_u[tcsl])(cells[j].c & 0xFF));
  2458. #else /* COMMENT */
  2459.                     ch =(cells[j].c & 0xFF);
  2460. #endif /* COMMENT */
  2461.                 }
  2462.                 outbuf[j] = (ch >= 0 ? ch : '?');
  2463.             }
  2464.  
  2465.             for (j = VscrnGetWidth(vmode) - 1; j >= 0; j--) /* Strip trailing blanks */
  2466.               if (outbuf[j] != SP)
  2467.                 break;
  2468.             outbuf[j+1] = '\r';
  2469.             outbuf[j+2] = '\n';
  2470.             outbuf[j+3] = NUL;          /* Terminate string with NUL */
  2471.             if ( ISTVI(tt_type_mode) || ISWYSE(tt_type_mode) )
  2472.                 prtstr(outbuf,strlen(outbuf)+1);        /* Print the NUL */
  2473.             else
  2474.                 prtstr(outbuf,strlen(outbuf));
  2475.         }
  2476.  
  2477.         if ( xprintff )
  2478.             prtchar(FF);
  2479.  
  2480.         if ( turnoffprinter )
  2481.             printeroff();
  2482.     }
  2483. }
  2484.  
  2485. /* ------------------------------------------------------------------ */
  2486. /* End of Printer functions                                           */
  2487. /* ------------------------------------------------------------------ */
  2488.  
  2489. /*
  2490.    C H K A E S  --  Check ANSI Escape Sequence state.
  2491.    Previously used for both input and output, now (edit 190) used only
  2492.    for output of keystrokes.  Input is handled in cwrite().
  2493. */
  2494. int
  2495. chkaes(int esc, char c) {
  2496.     if (c == CAN || c == SUB)           /* CAN and SUB cancel any sequence */
  2497.       esc = ES_NORMAL;
  2498.     else                                /* Otherwise */
  2499.       switch (esc) {                    /* enter state switcher */
  2500.  
  2501.         case ES_NORMAL:                 /* NORMAL state */
  2502.           if (c == ESC)                 /* Got an ESC */
  2503.             esc = ES_GOTESC;            /* Change state to GOTESC */
  2504.           break;                        /* Otherwise stay in NORMAL state */
  2505.  
  2506.         case ES_GOTESC:                 /* GOTESC state */
  2507.           if (c == '[')                 /* Left bracket after ESC is CSI */
  2508.             esc = ES_GOTCSI;            /* Change to GOTCSI state */
  2509.           else if (c == 'P' || (c > 0134 && c < 0140)) /* P, ], ^, or _ */
  2510.             esc = ES_STRING;            /* Switch to STRING-absorption state */
  2511.           else if (c > 057 && c < 0177) /* Final character '0' thru '~' */
  2512.             esc = ES_NORMAL;            /* Back to normal */
  2513.           else if (c != ESC)            /* ESC in an escape sequence... */
  2514.             esc = ES_ESCSEQ;            /* starts a new escape sequence */
  2515.           break;                        /* Intermediate or ignored ctrl char */
  2516.  
  2517.         case ES_ESCSEQ:                 /* ESCSEQ -- in an escape sequence */
  2518.           if (c > 057 && c < 0177)      /* Final character '0' thru '~' */
  2519.             esc = ES_NORMAL;            /* Return to NORMAL state. */
  2520.           else if (c == ESC)            /* ESC ... */
  2521.             esc = ES_GOTESC;            /* starts a new escape sequence */
  2522.           break;                        /* Intermediate or ignored ctrl char */
  2523.  
  2524.         case ES_GOTCSI:                 /* GOTCSI -- In a control sequence */
  2525.           if (c > 077 && c < 0177)      /* Final character '@' thru '~' */
  2526.             esc = ES_NORMAL;            /* Return to NORMAL. */
  2527.           else if (c == ESC)            /* ESC ... */
  2528.             esc = ES_GOTESC;            /* starts over. */
  2529.           break;                        /* Intermediate or ignored ctrl char */
  2530.  
  2531.         case ES_STRING:                 /* Inside a string */
  2532.           if (c == ESC)                 /* ESC may be 1st char of terminator */
  2533.             esc = ES_TERMIN;            /* Go see. */
  2534.           break;                        /* Absorb all other characters. */
  2535.  
  2536.         case ES_TERMIN:                 /* May have a string terminator */
  2537.           if (c == '\\')                /* which must be backslash */
  2538.             esc = ES_NORMAL;            /* If so, back to NORMAL */
  2539.           else                          /* Otherwise */
  2540.             esc = ES_STRING;            /* Back to string absorption. */
  2541.       }
  2542.     return(esc);
  2543. }
  2544.  
  2545. char * 
  2546. protoString(void)
  2547. {
  2548.     static char buf[24];
  2549.  
  2550.     if ( viewonly )
  2551.        ckstrncpy( buf, "VIEW ONLY",sizeof(buf)) ;    
  2552.     else if ( ttyfd == -1
  2553. #ifdef CK_TAPI
  2554.          || (tttapi && ttyfd == -2) 
  2555. #endif /* CK_TAPI */
  2556.          ) {
  2557.         ckstrncpy(buf,"Not Connected",sizeof(buf));
  2558.     } else if ( !network )
  2559.         sprintf(buf, "Serial %ld", speed);         /* safe */
  2560.     else
  2561.         switch ( nettype ) {
  2562. #ifdef SUPERLAT
  2563.         case NET_SLAT:
  2564.             ckstrncpy(buf, "SuperLAT",sizeof(buf) ) ;
  2565.             break;
  2566. #endif /* SUPERLAT */
  2567.  
  2568. #ifdef DECNET
  2569.         case NET_DEC:
  2570.             switch ( ttnproto ) {
  2571.             case NP_LAT:
  2572.                 ckstrncpy(buf, "DECnet LAT",sizeof(buf));
  2573.                 break;
  2574.             case NP_CTERM:
  2575.                 ckstrncpy(buf, "DECnet CTERM",sizeof(buf));
  2576.                 break;
  2577.             default:
  2578.                 ckstrncpy(buf, "DECnet",sizeof(buf));
  2579.                 break;
  2580.             }
  2581.             break;
  2582. #endif /* DECNET */
  2583.  
  2584. #ifdef SSHBUILTIN
  2585.         case NET_SSH:
  2586.             ckstrncpy(buf, (char *)ssh_proto_ver(),sizeof(buf));
  2587.             break;
  2588. #endif /* SSHBUILTIN */
  2589.  
  2590.         case NET_TCPB:
  2591.             switch ( ttnproto ) {
  2592.             case NP_TELNET:
  2593.                 ckstrncpy(buf, "TELNET",sizeof(buf));
  2594. #ifdef CK_AUTHENTICATION
  2595.                 {
  2596.                     int ck_tn_authenticated(void);
  2597.                     if ( sstelnet ? TELOPT_U(TELOPT_AUTHENTICATION) :
  2598.                          TELOPT_ME(TELOPT_AUTHENTICATION) ) {
  2599.                         switch ( ck_tn_authenticated() ) {
  2600.                         case AUTHTYPE_KERBEROS_V4:
  2601.                             ckstrncat(buf,":K4",sizeof(buf));
  2602.                             break;
  2603.                         case AUTHTYPE_KERBEROS_V5:
  2604.                             ckstrncat(buf,":K5",sizeof(buf));
  2605.                             break;
  2606.                         case AUTHTYPE_SRP:
  2607.                             ckstrncat(buf,":SRP",sizeof(buf));
  2608.                             break;
  2609.                         case AUTHTYPE_NTLM:
  2610.                             ckstrncat(buf,":NTLM",sizeof(buf));
  2611.                             break;
  2612. #ifdef COMMENT
  2613.                         case AUTHTYPE_SSL:
  2614.                             /* Not really authentication */
  2615.                             ckstrncat(buf,":SSL",sizeof(buf));
  2616.                             break;
  2617. #endif /* COMMENT */
  2618.                         }
  2619.                     }
  2620.                 }
  2621. #endif /* CK_AUTHENTICATION */
  2622. #ifdef CK_ENCRYPTION
  2623.                 {
  2624.                     int ck_tn_encrypting(void);
  2625.                     int ck_tn_decrypting(void);
  2626. #ifdef CK_SSL
  2627.                     extern int tls_active_flag, ssl_active_flag;
  2628. #endif /* CK_SSL */
  2629.  
  2630.                     if ( TELOPT_ME(TELOPT_ENCRYPTION) ||
  2631.                          TELOPT_U(TELOPT_ENCRYPTION) ) {
  2632.                         switch ( (ck_tn_encrypting()?1:0) |
  2633.                                  (ck_tn_decrypting()?2:0))
  2634.                         {
  2635.                         case 0:
  2636.                             ckstrncat(buf,":pp",sizeof(buf));
  2637.                             break;
  2638.                         case 1:
  2639.                             ckstrncat(buf,":Ep",sizeof(buf));
  2640.                             break;
  2641.                         case 2:
  2642.                             ckstrncat(buf,":pD",sizeof(buf));
  2643.                             break;
  2644.                         case 3:
  2645.                             ckstrncat(buf,":ED",sizeof(buf));
  2646.                             break;
  2647.                         }
  2648.                     }
  2649. #ifdef CK_SSL
  2650.                     else if (tls_active_flag) {
  2651.                         ckstrncat(buf,":TLS",sizeof(buf));
  2652.                     } else if (ssl_active_flag) {
  2653.                         ckstrncat(buf,":SSL",sizeof(buf));
  2654.                     }
  2655. #endif /* CK_SSL */
  2656.                 }
  2657. #endif /* CK_ENCRYPTION */
  2658.                 break;
  2659.             case NP_RLOGIN:
  2660.                 ckstrncpy(buf, "LOGIN",sizeof(buf));
  2661.                 break;
  2662.             case NP_K4LOGIN:
  2663.                 ckstrncpy(buf, "K4LOGIN",sizeof(buf));
  2664.                 break;
  2665.             case NP_EK4LOGIN:
  2666.                 ckstrncpy(buf, "EK4LOGIN",sizeof(buf));
  2667.                 break;
  2668.             case NP_K5LOGIN:
  2669.                 ckstrncpy(buf, "K5LOGIN",sizeof(buf));
  2670.                 break;
  2671.             case NP_EK5LOGIN:
  2672.                 ckstrncpy(buf, "EK5LOGIN",sizeof(buf));
  2673.                 break;
  2674.             case NP_KERMIT:
  2675.                 ckstrncpy(buf, "KERMIT",sizeof(buf));
  2676.                 break;
  2677.             case NP_SSL:
  2678.         case NP_SSL_RAW:
  2679.                 ckstrncpy(buf, "SSL",sizeof(buf));
  2680.                 break;
  2681.             case NP_TLS:
  2682.         case NP_TLS_RAW:
  2683.                 ckstrncpy(buf, "TLS",sizeof(buf));
  2684.                 break;
  2685.             case NP_K5U2U:
  2686.                 ckstrncpy(buf, "K5U2U",sizeof(buf));
  2687.                 break;
  2688.             case NP_TCPRAW:
  2689.             default:
  2690.                 ckstrncpy(buf, "TCP/IP",sizeof(buf));
  2691.                 break;
  2692.             }
  2693.             break;
  2694.         case NET_PIPE:
  2695.             ckstrncpy(buf, "Named Pipe",sizeof(buf));
  2696.             break;
  2697.         case NET_BIOS:
  2698.             ckstrncpy(buf, "NetBIOS",sizeof(buf));
  2699.             break;
  2700.         case NET_FILE:
  2701.             ckstrncpy(buf, "FILE",sizeof(buf));
  2702.             break;
  2703.         case NET_CMD:
  2704.             ckstrncpy(buf, "COMMAND",sizeof(buf));
  2705.             break;
  2706.         case NET_DLL:
  2707.             ckstrncpy(buf, "DLL",sizeof(buf));
  2708.             break;
  2709.         default:
  2710.             ckstrncpy(buf, "(unknown)",sizeof(buf));
  2711.         }
  2712.     return(buf);
  2713. }
  2714.  
  2715. /* ------------------------------------------------------------------ */
  2716. /* ipadl25 - Make normal CONNECT-mode status line                     */
  2717. /* ------------------------------------------------------------------ */
  2718. void
  2719. ipadl25() {
  2720.     int i;
  2721.  
  2722.     vikinit() ;                         /* Update VIK Table */
  2723.  
  2724.     if ( IS97801(tt_type_mode) ) {
  2725.         if ( sni_chcode )
  2726.             ckstrncpy(usertext, "CH.CODE",(MAXTERMCOL) + 1);
  2727.         else
  2728.             ckstrncpy(usertext, "ch.code",(MAXTERMCOL) + 1);
  2729.         if ( sni_bitmode == 8 )
  2730.             ckstrncat(usertext,"-8",(MAXTERMCOL) + 1);
  2731.         else
  2732.             ckstrncat(usertext,"-7",(MAXTERMCOL) + 1);
  2733.     } else {
  2734. #ifdef DECLED
  2735.         ckstrncpy(usertext," ",(MAXTERMCOL) + 1);
  2736.         for ( i=0; i<4 ; i++)
  2737.             ckstrncat( usertext, decled[i] ? "\x0F " : "\x07 ",
  2738.                        (MAXTERMCOL) + 1) ;
  2739. #else /* DECLED */
  2740.         strncpy(usertext," K-95 ",(MAXTERMCOL) + 1);
  2741. #endif /* DECLED */
  2742.     }
  2743. #ifdef PCTERM
  2744.     if ( tt_pcterm ) {
  2745.         ckstrncat(usertext,"PCTERM",(MAXTERMCOL) + 1);
  2746.     } else
  2747. #endif /* PCTERM */
  2748.     if (debses) {
  2749.         ckstrncat(usertext,"DEBUG",(MAXTERMCOL) + 1);
  2750.     } else if (tt_type_mode > -1 && tt_type_mode <= max_tt) {
  2751.         ckstrncat(usertext,tt_info[tt_type_mode].x_name,(MAXTERMCOL) + 1);
  2752.  
  2753.         switch ( tt_kb_mode ) {
  2754.         case KBM_HE:
  2755.             ckstrncat(usertext,"-H",(MAXTERMCOL) + 1);
  2756.             break;
  2757.         case KBM_RU:
  2758.             ckstrncat(usertext,"-R",(MAXTERMCOL) + 1);
  2759.             break;
  2760.         case KBM_EM:
  2761.             ckstrncat(usertext,"-E",(MAXTERMCOL) + 1);
  2762.             break;
  2763.         case KBM_WP:
  2764.             ckstrncat(usertext,"-W",(MAXTERMCOL) + 1);
  2765.             break;
  2766.         }
  2767.     }
  2768.  
  2769.     if ( viewonly )
  2770.        ckstrncpy( filetext, "VIEW ONLY",sizeof(filetext)) ;
  2771.     else if (printon) {
  2772.         if ( is_xprint() )
  2773.             ckstrncpy( filetext, "CTRL PRINT" ,sizeof(filetext)) ;
  2774.         else if ( is_cprint() )
  2775.             ckstrncpy( filetext, "COPY PRINT",sizeof(filetext) ) ;
  2776.         else if ( is_aprint() )
  2777.             ckstrncpy( filetext, "AUTO PRINT",sizeof(filetext) ) ;
  2778.         else if ( is_uprint() )
  2779.             ckstrncpy( filetext, "USER PRINT",sizeof(filetext) ) ;
  2780.         else
  2781.             ckstrncpy(filetext,"PRINTER ON",sizeof(filetext));
  2782.     } else 
  2783.         ckstrncpy( filetext, protoString(), sizeof(filetext));
  2784.  
  2785. #ifdef PCTERM
  2786.     if ( tt_pcterm ) {
  2787.         strcpy(helptext,"Ctrl-CAPSLOCK to deactivate");        /* safe */
  2788.     } else
  2789. #endif /* PCTERM */
  2790.     if (ISVTNT(tt_type_mode) && ttnum != -1)
  2791.         strcpy(helptext, "No Help" ) ;
  2792. #ifndef NOKVERBS
  2793.     else if (vik.help > 255 && keyname(vik.help))
  2794.       ckmakmsg(helptext, sizeof(helptext), "Help: ", keyname(vik.help),
  2795.                 NULL,NULL);
  2796. #endif /* NOKVERBS */
  2797.     else if ( tt_escape )
  2798.       sprintf(helptext, "Help: ^%c?", ctl(escape));     /* safe */
  2799.     else
  2800.         strcpy(helptext, "No Help" ) ;
  2801.  
  2802. #ifdef PCTERM
  2803.     if ( tt_pcterm ) {
  2804.         exittext[0] = '\0';
  2805.     } else
  2806. #endif /* PCTERM */
  2807.     if (ISVTNT(tt_type_mode) && ttnum != -1)
  2808.         strcpy(exittext, "No Exit" ) ;
  2809. #ifndef NOKVERBS
  2810.     else if (vik.exit > 255 && keyname(vik.exit))
  2811.         ckmakmsg(exittext, sizeof(exittext), esc_msg, " ", keyname(vik.exit), NULL);
  2812. #endif /* NOKVERBS */
  2813.     else if ( tt_escape )
  2814.         sprintf(exittext, "%s ^%c?", esc_msg, ctl(escape));     /* safe */
  2815. #ifndef NOKVERBS
  2816.     else if ( vik.quit > 255 && keyname(vik.quit) )
  2817.         ckmakmsg( exittext, sizeof(exittext), "Quit: ", keyname(vik.quit),
  2818.                   NULL, NULL);
  2819. #endif /* NOKVERBS */
  2820.     else
  2821.         strcpy( exittext, "No Exit" ) ;
  2822.  
  2823.    if ( viewonly )
  2824.       hostname[0] = '\0' ;
  2825.    else
  2826.    {
  2827.       if (!network) {
  2828. #ifndef NODIAL
  2829.          if ( d_name )
  2830.             strncpy(hostname, d_name, 40);
  2831.          else
  2832. #endif /* NODIAL */
  2833.             strncpy(hostname, ttname, 40);
  2834. #ifdef NT
  2835.          _strupr(hostname);
  2836. #else /* NT */
  2837.          strupr(hostname);
  2838. #endif /* NT */
  2839.       }
  2840.       else {
  2841.          strncpy(hostname, ttname, 40);
  2842. #ifdef CK_NETBIOS
  2843.          if ( ( nettype == NET_BIOS ) && ( *ttname == '*' ) )
  2844.             strncpy(hostname+1, NetBiosRemote, NETBIOS_NAME_LEN ) ;
  2845. #endif /* CK_NETBIOS */
  2846.       }
  2847.    }
  2848.     VscrnIsDirty(VTERM);  /* status line needs to be updated */
  2849. }
  2850.  
  2851. /*
  2852.    sendchar() simply sends a byte to the host.  No translation,
  2853.    no local echo buffer, no half-duplex mode.
  2854. */
  2855. int
  2856. sendchar(unsigned char c) {
  2857. /*
  2858.    NOTE: ttoci() uses an ioctl() that has been observed to hang, inexplicably,
  2859.    on some systems (e.g. high-end PS/2s that haven't been rebooted in a month,
  2860.    and have been going back and forth between SLIP and Kermit.)  In fact,
  2861.    this was reported only once, and rebooting the system made the problem go
  2862.    away.
  2863.  
  2864.    A NEWER NOTE: As of 8 May 94, ttoci() uses DosWrite, but first does an
  2865.    ioctl() to make sure the connection is OK.  Hopefully, this combines the
  2866.    the benefits of both methods: failure detection, buffering, flow control.
  2867. */
  2868.     int x, i = 0;
  2869.     long wait = 0;
  2870.     con_event evt ;
  2871.  
  2872.  
  2873. /*
  2874.   Send a character to the serial line in immediate mode, checking to avoid
  2875.   overwriting a character already waiting to be sent.  If we fail, e.g. because
  2876.   FLOW is RTS/CTS and CTS is not on (like when modems are retraining), enter
  2877.   a retry loop up to the timeout limit.
  2878. */
  2879.     x = ttoci(dopar(c));                /* Try to send the character */
  2880.     if (x > 0 ||                        /* Transmission error */
  2881.          x == -1) {                     /* Connection failed  */
  2882.         KEY k;
  2883.         int w, oldw;
  2884.  
  2885.         debug(F101,"sendchar blocked char","",c);
  2886.         oldw = 0;                       /* For updating status line once/sec */
  2887.         save_status_line();             /* Save current status line */
  2888.         escapestatus[VTERM] = TRUE ;
  2889.         do {
  2890.             w = (waittime - wait) / 1000L;
  2891.             if (w != oldw) {            /* Countdown timer in status line */
  2892.                 oldw = w;
  2893.                 sprintf(usertext, " TRANSMISSION BLOCKED: %d",w);       /* safe */
  2894.                 helptext[0] = '\0';
  2895.                 VscrnIsDirty(VTERM);  /* status line needs to be updated */
  2896.             }
  2897.             if (evtinbuf(VTERM) > 0) {          /* Is an event waiting? */
  2898.                 evt = congev(VTERM,0);          /* Read it */
  2899.                 switch (evt.type) {
  2900.                 case key:
  2901.                     k = evt.key.scancode ;
  2902.                     break;
  2903. #ifndef NOKVERBS
  2904.                 case kverb:
  2905.                     k = evt.kverb.id | F_KVERB ;
  2906.                     break;
  2907. #endif /* NOKVERBS */
  2908.                 case macro:
  2909.                     if ( evt.macro.string )
  2910.                         free( evt.macro.string ) ;
  2911.                     k = -1;
  2912.                     break;
  2913.                 case literal:
  2914.                     if ( evt.literal.string )
  2915.                         free( evt.literal.string ) ;
  2916.                     k = -1;
  2917.                     break;
  2918.                 case csi:
  2919.                 case esc:
  2920.                 default:
  2921.                     k = -1 ;
  2922.                 }
  2923.                 debug(F101,"BLOCKED key","",k);
  2924. #ifndef NOKVERBS
  2925.                 if (k == K_EXIT | F_KVERB) { /* Let them escape back... */
  2926.                     SetConnectMode(FALSE,CSX_ESCAPE);      /* this way */
  2927.                     return 0;
  2928.                 } else if (k == (F_KVERB | K_QUIT)) {
  2929.                     hangnow = 1;
  2930.                     quitnow = 1;
  2931.                     strcpy(termessage, "Hangup and quit.\n");
  2932.                     SetConnectMode(FALSE,CSX_USERDISC);
  2933.                     return 0;
  2934.                 } else
  2935. #endif /* NOKVERBS */
  2936.                     if ( tt_escape && k == escape) { /* or this way */
  2937.                     evt = congev(VTERM,0);              /* Read it */
  2938.                     switch (evt.type) {
  2939.                     case key:
  2940.                         k = evt.key.scancode ;
  2941.                         break;
  2942. #ifndef NOKVERBS
  2943.                     case kverb:
  2944.                         k = evt.kverb.id | F_KVERB;
  2945.                         break;
  2946. #endif /* NOKVERBS */
  2947.                     case macro:
  2948.                         if ( evt.macro.string )
  2949.                             free( evt.macro.string ) ;
  2950.                         k = -1;
  2951.                         break;
  2952.                     case literal:
  2953.                         if ( evt.literal.string )
  2954.                             free( evt.literal.string ) ;
  2955.                         k = -1;
  2956.                         break;
  2957.                     case csi:
  2958.                     case esc:
  2959.                     default:
  2960.                         k = -1 ;
  2961.                     }
  2962.                     if ((k == 'c') || (k == 'C') || (k == 3)) {
  2963.                         SetConnectMode(FALSE,CSX_ESCAPE);
  2964.                         return 0;
  2965.                     } else bleep(BP_WARN);
  2966.                 } else bleep(BP_WARN);          /* Anything else, just beep. */
  2967.             }
  2968.             msleep(INTERVAL);           /* Sleep a bit */
  2969.             wait += INTERVAL;           /* Go round till limit exhausted */
  2970.             x = ttoci(dopar(c));        /* Try to send again */
  2971.         } while ((x > 0 || x == -1) && (wait < waittime)
  2972.             && (ttyfd != -1 && ttyfd != -2));
  2973.         restore_status_line();
  2974.         escapestatus[VTERM] = FALSE ;
  2975.     }
  2976.     if (x < 0 || wait >= waittime) {            /* Go back to prompt if we failed */
  2977.         while (evtinbuf(VTERM) > 0)
  2978.         {
  2979.             evt = congev(VTERM,0);      /* Flush any remaining typeahead */
  2980.             if ( evt.type == macro )
  2981.             {
  2982.                 if ( evt.macro.string )
  2983.                     free( evt.macro.string ) ;
  2984.             }
  2985.             else if ( evt.type == literal ) {
  2986.                 if ( evt.literal.string )
  2987.                     free( evt.literal.string );
  2988.             }
  2989.         }
  2990.         SetConnectMode(FALSE,CSX_IOERROR);
  2991.         if (network)
  2992.             sprintf(termessage,
  2993.                      "Can't transmit to network, error status: %d\n", x);       /* safe */
  2994.         else {
  2995.             ckmakxmsg(termessage, sizeof(termessage),
  2996.                       "Serial port blocked",
  2997.                      ( x & 0x01 /* TX_WAITING_FOR_CTS */ )
  2998.                      ? "\nTx waiting for CTS to be turned ON" : "",
  2999.                      ( x & 0x02 /* TX_WAITING_FOR_DSR  */ )
  3000.                      ? "\nTx waiting for DSR to be turned ON" : "",
  3001.                      ( x & 0x04 /* TX_WAITING_FOR_DCD */ )
  3002.                      ? "\nTx waiting for DCD to be turned ON" : "",
  3003.                      ( x & 0x08 /* TX_WAITING_FOR_XON */ )
  3004.                      ? "\nTx waiting because XOFF received" : "",
  3005.                      ( x & 0x10 /* TX_WAITING_TO_SEND_XON */ )
  3006.                      ? "\nTx waiting because XOFF transmitted" : "",
  3007.                      ( x & 0x20 /* TX_WAITING_WHILE_BREAK_ON */ )
  3008.                      ? "\nTx because BREAK is being transmitted" : "",
  3009.                      ( x & 0x40 /* TX_WAITING_TO_SEND_IMM */ )
  3010.                      ? "\nCharacter waiting to transmit immediately" : "",
  3011.                      ( x & 0x80 /* RX_WAITING_FOR_DSR */ )
  3012.                      ? "\nRx waiting for DSR to be turned ON" : "",
  3013.                        "\n", NULL, NULL );
  3014.         }
  3015.     }
  3016.     return 0;
  3017. }
  3018.  
  3019. void
  3020. sendcharduplex(unsigned char key, int no_xlate ) {
  3021.     unsigned char csave;
  3022.     unsigned short xkey, xkey7;
  3023.     CHAR * bytes = NULL;
  3024.     int count = 1,i=0;
  3025.  
  3026.     key &= cmdmsk;                      /* Do any requested masking */
  3027.     csave = key;
  3028.  
  3029.     /* HACK ALERT */
  3030.     /* The following reference to tt_kb_mode is done to try to allow */
  3031.     /* the russian and hebrew modes to work within the current       */
  3032.     /* architecture of K95.  The translation tables for Russian and  */
  3033.     /* Hebrew modes are hard coded values belonging to CP866 and     */
  3034.     /* CP862.  If they are translated, they will be destroyed.       */
  3035.     /* We also only make the change here since at the present time   */
  3036.     /* the translations are only single characters, and not strings. */
  3037.  
  3038.     debug(F111,"sendcharduplex","no_xlate",no_xlate);
  3039.  
  3040.     if ( !no_xlate &&                   /* Translating this string, and */
  3041.          os2_outesc == ES_NORMAL )      /* If not inside escape seq.. */
  3042.     {                                   /* Translate character sets */
  3043.         count = ltorxlat(key, &bytes);
  3044.         if ( count <= 0 ) {
  3045.             debug(F111,"sendcharduplex ltorxlat()","key",key);
  3046.             debug(F111,"sendcharduplex ltorxlat()","count",count);
  3047.             return;
  3048.         }
  3049.         key = bytes[0];
  3050.     }
  3051.     os2_outesc = chkaes( os2_outesc, key ) ;
  3052.  
  3053.     for (i=0 ;i<count;i++ ) {
  3054.         if ( i>0 ) {
  3055.             key = bytes[i];
  3056.         }
  3057.  
  3058.         if (sosi
  3059. #ifdef NETCONN
  3060. #ifdef TCPSOCKET
  3061.              || network && (IS_TELNET() && !TELOPT_ME(TELOPT_BINARY))
  3062. #endif /* TCPSOCKET */
  3063. #endif /* NETCONN */
  3064.              ) {
  3065.             /* Shift-In/Out selected? or not a BINARY Telnet session */
  3066.             if (cmask == 0177 || pmask == 0177) { /* In 7-bit environment? */
  3067.                 if (key & 0200) {           /* 8-bit character? */
  3068.                     if (outshift == 0) {    /* If not shifted, */
  3069.                         sendchar(SO);       /* shift. */
  3070.                         outshift = 1;
  3071.                     }
  3072.                 } else {
  3073.                     if (outshift == 1) {    /* 7-bit character */
  3074.                         sendchar(SI);       /* If shifted, */
  3075.                         outshift = 0;       /* unshift. */
  3076.                     }
  3077.                 }
  3078.             }
  3079.         }
  3080.  
  3081.         key = key & cmask & pmask; /* Apply Kermit-to-host mask now. */
  3082.         if (key == CR) {            /* Handle TERMINAL NEWLINE */
  3083.             int stuff = -1, stuff2 = -1;
  3084.             if (tnlm) {                     /* TERMINAL NEWLINE ON */
  3085.                 stuff = LF;                 /* Stuff LF */
  3086.             }
  3087. #ifdef NETCONN
  3088. #ifdef TCPSOCKET
  3089.     /* TELNET NEWLINE MODE */
  3090.             if (network)
  3091.             {
  3092.                 if (IS_TELNET())
  3093.                 {
  3094.                     switch (TELOPT_ME(TELOPT_BINARY) ? tn_b_nlm : tn_nlm) { /* NVT or BINARY */
  3095.                     case TNL_CR:
  3096.                         break;
  3097.                     case TNL_CRNUL:
  3098.                         stuff2 = stuff ;
  3099.                         stuff  = NUL ;
  3100.                         break;
  3101.                     case TNL_CRLF:
  3102.                         stuff2 = stuff ;
  3103.                         stuff = LF ;
  3104.                         break;
  3105.                     }
  3106.                 }
  3107. #ifdef RLOGCODE
  3108.                 else if (IS_RLOGIN())
  3109.                 {
  3110.                     switch (tn_b_nlm) { /* always BINARY */
  3111.                     case TNL_CR:
  3112.                         break;
  3113.                     case TNL_CRNUL:
  3114.                         stuff2 = stuff ;
  3115.                         stuff  = NUL ;
  3116.                         break;
  3117.                     case TNL_CRLF:
  3118.                         stuff2 = stuff ;
  3119.                         stuff = LF ;
  3120.                         break;
  3121.                     }
  3122.                 }
  3123. #endif /* RLOGCODE */
  3124. #ifdef SSHBUILTIN
  3125.                 else if (IS_SSH())
  3126.                 {
  3127.                     switch (tn_b_nlm) { /* always BINARY */
  3128.                     case TNL_CR:
  3129.                         break;
  3130.                     case TNL_CRNUL:
  3131.                         stuff2 = stuff ;
  3132.                         stuff  = NUL ;
  3133.                         break;
  3134.                     case TNL_CRLF:
  3135.                         stuff2 = stuff ;
  3136.                         stuff = LF ;
  3137.                         break;
  3138.                     }
  3139.                 }
  3140. #endif /* SSHBUILTIN */
  3141.             }
  3142. #endif /* TCPSOCKET */
  3143. #endif /* NETCONN */
  3144.  
  3145.             if (stuff > -1) {
  3146.                 if ( network ) {                /* on a network we want to send  */
  3147.                     char crlf[3] ; int cnt=2 ;  /* both characters in one packet */
  3148.                     crlf[0] = dopar(key) ;       /* so we use ttol() instead of   */
  3149.                     crlf[1] = dopar(stuff) ;    /* sendchar()                    */
  3150.                     if (stuff2 > -1) {
  3151.                         cnt++ ;
  3152.                         crlf[2] = stuff2 ;
  3153.                     }
  3154.  
  3155.                     if ( wy_block ) {
  3156.                         le_puts(crlf,cnt);
  3157.                     } else {
  3158.                         ttol(crlf,cnt) ;
  3159.                     }
  3160.                     if (duplex && !wy_block) {
  3161.                         le_putchar(key);
  3162.                         le_putchar(stuff);
  3163.                         if (stuff2 > -1)
  3164.                             le_putchar(stuff2);
  3165.                     }
  3166.                     return ;                    /* we are done */
  3167.                 }
  3168.                 else  /* not network */
  3169.                 {
  3170.                     sendchar(dopar(key));   /* Send the CR */
  3171.                     if (duplex) {               /* If local echoing... */
  3172.                         le_putchar(key);    /*   echo to screen */
  3173.                     }
  3174.                     key = stuff;
  3175.                     csave = key;
  3176.                 }
  3177.             }
  3178.             else if (tt_crd && duplex) {    /* CR-DISPLAY CRLF & local echo */
  3179.                 le_putchar(CR);
  3180.                 csave = LF;
  3181.                 key = CR;                   /* ... but only send a CR */
  3182.             }
  3183.         }
  3184. #ifdef TNCODE
  3185.         /* If user types the 0xff character (TELNET IAC), it must be doubled. */
  3186.         else
  3187.             if (dopar(key) == IAC && network && IS_TELNET())
  3188.                 sendchar(IAC); /* and the other one just below. */
  3189. #endif /* TNCODE */
  3190.  
  3191.         sendchar(dopar(key));
  3192.         if (duplex) {
  3193.             le_putchar(csave);
  3194.         }
  3195.     }
  3196. }
  3197.  
  3198. int
  3199. sendchars(unsigned char * s, int len) {
  3200.     int x, i = 0;
  3201.     long wait = 0;
  3202.     con_event evt ;
  3203.  
  3204.     debug(F111,"sendchars","len of s",len);
  3205.  
  3206. /*
  3207.   Send a character to the serial line in immediate mode, checking to avoid
  3208.   overwriting a character already waiting to be sent.  If we fail, e.g. because
  3209.   FLOW is RTS/CTS and CTS is not on (like when modems are retraining), enter
  3210.   a retry loop up to the timeout limit.
  3211. */
  3212.  
  3213.     if (tt_pacing > 0 &&                /* taking care of pacing   */
  3214.          !wy_block) {                   /* if everything goes well */
  3215.         x = len;
  3216.         for ( i=0 ; i<len ; i++ ) {
  3217.             if (ttoc(dopar(s[i])) <= 0)
  3218.             {
  3219.                 x = i;
  3220.                 break;
  3221.             }
  3222.             msleep(tt_pacing);
  3223.         }
  3224.     }
  3225.     else {
  3226.         if ( parity ) {
  3227.             for ( i=0 ; i<len ; i++ )
  3228.                 s[i]=dopar(s[i]);
  3229.         }
  3230.         if ( wy_block ) {
  3231.             le_puts(s,len);
  3232.             x = len;
  3233.         }
  3234.         else
  3235.             x = ttol(s,len);                    /* Try to send the string */
  3236.     }
  3237.     if (x<len) {                                /* Transmission error */
  3238.         KEY k;
  3239.         int w, oldw;
  3240.  
  3241.         debug(F100,"sendchars blocked","",0);
  3242.         oldw = 0;                       /* For updating status line once/sec */
  3243.         save_status_line();             /* Save current status line */
  3244.         escapestatus[VTERM] = TRUE ;
  3245.         do {
  3246.             w = (waittime - wait) / 1000L;
  3247.             if (w != oldw) {            /* Countdown timer in status line */
  3248.                 oldw = w;
  3249.                 sprintf(usertext, " TRANSMISSION BLOCKED: %d",w);       /* safe */
  3250.                 helptext[0] = '\0';
  3251.                 VscrnIsDirty(VTERM);  /* status line needs to be updated */
  3252.             }
  3253.             if (evtinbuf(VTERM) > 0) {          /* Is an event waiting? */
  3254.                 evt = congev(VTERM,0);          /* Read it */
  3255.                 switch (evt.type) {
  3256.                 case key:
  3257.                     k = evt.key.scancode ;
  3258.                     break;
  3259. #ifndef NOKVERBS
  3260.                 case kverb:
  3261.                     k = evt.kverb.id | F_KVERB ;
  3262.                     break;
  3263. #endif /* NOKVERBS */
  3264.                 case macro:
  3265.                     if ( evt.macro.string )
  3266.                         free( evt.macro.string ) ;
  3267.                     k = -1;
  3268.                     break;
  3269.                 case literal:
  3270.                     if ( evt.literal.string )
  3271.                         free( evt.literal.string ) ;
  3272.                     k = -1;
  3273.                     break;
  3274.                 case csi:
  3275.                 case esc:
  3276.                 default:
  3277.                     k = -1 ;
  3278.                 }
  3279.                 debug(F101,"BLOCKED key","",k);
  3280. #ifndef NOKVERBS
  3281.                 if (k == (F_KVERB | K_EXIT)) { /* Let them escape back... */
  3282.                     SetConnectMode(FALSE,CSX_ESCAPE);      /* this way */
  3283.                     return 0;
  3284.                 } else if (k == (F_KVERB | K_QUIT)) {
  3285.                     SetConnectMode(0,CSX_USERDISC);
  3286.                     hangnow = 1;
  3287.                     quitnow = 1;
  3288.                     strcpy(termessage, "Hangup and quit.\n");
  3289.                     return 0;
  3290.                 } else
  3291. #endif /* NOKVERBS */
  3292.                     if (tt_escape && k == escape) { /* or this way */
  3293.                     evt = congev(VTERM,0);              /* Read it */
  3294.                     switch (evt.type) {
  3295.                     case key:
  3296.                         k = evt.key.scancode ;
  3297.                         break;
  3298. #ifndef NOKVERBS
  3299.                     case kverb:
  3300.                         k = evt.kverb.id | F_KVERB;
  3301.                         break;
  3302. #endif /* NOKVERBS */
  3303.                     case macro:
  3304.                         if ( evt.macro.string )
  3305.                             free( evt.macro.string ) ;
  3306.                         k = -1;
  3307.                         break;
  3308.                     case literal:
  3309.                         if ( evt.literal.string )
  3310.                             free( evt.literal.string ) ;
  3311.                         k = -1;
  3312.                         break;
  3313.                     case csi:
  3314.                     case esc:
  3315.                     default:
  3316.                         k = -1 ;
  3317.                     }
  3318.                     if ((k == 'c') || (k == 'C') || (k == 3)) {
  3319.                         SetConnectMode(FALSE,CSX_ESCAPE);
  3320.                         return 0;
  3321.                     }
  3322.                     else
  3323.                         bleep(BP_WARN);
  3324.                 }
  3325.                 else
  3326.                     bleep(BP_WARN);             /* Anything else, just beep. */
  3327.             }
  3328.             msleep(INTERVAL);           /* Sleep a bit */
  3329.             wait += INTERVAL;           /* Go round till limit exhausted */
  3330.             if ( x>0 ) {                /* Something was sent last time */
  3331.                 s+=x ;                  /* So advance the pointer */
  3332.                 len-=x ;                /* And reduce the length */
  3333.             }
  3334.             x = ttol(s,len);    /* Try to send again */
  3335.         } while ((x <= 0) && (wait < waittime));
  3336.         restore_status_line();
  3337.         escapestatus[VTERM] = FALSE ;
  3338.     }
  3339.     if (wait >= waittime) {             /* Go back to prompt if we failed */
  3340.         while (evtinbuf(VTERM) > 0)
  3341.         {
  3342.             evt = congev(VTERM,0);      /* Flush any remaining typeahead */
  3343.             if ( evt.type == macro && evt.macro.string )
  3344.                 free( evt.macro.string ) ;
  3345.             else if ( evt.type == literal && evt.literal.string )
  3346.                 free( evt.literal.string );
  3347.         }
  3348.         SetConnectMode(FALSE,CSX_IOERROR);
  3349.         x = 0 ;      /* ttol() doesn't return error status */
  3350.         if (network)
  3351.             sprintf(termessage,
  3352.                      "Can't transmit to network, error status: %d\n", x);
  3353.         else {
  3354.             ckmakxmsg(termessage, sizeof(termessage),
  3355.                       "Serial port blocked",
  3356.                      ( x & 0x01 /* TX_WAITING_FOR_CTS */ )
  3357.                      ? "\nTx waiting for CTS to be turned ON" : "",
  3358.                      ( x & 0x02 /* TX_WAITING_FOR_DSR  */ )
  3359.                      ? "\nTx waiting for DSR to be turned ON" : "",
  3360.                      ( x & 0x04 /* TX_WAITING_FOR_DCD */ )
  3361.                      ? "\nTx waiting for DCD to be turned ON" : "",
  3362.                      ( x & 0x08 /* TX_WAITING_FOR_XON */ )
  3363.                      ? "\nTx waiting because XOFF received" : "",
  3364.                      ( x & 0x10 /* TX_WAITING_TO_SEND_XON */ )
  3365.                      ? "\nTx waiting because XOFF transmitted" : "",
  3366.                      ( x & 0x20 /* TX_WAITING_WHILE_BREAK_ON */ )
  3367.                      ? "\nTx because BREAK is being transmitted" : "",
  3368.                      ( x & 0x40 /* TX_WAITING_TO_SEND_IMM */ )
  3369.                      ? "\nCharacter waiting to transmit immediately" : "",
  3370.                      ( x & 0x80 /* RX_WAITING_FOR_DSR */ )
  3371.                      ? "\nRx waiting for DSR to be turned ON" : "",
  3372.                        "\n", NULL, NULL );
  3373.         }
  3374.     }
  3375.     return 0;
  3376. }
  3377.  
  3378. void
  3379. sendcharsduplex(unsigned char * s, int len, int no_xlate ) {
  3380.     int i,j,n ;
  3381.     static unsigned char * sendbuf = NULL;
  3382.     static buflen = 0;
  3383.     unsigned char * bufptr, *stuffptr ;
  3384.     CHAR * bytes = NULL;
  3385.     int count = 1;
  3386.  
  3387.     /* count number of CRs that might require stuffing of LFs */
  3388.     for ( i=0,n=0 ;i<len;i++ ) {
  3389.         if ( s[i] == CR ) {
  3390.             n++;
  3391.         }
  3392.     }
  3393.     debug(F111,"sendcharsduplex","len of s",len);
  3394.     debug(F111,"sendcharsduplex","num of CRs",n);
  3395.     debug(F111,"sendcharsduplex","old buflen",buflen);
  3396.     debug(F111,"sendcharsduplex","no_xlate",no_xlate);
  3397.  
  3398.     if ( (tt_utf8 ? 3*len : (len+n+1)) > buflen && sendbuf != NULL ) {
  3399.         free(sendbuf);
  3400.         sendbuf = NULL;
  3401.         buflen = 0;
  3402.     }
  3403.  
  3404.     if ( sendbuf == NULL ) {
  3405.         sendbuf = (unsigned char *)malloc((tt_utf8 ? 3*len : (len+n+1)));
  3406.         if ( sendbuf == NULL )
  3407.             return;
  3408.         buflen = (tt_utf8 ? 3*len : (len+n+1));
  3409.     }
  3410.     debug(F111,"sendcharsduplex","new buflen",buflen);
  3411.  
  3412.    stuffptr = bufptr = sendbuf - 1 ;
  3413.    for ( i = 0 ; i < len ; i++ )
  3414.    {
  3415.        bufptr = ++stuffptr ;
  3416.        *bufptr = s[i] & cmdmsk;         /* Do any requested masking */
  3417.  
  3418.        if ( !no_xlate &&                /* If translating this string, and */
  3419.             os2_outesc == ES_NORMAL) {  /* If not inside escape seq.. */
  3420.            count = ltorxlat(*bufptr, &bytes);
  3421.            if ( count > 0 )
  3422.                *bufptr = bytes[0];
  3423.        }
  3424.  
  3425.        for ( j=0;j<count;j++ ) {
  3426.            if ( j>0 ) {
  3427.                bufptr = ++stuffptr;
  3428.                *bufptr = bytes[++j];
  3429.            }
  3430.            os2_outesc = chkaes( os2_outesc, *bufptr ) ;
  3431.  
  3432.        if (sosi
  3433. #ifdef NETCONN
  3434. #ifdef TCPSOCKET
  3435.             || (network && IS_TELNET() && !TELOPT_ME(TELOPT_BINARY))
  3436. #endif /* TCPSOCKET */
  3437. #endif /* NETCONN */
  3438.             ) {
  3439.         /* Shift-In/Out selected? or not a BINARY Telnet session */
  3440.            if (cmask == 0177 || pmask == 0177) { /* In 7-bit environment? */
  3441.                if (*bufptr & 0200) {            /* 8-bit character? */
  3442.                    if (outshift == 0) { /* If not shifted, */
  3443.                        /* sendchar(SO); /* shift. */
  3444.                        *(++stuffptr) = SO ;
  3445.                        outshift = 1;
  3446.                    }
  3447.                }
  3448.                else {
  3449.                    if (outshift == 1) { /* 7-bit character */
  3450.                        /* sendchar(SI); /* If shifted, */
  3451.                        *(++stuffptr) = SI ;
  3452.                        outshift = 0;    /* unshift. */
  3453.                    }
  3454.                }
  3455.            }
  3456.        }
  3457.  
  3458.        *bufptr = *bufptr & cmask & pmask; /* Apply Kermit-to-host mask now. */
  3459.        if (duplex && !wy_block) {
  3460.            le_putchar(*bufptr) ;
  3461.        }
  3462.        if (*bufptr == CR) {             /* Handle TERMINAL NEWLINE */
  3463.            if (tnlm) {                  /* TERMINAL NEWLINE ON */
  3464.                *(++stuffptr) = LF;                      /* Stuff LF */
  3465.            }
  3466. #ifdef NETCONN
  3467. #ifdef TCPSOCKET
  3468.        /* TELNET NEWLINE MODE */
  3469.            if (network)
  3470.            {
  3471.                if (IS_TELNET())
  3472.                {
  3473.                    switch (TELOPT_ME(TELOPT_BINARY) ? tn_b_nlm : tn_nlm) { /* NVT or BINARY */
  3474.                    case TNL_CR:
  3475.                        break;
  3476.                    case TNL_CRNUL:
  3477.                        *(++stuffptr)  = dopar(NUL) ;
  3478.                        break;
  3479.                    case TNL_CRLF:
  3480.                        *(++stuffptr) = dopar(LF) ;
  3481.                        break;
  3482.                    }
  3483.                }
  3484. #ifdef RLOGCODE
  3485.                else if (IS_RLOGIN())
  3486.                {
  3487.                    switch (tn_b_nlm) { /* always BINARY */
  3488.                    case TNL_CR:
  3489.                        break;
  3490.                    case TNL_CRNUL:
  3491.                        *(++stuffptr)  = dopar(NUL) ;
  3492.                        break;
  3493.                    case TNL_CRLF:
  3494.                        *(++stuffptr) = dopar(LF) ;
  3495.                        break;
  3496.                    }
  3497.                }
  3498. #endif /* RLOGCODE */
  3499. #ifdef SSHBUILTIN
  3500.                else if (IS_SSH())
  3501.                {
  3502.                    switch (tn_b_nlm) { /* always BINARY */
  3503.                    case TNL_CR:
  3504.                        break;
  3505.                    case TNL_CRNUL:
  3506.                        *(++stuffptr)  = dopar(NUL) ;
  3507.                        break;
  3508.                    case TNL_CRLF:
  3509.                        *(++stuffptr) = dopar(LF) ;
  3510.                        break;
  3511.                    }
  3512.                }
  3513. #endif /* SSHBUILTIN */
  3514.            }
  3515. #endif /* TCPSOCKET */
  3516. #endif /* NETCONN */
  3517.  
  3518.            if ( duplex & tt_crd && !wy_block) { /* CR-DISPLAY CRLF & local echo */
  3519.                le_putchar(LF);
  3520.            }
  3521.        } /* CR */
  3522. #ifdef TNCODE
  3523.        else {
  3524.     /* If user types the 0xff character (TELNET IAC), it must be doubled. */
  3525.            if (dopar(*bufptr) == IAC && network && IS_TELNET())
  3526.                *(++stuffptr) = dopar(IAC); /* and the other one just below. */
  3527.        }
  3528. #endif /* TNCODE */
  3529.        *bufptr = dopar(*bufptr) ;
  3530.  
  3531.        } /* for (j) */
  3532.    }    /* for (i) */
  3533.     *(stuffptr+1) = '\0' ; /* add NULL for debug.log */
  3534.     debug(F111,"sendcharsduplex","len of sendbuf",strlen(sendbuf));
  3535.     sendchars( sendbuf, (stuffptr - sendbuf+1) ) ;
  3536. }
  3537.  
  3538.  
  3539. /*  S E N D E S C S E Q  --  Send ESC followed by the given string  */
  3540. /*
  3541.   Used for sending host-requested reports, as well as for sending
  3542.   F-keys, arrow keys, etc.  Translation, shifting, etc, are not issues here.
  3543. */
  3544. int
  3545. sendescseq(CHAR *s) {
  3546.     char c;
  3547.     unsigned char sendstr[24], * p  ;
  3548.  
  3549.     /* Handle 7-bit vs 8-bit escape sequences...*/
  3550.  
  3551.     if (send_c1 && ((*s == '[' || *s == 'O'))) /* 8-bit C1 controls... */
  3552.     {
  3553.        sendstr[0] = (*s++ ^ (CHAR) 0x40) | (CHAR) 0x80;
  3554.     }
  3555.     else                                /* Or 7-bit escape sequences... */
  3556.     {
  3557.         if ( ISDG200(tt_type) )
  3558.             sendstr[0] = XRS ;
  3559.         else
  3560.             sendstr[0] = ESC;
  3561.     }
  3562.     p = sendstr + 1 ;
  3563.  
  3564.     if (duplex && !wy_block) {          /* Half duplex, echo it to the */
  3565.         le_putchar(sendstr[0]);
  3566.     }
  3567.  
  3568.     for ( ; *s ; s++)
  3569.     {
  3570.         *p = *s ;
  3571.         p++ ;
  3572.         if (duplex && !wy_block) {
  3573.             le_putchar(*s);
  3574.         }
  3575.     }
  3576.     *p = '\0' ;   /* tack on a Null for debug.log */
  3577.     sendchars(sendstr,p-sendstr);
  3578.     return(0) ;
  3579. }
  3580.  
  3581.  
  3582.  
  3583. /* ------------------------------------------------------------------ */
  3584. /* IsDoubleWidth -                                                    */
  3585. /* ------------------------------------------------------------------ */
  3586. bool
  3587. isdoublewidth( unsigned short y )     /* based from 1 */
  3588. {
  3589.     return VscrnGetLineVtAttr(VTERM,y-1) & VT_LINE_ATTR_DOUBLE_WIDE ;
  3590. }
  3591.  
  3592. /* ------------------------------------------------------------------ */
  3593. /* CursorNextLine -                                                   */
  3594. /* ------------------------------------------------------------------ */
  3595. void
  3596. cursornextline() {
  3597.     if ( decsasd == SASD_TERMINAL ) {
  3598.         /* Due to a log from dcombeer I am no longer sure that */
  3599.         /* cursornextline() or cursorprevline() is affected by */
  3600.         /* Origin mode                                         */
  3601.  
  3602.         if (marginbot > wherey[VTERM]) {
  3603.             if ( printon && is_aprint() ) {
  3604.                 prtline( wherey[VTERM], LF ) ;
  3605.             }
  3606.             lgotoxy(VTERM,1, wherey[VTERM] + 1);
  3607.         } else if ( wy_autopage ) {
  3608.             if ( printon && is_aprint() ) {
  3609.                 prtline( wherey[VTERM], LF ) ;
  3610.             }
  3611.             lgotoxy(VTERM, 1, margintop);
  3612.         } else if (ISVT100(tt_type_mode) || ISANSI(tt_type_mode)) {
  3613.             wrtch(CR);
  3614.             wrtch(LF);
  3615.         }
  3616.     }
  3617.     else if ( (ISWYSE(tt_type_mode) || ISTVI(tt_type_mode)) && autoscroll
  3618.               && !protect ){
  3619.         wrtch(CR);
  3620.         wrtch(LF);
  3621.     }
  3622.  
  3623.     if ( wrapit )
  3624.         wrapit = FALSE;
  3625. }
  3626.  
  3627. /* ------------------------------------------------------------------ */
  3628. /* CursorPrevLine -                                                   */
  3629. /* ------------------------------------------------------------------ */
  3630. void
  3631. cursorprevline() {
  3632.     if ( printon && is_aprint() ) {
  3633.         prtline( wherey[VTERM], LF ) ;
  3634.     }
  3635.     if ( decsasd == SASD_TERMINAL ) {
  3636.         /* Due to a log from dcombeer I am no longer sure that */
  3637.         /* cursornextline() or cursorprevline() is affected by */
  3638.         /* Origin mode                                         */
  3639.  
  3640.         if (margintop != wherey[VTERM])
  3641.             lgotoxy(VTERM, 1, wherey[VTERM] - 1);
  3642.         else if ( wy_autopage )
  3643.             lgotoxy(VTERM, 1, marginbot);
  3644.     }
  3645.     if ( wrapit )
  3646.         wrapit = FALSE;
  3647. }
  3648.  
  3649. /* ------------------------------------------------------------------ */
  3650. /* CursorUp -                                                         */
  3651. /* ------------------------------------------------------------------ */
  3652. void
  3653. cursorup(int wrap) {
  3654.     if ( printon && is_aprint() ) {
  3655.         prtline( wherey[VTERM], LF ) ;
  3656.     }
  3657.     if ( decsasd == SASD_TERMINAL ) {
  3658.         if ((relcursor ? margintop : 1) != wherey[VTERM])
  3659.             lgotoxy(VTERM, wherex[VTERM], wherey[VTERM] - 1);
  3660.         else if ( wrap ||
  3661.                   ISWYSE(tt_type_mode) ||
  3662.                   ISTVI(tt_type_mode) ||
  3663.                   ISHZL(tt_type_mode) ||
  3664.                   ISDG200(tt_type_mode))
  3665.             lgotoxy(VTERM, wherex[VTERM],
  3666.                      (relcursor ? marginbot :
  3667.                        VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0)));
  3668.     }
  3669.     if ( wrapit )
  3670.         wrapit = FALSE;
  3671. }
  3672.  
  3673. /* ------------------------------------------------------------------ */
  3674. /* CursorDown -                                                       */
  3675. /* ------------------------------------------------------------------ */
  3676. void
  3677. cursordown(int wrap) {
  3678.     if ( decsasd == SASD_TERMINAL ) {
  3679.         if ((relcursor ? marginbot :
  3680.               VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0)) > wherey[VTERM])
  3681.         {
  3682.             if ( printon && is_aprint() ) {
  3683.                 prtline( wherey[VTERM], LF ) ;
  3684.             }
  3685.             lgotoxy(VTERM,wherex[VTERM], wherey[VTERM] + 1);
  3686.         } else if ( wrap ||
  3687.                     ((ISWYSE(tt_type_mode) ||
  3688.                      ISTVI(tt_type_mode) ||
  3689.                      ISHZL(tt_type_mode) ||
  3690.                      ISDG200(tt_type_mode)) &&
  3691.                     !autoscroll || protect || wy_autopage) )
  3692.         {
  3693.             if ( printon && is_aprint() ) {
  3694.                 prtline( wherey[VTERM], LF ) ;
  3695.             }
  3696.             lgotoxy(VTERM, wherex[VTERM], (relcursor ? margintop : 1));
  3697.         } else if ( (ISWYSE(tt_type_mode) || ISTVI(tt_type_mode)) &&
  3698.                   autoscroll && !protect)
  3699.             wrtch(LF);
  3700.     }
  3701.     if ( wrapit )
  3702.         wrapit = FALSE;
  3703. }
  3704.  
  3705. /* ------------------------------------------------------------------ */
  3706. /* CursorRight -                                                      */
  3707. /* ------------------------------------------------------------------ */
  3708. void
  3709. cursorright(int wrap) {
  3710.     if ( decsasd == SASD_STATUS ) {
  3711.         if (wherex[VSTATUS] < VscrnGetWidth(VTERM))
  3712.            lgotoxy(VSTATUS, wherex[VSTATUS]+1,1);
  3713.     }
  3714.     else {
  3715.         char dwl = isdoublewidth(wherey[VTERM]) ;
  3716.         if (wherex[VTERM] < ( dwl ? VscrnGetWidth(VTERM) / 2 : VscrnGetWidth(VTERM)))
  3717.             lgotoxy( VTERM, wherex[VTERM] + 1, wherey[VTERM]);
  3718.         else if ( wrap ||
  3719.                   ISUNIXCON(tt_type_mode) ||
  3720.                   ISWYSE(tt_type_mode) ||
  3721.                   ISTVI(tt_type_mode) ||
  3722. #ifdef COMMENT
  3723.                   ISHFT(tt_type_mode) ||
  3724. #endif /* COMMENT */
  3725.                   ISDG200(tt_type_mode)) {
  3726.             cursornextline();
  3727.             if ( wrapit ) {
  3728.                 cursorright(0);
  3729.                 wrapit = FALSE ;
  3730.             }
  3731.         }
  3732.     }
  3733.     if ( wrapit )
  3734.         wrapit = FALSE;
  3735. }
  3736.  
  3737. /* ------------------------------------------------------------------ */
  3738. /* CursorLeft -                                                       */
  3739. /* ------------------------------------------------------------------ */
  3740. void
  3741. cursorleft(int wrap) {
  3742.     char dwl = isdoublewidth(wherey[VTERM]) ;
  3743.  
  3744.     if ( decsasd == SASD_STATUS ) {
  3745.         if (wherex[VSTATUS] > 1)
  3746.             lgotoxy( VSTATUS, wherex[VSTATUS] - 1, 1);
  3747.     }
  3748.     else {
  3749.         if (wherex[VTERM] > 1)
  3750.             lgotoxy( VTERM,
  3751.                      wherex[VTERM] - 1,
  3752.                      wherey[VTERM]);
  3753.         else if ( wrap ||
  3754.                   (ISUNIXCON(tt_type_mode) ||
  3755. #ifdef COMMENT
  3756.                     ISHFT(tt_type_mode) ||
  3757. #endif /* COMMENT */
  3758.                     ISWYSE(tt_type_mode) ||
  3759.                     ISTVI(tt_type_mode) ||
  3760.                     ISDG200(tt_type_mode))) {
  3761.             lgotoxy( VTERM,
  3762.                      ( dwl ? VscrnGetWidth(VTERM) / 2 : VscrnGetWidth(VTERM)),
  3763.                      wherey[VTERM] - 1 );
  3764.         }
  3765.     }
  3766.     if ( wrapit )
  3767.         wrapit = FALSE;
  3768. }
  3769.  
  3770. /* ------------------------------------------------------------------ */
  3771. /* ReverseScreen                                                                              */
  3772. /* ------------------------------------------------------------------ */
  3773. void
  3774. reversescreen(BYTE vmode) {
  3775.     int         r, c, width;
  3776.  
  3777. #ifdef ONETERMUPD
  3778.     viocell *   cell=NULL ;
  3779.  
  3780.     for (r = 0; r < VscrnGetHeight(vmode)-(tt_status[VTERM]?1:0); r++) {          /* Loop for each row */
  3781.         width = VscrnGetLineWidth(vmode,r) ;
  3782.         for (c = 0;c < width;c++) { /* Loop for each character in row */
  3783.             cell = VscrnGetCell( vmode, c, r ) ;
  3784.             cell->a = byteswapcolors(cell->a);
  3785.         }
  3786.     }
  3787. #else
  3788.     if ( IsConnectMode() ) {  /* In Terminal Mode */
  3789.         viocell *   cell=NULL ;
  3790.  
  3791.         for (r = 0; r < VscrnGetHeight(vmode)-(tt_status[VTERM]?1:0); r++) {      /* Loop for each row */
  3792.             width = VscrnGetLineWidth(vmode,r) ;
  3793.             for (c = 0;c < width;c++) { /* Loop for each character in row */
  3794.                 cell = VscrnGetCell( vmode, c, r ) ;
  3795.                 cell->a = byteswapcolors(cell->a);
  3796.                 }
  3797.             }
  3798.         }
  3799.     else {
  3800.         int x =0;
  3801.         USHORT          n=0;
  3802.         viocell   cells[MAXSCRNCOL];
  3803.  
  3804.         n = cmd_cols ;
  3805.         for (r = 0; r < cmd_rows; r++) {        /* Loop for each row */
  3806.            ReadCellStr(cells, &n, r, 0);        /* Read this row from the screen */
  3807.            for (c = 0; c < cmd_cols; c++) {     /* Loop for each character in row */
  3808.                 cells[c].a = swapcolors(cells[c].a);
  3809.                 }
  3810.             WrtCellStr(cells, n, r, 0);  /* Write the row back. */
  3811.         }
  3812.     }
  3813. #endif /* ONETERMUPD */
  3814. }
  3815.  
  3816. /* ------------------------------------------------------------------ */
  3817. /* FlipScreen                                                                             */
  3818. /* ------------------------------------------------------------------ */
  3819. void                            /* Flip screen between */
  3820. flipscreen(BYTE vmode) {        /* tell Vscrn code to swap foreground     */
  3821.                                /* and background colors on screen update */
  3822.     if ( vmode == VTERM ) {
  3823.         decscnm = decscnm ? FALSE : TRUE ;
  3824.         defaultattribute =
  3825.             swapcolors(defaultattribute);
  3826.         underlineattribute =
  3827.             swapcolors(underlineattribute);
  3828.         italicattribute = swapcolors(italicattribute);
  3829.         reverseattribute=swapcolors(reverseattribute);
  3830.         graphicattribute=swapcolors(graphicattribute);
  3831.         attribute = swapcolors( attribute );
  3832.     } else if ( vmode == VCMD ) {
  3833.         colorcmd = swapcolors(colorcmd);
  3834.     }
  3835.     reversescreen(vmode);
  3836. }
  3837.  
  3838. int
  3839. savscrbk(mode,name,disp) int mode; char * name; int disp; {
  3840.     char *tp;
  3841.     static struct filinfo xx;
  3842.     int savfil, i, j, k;
  3843.     char buf[1024];
  3844.  
  3845.     zclose(ZMFILE);
  3846.  
  3847.     if (disp) {
  3848.         xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3849.         xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = '\0';
  3850.         xx.lblopts = 0;
  3851.         savfil = zopeno(ZMFILE,name,NULL,&xx);
  3852.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  3853.  
  3854.     if (savfil) {
  3855.         int    i, j, first, last;
  3856.         USHORT n;
  3857.         viocell cells[MAXTERMCOL];
  3858.         char    outbuf[MAXTERMCOL + 1];
  3859.         int     turnoffprinter = FALSE ;
  3860.         ULONG   beg, top, end;
  3861.  
  3862.         beg = VscrnGetBegin(mode);
  3863.         top = VscrnGetTop(mode);
  3864.         end = VscrnGetEnd(mode);
  3865.  
  3866.         n = VscrnGetWidth(mode) * sizeof(viocell);      /* Line width, incl attributes */
  3867.         for (i = beg; i != end; i = (i+1)%VscrnGetBufferSize(mode)) {
  3868.             /* For each scrollback line, i... */
  3869.             memcpy(cells,VscrnGetCells(mode,i-top),n);
  3870.  
  3871.             for (j = 0; j < VscrnGetWidth(mode); j++) { /* Strip away the attribute bytes */
  3872.                 if ( isunicode() )
  3873.                 {
  3874.                     if (GNOW->itol )
  3875.                         outbuf[j] = (*GNOW->itol)(cells[j].c);
  3876.                 }
  3877.                 else {
  3878.                     outbuf[j] =(cells[j].c & 0xFF);
  3879.                 }
  3880.                 if (outbuf[j] == NUL)           /* Don't allow NULs in the stream */
  3881.                     outbuf[j] = SP;
  3882.             }
  3883.  
  3884.             for (j = VscrnGetWidth(mode) - 1; j >= 0; j--) /* Strip trailing blanks */
  3885.                 if (outbuf[j] != SP)
  3886.                     break;
  3887.             outbuf[j+1] = NUL;          /* Terminate string with NUL */
  3888.             zsoutl(ZMFILE,outbuf);
  3889.         }
  3890.         zclose(ZMFILE);
  3891.         return(1);
  3892.     } else {
  3893.         return(0);
  3894.     }
  3895. }
  3896.  
  3897. int
  3898. pnumber(int *achar) {
  3899.     int num = 0;
  3900.     while (isdigit(*achar)) {           /* Get number */
  3901.         num = (num * 10) + (*achar) - 48;
  3902.             *achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  3903.     }
  3904.     return (num);
  3905. }
  3906.  
  3907. /* ----------------------------------------------------------------- */
  3908. /* Clear Functions                                                   */
  3909. /* ----------------------------------------------------------------- */
  3910.  
  3911. unsigned char
  3912. geterasecolor( int vmode )
  3913. {
  3914.     unsigned char erasecolor = 0 ;
  3915.  
  3916.     switch ( vmode ) {
  3917.     case VSTATUS:
  3918.         if ( !ISVT220(tt_type_mode) ) {
  3919.             erasecolor = colorstatus ;
  3920.             break;
  3921.         }
  3922.         /* else fall through and act as VTERM */
  3923.     case VTERM:
  3924.         if ( erasemode == 0 ) {
  3925.             erasecolor = attribute ;
  3926.         }
  3927.         else {
  3928.             erasecolor = defaultattribute ;
  3929.         }
  3930.         break;
  3931.  
  3932.     case VCMD:
  3933.     default:
  3934.         erasecolor = colorcmd;
  3935.     }
  3936.     return erasecolor;
  3937. }
  3938.  
  3939. void
  3940. clrscreen( BYTE vmode, CHAR fillchar ) {
  3941.     int             y;
  3942.     videoline *     line ;
  3943.  
  3944.     /* This function becomes really simple with the new model
  3945.        since all we do is move the top of the screen down in
  3946.        the vscrn buffer by the size of the screen.
  3947.     */
  3948.  
  3949.     if ( fillchar == NUL )
  3950.         fillchar = SP ;
  3951.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  3952.         vmode = VSTATUS ;
  3953.  
  3954.     if ( IS97801(tt_type_mode) ) {
  3955.         VscrnScroll(vmode,UPWARD,margintop-1,
  3956.                      marginbot-1,
  3957.                      marginbot-margintop+1,
  3958.                      margintop==1 &&
  3959.                      marginbot==(VscrnGetHeight(vmode)-(tt_status[vmode]?1:0)),
  3960.                      fillchar);
  3961.     }
  3962.     else {
  3963.         VscrnScroll(vmode,UPWARD,
  3964.                      0,VscrnGetHeight(vmode)-(tt_status[vmode]?2:1),
  3965.                      VscrnGetHeight(vmode)-(tt_status[vmode]?1:0),
  3966.                      TRUE,fillchar);
  3967.     }
  3968. }
  3969.  
  3970. void
  3971. clrtoeoln( BYTE vmode, CHAR fillchar ) {
  3972.     int x ;
  3973.     videoline * line = NULL ;
  3974.     unsigned char cellcolor = geterasecolor(vmode);
  3975.  
  3976.     if ( fillchar == NUL )
  3977.         fillchar = SP ;
  3978.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  3979.         vmode = VSTATUS ;
  3980.  
  3981.     /* take care of current line */
  3982.     line = VscrnGetLineFromTop( vmode,wherey[vmode]-1 ) ;
  3983.     for ( x=wherex[vmode]-1 ; x < MAXTERMCOL ; x++ )
  3984.         {
  3985.         line->cells[x].c = fillchar ;
  3986.         line->cells[x].a = cellcolor ;
  3987.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  3988.         }
  3989. }
  3990.  
  3991. void
  3992. clreoscr_escape( BYTE vmode, CHAR fillchar ) {
  3993.     int x,y,h;
  3994.     videoline * line = NULL;
  3995.     unsigned char cellcolor = geterasecolor(vmode) ;
  3996.  
  3997.     if ( fillchar == NUL )
  3998.         fillchar = SP ;
  3999.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4000.         vmode = VSTATUS ;
  4001.  
  4002.     if (wherex[vmode] == 1 && wherey[vmode] == 1) {
  4003.         clrscreen(vmode,fillchar);
  4004.         return;
  4005.     }
  4006.  
  4007.     RequestVscrnMutex(vmode, SEM_INDEFINITE_WAIT) ;
  4008.     /* take care of current line */
  4009.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4010.     for ( x=wherex[vmode]-1 ; x <MAXTERMCOL ; x++ )
  4011.     {
  4012.         line->cells[x].c = fillchar ;
  4013.         line->cells[x].a = cellcolor;
  4014.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4015.     }
  4016.     line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4017.  
  4018.     /* now take care of additional lines */
  4019.     if ( IS97801(tt_type_mode) )
  4020.         h = marginbot-1;
  4021.     else
  4022.         h = VscrnGetHeight(vmode)-(tt_status[vmode]?1:0) ;
  4023.     for ( y=wherey[vmode] ; y<h ; y++)
  4024.     {
  4025.         line = VscrnGetLineFromTop(vmode,y) ;
  4026.         for ( x=0 ; x <MAXTERMCOL ; x++ )
  4027.         {
  4028.             line->cells[x].c = fillchar ;
  4029.             line->cells[x].a = cellcolor;
  4030.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4031.         }
  4032.         line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4033.     }
  4034.     ReleaseVscrnMutex(vmode);
  4035. }
  4036.  
  4037. void
  4038. clrboscr_escape( BYTE vmode, CHAR fillchar ) {
  4039.     int x,y,h;
  4040.     videoline * line = NULL;
  4041.     unsigned char cellcolor = geterasecolor(vmode) ;
  4042.  
  4043.     if ( fillchar == NUL )
  4044.         fillchar = SP ;
  4045.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4046.         vmode = VSTATUS ;
  4047.  
  4048.     /* now take care of first wherey[VTERM]-1 lines */
  4049.     if ( IS97801(tt_type_mode) )
  4050.         h = margintop-1;
  4051.     else
  4052.         h = 0;
  4053.     for ( y=h ; y<wherey[vmode]-1 ; y++ )
  4054.         {
  4055.         line = VscrnGetLineFromTop(vmode,y) ;
  4056.         for ( x=0 ; x <MAXTERMCOL ; x++ )
  4057.             {
  4058.             line->cells[x].c = fillchar ;
  4059.             line->cells[x].a = cellcolor;
  4060.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4061.             }
  4062.         line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4063.         }
  4064.  
  4065.     /* take care of current line */
  4066.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4067.     for ( x=0 ; x < wherex[vmode] ; x++ )
  4068.         {
  4069.         line->cells[x].c = fillchar ;
  4070.         line->cells[x].a = cellcolor;
  4071.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4072.         }
  4073.     line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4074. }
  4075.  
  4076. void
  4077. clrregion( BYTE vmode, CHAR fillchar ) {
  4078.     int             y;
  4079.     videoline *     line ;
  4080.  
  4081.     /* This function becomes really simple with the new model
  4082.        since all we do is move the top of the screen down in
  4083.        the vscrn buffer by the size of the screen.
  4084.     */
  4085.  
  4086.     if ( wherey[VTERM] < margintop ||
  4087.          wherey[VTERM] > marginbot )
  4088.         return;
  4089.  
  4090.     if ( fillchar == NUL )
  4091.         fillchar = SP ;
  4092.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4093.         vmode = VSTATUS ;
  4094.  
  4095.     VscrnScroll(vmode,UPWARD,margintop-1,
  4096.                  marginbot-1,
  4097.                  marginbot-margintop+1,
  4098.                  margintop==1 &&
  4099.                  marginbot==(VscrnGetHeight(vmode)-(tt_status[vmode]?1:0)),
  4100.                  fillchar);
  4101. }
  4102.  
  4103. void
  4104. clreoreg_escape( BYTE vmode, CHAR fillchar ) {
  4105.     int x,y,h;
  4106.     videoline * line = NULL;
  4107.     unsigned char cellcolor = geterasecolor(vmode) ;
  4108.  
  4109.     if ( wherey[VTERM] < margintop ||
  4110.          wherey[VTERM] > marginbot )
  4111.         return;
  4112.  
  4113.     if ( fillchar == NUL )
  4114.         fillchar = SP ;
  4115.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4116.         vmode = VSTATUS ;
  4117.  
  4118.     if (wherex[vmode] == 1 && wherey[vmode] == 1) {
  4119.         clrscreen(vmode,fillchar);
  4120.         return;
  4121.     }
  4122.  
  4123.     RequestVscrnMutex(vmode, SEM_INDEFINITE_WAIT) ;
  4124.     /* take care of current line */
  4125.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4126.     for ( x=wherex[vmode]-1 ; x <MAXTERMCOL ; x++ )
  4127.     {
  4128.         line->cells[x].c = fillchar ;
  4129.         line->cells[x].a = cellcolor;
  4130.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4131.     }
  4132.     line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4133.  
  4134.     /* now take care of additional lines */
  4135.     h = marginbot-1;
  4136.     for ( y=wherey[vmode] ; y<h ; y++)
  4137.     {
  4138.         line = VscrnGetLineFromTop(vmode,y) ;
  4139.         for ( x=0 ; x <MAXTERMCOL ; x++ )
  4140.         {
  4141.             line->cells[x].c = fillchar ;
  4142.             line->cells[x].a = cellcolor;
  4143.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4144.         }
  4145.         line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4146.     }
  4147.     ReleaseVscrnMutex(vmode);
  4148. }
  4149.  
  4150. void
  4151. clrboreg_escape( BYTE vmode, CHAR fillchar ) {
  4152.     int x,y,h;
  4153.     videoline * line = NULL;
  4154.     unsigned char cellcolor = geterasecolor(vmode) ;
  4155.  
  4156.     if ( wherey[VTERM] < margintop ||
  4157.          wherey[VTERM] > marginbot )
  4158.         return;
  4159.  
  4160.     if ( fillchar == NUL )
  4161.         fillchar = SP ;
  4162.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4163.         vmode = VSTATUS ;
  4164.  
  4165.     /* now take care of first wherey[VTERM]-1 lines */
  4166.     h = margintop-1;
  4167.     for ( y=h ; y<wherey[vmode]-1 ; y++ )
  4168.         {
  4169.         line = VscrnGetLineFromTop(vmode,y) ;
  4170.         for ( x=0 ; x <MAXTERMCOL ; x++ )
  4171.             {
  4172.             line->cells[x].c = fillchar ;
  4173.             line->cells[x].a = cellcolor;
  4174.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4175.             }
  4176.         line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4177.         }
  4178.  
  4179.     /* take care of current line */
  4180.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4181.     for ( x=0 ; x < wherex[vmode] ; x++ )
  4182.         {
  4183.         line->cells[x].c = fillchar ;
  4184.         line->cells[x].a = cellcolor;
  4185.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4186.         }
  4187.     line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  4188. }
  4189.  
  4190. void
  4191. clrbol_escape( BYTE vmode, CHAR fillchar ) {
  4192.     videoline * line = NULL ;
  4193.     int x ;
  4194.     unsigned char cellcolor = geterasecolor(vmode) ;
  4195.  
  4196.     if ( fillchar == NUL )
  4197.         fillchar = SP ;
  4198.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4199.         vmode = VSTATUS ;
  4200.  
  4201.     /* take care of current line */
  4202.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4203.     for ( x=0 ; x < wherex[vmode] ; x++ )
  4204.         {
  4205.         line->cells[x].c = fillchar ;
  4206.         line->cells[x].a = cellcolor;
  4207.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4208.         }
  4209. }
  4210.  
  4211. void
  4212. clrline_escape( BYTE vmode, CHAR fillchar ) {
  4213.     videoline * line = NULL ;
  4214.     int x ;
  4215.     unsigned char cellcolor = geterasecolor(vmode) ;
  4216.  
  4217.     if ( fillchar == NUL )
  4218.         fillchar = SP ;
  4219.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4220.         vmode = VSTATUS ;
  4221.  
  4222.     /* take care of current line */
  4223.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4224.     for ( x=0 ; x < MAXTERMCOL ; x++ )
  4225.     {
  4226.         line->cells[x].c = fillchar ;
  4227.         line->cells[x].a = cellcolor;
  4228.         line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4229.     }
  4230. }
  4231.  
  4232. void
  4233. clrcol_escape( BYTE vmode, CHAR fillchar ) {
  4234.     int ys ;
  4235.     int x  = wherex[VTERM]-1 ;
  4236.     int y ;
  4237.     viocell cell = { fillchar, geterasecolor(vmode) } ;
  4238.     vtattrib vta ={0,0,0,0,0,0,0,0,0,0};
  4239.  
  4240.     if ( fillchar == NUL )
  4241.         cell.c = SP ;
  4242.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4243.         vmode = VSTATUS ;
  4244.  
  4245.     if ( IS97801(tt_type_mode) ) {
  4246.         y = margintop-1;
  4247.         ys = marginbot-1;
  4248.     }
  4249.     else {
  4250.         ys = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  4251.         y = 0;
  4252.     }
  4253.     for ( ; y<ys ; y++ )
  4254.         VscrnWrtCell( VTERM, cell, vta, y, x ) ;
  4255. }
  4256.  
  4257. /* Clears a rectangle from current cursor position to row,col */
  4258. /* using fillchar.                                            */
  4259. void
  4260. clrrect_escape( BYTE vmode, int top, int left, int bot, int right, CHAR fillchar )
  4261. {
  4262.     int startx, starty, endx, endy, l, x ;
  4263.     videoline * line = NULL ;
  4264.     unsigned char cellcolor = geterasecolor(vmode) ;
  4265.  
  4266.     if ( left < right ) {
  4267.         startx = left - 1 ;
  4268.         endx   = right - 1 ;
  4269.     }
  4270.     else {
  4271.         startx = right - 1 ;
  4272.         endx = left - 1 ;
  4273.     }
  4274.  
  4275.     if ( top < bot ) {
  4276.         starty = top - 1 ;
  4277.         endy   = bot - 1 ;
  4278.     }
  4279.     else {
  4280.         starty = bot - 1 ;
  4281.         endy = top - 1 ;
  4282.     }
  4283.  
  4284.     if ( fillchar == NUL )
  4285.         fillchar = SP ;
  4286.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4287.         vmode = VSTATUS ;
  4288.  
  4289.     /* check to see if any of the lines are protected */
  4290.     /* if so, abort                                   */
  4291.  
  4292.     for ( l=starty ; l <= endy ; l++ )
  4293.         if ( VscrnGetLineFromTop( vmode, l )->vt_line_attr & WY_LINE_ATTR_PROTECTED )
  4294.             return ;
  4295.  
  4296.     /* so now we just need to clear each row */
  4297.  
  4298.     for ( l=starty ; l <= endy ; l++ ) {
  4299.         line = VscrnGetLineFromTop( vmode, l ) ;
  4300.         for ( x=startx ; x <= endx ; x++ )
  4301.         {
  4302.             line->cells[x].c = fillchar ;
  4303.             line->cells[x].a = cellcolor;
  4304.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4305.         }
  4306.  
  4307.     }
  4308. }
  4309.  
  4310. /* ----------------------------------------------------------------- */
  4311. /* Selective Clear Functions                                         */
  4312. /* ----------------------------------------------------------------- */
  4313. void
  4314. selclrscreen( BYTE vmode, CHAR fillchar ) {
  4315.     int             x=0, y=0, y2=0, linecount = VscrnGetBufferSize(vmode) ;
  4316.     videoline *     line=NULL, * newline = NULL ;
  4317.  
  4318.     if ( fillchar == NUL )
  4319.         fillchar = SP ;
  4320.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4321.         vmode = VSTATUS ;
  4322.  
  4323.     VscrnScroll(vmode,UPWARD,0,VscrnGetHeight(vmode)-(tt_status[vmode]?2:1),
  4324.                  VscrnGetHeight(vmode)-(tt_status[vmode]?1:0),TRUE,fillchar);
  4325.  
  4326.     /* Okay, so now we have scrolled the screen.  But the protected */
  4327.     /* fields need to be copied back to the new current screen      */
  4328.  
  4329.     for ( y = linecount - VscrnGetHeight(vmode) + (tt_status[vmode]?1:0) ;
  4330.           y < linecount ; y++,y2++ ) {
  4331.         line = VscrnGetLineFromTop( vmode,y ) ;
  4332.         newline = VscrnGetLineFromTop( vmode,y2 ) ;
  4333.         for ( x = 0 ; x < MAXTERMCOL ; x++ ) {
  4334.             if ( line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) {
  4335.                 newline->cells[x] = line->cells[x] ;
  4336.                 newline->vt_char_attrs[x] = line->vt_char_attrs[x] ;
  4337.                 }
  4338.             }
  4339.         }
  4340. }
  4341.  
  4342.  
  4343. void
  4344. selclrtoeoln( BYTE vmode, CHAR fillchar ) {
  4345.     int x ;
  4346.     videoline * line = NULL ;
  4347.     unsigned char cellcolor = geterasecolor(vmode) ;
  4348.  
  4349.     if ( fillchar == NUL )
  4350.         fillchar = SP ;
  4351.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4352.         vmode = VSTATUS ;
  4353.  
  4354.     /* take care of current line */
  4355.     line = VscrnGetLineFromTop( vmode,wherey[vmode]-1 ) ;
  4356.     for ( x=wherex[vmode]-1 ; x < MAXTERMCOL ; x++ )
  4357.         {
  4358.         if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4359.             line->cells[x].c = fillchar ;
  4360.             line->cells[x].a = cellcolor;
  4361.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4362.             }
  4363.         }
  4364. }
  4365.  
  4366. void
  4367. selclreoscr_escape( BYTE vmode, CHAR fillchar ) {
  4368.     int x,y;
  4369.     videoline * line = NULL;
  4370.     unsigned char cellcolor = geterasecolor(vmode) ;
  4371.  
  4372.     if ( fillchar == NUL )
  4373.         fillchar = SP ;
  4374.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4375.         vmode = VSTATUS ;
  4376.  
  4377.     if (wherex[vmode] == 1 && wherey[vmode] == 1) {
  4378.         selclrscreen(vmode, fillchar);
  4379.         return;
  4380.     }
  4381.  
  4382.     /* take care of current line */
  4383.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4384.     for ( x=wherex[vmode]-1 ; x <MAXTERMCOL ; x++ )
  4385.         {
  4386.         if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4387.             line->cells[x].c = fillchar ;
  4388.             line->cells[x].a = cellcolor;
  4389.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4390.             }
  4391.         }
  4392.  
  4393.     /* now take care of additional lines */
  4394.     for ( y=wherey[vmode] ; y<VscrnGetHeight(vmode)-(tt_status[vmode]?1:0) ; y++ )
  4395.         {
  4396.         line = VscrnGetLineFromTop(vmode,y) ;
  4397.         for ( x=0 ; x <MAXTERMCOL ; x++ )
  4398.             {
  4399.             if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4400.                 line->cells[x].c = fillchar ;
  4401.                 line->cells[x].a = cellcolor;
  4402.                 line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4403.                 }
  4404.             }
  4405.         }
  4406. }
  4407.  
  4408. void
  4409. selclrboscr_escape( BYTE vmode, CHAR fillchar ) {
  4410.     int x,y;
  4411.     videoline * line = NULL;
  4412.     unsigned char cellcolor = geterasecolor(vmode) ;
  4413.  
  4414.     if ( fillchar == NUL )
  4415.         fillchar = SP ;
  4416.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4417.         vmode = VSTATUS ;
  4418.  
  4419.     /* now take care of first wherey[vmode]-1 lines */
  4420.     for ( y=0 ; y<wherey[vmode]-1 ; y++ )
  4421.         {
  4422.         line = VscrnGetLineFromTop(vmode,y) ;
  4423.         for ( x=0 ; x <MAXTERMCOL ; x++ )
  4424.             {
  4425.             if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4426.                 line->cells[x].c = fillchar ;
  4427.                 line->cells[x].a = cellcolor;
  4428.                 line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4429.                 }
  4430.             }
  4431.         }
  4432.  
  4433.     /* take care of current line */
  4434.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4435.     for ( x=0 ; x < wherex[vmode] ; x++ )
  4436.         {
  4437.         if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4438.             line->cells[x].c = fillchar ;
  4439.             line->cells[x].a = cellcolor;
  4440.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4441.             }
  4442.         }
  4443. }
  4444.  
  4445. void
  4446. selclrbol_escape( BYTE vmode, CHAR fillchar ) {
  4447.     videoline * line = NULL ;
  4448.     int x ;
  4449.     unsigned char cellcolor = geterasecolor(vmode) ;
  4450.  
  4451.     if ( fillchar == NUL )
  4452.         fillchar = SP ;
  4453.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4454.         vmode = VSTATUS ;
  4455.  
  4456.     /* take care of current line */
  4457.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4458.     for ( x=0 ; x < wherex[vmode] ; x++ )
  4459.         {
  4460.         if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4461.             line->cells[x].c = fillchar ;
  4462.             line->cells[x].a = cellcolor;
  4463.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4464.             }
  4465.         }
  4466. }
  4467.  
  4468. void
  4469. selclrline_escape( BYTE vmode, CHAR fillchar ) {
  4470.     videoline * line = NULL ;
  4471.     int x ;
  4472.     unsigned char cellcolor = geterasecolor(vmode);
  4473.  
  4474.     if ( fillchar == NUL )
  4475.         fillchar = SP ;
  4476.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4477.         vmode = VSTATUS ;
  4478.  
  4479.     /* take care of current line */
  4480.     line = VscrnGetLineFromTop(vmode,wherey[vmode]-1) ;
  4481.     for ( x=0 ; x < MAXTERMCOL ; x++ )
  4482.     {
  4483.         if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4484.             line->cells[x].c = fillchar ;
  4485.             line->cells[x].a = cellcolor;
  4486.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4487.         }
  4488.     }
  4489. }
  4490.  
  4491.  
  4492. void
  4493. selclrcol_escape( BYTE vmode, CHAR fillchar ) {
  4494.     int ys = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  4495.     int x  = wherex[VTERM]-1 ;
  4496.     int y ;
  4497.     viocell cell = { fillchar, geterasecolor(vmode) } ;
  4498.     vtattrib vta ={0,0,0,0,0,0,0,0,0,0};
  4499.  
  4500.     if ( fillchar == NUL )
  4501.         cell.c = SP ;
  4502.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4503.         vmode = VSTATUS ;
  4504.  
  4505.     for ( y=0 ; y<ys ; y++ ) {
  4506.         if ( !VscrnGetVtCharAttr(VTERM,x,y).unerasable )
  4507.             VscrnWrtCell( VTERM, cell, vta, y, x ) ;
  4508.     }
  4509. }
  4510.  
  4511. /* Clears a rectangle from current cursor position to row,col */
  4512. /* using fillchar.                                            */
  4513. void
  4514. selclrrect_escape( BYTE vmode, int top, int left, int bot, int right,
  4515.                    CHAR fillchar )
  4516. {
  4517.     int startx, starty, endx, endy, l, x ;
  4518.     videoline * line = NULL ;
  4519.     unsigned char cellcolor = geterasecolor(vmode) ;
  4520.  
  4521.     if ( left < right ) {
  4522.         startx = left - 1 ;
  4523.         endx   = right - 1 ;
  4524.     }
  4525.     else {
  4526.         startx = right - 1 ;
  4527.         endx = left - 1 ;
  4528.     }
  4529.  
  4530.     if ( top < bot ) {
  4531.         starty = top - 1 ;
  4532.         endy   = bot - 1 ;
  4533.     }
  4534.     else {
  4535.         starty = bot - 1 ;
  4536.         endy = top - 1 ;
  4537.     }
  4538.  
  4539.     if ( fillchar == NUL )
  4540.         fillchar = SP ;
  4541.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4542.         vmode = VSTATUS ;
  4543.  
  4544.     /* check to see if any of the lines are protected */
  4545.     /* if so, abort                                   */
  4546.  
  4547.     for ( l=starty ; l <= endy ; l++ )
  4548.         if ( VscrnGetLineFromTop( vmode, l )->vt_line_attr & WY_LINE_ATTR_PROTECTED )
  4549.             return ;
  4550.  
  4551.     /* so now we just need to clear each row */
  4552.  
  4553.     for ( l=starty ; l <= endy ; l++ ) {
  4554.         line = VscrnGetLineFromTop( vmode, l ) ;
  4555.         for ( x=startx ; x <= endx ; x++ )
  4556.         {
  4557.             if ( !(line->vt_char_attrs[x] & VT_CHAR_ATTR_PROTECTED ) ) {
  4558.                 line->cells[x].c = fillchar ;
  4559.                 line->cells[x].a = cellcolor;
  4560.                 line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  4561.             }
  4562.         }
  4563.     }
  4564. }
  4565.  
  4566. /* Draws a box from current cursor to row,col */
  4567. void
  4568. boxrect_escape( BYTE vmode, int row, int col )
  4569. {
  4570.     int brow, bcol, erow, ecol, x, y ;
  4571.     viocell cell ;
  4572.     vtattrib vta = {0,0,0,0,0,0,0,0,0,0,0};
  4573.  
  4574.     if ( vmode == VTERM ) {
  4575.         cell.a = attribute ;
  4576.         vta = attrib ;
  4577.     }
  4578.     else
  4579.         cell.a = colorcmd ;
  4580.  
  4581.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  4582.         vmode = VSTATUS ;
  4583.  
  4584.     if ( wherey[vmode] < row ) {
  4585.         brow = wherey[vmode] ;
  4586.         erow = row ;
  4587.     }
  4588.     else {
  4589.         brow = row ;
  4590.         erow = wherey[vmode] ;
  4591.     }
  4592.  
  4593.     if ( wherex[vmode] < col ) {
  4594.         bcol = wherex[vmode] ;
  4595.         ecol = col ;
  4596.     }
  4597.     else {
  4598.         bcol = col ;
  4599.         ecol = wherex[vmode] ;
  4600.     }
  4601.  
  4602.     cell.c = '|' ;
  4603.     for ( y = brow ; y <= erow ; y++ ) {
  4604.         VscrnWrtCell( vmode, cell, vta, y, bcol ) ;
  4605.     }
  4606.     for ( y = brow ; y <= erow ; y++ ) {
  4607.         VscrnWrtCell( vmode, cell, vta, y, ecol ) ;
  4608.     }
  4609.     cell.c = '-' ;
  4610.     for ( x = bcol ; x <= ecol ; x++ ) {
  4611.         VscrnWrtCell( vmode, cell, vta, brow, x ) ;
  4612.     }
  4613.     for ( x = bcol ; x <= ecol ; x++ ) {
  4614.         VscrnWrtCell( vmode, cell, vta, erow, x ) ;
  4615.     }
  4616. }
  4617.  
  4618. void
  4619. decdwl_escape(bool dwlflag) {
  4620.     videoline * line = NULL ;
  4621.     unsigned char   linenumber=0;
  4622.     unsigned char   newx=0;
  4623.     viocell       * cells = NULL ;
  4624.     int             i=0;
  4625.     char buffer[MAXTERMCOL+1] ;
  4626.  
  4627.     /* DECDWL */
  4628.     line = VscrnGetLineFromTop(VTERM,wherey[VTERM]-1) ;
  4629.     cells = line->cells ;
  4630.  
  4631.      if ( dwlflag != line->vt_line_attr ) {
  4632.          /* change size */
  4633.        line->vt_line_attr = dwlflag ;
  4634.     }
  4635. }
  4636.  
  4637. void
  4638. udkreset( void )
  4639. {
  4640.     int i;
  4641.     udklock = FALSE;                   /* Unlock User Defined Keys */
  4642.     for ( i=0 ; i<200 ; i++ )          /* Reset the User Defined Keys */
  4643.     {
  4644.        if ( udkfkeys[i] )
  4645.          free(udkfkeys[i]);
  4646.         udkfkeys[i] = NULL ;
  4647.     }
  4648.  
  4649.     if ( ISTVI(tt_type_mode) ) {
  4650.         udkfkeys[0]  = strdup("\01@\r");        /* F1 */
  4651.         udkfkeys[1]  = strdup("\01A\r");
  4652.         udkfkeys[2]  = strdup("\01B\r");
  4653.         udkfkeys[3]  = strdup("\01C\r");
  4654.         udkfkeys[4]  = strdup("\01D\r");
  4655.         udkfkeys[5]  = strdup("\01E\r");
  4656.         udkfkeys[6]  = strdup("\01F\r");
  4657.         udkfkeys[7]  = strdup("\01G\r");
  4658.         udkfkeys[8]  = strdup("\01H\r");
  4659.         udkfkeys[9]  = strdup("\01I\r");
  4660.         udkfkeys[10] = strdup("\01J\r");
  4661.         udkfkeys[11] = strdup("\01K\r");
  4662.         udkfkeys[12] = strdup("\01L\r");
  4663.         udkfkeys[13] = strdup("\01M\r");
  4664.         udkfkeys[14] = strdup("\01N\r");
  4665.         udkfkeys[15] = strdup("\01O\r");        /* F16 */
  4666.         udkfkeys[16] = strdup("\01`\r");        /* Shift-F1 */
  4667.         udkfkeys[17] = strdup("\01a\r");
  4668.         udkfkeys[18] = strdup("\01b\r");
  4669.         udkfkeys[19] = strdup("\01c\r");
  4670.         udkfkeys[20] = strdup("\01d\r");
  4671.         udkfkeys[21] = strdup("\01e\r");
  4672.         udkfkeys[22] = strdup("\01f\r");
  4673.         udkfkeys[23] = strdup("\01g\r");
  4674.         udkfkeys[24] = strdup("\01h\r");
  4675.         udkfkeys[25] = strdup("\01i\r");
  4676.         udkfkeys[26] = strdup("\01j\r");
  4677.         udkfkeys[27] = strdup("\01k\r");
  4678.         udkfkeys[28] = strdup("\01l\r");
  4679.         udkfkeys[29] = strdup("\01m\r");
  4680.         udkfkeys[30] = strdup("\01n\r");
  4681.         udkfkeys[31] = strdup("\01o\r");        /* Shift-F16 */
  4682.         udkfkeys[32] = strdup("\x08");          /* Backspace */
  4683.         udkfkeys[33] = strdup("\x1BT");         /* Clr Line */
  4684.         udkfkeys[34] = strdup("\x1Bt");         /* Shift Clr Line */
  4685.         udkfkeys[35] = strdup("\x1BY");         /* Clr Page */
  4686.         udkfkeys[36] = strdup("\x1By");         /* Shift Clr Page */
  4687.         udkfkeys[37] = strdup("\x1BW");         /* Del Char */
  4688.         udkfkeys[38] = strdup("\x1BR");         /* Del Line */
  4689.         udkfkeys[39] = strdup("\x0D");          /* Enter */
  4690.         udkfkeys[40] = strdup("\x1B");          /* Escape */
  4691.         udkfkeys[41] = strdup("\x1E");          /* Home */
  4692.         udkfkeys[42] = strdup("\x1B{");         /* Shift Home */
  4693.         udkfkeys[43] = strdup("\x1Bq");         /* Insert */
  4694.         udkfkeys[44] = strdup("\x1BQ");         /* Ins Char */
  4695.         udkfkeys[45] = strdup("\x1B\x45");      /* Ins Line */
  4696.         udkfkeys[46] = strdup("\x1BK");         /* Page Next*/
  4697.         udkfkeys[47] = strdup("\x1BJ");         /* Page Prev*/
  4698.         udkfkeys[48] = strdup("\x1Br");         /* Replace */
  4699.         udkfkeys[49] = strdup("\x0D");          /* Return */
  4700.         udkfkeys[50] = strdup("\x09");          /* Tab */
  4701.         udkfkeys[51] = strdup("\x1BI");         /* Shift Tab */
  4702.         udkfkeys[52] = strdup("\x1BP");         /* Print Screen */
  4703.         udkfkeys[53] = NULL;                    /* Shift Esc */
  4704.         udkfkeys[54] = strdup("\x08");          /* Shift BS */
  4705.         udkfkeys[55] = NULL ;                   /* Shift Enter */
  4706.         udkfkeys[56] = NULL ;                   /* Shift Return */
  4707.         udkfkeys[57] = strdup("\x0b");          /* Up Arrow - VT */
  4708.         udkfkeys[58] = strdup("\x16");          /* Dn Arrow - SYN */
  4709.         udkfkeys[59] = strdup("\x08");          /* Left Arrow - BS */
  4710.         udkfkeys[60] = strdup("\x0C");          /* Right Arrow - FF */
  4711.         udkfkeys[61] = NULL ;                   /* Shift Up Arrow */
  4712.         udkfkeys[62] = NULL ;                   /* Shift Dn Arrow */
  4713.         udkfkeys[63] = NULL ;                   /* Shift Left Arrow */
  4714.         udkfkeys[64] = NULL ;                   /* Shift Right Arrow */
  4715.         udkfkeys[65] = strdup("\0337");         /* Send */
  4716.         udkfkeys[66] = strdup("\0336");         /* Shift-Send */
  4717.     }
  4718.  
  4719.     if ( ISWYSE(tt_type_mode) ) {
  4720.         udkfkeys[0]  = strdup("\01@\r");        /* F1 */
  4721.         udkfkeys[1]  = strdup("\01A\r");
  4722.         udkfkeys[2]  = strdup("\01B\r");
  4723.         udkfkeys[3]  = strdup("\01C\r");
  4724.         udkfkeys[4]  = strdup("\01D\r");
  4725.         udkfkeys[5]  = strdup("\01E\r");
  4726.         udkfkeys[6]  = strdup("\01F\r");
  4727.         udkfkeys[7]  = strdup("\01G\r");
  4728.         udkfkeys[8]  = strdup("\01H\r");
  4729.         udkfkeys[9]  = strdup("\01I\r");
  4730.         udkfkeys[10] = strdup("\01J\r");
  4731.         udkfkeys[11] = strdup("\01K\r");
  4732.         udkfkeys[12] = strdup("\01L\r");
  4733.         udkfkeys[13] = strdup("\01M\r");
  4734.         udkfkeys[14] = strdup("\01N\r");
  4735.         udkfkeys[15] = strdup("\01O\r");
  4736.         udkfkeys[16] = strdup("\01P\r");
  4737.         udkfkeys[17] = strdup("\01Q\r");
  4738.         udkfkeys[18] = strdup("\01R\r");
  4739.         udkfkeys[19] = strdup("\01S\r");        /* F20 */
  4740.  
  4741.         udkfkeys[20] = strdup("\01`\r");        /* Shift-F1 */
  4742.         udkfkeys[21] = strdup("\01a\r");
  4743.         udkfkeys[22] = strdup("\01b\r");
  4744.         udkfkeys[23] = strdup("\01c\r");
  4745.         udkfkeys[24] = strdup("\01d\r");
  4746.         udkfkeys[25] = strdup("\01e\r");
  4747.         udkfkeys[26] = strdup("\01f\r");
  4748.         udkfkeys[27] = strdup("\01g\r");
  4749.         udkfkeys[28] = strdup("\01h\r");
  4750.         udkfkeys[29] = strdup("\01i\r");
  4751.         udkfkeys[30] = strdup("\01j\r");
  4752.         udkfkeys[31] = strdup("\01k\r");
  4753.         udkfkeys[32] = strdup("\01l\r");
  4754.         udkfkeys[33] = strdup("\01m\r");
  4755.         udkfkeys[34] = strdup("\01n\r");
  4756.         udkfkeys[35] = strdup("\01o\r");
  4757.         udkfkeys[36] = strdup("\01p\r");
  4758.         udkfkeys[37] = strdup("\01q\r");
  4759.         udkfkeys[38] = strdup("\01r\r");
  4760.         udkfkeys[39] = strdup("\01s\r");        /* Shift-F20 */
  4761.  
  4762.         udkfkeys[40] = strdup("\x08");          /* Backspace */
  4763.         udkfkeys[41] = strdup("\x1BT");         /* Clr Line */
  4764.         udkfkeys[42] = strdup("\x1Bt");         /* Shift Clr Line */
  4765.         udkfkeys[43] = strdup("\x1BY");         /* Clr Page */
  4766.         udkfkeys[44] = strdup("\x1By");         /* Shift Clr Page */
  4767.         udkfkeys[45] = strdup("\x1BW");         /* Del Char */
  4768.         udkfkeys[46] = strdup("\x1BR");         /* Del Line */
  4769.         udkfkeys[47] = strdup("\x0D");          /* Enter */
  4770.         udkfkeys[48] = strdup("\x1B");          /* Escape */
  4771.         udkfkeys[49] = strdup("\x1E");          /* Home */
  4772.         udkfkeys[50] = strdup("\x1B{");         /* Shift Home */
  4773.         udkfkeys[51] = strdup("\x1Bq");         /* Insert */
  4774.         udkfkeys[52] = strdup("\x1BQ");         /* Ins Char */
  4775.         udkfkeys[53] = strdup("\x1B\x45");      /* Ins Line */
  4776.         udkfkeys[54] = strdup("\x1BK");         /* Page Next*/
  4777.         udkfkeys[55] = strdup("\x1BJ");         /* Page Prev*/
  4778.         udkfkeys[56] = strdup("\x1Br");         /* Replace */
  4779.         udkfkeys[57] = strdup("\x0D");          /* Return */
  4780.         udkfkeys[58] = strdup("\x09");          /* Tab */
  4781.         udkfkeys[59] = strdup("\x1BI");         /* Shift Tab */
  4782.         udkfkeys[60] = strdup("\x1BP");         /* Print Screen */
  4783.         udkfkeys[61] = NULL;                    /* Shift Esc */
  4784.         udkfkeys[62] = strdup("\x08");          /* Shift BS */
  4785.         udkfkeys[63] = NULL ;                   /* Shift Enter */
  4786.         udkfkeys[64] = NULL ;                   /* Shift Return */
  4787.         udkfkeys[65] = strdup("\x0b");          /* Up Arrow - VT */
  4788.         udkfkeys[66] = strdup("\x0a");          /* Dn Arrow - LF */
  4789.         udkfkeys[67] = strdup("\x08");          /* Left Arrow - BS */
  4790.         udkfkeys[68] = strdup("\x0c");          /* Right Arrow - NL */
  4791.         udkfkeys[69] = NULL ;                   /* Shift Up Arrow */
  4792.         udkfkeys[70] = NULL ;                   /* Shift Dn Arrow */
  4793.         udkfkeys[71] = NULL ;                   /* Shift Left Arrow */
  4794.         udkfkeys[72] = NULL ;                   /* Shift Right Arrow */
  4795.         udkfkeys[73] = strdup("\x1B\x37");      /* Send */
  4796.         udkfkeys[74] = NULL ;                   /* Shift Send */
  4797.     }
  4798.  
  4799.     if ( ISAT386(tt_type_mode) ) {
  4800.         udkfkeys[0]  = strdup("\x1BOP");
  4801.         udkfkeys[1]  = strdup("\x1BOQ");
  4802.         udkfkeys[2]  = strdup("\x1BOR");
  4803.         udkfkeys[3]  = strdup("\x1BOS");
  4804.         udkfkeys[4]  = strdup("\x1BOT");
  4805.         udkfkeys[5]  = strdup("\x1BOU");
  4806.         udkfkeys[6]  = strdup("\x1BOV");
  4807.         udkfkeys[7]  = strdup("\x1BOW");
  4808.         udkfkeys[8]  = strdup("\x1BOX");
  4809.         udkfkeys[9]  = strdup("\x1BOY");
  4810.         udkfkeys[10] = strdup("\x1BOZ");
  4811.         udkfkeys[11] = strdup("\x1BOA");
  4812.         udkfkeys[12] = strdup("\x1BOp");
  4813.         udkfkeys[13] = strdup("\x1BOq");
  4814.         udkfkeys[14] = strdup("\x1BOr");
  4815.         udkfkeys[15] = strdup("\x1BOs");
  4816.         udkfkeys[16] = strdup("\x1BOt");
  4817.         udkfkeys[17] = strdup("\x1BOu");
  4818.         udkfkeys[18] = strdup("\x1BOv");
  4819.         udkfkeys[19] = strdup("\x1BOw");
  4820.         udkfkeys[20] = strdup("\x1BOx");
  4821.         udkfkeys[21] = strdup("\x1BOy");
  4822.         udkfkeys[22] = strdup("\x1BOz");
  4823.         udkfkeys[23] = strdup("\x1BOa");
  4824.         udkfkeys[24] = strdup("\x1BOP");
  4825.         udkfkeys[25] = strdup("\x1BOQ");
  4826.         udkfkeys[26] = strdup("\x1BOR");
  4827.         udkfkeys[27] = strdup("\x1BOS");
  4828.         udkfkeys[28] = strdup("\x1BOT");
  4829.         udkfkeys[29] = strdup("\x1BOU");
  4830.         udkfkeys[30] = strdup("\x1BOV");
  4831.         udkfkeys[31] = strdup("\x1BOW");
  4832.         udkfkeys[32] = strdup("\x1BOX");
  4833.         udkfkeys[33] = strdup("\x1BOY");
  4834.         udkfkeys[34] = strdup("\x1BOZ");
  4835.         udkfkeys[35] = strdup("\x1BOA");
  4836.         udkfkeys[36] = strdup("\x1BOp");
  4837.         udkfkeys[37] = strdup("\x1BOq");
  4838.         udkfkeys[38] = strdup("\x1BOr");
  4839.         udkfkeys[39] = strdup("\x1BOs");
  4840.         udkfkeys[40] = strdup("\x1BOt");
  4841.         udkfkeys[41] = strdup("\x1BOu");
  4842.         udkfkeys[42] = strdup("\x1BOv");
  4843.         udkfkeys[43] = strdup("\x1BOw");
  4844.         udkfkeys[44] = strdup("\x1BOx");
  4845.         udkfkeys[45] = strdup("\x1BOy");
  4846.         udkfkeys[46] = strdup("\x1BOz");
  4847.         udkfkeys[47] = strdup("\x1BOa");
  4848.         udkfkeys[48] = strdup("\x1B[H");
  4849.         udkfkeys[49] = strdup("\x1B[A");
  4850.         udkfkeys[50] = strdup("\x1B[V");
  4851.         udkfkeys[51] = strdup("\x1B[S");
  4852.         udkfkeys[52] = strdup("\x1B[D");
  4853.         udkfkeys[53] = strdup("\x1B[G");
  4854.         udkfkeys[54] = strdup("\x1B[C");
  4855.         udkfkeys[55] = strdup("\x1B[T");
  4856.         udkfkeys[56] = strdup("\x1B[Y");
  4857.         udkfkeys[57] = strdup("\x1B[B");
  4858.         udkfkeys[58] = strdup("\x1B[U");
  4859.         udkfkeys[59] = strdup("\x1B[@");
  4860.         udkfkeys[60] = strdup("\x1B[2");
  4861.     }
  4862.  
  4863.     if ( ISSCO(tt_type_mode) ) {
  4864.         udkfkeys[0]  = strdup("\x1B[M");
  4865.         udkfkeys[1]  = strdup("\x1B[N");
  4866.         udkfkeys[2]  = strdup("\x1B[O");
  4867.         udkfkeys[3]  = strdup("\x1B[P");
  4868.         udkfkeys[4]  = strdup("\x1B[Q");
  4869.         udkfkeys[5]  = strdup("\x1B[R");
  4870.         udkfkeys[6]  = strdup("\x1B[S");
  4871.         udkfkeys[7]  = strdup("\x1B[T");
  4872.         udkfkeys[8]  = strdup("\x1B[U");
  4873.         udkfkeys[9]  = strdup("\x1B[V");
  4874.         udkfkeys[10] = strdup("\x1B[W");
  4875.         udkfkeys[11] = strdup("\x1B[X");
  4876.         udkfkeys[12] = strdup("\x1B[Y");
  4877.         udkfkeys[13] = strdup("\x1B[Z");
  4878.         udkfkeys[14] = strdup("\x1B[a");
  4879.         udkfkeys[15] = strdup("\x1B[b");
  4880.         udkfkeys[16] = strdup("\x1B[c");
  4881.         udkfkeys[17] = strdup("\x1B[d");
  4882.         udkfkeys[18] = strdup("\x1B[e");
  4883.         udkfkeys[19] = strdup("\x1B[f");
  4884.         udkfkeys[20] = strdup("\x1B[g");
  4885.         udkfkeys[21] = strdup("\x1B[h");
  4886.         udkfkeys[22] = strdup("\x1B[i");
  4887.         udkfkeys[23] = strdup("\x1B[j");
  4888.         udkfkeys[24] = strdup("\x1B[k");
  4889.         udkfkeys[25] = strdup("\x1B[l");
  4890.         udkfkeys[26] = strdup("\x1B[m");
  4891.         udkfkeys[27] = strdup("\x1B[n");
  4892.         udkfkeys[28] = strdup("\x1B[o");
  4893.         udkfkeys[29] = strdup("\x1B[p");
  4894.         udkfkeys[30] = strdup("\x1B[q");
  4895.         udkfkeys[31] = strdup("\x1B[r");
  4896.         udkfkeys[32] = strdup("\x1B[s");
  4897.         udkfkeys[33] = strdup("\x1B[t");
  4898.         udkfkeys[34] = strdup("\x1B[u");
  4899.         udkfkeys[35] = strdup("\x1B[v");
  4900.         udkfkeys[36] = strdup("\x1B[w");
  4901.         udkfkeys[37] = strdup("\x1B[x");
  4902.         udkfkeys[38] = strdup("\x1B[y");
  4903.         udkfkeys[39] = strdup("\x1B[z");
  4904.         udkfkeys[40] = strdup("\x1B[@");
  4905.         udkfkeys[41] = strdup("\x1B[[");
  4906.         udkfkeys[42] = strdup("\x1B[\\");
  4907.         udkfkeys[43] = strdup("\x1B[]");
  4908.         udkfkeys[44] = strdup("\x1B[^");
  4909.         udkfkeys[45] = strdup("\x1B[_");
  4910.         udkfkeys[46] = strdup("\x1B[`");
  4911.         udkfkeys[47] = strdup("\x1B[{");
  4912.         udkfkeys[48] = strdup("\x1B[H");
  4913.         udkfkeys[49] = strdup("\x1B[A");
  4914.         udkfkeys[50] = strdup("\x1B[I");
  4915.         udkfkeys[51] = strdup("-");
  4916.         udkfkeys[52] = strdup("\x1B[D");
  4917.         udkfkeys[53] = strdup("\x1B[E");
  4918.         udkfkeys[54] = strdup("\x1B[C");
  4919.         udkfkeys[55] = strdup("+");
  4920.         udkfkeys[56] = strdup("\x1B[F");
  4921.         udkfkeys[57] = strdup("\x1B[B");
  4922.         udkfkeys[58] = strdup("\x1B[G");
  4923.         udkfkeys[59] = strdup("\x1B[L");
  4924.     }
  4925.  
  4926.     if ( ISLINUX(tt_type_mode) ) {
  4927.         udkfkeys[0]  = strdup("\x1B[[A");
  4928.         udkfkeys[1]  = strdup("\x1B[[B");
  4929.         udkfkeys[2]  = strdup("\x1B[[C");
  4930.         udkfkeys[3]  = strdup("\x1B[[D");
  4931.         udkfkeys[4]  = strdup("\x1B[[E");
  4932.         udkfkeys[5]  = strdup("\x1B[17~");
  4933.         udkfkeys[6]  = strdup("\x1B[18~");
  4934.         udkfkeys[7]  = strdup("\x1B[19~");
  4935.         udkfkeys[8]  = strdup("\x1B[20~");
  4936.         udkfkeys[9]  = strdup("\x1B[21~");
  4937.         udkfkeys[10] = strdup("\x1B[23~");
  4938.         udkfkeys[11] = strdup("\x1B[24~");
  4939.         udkfkeys[12] = strdup("\x1B[25~");
  4940.         udkfkeys[13] = strdup("\x1B[26~");
  4941.         udkfkeys[14] = strdup("\x1B[28~");
  4942.         udkfkeys[15] = strdup("\x1B[29~");
  4943.         udkfkeys[16] = strdup("\x1B[31~");
  4944.         udkfkeys[17] = strdup("\x1B[32~");
  4945.         udkfkeys[18] = strdup("\x1B[33~");
  4946.         udkfkeys[19] = strdup("\x1B[34~");
  4947.         udkfkeys[20] = strdup("\x1B[35~");
  4948.         udkfkeys[21] = strdup("\x1B[36~");
  4949.         udkfkeys[22] = strdup("\x1B[37~");
  4950.         udkfkeys[23] = strdup("\x1B[38~");
  4951.         udkfkeys[24] = strdup("\x1B[39~");
  4952.         udkfkeys[25] = strdup("\x1B[40~");
  4953.         udkfkeys[26] = strdup("\x1B[41~");
  4954.         udkfkeys[27] = strdup("\x1B[42~");
  4955.         udkfkeys[28] = strdup("\x1B[43~");
  4956.         udkfkeys[29] = strdup("\x1B[44~");
  4957.         udkfkeys[30] = strdup("\x1B[45~");
  4958.         udkfkeys[31] = strdup("\x1B[46~");
  4959.         udkfkeys[32] = strdup("\x1B[47~");
  4960.         udkfkeys[33] = strdup("\x1B[48~");
  4961.         udkfkeys[34] = strdup("\x1B[49~");
  4962.         udkfkeys[35] = strdup("\x1B[50~");
  4963.         udkfkeys[36] = strdup("\x1B[51~");
  4964.         udkfkeys[37] = strdup("\x1B[52~");
  4965.         udkfkeys[38] = strdup("\x1B[53~");
  4966.         udkfkeys[39] = strdup("\x1B[54~");
  4967.         udkfkeys[40] = strdup("\x1B[55~");
  4968.         udkfkeys[41] = strdup("\x1B[56~");
  4969.         udkfkeys[42] = strdup("\x1B[57~");
  4970.         udkfkeys[43] = strdup("\x1B[58~");
  4971.         udkfkeys[44] = strdup("\x1B[59~");
  4972.         udkfkeys[45] = strdup("\x1B[60~");
  4973.         udkfkeys[46] = strdup("\x1B[61~");
  4974.         udkfkeys[47] = strdup("\x1B[62~");
  4975.         udkfkeys[48] = strdup("\x1B[1~");       /* home */
  4976.         udkfkeys[49] = strdup("\x1B[A");        /* up */
  4977.         udkfkeys[50] = strdup("\x1B[5~");
  4978.         udkfkeys[51] = strdup("-");
  4979.         udkfkeys[52] = strdup("\x1B[D");
  4980.         udkfkeys[53] = strdup("\x1B[G");
  4981.         udkfkeys[54] = strdup("\x1B[C");
  4982.         udkfkeys[55] = strdup("+");
  4983.         udkfkeys[56] = strdup("\x1B[4~");
  4984.         udkfkeys[57] = strdup("\x1B[B");
  4985.         udkfkeys[58] = strdup("\x1B[6~");
  4986.         udkfkeys[59] = strdup("\x1B[2~");
  4987.         udkfkeys[60] = strdup("\x1B[3~");
  4988.     }
  4989.  
  4990.     if ( ISHP(tt_type_mode) ) {
  4991.         udkfkeys[0]  = strdup("\x1Bp");
  4992.         udkfkeys[1]  = strdup("\x1Bq");
  4993.         udkfkeys[2]  = strdup("\x1Br");
  4994.         udkfkeys[3]  = strdup("\x1Bs");
  4995.         udkfkeys[4]  = strdup("\x1Bt");
  4996.         udkfkeys[5]  = strdup("\x1Bu");
  4997.         udkfkeys[6]  = strdup("\x1Bv");
  4998.         udkfkeys[7]  = strdup("\x1Bw");
  4999.         udkfkeys[8]  = NULL;
  5000.         udkfkeys[9]  = NULL;
  5001.         udkfkeys[10] = NULL;
  5002.         udkfkeys[11] = NULL;
  5003.         udkfkeys[12] = NULL;
  5004.         udkfkeys[13] = NULL;
  5005.         udkfkeys[14] = NULL;
  5006.         udkfkeys[15] = NULL;
  5007.         udkfkeys[16] = strdup("\x1Bi");
  5008.         udkfkeys[17] = strdup("\r");
  5009.         udkfkeys[18] = strdup("\r");
  5010.     }
  5011.  
  5012.     if ( ISDG200(tt_type_mode) ) {
  5013.         /* function keys */
  5014.         udkfkeys[0]  = strdup("\036q");
  5015.         udkfkeys[1]  = strdup("\036r");
  5016.         udkfkeys[2]  = strdup("\036s");
  5017.         udkfkeys[3]  = strdup("\036t");
  5018.         udkfkeys[4]  = strdup("\036u");
  5019.         udkfkeys[5]  = strdup("\036v");
  5020.         udkfkeys[6]  = strdup("\036w");
  5021.         udkfkeys[7]  = strdup("\036x");
  5022.         udkfkeys[8]  = strdup("\036y");
  5023.         udkfkeys[9]  = strdup("\036z");
  5024.         udkfkeys[10] = strdup("\036{");
  5025.         udkfkeys[11] = strdup("\036|");
  5026.         udkfkeys[12] = strdup("\036}");
  5027.         udkfkeys[13] = strdup("\036~");
  5028.         udkfkeys[14] = strdup("\036p");
  5029.         udkfkeys[15] = strdup("\036a");
  5030.         udkfkeys[16] = strdup("\036b");
  5031.         udkfkeys[17] = strdup("\036c");
  5032.         udkfkeys[18] = strdup("\036d");
  5033.         udkfkeys[19] = strdup("\036e");
  5034.         udkfkeys[20] = strdup("\036f");
  5035.         udkfkeys[21] = strdup("\036g");
  5036.         udkfkeys[22] = strdup("\036h");
  5037.         udkfkeys[23] = strdup("\036i");
  5038.         udkfkeys[24] = strdup("\036j");
  5039.         udkfkeys[25] = strdup("\036k");
  5040.         udkfkeys[26] = strdup("\036l");
  5041.         udkfkeys[27] = strdup("\036m");
  5042.         udkfkeys[28] = strdup("\036n");
  5043.         udkfkeys[29] = strdup("\036`");
  5044.         udkfkeys[30] = strdup("\0361");
  5045.         udkfkeys[31] = strdup("\0362");
  5046.         udkfkeys[32] = strdup("\0363");
  5047.         udkfkeys[33] = strdup("\0364");
  5048.         udkfkeys[34] = strdup("\0365");
  5049.         udkfkeys[35] = strdup("\0366");
  5050.         udkfkeys[36] = strdup("\0367");
  5051.         udkfkeys[37] = strdup("\0368");
  5052.         udkfkeys[38] = strdup("\0369");
  5053.         udkfkeys[39] = strdup("\036:");
  5054.         udkfkeys[40] = strdup("\036;");
  5055.         udkfkeys[41] = strdup("\036<");
  5056.         udkfkeys[42] = strdup("\036=");
  5057.         udkfkeys[43] = strdup("\036>");
  5058.         udkfkeys[44] = strdup("\0360");
  5059.         udkfkeys[45] = strdup("\036!");
  5060.         udkfkeys[46] = strdup("\036\"");
  5061.         udkfkeys[47] = strdup("\036#");
  5062.         udkfkeys[48] = strdup("\036$");
  5063.         udkfkeys[49] = strdup("\036%");
  5064.         udkfkeys[50] = strdup("\036&");
  5065.         udkfkeys[51] = strdup("\036'");
  5066.         udkfkeys[52] = strdup("\036(");
  5067.         udkfkeys[53] = strdup("\036)");
  5068.         udkfkeys[54] = strdup("\036*");
  5069.         udkfkeys[55] = strdup("\036+");
  5070.         udkfkeys[56] = strdup("\036,");
  5071.         udkfkeys[57] = strdup("\036-");
  5072.         udkfkeys[58] = strdup("\036.");
  5073.         udkfkeys[59] = strdup("\036 ");
  5074.  
  5075.         /* arrow keys - native */
  5076.         udkfkeys[60] = strdup("\027");
  5077.         udkfkeys[61] = strdup("\032");
  5078.         udkfkeys[62] = strdup("\031");
  5079.         udkfkeys[63] = strdup("\030");
  5080.         udkfkeys[64] = strdup("\036\027");
  5081.         udkfkeys[65] = strdup("\036\032");
  5082.         udkfkeys[66] = strdup("\036\031");
  5083.         udkfkeys[67] = strdup("\036\030");
  5084.  
  5085.         /* other - native */
  5086.         udkfkeys[68] = strdup("\014");
  5087.         udkfkeys[69] = strdup("\036\\");
  5088.         udkfkeys[70] = strdup("\036]");
  5089.         udkfkeys[71] = strdup("\013");
  5090.         udkfkeys[72] = strdup("\036^");
  5091.         udkfkeys[73] = strdup("\036_");
  5092.         udkfkeys[74] = strdup("\036\021");
  5093.         udkfkeys[75] = strdup("\010");
  5094.         udkfkeys[76] = strdup("\014");
  5095.         udkfkeys[77] = strdup("\036X");
  5096.         udkfkeys[78] = strdup("\036Y");
  5097.         udkfkeys[79] = strdup("\013");
  5098.         udkfkeys[80] = strdup("\036Z");
  5099.         udkfkeys[81] = strdup("\036{");
  5100.         udkfkeys[82] = strdup("\036\001");
  5101.         udkfkeys[83] = strdup("\031");
  5102.         udkfkeys[84] = strdup("\036\010");
  5103.  
  5104.         /* arrow keys - unix mode */
  5105.         udkfkeys[85] = strdup("\036PA");
  5106.         udkfkeys[86] = strdup("\036PB");
  5107.         udkfkeys[87] = strdup("\036PD");
  5108.         udkfkeys[88] = strdup("\036PC");
  5109.         udkfkeys[89] = strdup("\036Pa");
  5110.         udkfkeys[90] = strdup("\036Pb");
  5111.         udkfkeys[91] = strdup("\036Pd");
  5112.         udkfkeys[92] = strdup("\036Pc");
  5113.  
  5114.         /* other - unix mode */
  5115.         udkfkeys[93] = strdup("\036PH");
  5116.         udkfkeys[94] = strdup("\036\\");
  5117.         udkfkeys[95] = strdup("\036]");
  5118.         udkfkeys[96] = strdup("\036PE");
  5119.         udkfkeys[97] = strdup("\036^");
  5120.         udkfkeys[98] = strdup("\036_");
  5121.         udkfkeys[99] = strdup("\036P0");
  5122.         udkfkeys[100] = strdup("\036PF");
  5123.         udkfkeys[101] = strdup("\036PH");
  5124.         udkfkeys[102] = strdup("\036X");
  5125.         udkfkeys[103] = strdup("\036Y");
  5126.         udkfkeys[104] = strdup("\036PE");
  5127.         udkfkeys[105] = strdup("\036Z");
  5128.         udkfkeys[106] = strdup("\036[");
  5129.         udkfkeys[107] = strdup("\036P1");
  5130.         udkfkeys[108] = strdup("\177");
  5131.         udkfkeys[109] = strdup("\036Pf");
  5132.     }
  5133.  
  5134.     if ( IS97801(tt_type_mode) ) {
  5135.         udkfkeys[0]   = strdup("\033@");
  5136.         udkfkeys[1]   = strdup("\033A");
  5137.         udkfkeys[2]   = strdup("\033B");
  5138.         udkfkeys[3]   = strdup("\033C");
  5139.         udkfkeys[4]   = strdup("\033D");
  5140.         udkfkeys[5]   = strdup("\033F");
  5141.         udkfkeys[6]   = strdup("\033G");
  5142.         udkfkeys[7]   = strdup("\033H");
  5143.         udkfkeys[8]   = strdup("\033I");
  5144.         udkfkeys[9]   = strdup("\033J");
  5145.         udkfkeys[10]  = strdup("\033K");
  5146.         udkfkeys[11]  = strdup("\033L");
  5147.         udkfkeys[12]  = strdup("\033M");
  5148.         udkfkeys[13]  = strdup("\033N");
  5149.         udkfkeys[14]  = strdup("\033O");
  5150.         udkfkeys[15]  = strdup("\033P");
  5151.         udkfkeys[16]  = strdup("\0330");
  5152.         udkfkeys[17]  = strdup("\033_");
  5153.         udkfkeys[18]  = strdup("\033d");
  5154.         udkfkeys[19]  = strdup("\033T");
  5155.         udkfkeys[20]  = strdup("\033V");
  5156.         udkfkeys[21]  = strdup("\033X");
  5157.         udkfkeys[22]  = strdup("\0334");
  5158.         udkfkeys[23]  = strdup("\033g");
  5159.         udkfkeys[24]  = strdup("\x09");
  5160.         udkfkeys[25]  = strdup("\033[Z");
  5161.         udkfkeys[26]  = strdup("\033^");
  5162.         udkfkeys[27]  = strdup("\033>");
  5163.         udkfkeys[28]  = strdup("\033m");
  5164.         udkfkeys[29]  = strdup("\004");
  5165.         udkfkeys[30]  = strdup("\033[S");
  5166.         udkfkeys[31]  = strdup("\033[T");
  5167.         udkfkeys[32]  = strdup("\033[H");
  5168.         udkfkeys[33]  = strdup("\033[P");
  5169.         udkfkeys[34]  = strdup("\033[A");
  5170.         udkfkeys[35]  = strdup("\033p");
  5171.         udkfkeys[36]  = strdup("\033[D");
  5172.         udkfkeys[37]  = strdup("\033!");
  5173.         udkfkeys[38]  = strdup("\033[C");
  5174.         udkfkeys[39]  = strdup("\033[M");
  5175.         udkfkeys[40]  = strdup("\033[B");
  5176.         udkfkeys[41]  = strdup("00");
  5177.         udkfkeys[42]  = strdup("\033z");
  5178.         udkfkeys[43]  = strdup("\033]");
  5179.         udkfkeys[44]  = strdup("\033[@");
  5180.         udkfkeys[45]  = strdup("\033o");
  5181.         udkfkeys[46]  = strdup("\033[L");
  5182.         udkfkeys[47]  = strdup("\0336");
  5183.         udkfkeys[48]  = strdup("\0337");
  5184.         udkfkeys[49]  = strdup("\0338");
  5185.         udkfkeys[50]  = strdup("\033l");
  5186.         udkfkeys[51]  = strdup("\033Z");
  5187.         udkfkeys[52]  = strdup("\033 ");
  5188.         udkfkeys[53]  = strdup("\033;");
  5189.         udkfkeys[54]  = strdup("\033\"");
  5190.         udkfkeys[55]  = strdup("\033#");
  5191.         udkfkeys[56]  = strdup("\033$");
  5192.         udkfkeys[57]  = strdup("\033%");
  5193.         udkfkeys[58]  = strdup("\033&");
  5194.         udkfkeys[59]  = strdup("\033\\");
  5195.         udkfkeys[60]  = strdup("\033<");
  5196.         udkfkeys[61]  = strdup("\033=");
  5197.         udkfkeys[62]  = strdup("\033 ");
  5198.         udkfkeys[63]  = strdup("\033+");
  5199.         udkfkeys[64]  = strdup("\033,");
  5200.         udkfkeys[65]  = strdup("\033_");
  5201.         udkfkeys[66]  = strdup("\033.");
  5202.         udkfkeys[67]  = strdup("\033/");
  5203.         udkfkeys[68]  = strdup("\0331");
  5204.         udkfkeys[69]  = strdup("\0332");
  5205.         udkfkeys[70]  = strdup("\0333");
  5206.         udkfkeys[71]  = strdup("\033U");
  5207.         udkfkeys[72]  = strdup("\033W");
  5208.         udkfkeys[73]  = strdup("\033Y");
  5209.         udkfkeys[74]  = strdup("\0335");
  5210.         udkfkeys[75]  = strdup("\033g");
  5211.         udkfkeys[76]  = strdup("\033[Z");
  5212.         udkfkeys[77]  = strdup("\033[Z");
  5213.         udkfkeys[78]  = strdup("\033^");
  5214.         udkfkeys[79]  = strdup("\033>");
  5215.         udkfkeys[80]  = strdup("\033m");
  5216.         udkfkeys[81]  = strdup("\033~");
  5217.         udkfkeys[82]  = strdup("\033[S");
  5218.         udkfkeys[83]  = strdup("\033[T");
  5219.         udkfkeys[84]  = strdup("\033q");
  5220.         udkfkeys[85]  = strdup("\033[P");
  5221.         udkfkeys[86]  = strdup("\033[A");
  5222.         udkfkeys[87]  = strdup("\033p");
  5223.         udkfkeys[88]  = strdup("\0339");
  5224.         udkfkeys[89]  = strdup("\033~");
  5225.         udkfkeys[90]  = strdup("\033:");
  5226.         udkfkeys[91]  = strdup("\033[M");
  5227.         udkfkeys[92]  = strdup("\033[B");
  5228.         udkfkeys[93]  = strdup("00");
  5229.         udkfkeys[94]  = strdup("\033z");
  5230.         udkfkeys[95]  = strdup("\033]");
  5231.         udkfkeys[96]  = strdup("\033[@");
  5232.         udkfkeys[97]  = strdup("\033o");
  5233.         udkfkeys[98]  = strdup("\033[L");
  5234.         udkfkeys[99]  = strdup("\0336");
  5235.         udkfkeys[100]  = strdup("\0337");
  5236.         udkfkeys[101]  = strdup("\0338");
  5237.         udkfkeys[102] = strdup("\033l");
  5238.         udkfkeys[103] = strdup("\033Z");
  5239.         /* Ctrl key definitions default to NULL */
  5240.     }
  5241.  
  5242.     if ( ISBA80(tt_type_mode) ) {
  5243.         udkfkeys[0]   = strdup("\033[=N1\015");
  5244.         udkfkeys[1]   = strdup("\033[=N2\015");
  5245.         udkfkeys[2]   = strdup("\033[=N3\015");
  5246.         udkfkeys[3]   = strdup("\033[=N4\015");
  5247.         udkfkeys[4]   = strdup("\033[=N5\015");
  5248.         udkfkeys[5]   = strdup("\033[=N6\015");
  5249.         udkfkeys[6]   = strdup("\033[=N7\015");
  5250.         udkfkeys[7]   = strdup("\033[=N8\015");
  5251.         udkfkeys[8]   = strdup("\033[=N9\015");
  5252.         udkfkeys[9]   = strdup("\033[=>a");
  5253.         udkfkeys[10]  = strdup("\033[=>b");
  5254.         udkfkeys[11]  = strdup("\033[=>c");
  5255.         udkfkeys[12]  = strdup("\033[=>d");
  5256.         udkfkeys[13]  = strdup("\033[=>e");
  5257.         udkfkeys[14]  = strdup("\033[=>f");
  5258.         udkfkeys[15]  = strdup("\033[=>g");
  5259.         udkfkeys[16]  = strdup("\033[=>h");
  5260.         udkfkeys[17]  = strdup("\033[=>i");
  5261.         udkfkeys[18]  = strdup("\033[=>j");
  5262.         udkfkeys[19]  = strdup("\033[=>k");
  5263.         udkfkeys[20]  = strdup("\033[=>l");
  5264.         udkfkeys[21]  = strdup("\033[=>m");
  5265.         udkfkeys[22]  = strdup("\033[=>n");
  5266.         udkfkeys[23]  = strdup("\033[=>o");
  5267.         udkfkeys[24]  = strdup("\033[=>p");
  5268.         udkfkeys[25]  = strdup("\033[=>q");
  5269.         udkfkeys[26]  = strdup("\033[=>r");
  5270.         udkfkeys[27]  = strdup("\033[=>s");
  5271.         udkfkeys[28]  = strdup("\033[=>t");
  5272.         udkfkeys[29]  = strdup("\033[=>u");
  5273.         udkfkeys[30]  = strdup("\033[=>v");
  5274.         udkfkeys[31]  = strdup("\033[=>w");
  5275.         udkfkeys[32]  = strdup("\033[=>x");
  5276.         udkfkeys[33]  = strdup("\033[=<0");
  5277.         udkfkeys[34]  = strdup("\033[=<1");
  5278.         udkfkeys[35]  = strdup("\033[=<2");
  5279.         udkfkeys[36]  = strdup("\033[=<4");
  5280.         udkfkeys[37]  = strdup("\033[=<5");
  5281.         udkfkeys[38]  = strdup("\033[=<6");
  5282.         udkfkeys[39]  = strdup("\033[=<7");
  5283.         udkfkeys[40]  = strdup("\033[=<8");
  5284.         udkfkeys[41]  = strdup("\033[=<9");
  5285.         udkfkeys[42]  = strdup("\033[=<f");
  5286.         udkfkeys[43]  = strdup("\033[=<g");
  5287.         udkfkeys[44]  = strdup("\033[=<p");
  5288.         udkfkeys[45]  = strdup("\033[=<B");
  5289.         udkfkeys[46]  = strdup("\033[=<F");
  5290.         udkfkeys[47]  = strdup("\033[=<G");
  5291.         udkfkeys[48]  = strdup("\033[=<H");
  5292.         udkfkeys[49]  = strdup("\033[=<I");
  5293.         udkfkeys[50]  = strdup("\033[=<J");
  5294.         udkfkeys[51]  = strdup("\033[=<K");
  5295.         udkfkeys[52]  = strdup("\033[=<L");
  5296.         udkfkeys[53]  = strdup("\033[=<M");
  5297.         udkfkeys[54]  = strdup("\033[=<O");
  5298.         udkfkeys[55]  = strdup("\033[=<P");
  5299.         udkfkeys[56]  = strdup("\033[=<Q");
  5300.         udkfkeys[57]  = strdup("\033[=<R");
  5301.         udkfkeys[58]  = strdup("\033[=<T");
  5302.         udkfkeys[59]  = strdup("\033[=<U");
  5303.         udkfkeys[60]  = strdup("\033[=<V");
  5304.         udkfkeys[61]  = strdup("\033[=<W");
  5305.     }
  5306.  
  5307.     if (ISSUN(tt_type_mode)) {
  5308.         udkfkeys[0]   = strdup("\033[192z");   /* K_SUN_STOP        */
  5309.         udkfkeys[1]   = strdup("\033[193z");   /* K_SUN_AGAIN       */
  5310.         udkfkeys[2]   = strdup("\033[194z");   /* K_SUN_PROPS       */
  5311.         udkfkeys[3]   = strdup("\033[195z");   /* K_SUN_UNDO        */
  5312.         udkfkeys[4]   = strdup("\033[196z");   /* K_SUN_FRONT       */
  5313.         udkfkeys[5]   = strdup("\033[197z");   /* K_SUN_COPY        */
  5314.         udkfkeys[6]   = strdup("\033[198z");   /* K_SUN_OPEN        */
  5315.         udkfkeys[7]   = strdup("\033[199z");   /* K_SUN_PASTE       */
  5316.         udkfkeys[8]   = strdup("\033[200z");   /* K_SUN_FIND        */
  5317.         udkfkeys[9]   = strdup("\033[201z");   /* K_SUN_CUT         */
  5318.         udkfkeys[10]  = strdup("\033[207z");   /* K_SUN_HELP        */
  5319.     }
  5320.  
  5321.     if (ISIBM31(tt_type_mode)) {
  5322.         extern int i31_lta;
  5323.         int i,j;
  5324.  
  5325.         udkfkeys[0]   = strdup("\033a\003");   /* K_I31_F01         */
  5326.         udkfkeys[1]   = strdup("\033b\003");   /* K_I31_F02         */
  5327.         udkfkeys[2]   = strdup("\033c\003");   /* K_I31_F03         */
  5328.         udkfkeys[3]   = strdup("\033d\003");   /* K_I31_F04         */
  5329.         udkfkeys[4]   = strdup("\033e\003");   /* K_I31_F05         */
  5330.         udkfkeys[5]   = strdup("\033f\003");   /* K_I31_F06         */
  5331.         udkfkeys[6]   = strdup("\033g\003");   /* K_I31_F07         */
  5332.         udkfkeys[7]   = strdup("\033h\003");   /* K_I31_F08         */
  5333.         udkfkeys[8]   = strdup("\033i\003");   /* K_I31_F09         */
  5334.         udkfkeys[9]   = strdup("\033j\003");   /* K_I31_F10         */
  5335.         udkfkeys[10]  = strdup("\033k\003");   /* K_I31_F11         */
  5336.         udkfkeys[11]  = strdup("\033l\003");   /* K_I31_F12         */
  5337.         udkfkeys[12]  = strdup("\033!a\003");  /* K_I31_F13         */
  5338.         udkfkeys[13]  = strdup("\033!b\003");  /* K_I31_F14         */
  5339.         udkfkeys[14]  = strdup("\033!c\003");  /* K_I31_F15         */
  5340.         udkfkeys[15]  = strdup("\033!d\003");  /* K_I31_F16         */
  5341.         udkfkeys[16]  = strdup("\033!e\003");  /* K_I31_F17         */
  5342.         udkfkeys[17]  = strdup("\033!f\003");  /* K_I31_F18         */
  5343.         udkfkeys[18]  = strdup("\033!g\003");  /* K_I31_F19         */
  5344.         udkfkeys[19]  = strdup("\033!h\003");  /* K_I31_F20         */
  5345.         udkfkeys[20]  = strdup("\033!i\003");  /* K_I31_F21         */
  5346.         udkfkeys[21]  = strdup("\033!j\003");  /* K_I31_F22         */
  5347.         udkfkeys[22]  = strdup("\033!k\003");  /* K_I31_F23         */
  5348.         udkfkeys[23]  = strdup("\033!l\003");  /* K_I31_F24         */
  5349.         udkfkeys[24]  = strdup("\033\"a\003"); /* K_I31_F25         */
  5350.         udkfkeys[25]  = strdup("\033\"b\003"); /* K_I31_F26         */
  5351.         udkfkeys[26]  = strdup("\033\"c\003"); /* K_I31_F27         */
  5352.         udkfkeys[27]  = strdup("\033\"d\003"); /* K_I31_F28         */
  5353.         udkfkeys[28]  = strdup("\033\"e\003"); /* K_I31_F29         */
  5354.         udkfkeys[29]  = strdup("\033\"f\003"); /* K_I31_F30         */
  5355.         udkfkeys[30]  = strdup("\033\"g\003"); /* K_I31_F31         */
  5356.         udkfkeys[31]  = strdup("\033\"h\003"); /* K_I31_F32         */
  5357.         udkfkeys[32]  = strdup("\033\"i\003"); /* K_I31_F33         */
  5358.         udkfkeys[33]  = strdup("\033\"j\003"); /* K_I31_F34         */
  5359.         udkfkeys[34]  = strdup("\033\"k\003"); /* K_I31_F35         */
  5360.         udkfkeys[35]  = strdup("\033\"l\003"); /* K_I31_F36         */
  5361.         udkfkeys[36]  = strdup("\033!m\003");  /* K_I31_PA1         */
  5362.         udkfkeys[37]  = strdup("\033!n\003");  /* K_I31_PA2         */
  5363.         udkfkeys[38]  = strdup("\033!o\003");  /* K_I31_PA3         */
  5364.         udkfkeys[39]  = strdup("\033!z");      /* K_I31_RESET       */
  5365.         udkfkeys[40]  = strdup("\033\"A");     /* K_I31_JUMP        */
  5366.         udkfkeys[41]  = strdup("\033L\003");   /* K_I31_CLEAR       */
  5367.         udkfkeys[42]  = strdup("\033I");       /* K_I31_ERASE_EOF   */
  5368.         udkfkeys[43]  = strdup("\033J");       /* K_I31_ERASE_EOP   */
  5369.         udkfkeys[44]  = strdup("\033K");       /* K_I31_ERASE_INP   */
  5370.         udkfkeys[45]  = strdup("\033P");       /* K_I31_INSERT_CHAR */
  5371.         udkfkeys[46]  = strdup("\033P \008");  /* K_I31_INSERT_SPACE*/
  5372.         udkfkeys[47]  = strdup("\033Q");       /* K_I31_DELETE      */
  5373.         udkfkeys[48]  = strdup("\033N");       /* K_I31_INS_LN      */
  5374.         udkfkeys[49]  = strdup("\033O");       /* K_I31_DEL_LN      */
  5375.         udkfkeys[50]  = strdup("\033U\003");   /* K_I31_PRINT_LINE  */
  5376.         udkfkeys[51]  = strdup("\033V\003");   /* K_I31_PRINT_MSG   */
  5377.         udkfkeys[52]  = strdup("\033W\003");   /* K_I31_PRINT_SHIFT */
  5378.         udkfkeys[53]  = strdup("\033 W\003");  /* K_I31_CANCEL      */
  5379.         udkfkeys[54]  = strdup("\033!8\003");  /* K_I31_SEND_LINE   */
  5380.         udkfkeys[55]  = strdup("\033 8\003");  /* K_I31_SEND_MSG    */
  5381.         udkfkeys[56]  = strdup("\0338\003");   /* K_I31_SEND_PAGE   */
  5382.         udkfkeys[57]  = strdup("\033H");       /* K_I31_HOME        */
  5383.         udkfkeys[58]  = strdup("\0332");       /* K_I31_BACK_TAB    */
  5384.  
  5385.         if ( i31_lta != ETX ) {
  5386.             for ( i=0;i<=58;i++ ) {
  5387.                 for ( j=strlen(udkfkeys[i])-1;j>=0;j-- ) {
  5388.                     if ( udkfkeys[i][j] == ETX )
  5389.                         udkfkeys[i][j] = i31_lta;
  5390.                 }
  5391.             }
  5392.         }
  5393.     }
  5394. }
  5395.  
  5396. void
  5397. showudk( void )
  5398. {
  5399. #ifndef NOKVERBS
  5400.     int i;
  5401.     printf("\n%s User Defined Keys:\n",
  5402.             ISSCO(tt_type)?"SCOANSI":
  5403.             ISAT386(tt_type)?"AT386":
  5404.             ISLINUX(tt_type)?"LINUX":
  5405.             ISANSI(tt_type)?"ANSI":
  5406.             ISWYSE(tt_type)?"WYSE":
  5407.             ISTVI(tt_type)?"TVI":
  5408.             ISH19(tt_type)?"HEATH":
  5409.             ISDG200(tt_type)?"DG":
  5410.             ISHP(tt_type)?"HP":
  5411.             IS97801(tt_type)?"SNI 97801-5XX":
  5412.             ISBA80(tt_type)?"Nixdorf BA80":
  5413.             ISIBM31(tt_type)?"IBM 31x1":
  5414.             ISSUN(tt_type)?"SUN":
  5415.             "DEC VT");
  5416.     printf("  Lock: %s\n\n", udklock ? "on": "off" ) ;
  5417.  
  5418.     if ( IS97801(tt_type) ) {
  5419.         for ( i=0; i<(K_SNI_MAX-K_SNI_MIN+1) ; i++ ) {
  5420.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5421.                 printf( "  snif%d = \\{%d}%s\n",i+1,
  5422.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5423.             else
  5424.                 printf( "  snif%d = %s\n",i+1,
  5425.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5426.         }
  5427.     }
  5428.     else if ( ISSUN(tt_type) ) {
  5429.         for ( i=0; i<=10 ; i++ ) {
  5430.             char * s = "" ;
  5431.             switch ( i ) {
  5432.             case 0: s = "sunstop"  ; break ;
  5433.             case 1: s = "sunagain" ; break ;
  5434.             case 2: s = "sunprops" ; break ;
  5435.             case 3: s = "sunundo"  ; break ;
  5436.             case 4: s = "sunfront" ; break ;
  5437.             case 5: s = "suncopy"  ; break ;
  5438.             case 6: s = "sunopen"  ; break ;
  5439.             case 7: s = "sunpaste" ; break ;
  5440.             case 8: s = "sunfind"  ; break ;
  5441.             case 9: s = "suncut"   ; break ;
  5442.             case 10: s = "sunhelp" ; break ;
  5443.             }
  5444.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5445.                 printf( "  %s = \\{%d}%s\n",s,
  5446.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5447.             else
  5448.                 printf( "  %s = %s\n",s,
  5449.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5450.         }
  5451.     }
  5452.     else if ( ISUNIXCON(tt_type) ) {
  5453.         for ( i=0; i<61 ; i++ ) {
  5454.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5455.                 printf( "  ansif%-3d = \\{%d}%s\n",i+1,
  5456.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5457.             else
  5458.                 printf( "  ansif%-3d = %s\n",i+1,
  5459.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5460.         }
  5461.     } 
  5462.     else if ( ISVT100(tt_type) )
  5463.         for ( i=1; i<=20 ; i++ )
  5464.         {
  5465.             if ( udkfkeys[i-1] && udkfkeys[i-1][0] < SP ) {
  5466.                 if ( i==15 )
  5467.                     printf("  udkdo   = \\{%d}%s\n",
  5468.                             udkfkeys[i-1][0],&(udkfkeys[i-1][1]));
  5469.                 else if ( i==16 )
  5470.                     printf("  udkhelp = \\{%d}%s\n",
  5471.                             udkfkeys[i-1][0],&(udkfkeys[i-1][1]));
  5472.                 else
  5473.                     printf("  udkf%-3d = \\{%d}%s\n",i,
  5474.                             udkfkeys[i-1][0],&(udkfkeys[i-1][1]));
  5475.             }
  5476.             else {
  5477.                 if ( i==15 )
  5478.                     printf("  udkdo   = %s\n",
  5479.                             udkfkeys[i-1]?udkfkeys[i-1]:"(unassigned)");
  5480.                 else if ( i==16 )
  5481.                     printf("  udkhelp = %s\n",
  5482.                             udkfkeys[i-1]?udkfkeys[i-1]:"(unassigned)");
  5483.                 else
  5484.                     printf("  udkf%-3d = %s\n",i,
  5485.                             udkfkeys[i-1]?udkfkeys[i-1]:"(unassigned)");
  5486.             }
  5487.         }
  5488.     else if ( ISWYSE(tt_type) ) {
  5489.         for ( i=0; i<20 ; i++ ) {
  5490.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5491.                 printf( "  wyf%-3d = \\{%d}%s\n",i+1,
  5492.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5493.             else
  5494.                 printf( "  wyf%-3d = %s\n",i+1,
  5495.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5496.         }
  5497.         for ( i=20; i<40 ; i++ ) {
  5498.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5499.                 printf( "  wysf%-3d = \\{%d}%s\n",i+1-20,
  5500.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5501.             else
  5502.                 printf( "  wysf%-3d = %s\n",i+1-20,
  5503.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5504.         }
  5505.         for ( i=40; i<75 ; i++ ) {
  5506.             char * s = "" ;
  5507.             switch ( i ) {
  5508.             case 40: s = "wybs"         ; break ;
  5509.             case 41: s = "wyclrln"      ; break ;
  5510.             case 42: s = "wysclrln"     ; break ;
  5511.             case 43: s = "wyclrpg"      ; break ;
  5512.             case 44: s = "wysclrpg"     ; break ;
  5513.             case 45: s = "wydelchar"    ; break ;
  5514.             case 46: s = "wydelln"      ; break ;
  5515.             case 47: s = "wyenter"      ; break ;
  5516.             case 48: s = "wyesc"        ; break ;
  5517.             case 49: s = "wyhome"       ; break ;
  5518.             case 50: s = "wyshome"      ; break ;
  5519.             case 51: s = "wyinsert"     ; break ;
  5520.             case 52: s = "wyinschar"    ; break ;
  5521.             case 53: s = "wyinsln"      ; break ;
  5522.             case 54: s = "wypgnext"     ; break ;
  5523.             case 55: s = "wypgprev"     ; break ;
  5524.             case 56: s = "wyreplace"    ; break ;
  5525.             case 57: s = "wyreturn"     ; break ;
  5526.             case 58: s = "wytab"        ; break ;
  5527.             case 59: s = "wystab"       ; break ;
  5528.             case 60: s = "wyprtscn"     ; break ;
  5529.             case 61: s = "wysesc"       ; break ;
  5530.             case 62: s = "wysbs"        ; break ;
  5531.             case 63: s = "wysenter"     ; break ;
  5532.             case 64: s = "wysreturn"    ; break ;
  5533.             case 65: s = "wyuparr"      ; break ;
  5534.             case 66: s = "wydnarr"      ; break ;
  5535.             case 67: s = "wylfarr"      ; break ;
  5536.             case 68: s = "wyrtarr"      ; break ;
  5537.             case 69: s = "wysuparr"     ; break ;
  5538.             case 70: s = "wysdnarr"     ; break ;
  5539.             case 71: s = "wyslfarr"     ; break ;
  5540.             case 72: s = "wysrtarr"     ; break ;
  5541.             case 73: s = "wysend"       ; break ;
  5542.             case 74: s = "wyssend"      ; break ;
  5543.             }
  5544.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5545.                 printf( "  %s = \\{%d}%s\n",s,
  5546.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5547.             else
  5548.                 printf( "  %s = %s\n",s,
  5549.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5550.         }
  5551.  
  5552.     }
  5553.     else if ( ISTVI(tt_type) ) {
  5554.         for ( i=0; i<15 ; i++ ) {
  5555.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5556.                 printf( "  tvif%-3d = \\{%d}%s\n",i+1,
  5557.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5558.             else
  5559.                 printf( "  tvif%-3d = %s\n",i+1,
  5560.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5561.         }
  5562.         for ( i=16; i<31 ; i++ ) {
  5563.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5564.                 printf( "  tvisf%-3d = \\{%d}%s\n",i+1-16,
  5565.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5566.             else
  5567.                 printf( "  tvisf%-3d = %s\n",i+1-16,
  5568.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5569.         }
  5570.         for ( i=32; i<67 ; i++ ) {
  5571.             char * s = "" ;
  5572.             switch ( i ) {
  5573.             case 32: s = "tvibs"        ; break ;
  5574.             case 33: s = "tviclrln"     ; break ;
  5575.             case 34: s = "tvisclrln"    ; break ;
  5576.             case 35: s = "tviclrpg"     ; break ;
  5577.             case 36: s = "tvisclrpg"    ; break ;
  5578.             case 37: s = "tvidelchar"   ; break ;
  5579.             case 38: s = "tvidelln"     ; break ;
  5580.             case 39: s = "tvienter"     ; break ;
  5581.             case 40: s = "tviesc"       ; break ;
  5582.             case 41: s = "tvihome"      ; break ;
  5583.             case 42: s = "tvishome"     ; break ;
  5584.             case 43: s = "tviinsert"    ; break ;
  5585.             case 44: s = "tviinschar"   ; break ;
  5586.             case 45: s = "tviinsln"     ; break ;
  5587.             case 46: s = "tvipgnext"    ; break ;
  5588.             case 47: s = "tvipgprev"    ; break ;
  5589.             case 48: s = "tvireplace"   ; break ;
  5590.             case 49: s = "tvireturn"    ; break ;
  5591.             case 50: s = "tvitab"       ; break ;
  5592.             case 51: s = "tvistab"      ; break ;
  5593.             case 52: s = "tviprtscn"    ; break ;
  5594.             case 53: s = "tvisesc"       ; break ;
  5595.             case 54: s = "tvisbs"        ; break ;
  5596.             case 55: s = "tvisenter"     ; break ;
  5597.             case 56: s = "tvisreturn"    ; break ;
  5598.             case 57: s = "tviuparr"      ; break ;
  5599.             case 58: s = "tvidnarr"      ; break ;
  5600.             case 59: s = "tvilfarr"      ; break ;
  5601.             case 60: s = "tvirtarr"      ; break ;
  5602.             case 61: s = "tvisuparr"     ; break ;
  5603.             case 62: s = "tvisdnarr"     ; break ;
  5604.             case 63: s = "tvislfarr"     ; break ;
  5605.             case 64: s = "tvisrtarr"     ; break ;
  5606.             case 65: s = "tvisend"       ; break ;
  5607.             case 66: s = "tvissend"      ; break ;
  5608.             }
  5609.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5610.                 printf( "  %s = \\{%d}%s\n",s,
  5611.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5612.             else
  5613.                 printf( "  %s = %s\n",s,
  5614.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5615.         }
  5616.     }
  5617.     else if ( ISDG200(tt_type) ) {
  5618.         for ( i=0; i<110 ; i++ ) {
  5619.             if ( udkfkeys[i] &&
  5620.                  (udkfkeys[i][0] < SP || udkfkeys[i][0] >= 127) )
  5621.                 printf( "  dgf%-3d = \\{%d}%s\n",i+1,
  5622.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5623.             else
  5624.                 printf( "  dgf%-3d = %s\n",i+1,
  5625.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5626.         }
  5627.     }
  5628.     else if ( ISHP(tt_type) ) {
  5629.         for ( i=0; i<=15 ; i++ ) {
  5630.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5631.                 printf( "  hpf%d = \\{%d}%s\n",i+1,
  5632.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5633.             else
  5634.                 printf( "  hpf%d = %s\n",i+1,
  5635.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5636.         }
  5637.         if ( udkfkeys[16] && udkfkeys[16][0] < SP )
  5638.             printf( "  hpbacktab = \\{%d}%s\n",
  5639.                     udkfkeys[16][0], &(udkfkeys[16][1]));
  5640.         else
  5641.             printf( "  hpbacktab = %s\n",
  5642.                     udkfkeys[16]?udkfkeys[16]:"(unassigned)");
  5643.         if ( udkfkeys[17] && udkfkeys[17][0] < SP )
  5644.             printf( "  hpenter = \\{%d}%s\n",
  5645.                     udkfkeys[17][0], &(udkfkeys[17][1]));
  5646.         else
  5647.             printf( "  hpenter = %s\n",
  5648.                     udkfkeys[17]?udkfkeys[17]:"(unassigned)");
  5649.         if ( udkfkeys[18] && udkfkeys[18][0] < SP )
  5650.             printf( "  hpreturn = \\{%d}%s\n",
  5651.                     udkfkeys[18][0], &(udkfkeys[18][1]));
  5652.         else
  5653.             printf( "  hpreturn = %s\n",
  5654.                     udkfkeys[18]?udkfkeys[18]:"(unassigned)");
  5655.  
  5656.     }
  5657.     else if ( ISIBM31(tt_type) ) {
  5658.         for ( i=0; i<(K_I31_MAX-K_I31_MIN+1) ; i++ ) {
  5659.             if ( udkfkeys[i] && udkfkeys[i][0] < SP )
  5660.                 printf( "  i31_f%d = \\{%d}%s\n",i+1,
  5661.                         udkfkeys[i][0], &(udkfkeys[i][1]));
  5662.             else
  5663.                 printf( "  i31_f%d = %s\n",i+1,
  5664.                         udkfkeys[i]?udkfkeys[i]:"(unassigned)");
  5665.         }
  5666.     }
  5667.     printf("\n");
  5668. #endif /* NOVKERBS */
  5669. }
  5670.  
  5671. void
  5672. SNI_bitmode(int bits) {
  5673.     int i;
  5674.     int cs;
  5675.  
  5676.     sni_bitmode = bits;
  5677.     if ( sni_bitmode == 7 ) {
  5678.                 /* Load National character set into G0/G1/G2/G3 */
  5679.                 /* GL to G0, GR to G1                           */
  5680.                 /* National keyboard is active                  */
  5681.                 for ( i = 0 ; i < 4 ; i++ ) {
  5682.                         G[i].designation = dec_nrc;
  5683.                         G[i].size = cs94 ;
  5684.                         G[i].c1 = TRUE ;
  5685.                         G[i].national = CSisNRC(dec_nrc);
  5686.                         G[i].rtoi = xl_u[dec_nrc];
  5687.                         if ( isunicode() ) {
  5688.                                 G[i].itol = NULL ;
  5689.                                 G[i].ltoi = NULL ;
  5690.                         }
  5691.             else {
  5692.                 G[i].itol = xl_tx[tcsl] ;
  5693.                 G[i].ltoi = xl_u[tcsl] ;
  5694.             }
  5695.             G[i].itor = xl_tx[dec_nrc];
  5696.         }
  5697.         GL = &G[0];
  5698.         GR = &G[1];
  5699.     } else if ( sni_bitmode == 8 ) {
  5700.         /* US-ASCII to G0 (GL) */
  5701.         /* Brackets to G1      */
  5702.         /* Blanks to G2        */
  5703.         /* Latin 1 to G3 (GR)  */
  5704.         /* Latin 1 keyboard is active */
  5705.         for ( i = 0 ; i < 4 ; i++ ) {
  5706.             switch ( i ) {
  5707.             case 0: cs = TX_ASCII; break;
  5708.             case 1: cs = TX_SNIBRACK; break;
  5709.             case 2: cs = TX_SNIBLANK; break;
  5710.             case 3: cs = TX_8859_1; break;
  5711.             default:
  5712.                 cs = TX_ASCII;
  5713.             }
  5714.  
  5715.             G[i].designation = cs;
  5716.             G[i].size = cs94 ;
  5717.             G[i].c1 = TRUE ;
  5718.             G[i].national = CSisNRC(cs);
  5719.             G[i].rtoi = xl_u[cs];
  5720.             if ( isunicode() ) {
  5721.                 G[i].itol = NULL ;
  5722.                 G[i].ltoi = NULL ;
  5723.             }
  5724.             else {
  5725.                 G[i].itol = xl_tx[tcsl] ;
  5726.                 G[i].ltoi = xl_u[tcsl] ;
  5727.             }
  5728.             G[i].itor = xl_tx[cs];
  5729.         }
  5730.         GL = &G[0];
  5731.         GR = &G[3];
  5732.     }
  5733. }
  5734.  
  5735. void
  5736. SNI_chcode( int state ) {
  5737.     int    x,y;
  5738.     USHORT w,h;
  5739.     USHORT ch;
  5740.  
  5741.     if ( sni_bitmode == 7 ) {
  5742.         if (!sni_chcode_7 || sni_chcode == state)
  5743.             return;
  5744.  
  5745.         sni_chcode = state;
  5746.         if ( sni_chcode ) {
  5747.             /* if the current National language is German then convert */
  5748.             /* NRC characters to US-ASCII characters in the current    */
  5749.             /* screen.
  5750.             */
  5751.             if ( G[0].designation == TX_GERMAN ) {
  5752.                 w = VscrnGetWidth(VTERM);
  5753.                 h = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  5754.                 for (y = 0; y < h; y++) {
  5755.                     for ( x = 0 ; x < w; x++ ) {
  5756.                         ch = VscrnGetCell( VTERM, x, y )->c;
  5757.                         if ( !isunicode() )
  5758.                             ch = xl_u[tcsl](ch);
  5759.                         switch ( ch ) {
  5760.                         case 0xA7: ch = '@'; break;
  5761.                         case 0xC4: ch = '['; break;
  5762.                         case 0xD6: ch = '\\'; break;
  5763.                         case 0xDC: ch = ']'; break;
  5764.                         case 0xE4: ch = '{'; break;
  5765.                         case 0xF6: ch = '|'; break;
  5766.                         case 0xFC: ch = '}'; break;
  5767.                         case 0xDF: ch = '~'; break;
  5768.                         default:
  5769.                             continue;
  5770.                         }
  5771.                         VscrnGetCell( VTERM, x, y )->c = ch;
  5772.                     }
  5773.                 }
  5774.                 for ( x = 0 ; x < w; x++ ) {
  5775.                     ch = VscrnGetCell( VSTATUS, x, 0 )->c;
  5776.                     if ( !isunicode() )
  5777.                         ch = xl_u[tcsl](ch);
  5778.                     switch ( ch ) {
  5779.                     case 0xA7: ch = '@'; break;
  5780.                     case 0xC4: ch = '['; break;
  5781.                     case 0xD6: ch = '\\'; break;
  5782.                     case 0xDC: ch = ']'; break;
  5783.                     case 0xE4: ch = '{'; break;
  5784.                     case 0xF6: ch = '|'; break;
  5785.                     case 0xFC: ch = '}'; break;
  5786.                     case 0xDF: ch = '~'; break;
  5787.                     default:
  5788.                         continue;
  5789.                     }
  5790.                     VscrnGetCell( VSTATUS, x, 0 )->c = ch;
  5791.                 }
  5792.                 VscrnIsDirty(VTERM);
  5793.             }
  5794.         } else {
  5795.             /* if the current National language is German then convert */
  5796.             /* US-ASCII characters to NRC characters in the current    */
  5797.             /* screen.                                                 */
  5798.             if ( G[0].designation == TX_GERMAN ) {
  5799.                 w = VscrnGetWidth(VTERM);
  5800.                 h = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  5801.                 for (y = 0; y < h; y++) {
  5802.                     for ( x = 0 ; x < w; x++ ) {
  5803.                         ch = VscrnGetCell( VTERM, x, y )->c;
  5804.                         if ( !isunicode() )
  5805.                             ch = xl_u[tcsl](ch);
  5806.                         switch ( ch ) {
  5807.                         case '@': ch = 0xA7; break;
  5808.                         case '[': ch = 0xC4; break;
  5809.                         case '\\': ch = 0xD6; break;
  5810.                         case ']': ch = 0xDC; break;
  5811.                         case '{': ch = 0xE4; break;
  5812.                         case '|': ch = 0xF6; break;
  5813.                         case '}': ch = 0xFC; break;
  5814.                         case '~': ch = 0xDF; break;
  5815.                         default:
  5816.                             continue;
  5817.                         }
  5818.                         if ( !isunicode() ) {
  5819.                             ch = xl_tx[tcsl](ch);
  5820.                         }
  5821.                         VscrnGetCell( VTERM, x, y )->c = ch;
  5822.                     }
  5823.                 }
  5824.                 for ( x = 0 ; x < w; x++ ) {
  5825.                     ch = VscrnGetCell( VSTATUS, x, 0 )->c;
  5826.                     if ( !isunicode() )
  5827.                         ch = xl_u[tcsl](ch);
  5828.                     switch ( ch ) {
  5829.                     case '@': ch = 0xA7; break;
  5830.                     case '[': ch = 0xC4; break;
  5831.                     case '\\': ch = 0xD6; break;
  5832.                     case ']': ch = 0xDC; break;
  5833.                     case '{': ch = 0xE4; break;
  5834.                     case '|': ch = 0xF6; break;
  5835.                     case '}': ch = 0xFC; break;
  5836.                     case '~': ch = 0xDF; break;
  5837.                     default:
  5838.                         continue;
  5839.                     }
  5840.                     if ( !isunicode() ) {
  5841.                         ch = xl_tx[tcsl](ch);
  5842.                     }
  5843.                     VscrnGetCell( VSTATUS, x, 0 )->c = ch;
  5844.                 }
  5845.                 VscrnIsDirty(VTERM);
  5846.             }
  5847.         }
  5848.     } else if ( sni_bitmode == 8 ) {
  5849.         if (!sni_chcode_8)
  5850.             return;
  5851.  
  5852.         sni_chcode = state;
  5853.     }
  5854. }
  5855.  
  5856. void
  5857. savecurpos(int vmode, int x) {          /* x: 0 = cursor only, 1 = all */
  5858.     int i ;
  5859.     saved[vmode] = TRUE;                        /* Remember they are saved */
  5860.     savedrow[vmode] = wherey[vmode];            /* Current row (absolute) */
  5861.     savedcol[vmode] = wherex[vmode];            /* Current column (absolute) */
  5862.     if (x) {
  5863.         savedattribute[vmode] = attribute;      /* Current PC video attributes */
  5864.         saveddefaultattribute[vmode] = defaultattribute ;
  5865.         savedunderlineattribute[vmode] = underlineattribute;
  5866.         saveditalicattribute[vmode] = italicattribute;
  5867.         savedreverseattribute[vmode]= reverseattribute;
  5868.         savedgraphicattribute[vmode]= graphicattribute;
  5869.         savedborderattribute[vmode]= borderattribute;
  5870.         savedattrib[vmode] = attrib;            /* Current DEC character attributes */
  5871.         saverelcursor[vmode] = relcursor;       /* Cursor addressing mode */
  5872.         savedwrap[vmode]     = tt_wrap;         /* Wrap mode */
  5873.  
  5874.         if ( x==1 ) {
  5875.             for (i=0; i<4; i++)
  5876.                 savedG[vmode][i] = G[i] ;
  5877.             savedGL[vmode] = GL ;
  5878.             savedGR[vmode] = GR ;
  5879.             savedSSGL[vmode] = SSGL ;
  5880.         }
  5881.     }
  5882. }
  5883.  
  5884. void
  5885. restorecurpos(int vmode, int x) {
  5886.     int i ;
  5887.     if (saved[vmode] == FALSE) {                /* Nothing saved, home the cursor */
  5888.         lgotoxy(vmode, 1, relcursor ? margintop : 1);
  5889.     }
  5890.     else {
  5891.         lgotoxy(vmode, savedcol[vmode], savedrow[vmode]);/* Goto saved position */
  5892.         if (x) {
  5893.             attribute = savedattribute[vmode];  /* Restore saved attributes */
  5894.             defaultattribute=saveddefaultattribute[vmode];
  5895.             underlineattribute=savedunderlineattribute[vmode];
  5896.             italicattribute=saveditalicattribute[vmode];
  5897.             reverseattribute=savedreverseattribute[vmode];
  5898.             graphicattribute=savedgraphicattribute[vmode];
  5899.             borderattribute=savedborderattribute[vmode];
  5900.             attrib = savedattrib[vmode];
  5901.             relcursor = saverelcursor[vmode];   /* Restore cursor addressing mode */
  5902.             tt_wrap = savedwrap[vmode] ;       /* Restore wrap mode */
  5903.  
  5904.             if ( x==1 ) {                       /* Restore char sets */
  5905.                 for (i=0; i<4; i++)
  5906.                     G[i] = savedG[vmode][i] ;
  5907.                 GL = savedGL[vmode] ;
  5908.                 GR = savedGR[vmode] ;
  5909.                 SSGL = savedSSGL[vmode] ;
  5910.             }
  5911.         }
  5912.     }
  5913. }
  5914.  
  5915. /* DECSASD - Select Active Status Display */
  5916. void
  5917. setdecsasd( bool x )
  5918. {
  5919.     if ( x == SASD_STATUS && decssdt == SSDT_HOST_WRITABLE ) {
  5920.         if ( decsasd == SASD_TERMINAL ) {
  5921.             savecurpos(VTERM,2);
  5922.             if ( saved[VSTATUS] )
  5923.                 restorecurpos(VSTATUS,2);
  5924.         }
  5925.         decsasd = x ;
  5926.     }
  5927.     else if (x == SASD_TERMINAL) {
  5928.         if ( decsasd == SASD_STATUS ) {
  5929.             savecurpos(VSTATUS,2);
  5930.             if ( saved[VTERM] )
  5931.                 restorecurpos(VTERM,2);
  5932.         }
  5933.         decsasd = 0 ;
  5934.     }
  5935. }
  5936.  
  5937. /* DECSSDT - Select Status Display Type */
  5938. void
  5939. setdecssdt( int x )
  5940. {
  5941.     int i;
  5942.     switch ( x ) {
  5943.     case SSDT_BLANK:
  5944.         settermstatus(FALSE);
  5945.         break;
  5946.     case SSDT_INDICATOR:
  5947.         settermstatus(TRUE);
  5948.         break;
  5949.     case SSDT_HOST_WRITABLE:
  5950.         if ( decssdt == SSDT_INDICATOR ) {
  5951.             lgotoxy(VSTATUS,1,1);
  5952.             clrtoeoln(VSTATUS,SP);
  5953.             savecurpos(VSTATUS,2);
  5954.             for ( i=0;i<MAXTERMCOL;i++ )
  5955.                 hoststatusline[i] = SP ;
  5956.             hoststatusline[MAXTERMCOL]=NUL;
  5957.         }
  5958.         settermstatus(TRUE);
  5959.         break;
  5960.     }
  5961.     decssdt = x ;
  5962.     VscrnIsDirty(VTERM);
  5963. }
  5964.  
  5965. void
  5966. setkeyclick(int on)
  5967. {
  5968.     keyclick = on;
  5969. #ifdef KUI
  5970.     KuiSetProperty(KUI_TERM_KEYCLICK, on, 0);
  5971. #endif /* KUI */
  5972. }
  5973.  
  5974. void                                    /* Reset the terminal emulator */
  5975. doreset(int x) {                        /* x = 0 (soft), nonzero (hard) */
  5976.     extern BYTE vmode ;
  5977.     extern int dgunix, dgunix_usr;
  5978.     int i;
  5979.  
  5980.     debug(F111,"doreset","x",x);
  5981.  
  5982.     tt_type_mode = tt_type ;
  5983.  
  5984.     attribute = defaultattribute = colornormal; /* Normal colors */
  5985.     underlineattribute = colorunderline ;
  5986.     reverseattribute = colorreverse;
  5987.     graphicattribute = colorgraphic;
  5988.     borderattribute  = colorborder;
  5989.     italicattribute  = coloritalic;
  5990.  
  5991.     saveddefaultattribute[VTERM] = colornormal; /* Default saved values */
  5992.     savedunderlineattribute[VTERM] = colorunderline ;
  5993.     saveditalicattribute[VTERM] = coloritalic;
  5994.     savedreverseattribute[VTERM] = colorreverse;
  5995.     savedgraphicattribute[VTERM] = colorgraphic;
  5996.     savedborderattribute[VTERM]  = colorborder;
  5997.     savedattribute[VTERM] = attribute;
  5998.  
  5999.     attrib.blinking = FALSE;            /* No blink */
  6000.     attrib.bold = FALSE;                /* No bold */
  6001.     attrib.invisible = FALSE;           /* Visible */
  6002.     attrib.underlined = FALSE;          /* No underline */
  6003.     attrib.reversed = FALSE;            /* No reverse video */
  6004.     attrib.unerasable = FALSE;          /* Erasable */
  6005.     attrib.graphic = FALSE ;            /* Not graphic character */
  6006.     attrib.dim = FALSE ;                /* No dim */
  6007.     attrib.wyseattr = FALSE ;
  6008.     attrib.italic = FALSE;              /* No italic */
  6009.     attrib.hyperlink = FALSE;
  6010.     attrib.linkid = 0;
  6011.     savedattrib[VTERM] = attrib;
  6012.  
  6013.     erasemode = user_erasemode;
  6014.  
  6015.     /* Restore DEC VT Graphic Set translation functions */
  6016.     for ( i = 0 ; i < 4 ; i++ )
  6017.     {
  6018.         G[i].designation = G[i].def_designation ;
  6019.         G[i].size = G[i].def_size ;
  6020.         G[i].c1 = G[i].def_c1 ;
  6021.         G[i].national = CSisNRC(G[i].designation) ;
  6022.         if ( tcs_transp ) {
  6023.             debug(F111,"doreset - ERROR","G(i).designation == TX_TRANSP",i);
  6024.             G[i].rtoi = NULL ;
  6025.             G[i].itol = NULL ;
  6026.             G[i].ltoi = NULL ;
  6027.             G[i].itor = NULL ;
  6028.         }
  6029.         else
  6030.         {
  6031.             G[i].rtoi = xl_u[G[i].designation];
  6032.             G[i].itol = xl_tx[tcsl] ;
  6033.             G[i].ltoi = xl_u[tcsl] ;
  6034.             G[i].itor = xl_tx[G[i].designation];
  6035.         }
  6036.         G[i].init = FALSE ;
  6037.     }
  6038.     GNOW = GL = &G[0] ;
  6039.     GR = ISLINUX(tt_type_mode) ? &G[1] : ISVT220(tt_type_mode) ? &G[2] : &G[1];
  6040.     SSGL = NULL ;
  6041.     decnrcm = decnrcm_usr;
  6042.     setdecsasd(SASD_TERMINAL);
  6043.     if ( IS97801(tt_type_mode) )
  6044.         setdecssdt( SSDT_HOST_WRITABLE );
  6045.     else if ( x )
  6046.         setdecssdt( tt_status_usr[VTERM] ? SSDT_INDICATOR : SSDT_BLANK );
  6047.  
  6048.     xprint = FALSE ;                    /* Turn off ctrl print */
  6049.     setaprint(FALSE);                   /* Turn off auto print */
  6050.     cprint = FALSE ;                    /* Turn off copy print */
  6051.     if ( !uprint ) {
  6052.         printeroff() ;                  /* Turn off the printer if it is on */
  6053.         printon = FALSE;                /* Printer is not on */
  6054.     }
  6055.     printregion = FALSE;                /* Printer extent is full screen */
  6056.     screenon = TRUE;                    /* The screen is turned on */
  6057. #ifdef CK_APC
  6058.     if ( !apcactive ) {
  6059.         apcactive = APC_INACTIVE;       /* An APC command is not active */
  6060.         apclength = 0;                  /* ... */
  6061.     }
  6062.     apcrecv = dcsrecv = oscrecv = pmrecv = pu1recv = pu2recv = c1strrecv = 0 ;
  6063. #endif /* CK_APC */
  6064.  
  6065.     vt52graphics = FALSE;               /* Get out of VT52 graphics mode */
  6066.     for ( i=0;i<VNUM;i++ )
  6067.         saved[i] = FALSE;               /* Nothing is saved */
  6068.     tnlm = tt_crd = FALSE;              /* We're not in newline mode */
  6069.     insertmode = FALSE;                 /* Not in character-insert mode */
  6070.     tt_arrow = TTK_NORM;                /* Arrow keypad to cursor mode */
  6071.     tt_keypad = TTK_NORM;               /* Auxilliary keypad to numeric mode */
  6072.     tt_shift_keypad = FALSE ;           /* Do not shift keypad values */
  6073.     tt_wrap = TRUE;                     /* (FALSE for real VT terminal!) */
  6074.     send_c1 = send_c1_usr;              /* Don't send C1 controls */
  6075.     keylock = FALSE;                    /* Keyboard is not locked */
  6076.  
  6077.     udkreset() ;                        /* Reset UDKs     */
  6078.     deccolm = FALSE;                    /* default column mode */
  6079.     tt_cols[VTERM] = tt_cols_usr ;
  6080.     if (tt_updmode == TTU_FAST ) /* set terminal scroll mode to original */
  6081.         JumpScroll();
  6082.     else
  6083.         SmoothScroll();
  6084.     if (vmode==VTERM)
  6085.         SetCols(VTERM) ;
  6086. #ifdef TCPSOCKET
  6087. #ifdef CK_NAWS
  6088.     if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0)
  6089.     {
  6090.         tn_snaws();
  6091. #ifdef RLOGCODE
  6092.         rlog_naws();
  6093. #endif /* RLOGCODE */
  6094. #ifdef SSHBUILTIN
  6095.         ssh_snaws();
  6096. #endif /* SSHBUILTIN */
  6097.     }
  6098. #endif /* CK_NAWS */
  6099. #endif /* TCPSOCKET */
  6100.     ipadl25();
  6101.  
  6102.     decsace = FALSE;
  6103.     decscnm = FALSE;
  6104.     if (decscnm_usr)                    /* Reverse Screen Mode */
  6105.         flipscreen(VTERM);
  6106.  
  6107.     for (i = 1; i < VscrnGetWidth(VTERM); i++)  /* Tab settings every 8 spaces except QNX */
  6108.       htab[i] = (i % (ISQNX(tt_type_mode)?4:8)) == 1 ? 'T' : '0'; /* was "== 0" */
  6109.     relcursor = FALSE;                  /* Cursor position is absolute */
  6110.  
  6111.     /* Real terminal sets margins to (1,24) */
  6112.     setmargins(1, VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));/* Scrolling region is whole screen */
  6113.     marginleft=1;
  6114.     marginright=VscrnGetWidth(VTERM);
  6115.  
  6116.     escstate = ES_NORMAL;               /* In case we're stuck in a string */
  6117.     setborder();                        /* Restore border color */
  6118.  
  6119.     if (x) {                            /* Now clear the screen and home the cursor*/
  6120.         if ( VscrnGetBufferSize(VTERM) > 0 && !VscrnIsClear(VTERM)) {
  6121.             clrscreen(VTERM,SP);
  6122.             lgotoxy(VTERM,1,1);       /* and home the cursor */
  6123.         }
  6124.     }
  6125.     VscrnSetDisplayHeight(VTERM,0);
  6126.     if (scrollflag[VTERM])              /* Were we rolled back? */
  6127.       scrollflag[VTERM] = 0;            /* Not any more ... */
  6128.     ipadl25();                          /* Put back regular status line */
  6129.  
  6130.     cursorena[VTERM] = tt_cursorena_usr;/* Cursor enabled? */
  6131.     cursoron[VTERM] = FALSE ;           /* Force newcursor to restore the cursor */
  6132.     tt_cursor = tt_cursor_usr ;
  6133.     setcursormode() ;
  6134.  
  6135.     if ( duplex_sav > -1 ) {            /* Restore user Echo setting */
  6136.         duplex = duplex_sav ;
  6137.         duplex_sav = -1 ;
  6138.     }
  6139.     deckbum = FALSE ;                   /* Keyboard in Typewriter mode */
  6140.     if ( savdecbkm )                    /* Restore Backspace mode to user default */
  6141.     {
  6142.         keymap[KEY_SCAN | 8] = savdecbkm ;
  6143.         savdecbkm = 0 ;
  6144.     }
  6145.  
  6146.     sco8bit = FALSE ;                   /* SCO ANSI 8th bit quoting off */
  6147.     scoBCS2 = FALSE ;                   /* SCO ANSI BCS2 mode */
  6148.     wyse8bit = FALSE ;
  6149.     crm = FALSE ;                       /* SCO ANSI c0 display off      */
  6150.     setkeyclick(FALSE);
  6151.  
  6152.     marginbell = FALSE ;
  6153.     marginbellcol = VscrnGetWidth(VTERM)-8 ;
  6154.  
  6155.     beepfreq = DEF_BEEP_FREQ ;
  6156.     beeptime = DEF_BEEP_TIME ;
  6157.  
  6158.     sni_pagemode = sni_pagemode_usr;    /* SNI 97801 AutoRoll */
  6159.     sni_scroll_mode = sni_scroll_mode_usr;/* SNI 97801 Roll */
  6160.     if ( IS97801(tt_type_mode) ) {
  6161.         SNI_chcode(sni_chcode_usr);     /* 97801 CH.CODE mode */
  6162.         sni_chcode_7 = TRUE;            /* 97801 CH.CODE key enabled 7-bit mode */
  6163.         sni_chcode_8 = TRUE;            /* 97801 CH.CODE key enabled 8-bit mode */
  6164.         SNI_bitmode((cmask == 0377) ? 8 : 7);
  6165.     }
  6166.  
  6167.     autoscroll = TRUE ;                 /* WYSE ASCII AutoScroll */
  6168.     protect = FALSE;                    /* WYSE ASCII Protect */
  6169.     writeprotect = FALSE ;              /* WYSE ASCII WriteProtect */
  6170.     WPattrib = defWPattrib;             /* WYSE ASCII WP Attribute */
  6171.     wysegraphics = FALSE ;
  6172.     wy_keymode = FALSE ;                /* WYSE ASCII Key Appl Mode */
  6173.     wy_enhanced = TRUE ;                /* WYSE ASCII Enhanced Mode On */
  6174.     wy_widthclr = FALSE ;               /* WYSE ASCII Width Clear Mode Off */
  6175.     wy_nullsuppress = TRUE;             /* WYSE ASCII Null Suppress On */
  6176.     if ( ISWYSE(tt_type_mode) ||
  6177.          ISTVI(tt_type_mode) ||
  6178.          ISHZL(tt_type_mode) ||
  6179.          ISDG200(tt_type_mode) ) {      /* WYSE ASCII Auto Page Mode */
  6180.         wy_autopage = TRUE;
  6181.     }
  6182.     else {
  6183.         wy_autopage = FALSE ;
  6184.     }
  6185.     if ( wy_monitor ) {                 /* WYSE ASCII Monitor Mode */
  6186.         setdebses(FALSE);
  6187.         wy_monitor = FALSE ;
  6188.     }
  6189.     hzgraphics = 0;                     /* Hazeltine Graphics Mode */
  6190.  
  6191.     switch ( tt_type_mode ) {           /* Do Attributes occupy a space in */
  6192.     case TT_WY30:
  6193.     case TT_WY50:
  6194.     case TT_TVI910:
  6195.     case TT_TVI925:
  6196.     case TT_TVI950:
  6197.         tt_hidattr = FALSE;
  6198.         break;
  6199.     case TT_HP2621:                     /* LINE or PAGE modes              */
  6200.     case TT_HPTERM:
  6201.     default:
  6202.         tt_hidattr = TRUE ;
  6203.         break;
  6204.     }
  6205.  
  6206.     if ( ISWY60(tt_type_mode) )         /* Set the proper Attribute Mode */
  6207.         attrmode = ATTR_PAGE_MODE | ATTR_CHAR_MODE ;
  6208.     else if ( ISWYSE(tt_type_mode) || ISTVI(tt_type_mode) )
  6209.         attrmode = ATTR_PAGE_MODE ;
  6210.     else if ( ISHP(tt_type_mode) )
  6211.         attrmode = ATTR_LINE_MODE ;
  6212.     else
  6213.         attrmode = ATTR_CHAR_MODE ;
  6214.  
  6215.     tt_kb_mode = KBM_EN ;               /* Turn off Special Keyboard Modes */
  6216.  
  6217.     tvi_ic = SP ;                       /* TVI Insert Char is space */
  6218.     wy_block = FALSE;                  /* TVI in Conversation mode */
  6219.  
  6220.     dgunix = dgunix_usr;
  6221.  
  6222.     Qsaved = FALSE;                     /* QANSI Saved Character sets */
  6223.  
  6224.     ba80_fkey_read = 0;                 /* We are not reading BA80 fkeys */
  6225.     vtnt_index = 0;
  6226.     vtnt_read  = VTNT_MIN_READ;
  6227.  
  6228.     dokverb(VTERM,K_ENDSCN);
  6229.     dokverb(VTERM,K_MARK_CANCEL);
  6230.  
  6231. #ifdef CKLEARN
  6232.     learnreset();
  6233. #endif /* CKLEARN */
  6234.  
  6235.     VscrnIsDirty(VTERM) ;
  6236. }
  6237.  
  6238.  
  6239. /*
  6240.   The flow of characters from the communication device to the screen is:
  6241.  
  6242.                            +---(debug)----+
  6243.                            |              |
  6244.   rdcomwrtscr --> cwrite --+--> vt100 --> wrtch
  6245.                                        |              |
  6246.                                        +--> vtescape--+
  6247.  
  6248.   rdcomwrtscr() reads character from communication device via ttinc() and:
  6249.    - converts 8-bit controls to 7-bit ESC sequences
  6250.    - handles TELNET negotiations
  6251.    - handles SO/SI (NOTE: this prevents
  6252.    - handles charset translation
  6253.    - handles newline-mode and cr-display
  6254.    - handles connection loss
  6255.    - passes all output chars to cwrite()
  6256.  
  6257.   cwrite()
  6258.    - handles debug output, direct to wrtch().
  6259.    - detects and parses escape-sequences:
  6260.      . builds up escape sequence in buffer
  6261.      . when complete, calls vtescape(), or does APC.
  6262.    - when not debugging & not in esc seq, sends all other chars to vt100().
  6263.  
  6264.   vt100()
  6265.    - handles ctrl chars in straightforward, modeless way (ENQ, tab, BS, beep)
  6266.    - *thinks* it handles SO/SI, but never gets called for this (???)
  6267.    - handles graphic chars via mode (G[], vtgraphics, etc) -> wrtch()
  6268.    - handles wraparound
  6269.  
  6270.   vtescape()
  6271.    - acts on escape sequences, changes state, moves cursor, etc.
  6272. */
  6273.  
  6274. /*
  6275.  * RDCOMWRTSCR  --  Read from the communication device and write to the screen.
  6276.  * This function is executed by a separate thread.
  6277.  */
  6278.  
  6279. void
  6280. rdcomwrtscr(void * pArgList)
  6281. {
  6282.     int c=0, cx=0, tx=0;
  6283.     int prty = -2;
  6284.     int prtyboost = 0;
  6285.  
  6286.     PostRdComWrtScrThreadSem() ;
  6287.     setint();
  6288.  
  6289.     while ( !Shutdown )
  6290.     {
  6291.  
  6292.         /* Close printer if necessary */
  6293.         if ( printerclose_t ) {
  6294.             if ( printerclose_t < time(NULL) ) {
  6295.                 printerclose();
  6296.             }
  6297.         }
  6298.  
  6299.         if ( !IsConnectMode() ||
  6300. #ifdef COMMENT
  6301.              what != W_CONNECT ||
  6302. #endif /* COMMENT */
  6303.              !term_io ||
  6304.              (ttyfd == -1
  6305. #ifdef CK_TAPI
  6306.                || (!tttapi && ttyfd == -2)
  6307. #endif /* CK_TAPI */
  6308.                ) &&
  6309.              !le_inbuf() ||
  6310.              holdscreen ) {
  6311.             /* debug(F110,"rdcomwrtscr","Waiting for CONNECT_MODE or HOLDSCREEN",0); */
  6312.             if (prty != -1 ) {
  6313.                 prty = -1;      /* lie */
  6314.                 SetThreadPrty(XYP_REG,0);
  6315.             }
  6316.             msleep(500);
  6317.             continue;
  6318.         }
  6319.  
  6320.         if ( priority != prty ) {
  6321. #ifdef NT
  6322.             SetThreadPrty(priority,isWin95() ? 3 : 11);
  6323. #else /* NT */
  6324.             SetThreadPrty(priority,3);
  6325. #endif /* NT */
  6326.             prty = priority;
  6327.             prtyboost = 0;
  6328.         }
  6329.  
  6330.         c = ttinc(-500);           /* Get a character from the host */
  6331.         if ( c < 0 ) {
  6332.             if ( ttyfd == -1
  6333. #ifdef CK_TAPI
  6334.                  || (!tttapi && ttyfd == -2)
  6335. #endif /* CK_TAPI */
  6336.                  ) {
  6337.                 SetConnectMode(FALSE,CSX_HOSTDISC);
  6338.                 strcpy(termessage, "Connection closed.\n");
  6339.             }
  6340.             else if (c == -2)
  6341.             {
  6342.                 SetConnectMode(FALSE,CSX_HOSTDISC);
  6343.                 strcpy(termessage, "Connection closed.\n");
  6344.                 ttclos(0) ;
  6345.                 /* link broken */
  6346.             }
  6347.             else if (c == -3)
  6348.             {
  6349.                 SetConnectMode(FALSE,CSX_SESSION);
  6350.                 strcpy(termessage, "Session Limit exceeded - closing connection.\n");
  6351.                 ttclos(0) ;
  6352.                 /* link broken */
  6353.             }
  6354.             else {
  6355.                 if (prtyboost == 1) {
  6356. #ifdef NT
  6357.                     SetThreadPrty(priority,isWin95() ? 3 : 11);
  6358. #else /* NT */
  6359.                     SetThreadPrty(priority,3);
  6360. #endif /* NT */
  6361.                     prtyboost = 0;
  6362.                 }
  6363.                 msleep(0);
  6364.             }
  6365.             continue;
  6366.         }
  6367.         else {
  6368.             scriptwrtbuf(c);
  6369.  
  6370.             if (prtyboost == 0) {
  6371. #ifdef NT
  6372.                 SetThreadPrty(priority,(isWin95() ? 3 : 11)+10);
  6373. #else /* NT */
  6374.                 SetThreadPrty(priority,13);
  6375. #endif /* NT */
  6376.                 prtyboost = 1;
  6377.             }
  6378.         }
  6379.  
  6380. #ifdef __DEBUG
  6381.         /* we want to be able to see things on a character */
  6382.         /* by character basis when debugging these threads */
  6383.         /* msleep(0) ; */
  6384. #endif /* __DEBUG */
  6385.     }
  6386.     PostRdComWrtScrThreadDownSem() ;
  6387.     ckThreadEnd(pArgList) ;
  6388. }
  6389.  
  6390. int
  6391. ltorxlat( int c, CHAR ** bytes )
  6392. {
  6393.     unsigned short xkey, xkey7;
  6394.     static CHAR mybyte;
  6395.     int count = 1;
  6396.  
  6397.     xkey = (unsigned short) c;
  6398.  
  6399.     if ( tt_kb_glgr ) {
  6400.         if (xkey <= 127)
  6401.         {
  6402.             if ( txrinfo[tcsl]->size != 94 )
  6403.                 xkey = (*xl_u[TX_ASCII])(xkey);
  6404.             else
  6405.             {
  6406.                 if (GL->ltoi)
  6407.                     xkey = (*GL->ltoi)(xkey);
  6408.             }
  6409.             if ( tt_utf8 ) {
  6410.                 count = ucs2_to_utf8( key, bytes );
  6411.                 return(count);
  6412.             }
  6413.             else if (GL->itor)
  6414.                 xkey = (*GL->itor)(xkey);
  6415.         }
  6416.         else
  6417.         {
  6418.             if ( tt_kb_mode == KBM_HE )
  6419.             {
  6420.                 xkey7 = xkey = xl_u[TX_CP862](xkey);
  6421.             }
  6422.             else if ( tt_kb_mode == KBM_RU )
  6423.             {
  6424.                 xkey7 = xkey = xl_u[TX_CP866](xkey);
  6425.             }
  6426.             else {
  6427.                 if (GL->ltoi)
  6428.                     xkey7 = (*GL->ltoi)(xkey);
  6429.                 else
  6430.                     xkey7 = 0xFFFF;
  6431.  
  6432.                 if (GR->ltoi)
  6433.                     xkey = (*GR->ltoi)(xkey);
  6434.             }
  6435.  
  6436.             if ( tt_utf8 ) {
  6437.                 count = ucs2_to_utf8( xkey, bytes );
  6438.                 return(count);
  6439.             }
  6440.             else {
  6441.                 if ( GL->itor )
  6442.                     xkey7 = (*GL->itor)(xkey7);
  6443.                 else
  6444.                     xkey7 = 0xFFFF;
  6445.  
  6446.                 if ( GR->itor)
  6447.                     xkey = (*GR->itor)(xkey);
  6448.                 else
  6449.                     xkey = 0xFFFF;
  6450.  
  6451.                 if ( xkey7 != 0xFFFF )
  6452.                     xkey = xkey7;
  6453.             }
  6454.         }
  6455.     } else {
  6456.         /* Use Keyboard Character-set based upon  */
  6457.         /* state of DECNRCM for VT terminals or   */
  6458.         /* CH.CODE and bit mode for SNI terminals */
  6459.  
  6460.         if (xkey > 127) {
  6461.             if ( tt_kb_mode == KBM_HE )
  6462.             {
  6463.                 xkey = xl_u[TX_CP862](xkey);
  6464.             }
  6465.             else if ( tt_kb_mode == KBM_RU )
  6466.             {
  6467.                 xkey = xl_u[TX_CP866](xkey);
  6468.             }
  6469.             else if ( IS97801(tt_type_mode) ) {
  6470.                 debug(F111,"ltorxlat()","xkey > 127",xkey);
  6471.                 debug(F111,"ltorxlat()","tcsl",tcsl);
  6472.                 xkey = xl_u[tcsl](xkey);
  6473.                 debug(F111,"ltorxlat()","xl_u[tcsl](xkey)",xkey);
  6474.             } else
  6475.                 xkey = xl_u[tcsl](xkey);
  6476.         }
  6477.  
  6478.         if ( tt_utf8 ) {
  6479.             count = ucs2_to_utf8( xkey, bytes );
  6480.             return(count);
  6481.         } else if ( ISVT100(tt_type_mode) && decnrcm ||
  6482.                     IS97801(tt_type_mode) && sni_bitmode == 7 && !sni_chcode) {
  6483.             xkey = xl_tx[dec_nrc](xkey);
  6484.             if ( IS97801(tt_type_mode) ) {
  6485.                 debug(F111,"ltorxlat() sni=7 !ch.code","xl_tx[decnrc]",xkey);
  6486.             }
  6487.         } else if (IS97801(tt_type_mode) && sni_bitmode == 7 && sni_chcode) {
  6488.             if ( IS97801(tt_type_mode) )
  6489.                 debug(F100,"ltorxlat() sni=7 ch.code","",0);
  6490.             if ( xkey > 127 ) {
  6491.                 bytes = NULL;
  6492.                 return(0);
  6493.             }
  6494.             /* otherwise, we use US-ASCII - no translation necessary */
  6495.         } else if ( cs_is_nrc(dec_kbd) ) {
  6496.             xkey = xl_tx[dec_kbd](xkey);
  6497.         } else if ( xkey > 127 ) {
  6498.             xkey = xl_tx[dec_kbd](xkey);
  6499.         }
  6500.     }
  6501.     if ( xkey == 0xFFFF ) {
  6502.         debug(F110,"ltorxlat()","xkey == 0xFFFF",0);
  6503.         bytes = NULL;
  6504.         return(0);
  6505.     }
  6506.  
  6507.     mybyte = (unsigned char) xkey;
  6508.     *bytes = &mybyte;
  6509.     return(1);
  6510. }
  6511.  
  6512. int
  6513. utorxlat( int c, CHAR ** bytes )
  6514. {
  6515.     unsigned short xkey, xkey7;
  6516.     static CHAR mybyte;
  6517.     int count = 1;
  6518.  
  6519.     xkey = (unsigned short) c;
  6520.  
  6521.     if ( tt_kb_glgr ) {
  6522.         if ( tt_utf8 ) {
  6523.             count = ucs2_to_utf8( key, bytes );
  6524.             return(count);
  6525.         }
  6526.         else if (GL->itor)
  6527.             xkey = (*GL->itor)(xkey);
  6528.     } else {
  6529.         /* Use Keyboard Character-set based upon  */
  6530.         /* state of DECNRCM for VT terminals or   */
  6531.         /* CH.CODE and bit mode for SNI terminals */
  6532.  
  6533.         if ( tt_utf8 ) {
  6534.             count = ucs2_to_utf8( xkey, bytes );
  6535.             return(count);
  6536.         } else if ( ISVT100(tt_type_mode) && decnrcm ||
  6537.                     IS97801(tt_type_mode) && sni_bitmode == 7 && !sni_chcode) {
  6538.             xkey = xl_tx[dec_nrc](xkey);
  6539.             if ( IS97801(tt_type_mode) ) {
  6540.                 debug(F111,"ltorxlat() sni=7 !ch.code","xl_tx[decnrc]",xkey);
  6541.             }
  6542.         } else if (IS97801(tt_type_mode) && sni_bitmode == 7 && sni_chcode) {
  6543.             if ( IS97801(tt_type_mode) )
  6544.                 debug(F100,"ltorxlat() sni=7 ch.code","",0);
  6545.             if ( xkey > 127 ) {
  6546.                 bytes = NULL;
  6547.                 return(0);
  6548.             }
  6549.             /* otherwise, we use US-ASCII - no translation necessary */
  6550.         } else if ( cs_is_nrc(dec_kbd) ) {
  6551.             xkey = xl_tx[dec_kbd](xkey);
  6552.         } else if ( xkey > 127 ) {
  6553.             xkey = xl_tx[dec_kbd](xkey);
  6554.         }
  6555.     }
  6556.     if ( xkey == 0xFFFF ) {
  6557.         debug(F110,"ltorxlat()","xkey == 0xFFFF",0);
  6558.         bytes = NULL;
  6559.         return(0);
  6560.     }
  6561.  
  6562.     mybyte = (unsigned char) xkey;
  6563.     *bytes = &mybyte;
  6564.     return(1);
  6565. }
  6566.  
  6567. int
  6568. rtolxlat( int c )
  6569. {
  6570.     int cx;
  6571.     /* Do not perform translations if we are VTNT */
  6572.     if ( tcs_transp || ISVTNT(tt_type_mode) )
  6573.         return(c);
  6574.  
  6575.     debug(F101,"rtolxlat c","",c);
  6576.     debug(F101,"rtolxlat tcsl","",tcsl);
  6577.  
  6578.     if ( ((ISANSI(tt_type_mode) || ISQANSI(tt_type_mode)) && sco8bit ||
  6579.            ISWY60(tt_type_mode) && wyse8bit)
  6580.          && c >= 32 )
  6581.         c |= 0200 ;             /* Shift 8th bit */
  6582.  
  6583.     if ( SSGL == NULL )
  6584.         GNOW = c > 127 ? GR : GL ;
  6585.     else {
  6586.         GNOW = c > 127 ? GR : SSGL ;
  6587.         SSGL = NULL ;
  6588.     }
  6589.  
  6590.     /* SNI 97801 has special translations if CH.CODE is ON */
  6591.     if ( IS97801(tt_type_mode) && sni_chcode ) {
  6592.         if ( sni_bitmode == 8 && c > 127 ) {
  6593.             /* 8-bit mode uses Latin-1 */
  6594.             cx = xl_u[TX_8859_1](c);
  6595.             if ( !isunicode() )
  6596.                 cx = xl_tx[tcsl](cx);
  6597.             debug(F101,"rtolxlat return 1","",cx);
  6598.             return(cx);
  6599.         } else if (sni_bitmode == 7 && GNOW == &G[0] ){
  6600.             /* 7-bit mode uses dec-nrc */
  6601.             cx = xl_u[TX_ASCII](c);
  6602.             debug(F101,"rtolxlat return 2","",cx);
  6603.             return(cx);
  6604.         }
  6605.         /* otherwise, perform a normal translation */
  6606.     }
  6607.  
  6608.     if ( !debses && tcs_transp ) {
  6609.         if ( GNOW == GR && !GNOW->national ) {
  6610.             c |= 0200;
  6611.             literal_ch = TRUE ;
  6612.         } else
  6613.             c &= ~0200;
  6614.  
  6615.         c &= cmdmsk;                        /* Apply command mask. */
  6616.     } else {
  6617.         if (!debses &&                      /* Not DEBUG mode       */
  6618.              c >= 32 &&                     /* Not Control-0 char   */
  6619.              !tcs_transp)                   /* Not transparent set */
  6620.             c |= 0200;                      /* Shift char to 8-bit  */
  6621.  
  6622.         if ( GNOW->national )
  6623.             c &= ~0200 ;                    /* Shift to 7-bit */
  6624.  
  6625.         c &= cmdmsk;                        /* Apply command mask. */
  6626.  
  6627.         /* Translate character sets */
  6628.         cx = c ;                    /* Save the old value */
  6629.         if ( !(GNOW == GL && c < 32) ) {
  6630.             if (GNOW->rtoi)
  6631.                 c = (*GNOW->rtoi)(c);
  6632.             if ( !isunicode() )
  6633.             {
  6634.                 if (GNOW->itol )
  6635.                     c = (*GNOW->itol)(c);
  6636.             }
  6637. #ifdef NT
  6638.             else
  6639.             {
  6640.                 if ( win95hsl && c >= 0x23BA && c <= 0x23BD )
  6641.                     c = tx_hslsub(c);
  6642.                 else if ( c >= 0xE000 && c <= 0xF8FF )
  6643.                     c = tx_usub(c);
  6644.                 if (win95lucida && c > 0x017f)
  6645.                     c = tx_lucidasub(c);
  6646.             }
  6647. #endif /* NT */
  6648.             if ( c < 0 )            /* Character could not be xlated */
  6649.                 c = '?' ;           /* to local character set */
  6650.         }
  6651.         if ( cx >= SP && c < SP ||
  6652.              c >=128 && c <= 159)
  6653.             literal_ch = TRUE ;
  6654.         debug(F101,"rtolxlat return 3","",c);
  6655.     }
  6656.     return(c);
  6657. }
  6658.  
  6659. int
  6660. utolxlat( int c )
  6661. {
  6662.     c = xl_tx[tcsl](c);
  6663.     return(c);
  6664. }
  6665.  
  6666. /*
  6667.   S C R I P T W R T B U F
  6668.   This function performs equivalent functionality for [M]INPUT commands
  6669.   as RDCOMWRTSCR does for CONNECT sessions.  Must process incoming
  6670.   Telnet operations and perform character set translations.
  6671.  
  6672.   And since it does exactly the same thing that RDCOMWRTSCR has done for
  6673.   years, there is no point in duplicating the code.  So now RDCOMWRTSCR
  6674.   calls SCRIPTWRTBUF to do the hard work.
  6675. */
  6676. int
  6677. scriptwrtbuf(unsigned short word)
  6678. /* scriptwrtbuf */ {
  6679.     int c, cx, tx;
  6680. #ifdef CK_TRIGGER
  6681.     extern char * tt_trigger[], * triggerval;
  6682. #endif /* CK_TRIGGER */
  6683.  
  6684.     debug(F111,"scriptwrtbuf","word",word);
  6685.  
  6686.     /* Close Printer if necessary */
  6687.     if ( printerclose_t ) {
  6688.         if ( printerclose_t < time(NULL) ) {
  6689.             printerclose();
  6690.         }
  6691.     }
  6692.  
  6693. pushed:
  6694.     if (f_pushed) {             /* Handle 8-bit controls */
  6695.         c = c_pushed;           /* by converting to ESC + 7-bit char */
  6696.         f_pushed = 0;
  6697.         f_popped = 1;
  6698.     }
  6699.     else
  6700.     {
  6701.         c = word;               /* Get a character from the host */
  6702.  
  6703. #ifdef TNCODE
  6704.         /* Handle TELNET negotiations here */
  6705.         if (network && IS_TELNET()) {
  6706.             static int got_cr = 0;
  6707.             switch ( c ) {
  6708.             case IAC:
  6709.                 if ((tx = tn_doop((CHAR)(c & 0xff),duplex,netinc)) == 0) {
  6710.                     return(0);
  6711.                 }
  6712.                 else if (tx == -1) {    /* I/O error */
  6713.                     strcpy(termessage, "TELNET negotiation error.\n");
  6714.                     SetConnectMode(FALSE,CSX_TN_ERR);      /* Quit */
  6715.                     return(-1);
  6716.                 }
  6717.                 else if (tx == -2) { /* Connection failed. */
  6718.                     extern int ttyfd ;
  6719.                     SetConnectMode(FALSE,CSX_HOSTDISC);
  6720.                     strcpy(termessage, "Connection closed by peer.\n");
  6721.                     ttclos(0) ;
  6722.                     return(-2);
  6723.                 }
  6724.                 else if (tx == -3) { /* Connection failed. */
  6725.                     extern int ttyfd ;
  6726.                     SetConnectMode(FALSE,CSX_TN_POL);
  6727.                     strcpy(termessage, "Connection closed due to telnet policy.\n");
  6728.                     ttclos(0) ;
  6729.                     return(-2);
  6730.                 }
  6731.                 else if (tx == 1) {     /* ECHO change */
  6732.                     duplex = 1; /* Get next char */
  6733.                     return(1);
  6734.                 }
  6735.                 else if (tx == 2) {     /* ECHO change */
  6736.                     duplex = 0; /* Get next char */
  6737.                     return(2);
  6738.                 }
  6739.                 else if (tx == 3) {     /* Quoted IAC */
  6740.                     c = 255;    /* proceeed with it. */
  6741.                 }
  6742. #ifdef IKS_OPTION
  6743.                 else if (tx == 4) {     /* IKS State Change */
  6744.                     if ( TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6745.                          !tcp_incoming) {
  6746.                         SetConnectMode(FALSE,CSX_IKSD);
  6747.                     }
  6748.                     return(4);
  6749.                 }
  6750. #endif /* IKS_OPTION */
  6751.                 else if (tx == 6) {
  6752.                     strcpy(termessage, "Remote Logout.\n");
  6753.                     SetConnectMode(FALSE,CSX_HOSTDISC);      /* Quit */
  6754.                     return(6);
  6755.                 }
  6756.                 else return(0); /* Unknown, get next char */
  6757.                 break;
  6758.             case CR:
  6759.                 got_cr = 1;
  6760.                 break;
  6761.             case NUL:
  6762.                 if ( !TELOPT_U(TELOPT_BINARY) && got_cr ) {
  6763.                     got_cr = 0;
  6764.                     return(0);
  6765.                 }
  6766.             default:
  6767.                 got_cr = 0;
  6768.             }
  6769.             if (IsConnectMode() &&
  6770.                 TELOPT_ME(TELOPT_ECHO) && tn_rem_echo) { /* I'm echo'ing incoming data */
  6771.                 ttoc(c);
  6772.             }
  6773.         }
  6774. #endif /* TNCODE */
  6775.  
  6776.         /* Output to the session log */
  6777.         /* The session log should be a pure log of what the host */
  6778.         /* is sending minus the Telnet stuff.  This way the file */
  6779.         /* can be used as an input stream to the emulator for    */
  6780.         /* testing bugs.  This can't happen if we perform C1 to  */
  6781.         /* ESC C0 and Character-set conversions.                 */
  6782.         if (seslog)
  6783.             logchar((USHORT)c);
  6784.  
  6785.         /* The purpose of copy-print is to allow K95 to display */
  6786.         /* the terminal output on the K95 screen while at the   */
  6787.         /* same time piping the raw data through a terminal     */
  6788.         /* hooked to the printer device (possibly in bi-di mode */
  6789.         /* so we print the raw character here and make cprint   */
  6790.         /* supercede the xprint flag.                           */
  6791.         /* If the terminal type is Wyse don't print the DC4     */
  6792.         /* which is going to result in cprint being turned off. */
  6793.         if (cprint && !(ISWYSE(tt_type_mode) && c == DC4))
  6794.             prtchar(c);
  6795.  
  6796.         f_popped = 0;
  6797.  
  6798.         /* Handle the UTF8 conversion if we are in that mode */
  6799.         if ( tt_utf8 ) {
  6800.             USHORT * ucs2 = NULL;
  6801.             int rc = utf8_to_ucs2( (CHAR)(c & 0xFF), &ucs2 );
  6802.             if ( rc > 0 )
  6803.                 return(0);
  6804.             else {
  6805.                 if (rc < 0) {
  6806.                     c = 0xfffd;
  6807.                     f_pushed = 1;
  6808.                     c_pushed = *ucs2;
  6809.                 } else
  6810.                     c = *ucs2;
  6811.  
  6812.                 if (c == 0x2028 || c == 0x2029) { /* LS or PS */
  6813.                     c = CR;
  6814.                     f_pushed = 1;
  6815.                     c_pushed = LF;
  6816.                 }
  6817.                 if ( isunicode() ) {
  6818.                     if ( win95hsl && c >= 0x23BA && c <= 0x23BD )
  6819.                         c = tx_hslsub(c);
  6820.                     else if ( c >= 0xE000 && c <= 0xF8FF )
  6821.                         c = tx_usub(c);
  6822.                     if (win95lucida && c > 0x017f)
  6823.                         c = tx_lucidasub(c);
  6824.                 } else {        
  6825.                     cx = c;
  6826.                     c = xl_tx[tcsl](cx);
  6827.                     if ( c < 0 )                /* Character could not be xlated */
  6828.                         c = '?' ;               /* to local character set */
  6829.                     if ( cx >= SP && c < SP ||
  6830.                          c >=128 && c <= 159)
  6831.                         literal_ch = TRUE ;
  6832.                 }
  6833.             }
  6834.         }
  6835.  
  6836.         if ((ISVT220(tt_type_mode) ||
  6837.              ISANSI(tt_type_mode)) &&
  6838.              !xprint ) {                /* VT220 and above... */
  6839.                 cx = tt_utf8 ? c : c & cmask & pmask;   /* C1 check must be masked */
  6840.  
  6841.             if (!tt_utf8 && ( GR->c1 ) &&
  6842.                  (cx > 127) && (cx < 160) /* It's a C1 character */
  6843.                  ) {
  6844.                 f_pushed = 1;
  6845.                 c_pushed = (c & 0x7F) | 0x40;
  6846.                 c = ESC;
  6847.             }
  6848.         }
  6849.     }
  6850.  
  6851.     if (c >= 0) {                       /* Got character with no error? */
  6852.         if ( !xprint ) {
  6853.             if (!tt_utf8)
  6854.                c = c & cmask & pmask ;  /* Maybe strip 8th bit */
  6855. #ifndef NOXFER
  6856.             if ( (IsConnectMode() && autodl) ||
  6857.                  (!IsConnectMode() && inautodl) )
  6858.                 autodown( c ) ;                 /* Download? */
  6859. #endif /* NOXFER */
  6860.             if (escstate == ES_NORMAL) {
  6861.                 if ( !tt_utf8 )
  6862.                     c = rtolxlat(c);
  6863.             }
  6864.             else {
  6865.                 c &= cmdmsk;            /* Apply command mask. */
  6866.             }
  6867.  
  6868.             if ((!debses) &&
  6869.                  ((tnlm &&              /* NEWLINE-MODE? */
  6870.                     (c == LF || c == FF || c == 11)) ||
  6871.                    (c == CR && tt_crd ) /* CR-DISPLAY CRLF ? */
  6872.                    )) {
  6873.                 cwrite((USHORT) CR);    /* Yes, output CR */
  6874.                 c = LF;                 /* and insert a linefeed */
  6875.             }
  6876.             cwrite((USHORT) c);
  6877.         } else {
  6878.             if (!GR->c1 && c >=128 && c <= 159) {
  6879.                 literal_ch = TRUE;
  6880.                 cwrite((USHORT) c);
  6881.                 literal_ch = FALSE;
  6882.             } else
  6883.                 cwrite((USHORT) c);
  6884.         }
  6885.  
  6886. #ifdef CK_TRIGGER
  6887.         if ( !xprint && tt_trigger[0] ) {
  6888.             int trigger = autoexitchk(c);
  6889.             if ( trigger > -1 ) {
  6890.                 if (triggerval) /* Make a copy of the trigger */
  6891.                     free(triggerval);
  6892.                 triggerval = NULL;
  6893.                 triggerval = strdup(tt_trigger[trigger]);
  6894.                 debug(F110,"scriptwrtbuf() triggerval",triggerval,0);
  6895.                 ckmakmsg(termessage, sizeof(termessage),
  6896.                          "Trigger \"", triggerval,
  6897.                          "\" found.\n", NULL);
  6898.                 SetConnectMode(FALSE,CSX_TRIGGER);
  6899.             }
  6900.         }
  6901. #endif /* CK_TRIGGER */
  6902.     }
  6903.     if (f_pushed)
  6904.         goto pushed ;
  6905.  
  6906.     debug(F100,"scriptwrtbuf returns","",0);
  6907.     return(0);
  6908. }
  6909.  
  6910. int
  6911. CSisNRC( int x )
  6912. {
  6913.     return cs_is_nrc(x);
  6914. }
  6915.  
  6916. /* Character-set final characters
  6917.  *
  6918.  *    A - British
  6919.  *    B - ASCII
  6920.  *    C - Finnish
  6921.  *    E - Norwegian/Dutch
  6922.  *    H - Swedish
  6923.  *    K - German
  6924.  *    Q - French Canadian
  6925.  *    R - French
  6926.  *    Y - Italian
  6927.  *    Z - Spanish
  6928.  *    0 - DEC Special Graphics
  6929.  *    4 - Dutch
  6930.  *    5 - Finnish
  6931.  *    6 - Norwegian/Dutch
  6932.  *    7 - Swedish
  6933.  *    < - DEC supplemental
  6934.  *    = - Swiss
  6935.  *
  6936.  */
  6937.  
  6938. int
  6939. isNRC( int x )
  6940. {
  6941.     switch ( x ) {
  6942.     case 'A':           /* FC_UKASCII TX_BRITISH */
  6943.     case 'B':           /* FC_USASCII TX_ASCII */
  6944.     case 'C': case '5': /* FC_FIASCII TX_FINNISH */
  6945.     case 'E': case '6': /* FC_NOASCII TX_NORWEGIAN */
  6946.     case 'H': case '7': /* FC_SWASCII TX_SWEDISH */
  6947.     case 'K':           /* FC_GEASCII TX_GERMAN */
  6948.     case 'Q':           /* FC_FCASCII TX_CN_FRENCH */
  6949.     case 'R': case 'f': /* FC_FRASCII TX_FRENCH */
  6950.     case 'Y':           /* FC_ITASCII TX_ITALIAN */
  6951.     case 'Z':           /* FC_SPASCII TX_SPANISH */
  6952.     case '4':           /* FC_DUASCII TX_DUTCH */
  6953.     case '=':           /* FC_CHASCII TX_SWISS */
  6954.     case '1':           /* DEC Alternate ROM - ASCII */
  6955.         return 1;
  6956.     default:
  6957.         return 0;
  6958.     }
  6959. }
  6960.  
  6961.  
  6962. /* See http://www.itscj.ipsj.or.jp/ISO-IR/ for Internation Char Set Registry */
  6963. unsigned char
  6964. charset( enum charsetsize size, unsigned short achar, struct _vtG * pG )
  6965. {
  6966.     unsigned char cs = TX_UNDEF ;
  6967.     unsigned char bchar ;
  6968.  
  6969.     switch ( size ) {
  6970.     case cs94:
  6971.         switch ( achar ) {
  6972. #ifdef SN97801_5XX
  6973.         case '@':       /* International (new) */
  6974.             break;
  6975.         case 'B':       /* International A (US-ASCII) */
  6976.             break;
  6977.         case 'K':       /* German character set (GR-ASCII) */
  6978.             break;
  6979.         case 'w':       /* Brackets character set (new) */
  6980.             break;
  6981.         case 'c':       /* FACET character set (new) */
  6982.             break;
  6983.         case 'v':       /* IBM character set (new) */
  6984.             break;
  6985.         case 'u':       /* EURO symbols (new) */
  6986.             break;
  6987.         case 't':       /* Mathematics symbols (new) */
  6988.             break;
  6989.         case 'y':       /* Blanks (new) */
  6990.             break;
  6991.         case 'x':       /* Load Area G2 (7-bit) or DRCS area (8-bit) if G0/G1 */
  6992.                         /* DRCS area always if G2/G3 */
  6993.             break;
  6994. #endif /* SN97801_5XX */
  6995.         case '@':  /* 97801 - Not quite US ASCII but close */
  6996.         case 'A':
  6997.             cs = TX_BRITISH ;
  6998.             break;
  6999.         case 'B':       /* Use the default value for G[0] */
  7000.             if (ISLINUX(tt_type_mode)) {
  7001.                 if ( pG == &G[0] )
  7002.                     cs = TX_ASCII;
  7003.                 else
  7004.                     cs = TX_8859_1 ;
  7005.             } else if ( !(ISVT100(tt_type_mode) && decnrcm) ) {
  7006.                 /*
  7007.                 From VT330/340 install guide page 81.:
  7008.                 "When you select an NRC set in multinational mode,
  7009.                 the NRC set replaces the ASCII set."
  7010.                 */
  7011. #ifdef COMMENT
  7012.                 cs = G[0].def_designation;
  7013. #else /* COMMENT */
  7014.                 cs = dec_nrc;
  7015. #endif /* COMMENT */
  7016.             }
  7017.             else {
  7018.                 cs = TX_ASCII ;
  7019.             }
  7020.             break;
  7021.         case '1':       /* DEC Alternate ROM */
  7022.             cs = TX_ASCII ;
  7023.             break;
  7024.         case 'C':
  7025.         case '5':
  7026.             cs = TX_FINNISH ;
  7027.             break;
  7028.         case 'E':
  7029.         case '6':
  7030.         case '`':
  7031.             cs = TX_NORWEGIAN ;
  7032.             break;
  7033.         case 'G':
  7034.         case 'H':
  7035.         case '7':
  7036.             cs = TX_SWEDISH ;
  7037.             break;
  7038.         case 'K':
  7039.             if ( ISLINUX(tt_type_mode) ) {       /* user defined */
  7040.                 if (pG == &G[0]) {
  7041.                     cs = TX_ASCII ;
  7042.                 } else {
  7043.                     cs = TX_CP850;               /* we will choose one */
  7044.                 }
  7045.             } else
  7046.                 cs = TX_GERMAN ;
  7047.             break;
  7048.         case 'Q':
  7049.         case '9':
  7050.             cs = TX_CN_FRENCH ;
  7051.             break;
  7052.         case 'R':
  7053.         case 'f':
  7054.             cs = TX_FRENCH ;
  7055.             break;
  7056.         case 'Y':
  7057.             cs = TX_ITALIAN ;
  7058.             break;
  7059.         case 'Z':
  7060.             cs = TX_SPANISH ;
  7061.             break;
  7062.         case '0':
  7063.             cs = TX_DECSPEC ;
  7064.             break;
  7065.         case '>':
  7066.         case '2':       /* DEC Alternate ROM - Special Graphics */
  7067.             cs = TX_DECTECH ;
  7068.             break;
  7069.         case '4':
  7070.             cs = TX_DUTCH ;
  7071.             break;
  7072.         case '<':
  7073.             if ( ISVT320(tt_type_mode) ) {
  7074.                 /* DEC User Preferred Supplemental VT320 and higher */
  7075.                 cs = dec_upss ;
  7076.             }
  7077.             else {
  7078.                 cs = TX_DECMCS ;
  7079.             }
  7080.             break;
  7081.         case '=':
  7082.             cs = TX_SWISS ;
  7083.             break;
  7084.         case '%':
  7085.             bchar = (escnext<=esclast)?escbuffer[escnext++]:0;
  7086.             if (bchar == '5') {
  7087.                 cs = TX_DECMCS ;
  7088.             }
  7089.             else if (bchar == '6') {
  7090.                 cs = TX_PORTUGUESE ;
  7091.             }
  7092. #ifdef COMMENT
  7093.             else if (bchar == '0') {
  7094.                 cs = DEC TURKISH ;
  7095.             }
  7096.             else if (bchar == '=') {
  7097.                 cs = HEBREW NRCS ;
  7098.             }
  7099.             else if ( bchar == '2' )
  7100.                 cs = TURKISH NRCS;
  7101.             else if ( bchar == '3' )
  7102.                 cs = SCS NRCS;
  7103. #endif /* COMMENT */
  7104.             break;
  7105.         case 'L':
  7106.             cs = TX_PORTUGUESE ;
  7107.             break;
  7108.         case 'i':
  7109.             cs = TX_HUNGARIAN ;
  7110.             break;
  7111.         case 'J':
  7112.             cs = TX_J201R ;
  7113.             break;
  7114.         case 'I':
  7115.             cs = TX_J201K ;
  7116.             break;
  7117.         case '*':
  7118.             cs = TX_IBMC0GRPH;  /* QANSI/Linux */
  7119.             break;
  7120.         case 'U':               /* QANSI/Linux */
  7121.         case '?':               /* This is a MSK hack for Word Perfect */
  7122.             if (pG == &G[0]) {
  7123.                 cs = TX_ASCII ;
  7124.             } else {
  7125.                 cs = TX_CP437 ;
  7126.             }
  7127.             break;
  7128.         case 'c':       /* FACET character set (new) */
  7129.             if ( IS97801(tt_type_mode) ) {
  7130.                 cs = TX_SNIFACET;
  7131.             }
  7132.             break;
  7133.         case 'e':       /* APL-ISO */
  7134.             cs = TX_APL1;
  7135.             break;
  7136.         case 'u':       /* EURO symbols (new) */
  7137.             if ( IS97801(tt_type_mode) ) {
  7138.                 cs = TX_SNIEURO;
  7139.             }
  7140.             break;
  7141.         case 'v':       /* IBM character set (new) */
  7142.             if ( IS97801(tt_type_mode) ) {
  7143.                 cs = TX_SNIIBM;
  7144.             }
  7145.             break;
  7146.         case 'w':       /* Brackets character set (new) */
  7147.             if ( IS97801(tt_type_mode) ) {
  7148.                 cs = TX_SNIBRACK;
  7149.             }
  7150.             break;
  7151.         case ' ':  /* space */
  7152.             bchar = (escnext<=esclast)?escbuffer[escnext++]:0;
  7153.             switch (bchar) {
  7154.             case '@':   /* soft character set */
  7155.                 /* not supported - do nothing */
  7156.                 debug(F100,"charset - host tried to activate soft-character-set","",0);
  7157.                 break;
  7158.             }
  7159.             break;
  7160. #ifdef COMMENT
  7161.         case '"':
  7162.             if ( bchar == '?' )
  7163.                 cs = DEC GREEK;
  7164.             else if ( bchar == '4' )
  7165.                 cs = DEC HEBREW;
  7166.             else if ( bchar == '>' )
  7167.                 cs = GREEK NRCS;
  7168.             break;
  7169.         case '&':
  7170.             if ( bchar == '4' )
  7171.                 cs = DEC CYRILLIC;
  7172.             else if ( bchar == '5' )
  7173.                 cs = RUSSIAN NRC;
  7174.             break;
  7175. #endif /* COMMENT */
  7176.  
  7177.         }
  7178.         break;
  7179.  
  7180.     case cs96:
  7181.         switch ( achar ) {
  7182. #ifdef SN97801_5XX
  7183.         case 'A':       /* 8859-1 */
  7184.         case 'B':       /* 8859-2 */
  7185.         case 'C':       /* 8859-3 */
  7186.         case 'D':       /* 8859-4 */
  7187.         case 'F':       /* 8859-5 (different) */
  7188.         case '@':       /* 8859-7 (different) */
  7189.         case 'T':       /* 8859-9 (different) */
  7190.         case 'x':       /* DRCS area */
  7191. #endif /* SN97801_5XX */
  7192.         case '<':       /* DEC User-preferred Supplemental */
  7193.             cs = dec_upss ;
  7194.             break;
  7195.  
  7196.         case 'A':
  7197.             cs = TX_8859_1 ;
  7198.             break;
  7199.         case 'B':
  7200.             cs = TX_8859_2 ;
  7201.             break;
  7202.         case 'C':
  7203.             cs = TX_8859_3 ;
  7204.             break;
  7205.         case 'D':
  7206.             cs = TX_8859_4 ;
  7207.             break;
  7208.         case 'F':
  7209.             cs = IS97801(tt_type_mode) ? TX_8859_5 : TX_8859_7 ;
  7210.             break;
  7211.         case '@':
  7212.             cs = TX_8859_7 ;
  7213.             break;
  7214.         case 'G':
  7215.             cs = TX_8859_6 ;
  7216.             break;
  7217.         case 'H':
  7218.             cs = TX_8859_8 ;
  7219.             break;
  7220.         case 'L':
  7221.             cs = TX_8859_5 ;
  7222.             break;
  7223.         case 'T': /* SNI-97801 */
  7224.             if ( !IS97801(tt_type_mode) )
  7225.                 break;
  7226.  
  7227.         case 'M': /* DEC VT3xx */
  7228.             cs = TX_8859_9 ;
  7229.             break;
  7230.  
  7231.         case 'V':
  7232.             cs = TX_8859_6 ;
  7233.             break;
  7234.  
  7235.         case '%':
  7236.             bchar = (escnext<=esclast)?escbuffer[escnext++]:0;
  7237.             if (bchar == '5') {
  7238.                 cs = TX_DECMCS ;
  7239.             }
  7240.         case '*':
  7241.             cs = TX_IBMC0GRPH;  /* QANSI/Linux */
  7242.             break;
  7243.         case 'U':               /* QANSI/Linux */
  7244.             /* fall through */
  7245.         case '?':               /* This is a MSK hack for Word Perfect */
  7246.             if (pG == &G[0]) {
  7247.                 cs = TX_ASCII ;
  7248.             } else {
  7249.                 cs = TX_CP437 ;
  7250.             }
  7251.             break;
  7252.         case 'b':
  7253.             cs = TX_8859_15;    /* Latin 9 */
  7254.             break;
  7255.  
  7256.             /* Warning the following have been allocated officially */
  7257.             /* the values below are not official.                   */
  7258.         case 'd':               /* Hack alert: DGI */
  7259.             cs = TX_DGI ;
  7260.             break;
  7261.         case 'e':               /* Hack alert: DG PC Graphics */
  7262.             cs = TX_DGPCGRPH;
  7263.             break;
  7264.         case 'f':               /* Hack alert: DG Line Drawing */
  7265.             cs = TX_DGLDGRPH;
  7266.             break;
  7267.         case 'g':               /* Hack alert: DG Word Processing Graphics */
  7268.             cs = TX_DGWPGRPH;
  7269.             break;
  7270.         case 'h':               /* Hack alert: HP Roman-8 */
  7271.             cs = TX_HPR8;
  7272.             break;
  7273.         case 'i':               /* Hack alert: HP Math-8 */
  7274.             cs = TX_HPMATH;
  7275.             break;
  7276.         case 'j':               /* Hack alert: HP Line-8 */
  7277.             cs = TX_HPLINE;
  7278.             break;
  7279.         }
  7280.     }
  7281.  
  7282.     if ( cs <= MAXTXSETS ) {
  7283.         pG->designation = cs ;
  7284.         pG->size = size ;
  7285.         pG->c1 = cs_is_std(cs) ;
  7286.         pG->national = CSisNRC( cs ) ;
  7287.         pG->rtoi = xl_u[cs] ;
  7288.         pG->itol = xl_tx[tcsl] ;
  7289.         pG->ltoi = xl_u[tcsl] ;
  7290.         pG->itor = xl_tx[cs] ;
  7291.     }
  7292.     else if ( cs != TX_UNDEF ) {
  7293.         debug(F110,"charset - ERROR","cs != TX_UNDEF",0);
  7294.         pG->designation = cs ;
  7295.         pG->c1 = FALSE ;
  7296.         pG->national = FALSE;
  7297.         pG->rtoi = NULL ;
  7298.         pG->itol = NULL ;
  7299.         pG->itor = NULL ;
  7300.         pG->ltoi = NULL ;
  7301.     }
  7302.     return cs ;
  7303. }
  7304.  
  7305. void
  7306. resetcolors( int x )
  7307. {
  7308.     if ( !x )
  7309.         attribute = defaultattribute ;
  7310.     else {
  7311.         if ( decscnm ) {
  7312.             defaultattribute =
  7313.                 byteswapcolors(colornormal);
  7314.             underlineattribute =
  7315.                 byteswapcolors(colorunderline);
  7316.             italicattribute = 
  7317.                 byteswapcolors(coloritalic);
  7318.             reverseattribute =
  7319.                 byteswapcolors(colorreverse);
  7320.             graphicattribute =
  7321.                 byteswapcolors(colorgraphic);
  7322.         }
  7323.         else {
  7324.             defaultattribute = colornormal ;
  7325.             underlineattribute = colorunderline;
  7326.             italicattribute = coloritalic;
  7327.             reverseattribute = colorreverse;
  7328.             graphicattribute = colorgraphic;
  7329.         }
  7330.         attribute = defaultattribute ;
  7331.         borderattribute = colorborder ;
  7332.     }
  7333. }
  7334.  
  7335. /*---------------------------------------------------------------------------*/
  7336. /* movetoscreen                                                              */
  7337. /*---------------------------------------------------------------------------*/
  7338. void
  7339. movetoscreen(char *source, int x, int y, int len) {
  7340.    /* x and y begin at 1 */
  7341.  
  7342.    int c,l=0 ;
  7343.    videoline * line = NULL ;
  7344.  
  7345.    line = VscrnGetLineFromTop(VTERM, y-1) ;
  7346.    while (l<len) {
  7347.       if ( x-1 == VscrnGetWidth(VTERM) ) {
  7348.          x=1 ;
  7349.          y++ ;
  7350.          line = VscrnGetLineFromTop(VTERM, y-1) ;
  7351.          }
  7352.       line->cells[x-1].c = source[l] ;
  7353.       x++ ;
  7354.       }
  7355.     VscrnIsDirty(VTERM);
  7356. }
  7357.  
  7358. void
  7359. os2debugoff() {                         /* Turn off debugging from outside */
  7360.     debug(F100,"os2debugoff","",0);
  7361.     attribute = defaultattribute;
  7362. }
  7363.  
  7364. void
  7365. os2bold() {                             /* Toggle boldness from the outside */
  7366.     tn_bold = 1 - tn_bold;
  7367. }
  7368.  
  7369. void                            /* Toggle session debugging */
  7370. flipdebug() {
  7371.     if (debses) {
  7372.         attribute = defaultattribute;   /* Back to normal coloring */
  7373.         setdebses(0);                     /* Turn off session debug flag */
  7374.     } else {
  7375.         setdebses(1);                     /* Turn on session debug flag */
  7376.     }
  7377.     if (!scrollflag[VTERM] && status_saved < 0)
  7378.       ipadl25();
  7379. }
  7380.  
  7381.  
  7382. #ifdef NETCONN
  7383. #ifdef TCPSOCKET
  7384. do_tn_cmd(CHAR x) {
  7385.     CHAR temp[3];
  7386.  
  7387.     if (network && IS_TELNET()) { /* TELNET */
  7388.         temp[0] = (CHAR) IAC;
  7389.         temp[1] = x;
  7390.         temp[2] = NUL;
  7391.         ttol((CHAR *)temp,2);
  7392.  
  7393.         if (tn_deb || debses || deblog) {
  7394.             extern char tn_msg[];
  7395.             ckmakmsg(tn_msg,TN_MSG_LEN,"TELNET SENT ",TELCMD(x),NULL,NULL);
  7396.             debug(F101,tn_msg,"",x);
  7397.             if (tn_deb || debses) tn_debug(tn_msg);
  7398.         }
  7399.     } else
  7400.       bleep(BP_FAIL);
  7401.     return(0);
  7402. }
  7403. #endif /* TCPSOCKET */
  7404. #endif /* NETCONN */
  7405.  
  7406. #ifndef NOKVERBS
  7407. void
  7408. bookmarkset( int vmode )
  7409. {
  7410.     int mark = 0 ;
  7411.     CHAR x1;
  7412.     con_event evt ;
  7413.  
  7414.     save_status_line();
  7415.     escapestatus[vmode] = TRUE ;
  7416.     strcpy(exittext,"Cancel: Space"); /* Make special one */
  7417.     strcpy(usertext," SET MARK: [ ]"); /* with mini-echo-buffer */
  7418.     if (vik.help > 255 && keyname(vik.help))
  7419.         sprintf(helptext, "Help: %s", keyname(vik.help));       /* safe */
  7420.     VscrnIsDirty(vmode);  /* status line needs to be updated */
  7421.  
  7422.     do {
  7423.         evt = congev(vmode,-1) ;
  7424.         switch (evt.type) {
  7425.         case key:
  7426. #ifdef COMMENT
  7427.             x1 = mapkey(evt.key.scancode); /* Get value from keymap */
  7428. #else
  7429.             x1 = evt.key.scancode ;
  7430. #endif
  7431.             break;
  7432.         case kverb:
  7433.             x1 = evt.kverb.id & ~F_KVERB;
  7434.             break;
  7435.         case macro:
  7436.             if ( evt.macro.string )
  7437.                 free( evt.macro.string ) ;
  7438.             x1 = 0;
  7439.             break;
  7440.         case literal:
  7441.             if ( evt.literal.string )
  7442.                 free( evt.literal.string ) ;
  7443.             x1 = 0;
  7444.             break;
  7445.         case csi:
  7446.         case esc:
  7447.         default:
  7448.             x1 = 0 ;
  7449.         }
  7450.         if ( x1 == K_HELP )
  7451.             popuphelp(vmode,hlp_bookmark);
  7452.     } while ( x1 == K_HELP );
  7453.     if ((x1 < '0') || (x1 > '9')) {
  7454.         if (x1 != SP)
  7455.             bleep(BP_FAIL);
  7456.         goto bookmark_exit;
  7457.     }
  7458.  
  7459.     sprintf(usertext," SET MARK: [%c]", x1); /* Echo char */
  7460.     VscrnIsDirty(vmode);  /* status line needs to be updated */
  7461.     msleep(500);      /* let the user see it for a bit */
  7462.     mark = x1 - '0' ;
  7463.     VscrnSetBookmark( vmode, mark,
  7464.                       (tt_roll[vmode] && scrollflag[vmode]) ?
  7465.                       VscrnGetScrollTop(vmode) : VscrnGetTop(vmode) ) ;
  7466.  
  7467.   bookmark_exit:                        /* Common exit point */
  7468.     escapestatus[vmode] = FALSE ;
  7469.     restore_status_line();              /* Restore status line */
  7470.     return;
  7471. }
  7472.  
  7473. int
  7474. bookmarkget( int vmode )
  7475. {
  7476.    return VscrnGetBookmark( vmode, 0 ) ;
  7477. }
  7478.  
  7479. void
  7480. bookmarkreset( int vmode )
  7481. {
  7482.    VscrnSetBookmark( vmode, 0, -1 ) ;
  7483. }
  7484.  
  7485. void
  7486. bookmarkjump( int vmode )
  7487. {
  7488.     int mark = 0, bookmark ;
  7489.     CHAR x1;
  7490.     con_event evt ;
  7491.  
  7492.     save_status_line();
  7493.     escapestatus[vmode] = TRUE ;
  7494.     strcpy(exittext,"Cancel: Space"); /* Make special one */
  7495.     strcpy(usertext," GO MARK: [ ]"); /* with mini-echo-buffer */
  7496.     if (vik.help > 255 && keyname(vik.help))
  7497.         sprintf(helptext, "Help: %s", keyname(vik.help));
  7498.     VscrnIsDirty(vmode);  /* status line needs to be updated */
  7499.  
  7500.     do {
  7501.         evt = congev(vmode,-1) ;
  7502.         switch (evt.type) {
  7503.         case key:
  7504. #ifdef COMMENT
  7505.             x1 = mapkey(evt.key.scancode); /* Get value from keymap */
  7506. #else
  7507.             x1 = evt.key.scancode ;
  7508. #endif
  7509.             break;
  7510.         case kverb:
  7511.             x1 = evt.kverb.id & ~F_KVERB;
  7512.             break;
  7513.         case macro:
  7514.             if ( evt.macro.string )
  7515.                 free( evt.macro.string ) ;
  7516.             x1 = 0;
  7517.             break;
  7518.         case literal:
  7519.             if ( evt.literal.string )
  7520.                 free( evt.literal.string ) ;
  7521.             x1 = 0;
  7522.             break;
  7523.         case csi:
  7524.         case esc:
  7525.         default:
  7526.             x1 = 0 ;
  7527.         }
  7528.         if ( x1 == K_HELP )
  7529.             popuphelp(vmode,hlp_bookmark);
  7530.     } while ( x1 == K_HELP );
  7531.     if ((x1 < '0') || (x1 > '9')) {
  7532.         if (x1 != SP)
  7533.             bleep(BP_FAIL);
  7534.         goto bookmark_exit;
  7535.     }
  7536.  
  7537.     sprintf(usertext," GO MARK: [%c]", x1); /* Echo char */
  7538.     VscrnIsDirty(vmode);  /* status line needs to be updated */
  7539.     msleep(500);      /* let the user see it for a bit */
  7540.     mark = x1 - '0' ;
  7541.     bookmark = VscrnGetBookmark( vmode, mark ) ;
  7542.  
  7543.     if ( bookmark < 0 )
  7544.     {
  7545.         bleep(BP_FAIL);
  7546.         goto bookmark_exit;
  7547.     }
  7548.  
  7549.     if (!tt_roll[vmode]) {
  7550.         if ( VscrnSetTop(vmode, bookmark) < 0 )
  7551.             bleep(BP_WARN) ;
  7552.     }
  7553.     else {
  7554.         if ( VscrnSetScrollTop(vmode, bookmark) < 0 )
  7555.             bleep(BP_WARN);
  7556.     }
  7557.  
  7558.   bookmark_exit:                        /* Common exit point */
  7559.     restore_status_line();              /* Restore status line */
  7560.     escapestatus[vmode] = FALSE ;
  7561.     return;
  7562. }
  7563.  
  7564. void
  7565. gotojump( int vmode )
  7566. {
  7567.    int line = 0, negative = 0, maxval = 0 ;
  7568.    CHAR x1;
  7569.    con_event evt ;
  7570.  
  7571.    save_status_line();
  7572.    escapestatus[vmode] = TRUE ;
  7573.  
  7574.    do {
  7575.       maxval = (VscrnGetEnd(vmode) - VscrnGetBegin(vmode) - VscrnGetHeight(vmode)
  7576.                  + VscrnGetBufferSize(vmode))%VscrnGetBufferSize(vmode) ;
  7577.  
  7578.       if ( negative && line < -maxval )
  7579.       {
  7580.          line = -maxval ;
  7581.          bleep(BP_NOTE);
  7582.       }
  7583.  
  7584.       if ( !negative && line > (maxval+1) )
  7585.       {
  7586.          line = maxval+1 ;
  7587.          bleep(BP_NOTE);
  7588.       }
  7589.  
  7590.        strcpy(exittext,"Cancel: Space"); /* Make special one */
  7591.        sprintf(usertext," GOTO: [%10d]",line); /* with mini-echo-buffer */
  7592.        helptext[0] = '\0' ;
  7593.        if (vik.help > 255 && keyname(vik.help))
  7594.            sprintf(hostname, "Help: %s", keyname(vik.help));
  7595.        VscrnIsDirty(vmode);  /* status line needs to be updated */
  7596.  
  7597.        evt = congev(vmode,-1) ;
  7598.        switch (evt.type) {
  7599.        case key:
  7600. #ifdef COMMENT
  7601.            x1 = mapkey(evt.key.scancode); /* Get value from keymap */
  7602. #else
  7603.            x1 = evt.key.scancode ;
  7604. #endif
  7605.            break;
  7606.        case kverb:
  7607.            x1 = evt.kverb.id & ~F_KVERB;
  7608.            break;
  7609.        case macro:
  7610.            if ( evt.macro.string )
  7611.                free( evt.macro.string ) ;
  7612.            x1 = 0;
  7613.            break;
  7614.        case literal:
  7615.            if ( evt.literal.string )
  7616.                free( evt.literal.string ) ;
  7617.            x1 = 0;
  7618.            break;
  7619.        case csi:
  7620.        case esc:
  7621.        default:
  7622.            x1 = 0 ;
  7623.        }
  7624.  
  7625.        if ( x1 == K_HELP )
  7626.        {
  7627.            popuphelp(vmode,hlp_bookmark);
  7628.        }
  7629.        else if ( x1 == '-' )
  7630.        {
  7631.            negative = (negative ? FALSE : TRUE) ;
  7632.        }
  7633.        else if ( x1 >= '0' && x1 <= '9' )
  7634.        {
  7635.            line = line * 10 + (x1-'0') ;
  7636.        }
  7637.        else if ( x1 == 8 || x1 == 127 )
  7638.        {
  7639.            line = line / 10 ;
  7640.        }
  7641.        else if ( x1 == 13 )
  7642.        {
  7643.            break;
  7644.        }
  7645.        else
  7646.        {
  7647.            if ( x1 != ' ' )
  7648.                bleep(BP_FAIL);
  7649.            goto bookmark_exit;
  7650.        }
  7651.  
  7652.        if ( ( negative && line > 0 ) || ( !negative && line < 0 ) )
  7653.            line = -line ;
  7654.  
  7655.    } while ( TRUE );
  7656.  
  7657.     msleep(500);      /* let the user see it for a bit */
  7658.  
  7659.     if ( line <= 0 )
  7660.     {
  7661.         if (!tt_roll[vmode]) {
  7662.             if ( VscrnSetTop(vmode, VscrnGetEnd(vmode)-VscrnGetHeight(vmode)+line) < 0 )
  7663.                 bleep(BP_WARN) ;
  7664.         }
  7665.         else {
  7666.             if ( VscrnSetScrollTop(vmode, VscrnGetEnd(vmode)-VscrnGetHeight(vmode)+line) < 0 )
  7667.                 bleep(BP_WARN);
  7668.         }
  7669.     }
  7670.     else
  7671.     {
  7672.         if (!tt_roll[vmode]) {
  7673.             if ( VscrnSetTop(vmode, VscrnGetBegin(vmode)+line-1) < 0 )
  7674.                 bleep(BP_WARN) ;
  7675.         }
  7676.         else {
  7677.             if ( VscrnSetScrollTop(vmode, VscrnGetBegin(vmode)+line-1) < 0 )
  7678.                 bleep(BP_WARN);
  7679.         }
  7680.     }
  7681.  
  7682.   bookmark_exit:                        /* Common exit point */
  7683.     restore_status_line();              /* Restore status line */
  7684.     escapestatus[vmode] = FALSE ;
  7685.     return;
  7686. }
  7687.  
  7688. BOOL
  7689. search( BYTE vmode, BOOL forward, BOOL prompt )
  7690. {
  7691. #ifdef DCMDBUF
  7692.    extern int * inpcas;
  7693. #else
  7694.    extern int inpcas[] ;
  7695. #endif /* DCMDBUF */
  7696.    static char searchstring[63] = "" ;
  7697.    CHAR x1;
  7698.    con_event evt ;
  7699.    int line = 1 ;
  7700.    int found = 0 ;
  7701.    static int len = 0 ;
  7702.    static int row=-1, col=-1 ;
  7703.  
  7704.     if ( prompt )
  7705.     {
  7706.         save_status_line();
  7707.         escapestatus[vmode] = TRUE ;
  7708.  
  7709.         do {
  7710.             len = strlen( searchstring ) ;
  7711.             strcpy(exittext,"Cancel: ESC"); /* Special one with edit buffer */
  7712.             sprintf(usertext," %s: [%-16s]",forward ? "SEARCH>" : "<SEARCH",
  7713.                   len <= 16 ? searchstring : &searchstring[len-16] );
  7714.             helptext[0] = '\0' ;
  7715.             if (vik.help > 255 && keyname(vik.help))
  7716.                 sprintf(hostname, "Help: %s", keyname(vik.help));
  7717.             VscrnIsDirty(vmode);  /* status line needs to be updated */
  7718.  
  7719.             evt = congev(vmode,-1) ;
  7720.             switch (evt.type) {
  7721.             case key:
  7722. #ifdef COMMENT
  7723.                 x1 = mapkey(evt.key.scancode); /* Get value from keymap */
  7724. #else
  7725.                 x1 = evt.key.scancode ;
  7726. #endif
  7727.                 break;
  7728.             case kverb:
  7729.                 x1 = evt.kverb.id & ~F_KVERB;
  7730.                 break;
  7731.             case macro:
  7732.                 if ( evt.macro.string )
  7733.                     free( evt.macro.string ) ;
  7734.                 x1 = 0;
  7735.                 break;
  7736.             case literal:
  7737.                 if ( evt.literal.string )
  7738.                     free( evt.literal.string ) ;
  7739.                 x1 = 0;
  7740.                 break;
  7741.             case esc:
  7742.             case csi:
  7743.             default:
  7744.                 x1 = 0 ;
  7745.             }
  7746.  
  7747.             if ( x1 == K_HELP )
  7748.             {
  7749.                 popuphelp(vmode,hlp_search);
  7750.             }
  7751.             else if ( x1 >= ' ' && x1 <= 126 || x1 >= 128 && x1 <= 255 )
  7752.             {
  7753.                 if ( len >= 62 ) {
  7754.                     bleep(BP_WARN);
  7755.                 }
  7756.                 else {
  7757.                     searchstring[len] = x1 ;
  7758.                     searchstring[len+1] = '\0' ;
  7759.                 }
  7760.             }
  7761.             else if ( x1 == 8 || x1 == 127 )
  7762.             {
  7763.                 searchstring[len-1] = '\0' ;
  7764.             }
  7765.             else if ( x1 == 13 )
  7766.             {
  7767.                 break;
  7768.             }
  7769.             else if ( x1 == 21 )
  7770.             {
  7771.                 searchstring[0] = '\0' ;
  7772.                 len = 0 ;
  7773.             }
  7774.             else
  7775.             {
  7776.                 if ( x1 != ESC )
  7777.                     bleep(BP_FAIL);
  7778.                 goto search_exit;
  7779.             }
  7780.         } while ( TRUE );
  7781.  
  7782.         msleep(500);      /* let the user see it for a bit */
  7783.         restore_status_line();          /* Restore status line */
  7784.         escapestatus[vmode] = FALSE ;
  7785.  
  7786.         col = VscrnGetCurPos(vmode)->x ;
  7787.         row = (( markmodeflag[vmode] ? VscrnGetTop(vmode) : VscrnGetScrollTop(vmode) )
  7788.                 + VscrnGetCurPos(vmode)->y)%VscrnGetBufferSize(vmode) ;
  7789.     }
  7790.     else
  7791.     {
  7792.         if ( row < 0 || col < 0 || !searchstring || !searchstring[0] )
  7793.         {
  7794.             bleep(BP_FAIL);
  7795.             goto search_exit ;
  7796.         }
  7797.  
  7798.         /* advance the cursor */
  7799.         if ( forward )
  7800.         {
  7801.             col++ ;
  7802.             if ( col == vscrn[vmode].lines[row%vscrn[vmode].linecount].width )
  7803.             {
  7804.                 if ( row != VscrnGetEnd(vmode) )
  7805.                 {
  7806.                     col = 0 ;
  7807.                     row++ ;
  7808.                 }
  7809.                 else
  7810.                 {
  7811.                     col--;
  7812.                     goto search_exit;
  7813.                 }
  7814.             }
  7815.             if ( row >= VscrnGetBufferSize( vmode ) )
  7816.                 row = 0 ;
  7817.         }
  7818.         else
  7819.         {
  7820.             col-- ;
  7821.             if ( col < 0 )
  7822.             {
  7823.                 if ( row != VscrnGetBegin(vmode) )
  7824.                 {
  7825.                     row-- ;
  7826.                     col = vscrn[vmode].lines[row%vscrn[vmode].linecount].width - 1 ;
  7827.                 }
  7828.                 else
  7829.                 {
  7830.                     col++;
  7831.                     goto search_exit;
  7832.                 }
  7833.             }
  7834.             if ( row < 0 )
  7835.                 row = VscrnGetBufferSize(vmode) -1 ;
  7836.         }
  7837.     }
  7838.  
  7839.     /* Now we have the string to search for */
  7840.     /* so lets search for it ???            */
  7841.     {
  7842.         char *s = searchstring ;
  7843.         int y=len,i;
  7844.         char *xx, *xp, *xq = (char *)0;
  7845.         CHAR c;
  7846.  
  7847.         i = 0 ;                         /* String pattern match position */
  7848.  
  7849.         if (!inpcas[cmdlvl] || !forward)
  7850.         {               /* INPUT CASE = IGNORE?  */
  7851.             xp = malloc(y+2);           /* Make a separate copy of the */
  7852.             if (!xp)
  7853.             {                   /* search string. */
  7854.                 row = col = -1 ;
  7855.                 return(found);
  7856.             }
  7857.             else
  7858.                 xq = xp;                        /* Keep pointer to beginning. */
  7859.  
  7860.             if ( !forward )
  7861.             {
  7862.                 xp = xp + len ;
  7863.                 *xp = NUL ;
  7864.                 xp--;
  7865.             }
  7866.  
  7867.             while (*s) {                        /* Yes, convert to lowercase */
  7868.                 *xp = *s;
  7869.                 if (!inpcas[cmdlvl] && isupper(*xp))
  7870.                     *xp = tolower(*xp);
  7871.                 if ( forward )
  7872.                     xp++;
  7873.                 else
  7874.                     xp--;
  7875.                 s++;
  7876.             }
  7877.             if ( forward )
  7878.                 *xp = NUL;                      /* Terminate it! */
  7879.             s = xq;                             /* Move search pointer to it. */
  7880.         }
  7881.  
  7882.         while (TRUE)
  7883.         {
  7884.             c = vscrn[vmode].lines[row].cells[col].c;                   /* Get next character */
  7885.             if (!inpcas[cmdlvl])
  7886.             {           /* Ignore alphabetic case? */
  7887.                 if (isupper(c))
  7888.                     c = tolower(c); /* Yes */
  7889.             }
  7890.             debug(F000,"search char","",c);
  7891.             debug(F000,"compare char","",(CHAR) s[i]);
  7892.             if (c == s[i])
  7893.             {           /* Check for match */
  7894.                 if ( i==0 )
  7895.                     VscrnUnmarkAll( vmode ) ;
  7896.                 VscrnMark( vmode, row, col, col );
  7897.                 i++;                    /* Got one, go to next character */
  7898.             }
  7899.             else
  7900.             {                   /* Don't have a match */
  7901.                 int j;
  7902.                 for (j = i; i > 0; )
  7903.                 {       /* [jrs] search backwards for it  */
  7904.                     i--;
  7905.                     if (c == s[i])
  7906.                     {
  7907.                         if (!strncmp(s,&s[j-i],i))
  7908.                         {
  7909.                             /* This code assumes the matching sub pattern */
  7910.                             /* appears entirely on one line.  But there   */
  7911.                             /* are situations where it might be split.    */
  7912.                             /* What then? */
  7913.                             VscrnUnmarkAll(vmode);
  7914.                             if ( forward )
  7915.                                 VscrnMark( vmode, row, col-i, col ) ;
  7916.                             else
  7917.                                 VscrnMark( vmode, row, col, col+i ) ;
  7918.                             i++;
  7919.                             break;
  7920.                         }
  7921.                     }
  7922.                 }
  7923.             }                           /* [jrs] or return to zero from -1 */
  7924.             if (s[i] == '\0')
  7925.             {           /* Matched all the way to end? */
  7926.                 VscrnMark( vmode, row, col, col ) ;
  7927.                 found = 1;                      /* Yes, */
  7928.                 line = row ;
  7929.                 break;                  /* done. */
  7930.             }
  7931.  
  7932.             /* check to see if we hit the begin or end of vscrn */
  7933.             if ( forward && row == VscrnGetEnd(vmode) && col == vscrn[vmode].lines[row%vscrn[vmode].linecount].width-1 ||
  7934.                  !forward && row == VscrnGetBegin(vmode) && col == 0 )
  7935.                 break;    /* search string not found */
  7936.  
  7937.             /* advance the cursor */
  7938.             if ( forward )
  7939.             {
  7940.                 col++ ;
  7941.                 if ( col == vscrn[vmode].lines[row%vscrn[vmode].linecount].width )
  7942.                 {
  7943.                     if ( row != VscrnGetEnd(vmode) )
  7944.                     {
  7945.                         col = 0 ;
  7946.                         row++ ;
  7947.                     }
  7948.                     else
  7949.                     {
  7950.                         col--;
  7951.                         break;
  7952.                     }
  7953.                 }
  7954.                 if ( row >= VscrnGetBufferSize( vmode ) )
  7955.                     row = 0 ;
  7956.             }
  7957.             else
  7958.             {
  7959.                 col-- ;
  7960.                 if ( col < 0 )
  7961.                 {
  7962.                     if ( row != VscrnGetBegin(vmode) )
  7963.                     {
  7964.                         row-- ;
  7965.                         col = vscrn[vmode].lines[row%vscrn[vmode].linecount].width - 1 ;
  7966.                     }
  7967.                     else
  7968.                     {
  7969.                         col++;
  7970.                         break;
  7971.                     }
  7972.                 }
  7973.                 if ( row < 0 )
  7974.                     row = VscrnGetBufferSize(vmode) -1 ;
  7975.             }
  7976.         }
  7977.  
  7978.         if ((!inpcas[cmdlvl] || !forward) && xq)
  7979.             free(xq); /* Free this if it was malloc'd. */
  7980.     }
  7981.  
  7982.     /* okay, did we find it?  if so, go there */
  7983.     if ( found )
  7984.     {
  7985.         if ( row >= VscrnGetTop(vmode) && row <= VscrnGetEnd(vmode) ||
  7986.              row <= VscrnGetEnd(vmode)
  7987.              && (row+VscrnGetBufferSize(vmode)) > VscrnGetTop(vmode)
  7988.              && VscrnGetEnd(vmode) < VscrnGetTop(vmode)
  7989.              )
  7990.         {
  7991.             if ( tt_roll[vmode] )
  7992.                 VscrnSetScrollTop(vmode, VscrnGetTop(vmode) ) ;
  7993.             VscrnSetCurPos( vmode, col,
  7994.                             (row - VscrnGetTop(vmode) +
  7995.                               VscrnGetHeight(vmode)-(tt_status[vmode]?1:0))
  7996.                             %(VscrnGetHeight(vmode)-(tt_status[vmode]?1:0)) ) ;
  7997.         }
  7998.         else
  7999.         {
  8000.             if(tt_roll[vmode])
  8001.                 VscrnSetScrollTop( vmode, row ) ;
  8002.             else
  8003.                 VscrnSetTop( vmode, row ) ;
  8004.             VscrnSetCurPos( vmode, col, 0 ) ;
  8005.         }
  8006.     }
  8007.  
  8008.   search_exit:                  /* Common exit point */
  8009.     if ( !found )
  8010.     {
  8011.         VscrnUnmarkAll(vmode);
  8012.         row = col = -1 ;             /* start next search from current cursor position */
  8013.     }
  8014.  
  8015.     return(found);
  8016. }
  8017.  
  8018. void
  8019. dokcompose( int mode, int ucs2 )
  8020. {
  8021.     int i, round=0;
  8022.     USHORT x[4]={SP,SP,SP,SP}, c=0;
  8023.     con_event evt;
  8024.  
  8025.     if (txrinfo[GL->designation]->family != AL_ROMAN ||
  8026.          txrinfo[GR->designation]->family != AL_ROMAN ) {
  8027.         bleep(BP_WARN);         /* Not Latin character-set */
  8028.         goto compose_exit;
  8029.     }
  8030.     save_status_line();
  8031.     escapestatus[mode] = TRUE ;
  8032.     strcpy(exittext,"Cancel: Space"); /* Make special one */
  8033.     if (vik.help > 255 && keyname(vik.help))
  8034.         sprintf(helptext, "Help: %s", keyname(vik.help));
  8035.  
  8036.     for (i=0; i < (ucs2 ? 4 : 2); i++)  {
  8037.         /* mini-echo-buffer */
  8038.         if ( ucs2 )
  8039.             sprintf(usertext," UNICODE: [%c%c%c%c]",x[0],x[1],x[2],x[3]);
  8040.         else
  8041.             sprintf(usertext," COMPOSE: [%c%c]",x[0],x[1]);
  8042.         VscrnIsDirty(mode);        /* Status line needs update */
  8043.  
  8044.         do {
  8045.             evt = congev(mode,-1) ;
  8046.             switch (evt.type) {
  8047.             case key:
  8048.                 x[i] = evt.key.scancode ;
  8049.                 break;
  8050.             case kverb:
  8051.                 x[i] = evt.kverb.id & ~F_KVERB;
  8052.                 break;
  8053.             case macro:
  8054.                 if ( evt.macro.string )
  8055.                     free( evt.macro.string ) ;
  8056.                 x[i] = SP;
  8057.             break;
  8058.             case literal:
  8059.                 if ( evt.literal.string )
  8060.                     free( evt.literal.string ) ;
  8061.                 x[i] = SP;
  8062.             break;
  8063.             case csi:
  8064.             case esc:
  8065.             default:
  8066.                 x[i] = SP;
  8067.             }
  8068.             if ( x[i] == K_HELP )
  8069.                 popuphelp(mode,ucs2 ? hlp_ucs2 : hlp_compose);
  8070.         } while ( x[i] == K_HELP );
  8071.         if ((x[i] <= SP) || (x[i] > 0x7E) || ucs2 && !isxdigit(x[i]) ) {
  8072.             if (x[i] != SP)
  8073.                 bleep(BP_WARN);
  8074.             goto compose_exit;
  8075.         }
  8076.     }
  8077.  
  8078.     if ( ucs2 ) {
  8079.         char hexstr[5];
  8080.  
  8081.         sprintf(usertext," UNICODE: [%c%c%c%c]",x[0],x[1],x[2],x[3]);
  8082.         VscrnIsDirty(mode);        /* Status line needs update */
  8083.  
  8084.         for ( i=0;i<4;i++ )
  8085.             hexstr[i] = x[i];
  8086.         hexstr[5] = NUL;
  8087.  
  8088.         c = hextoulong(hexstr,4);
  8089.     } else {
  8090.         sprintf(usertext," COMPOSE: [%c%c]",x[0],x[1]);
  8091.         VscrnIsDirty(mode);        /* Status line needs update */
  8092.  
  8093.         if (tcsl == TX_CP852) {     /* East European */
  8094.             for (i = 0; i < nl2ktab; i++) /* Look up the 2-char sequence */
  8095.                 if ((x[0] == l2ktab[i].c1) && (x[1] == l2ktab[i].c2))
  8096.                     break;
  8097.             if (i >= nl2ktab) {     /* Not found */
  8098.                 bleep(BP_WARN);
  8099.                 goto compose_exit;
  8100.             } else c = l2ktab[i].c3; /* Latin-2 Character we found */
  8101.  
  8102.             /* Convert to Unicode */
  8103.             c = (*xl_u[TX_8859_2])(c);
  8104.         } else {
  8105.             for (i = 0; i < nl1ktab; i++) /* Look up the 2-char sequence */
  8106.                 if ((x[0] == l1ktab[i].c1) && (x[1] == l1ktab[i].c2))
  8107.                     break;
  8108.             if (i >= nl1ktab) {         /* Not found */
  8109.                 bleep(BP_WARN);
  8110.                 goto compose_exit;
  8111.             } else
  8112.                 c = l1ktab[i].c3;    /* Latin-1 Character we found */
  8113.  
  8114.             /* Convert to Unicode */
  8115.             c = (*xl_u[TX_8859_1])(c);
  8116.  
  8117.             /* Convert c to local character set */
  8118.             c = (*xl_tx[tcsl])(c);
  8119.         }
  8120.     }
  8121.  
  8122.     /* We know have a UCS2 value in 'c'.  Output it */
  8123.     if ( mode == VTERM ) {
  8124.         /* Convert c to remote character set */
  8125.         if ( tt_utf8 ) {
  8126.             CHAR * bytes = NULL;
  8127.             int count,i;
  8128.  
  8129.             count = ucs2_to_utf8( c, &bytes );
  8130.             for ( i=0; i<count ; i++ )
  8131.                 sendcharduplex(bytes[i],TRUE);   /* Send it */
  8132.         } else {
  8133.             c = (*xl_tx[tcsr])(c);
  8134.             sendcharduplex(c,TRUE);             /* Send it */
  8135.         }
  8136.     } else {
  8137.         /* Convert c to local character set */
  8138.         c = (*xl_tx[tcsl])(c);
  8139.         putkey(mode,c);
  8140.     }
  8141.     msleep(333);                /* Some time to look at minibuffer */
  8142.  
  8143.   compose_exit:                 /* Common exit point */
  8144.     restore_status_line();      /* Restore status line */
  8145.     escapestatus[mode] = FALSE ;
  8146. }
  8147.  
  8148. /* Set the Keyboard Mode (English, Russian, Hebrew, ...) */
  8149.  
  8150. void
  8151. set_kb_mode( int kb_mode ) {
  8152.     static int tcsl_sav = -1;
  8153.     int i,x;
  8154.  
  8155.     if ( tt_kb_mode == kb_mode )
  8156.         return;
  8157.  
  8158.     tt_kb_mode = kb_mode;
  8159.  
  8160. #ifdef COMMENT
  8161.     /* I added this code because I didn't think that Russian and Hebrew  */
  8162.     /* keyboard modes could work without it.  However, it turns out that */
  8163.     /* sendcharduplex() has a special check to convert from CP866 to the */
  8164.     /* remote character set if Russian keyboard mode is in use or from   */
  8165.     /* CP862 if Hebrew is in use.  Therefore, this code is not necessary */
  8166.  
  8167.     switch ( kb_mode ) {
  8168.     case KBM_RU:
  8169.         if ( tcsl_sav == -1 )
  8170.             tcsl_sav = tcsl;
  8171.         tcsl = TX_CP866;
  8172.         break;
  8173.     case KBM_HE:
  8174.         if ( tcsl_sav == -1 )
  8175.             tcsl_sav = tcsl;
  8176.         tcsl = TX_CP862;
  8177.         break;
  8178.     default:
  8179.         if ( tcsl_sav != -1 ) {
  8180.             tcsl = tcsl_sav;
  8181.             tcsl_sav = -1;
  8182.         }
  8183.     }
  8184.  
  8185.     for (i = 0; i < 4; i++) {
  8186.         x = G[i].designation;
  8187.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  8188.         x = G[i].def_designation;
  8189.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  8190.  
  8191.         /* initialize DEC Graphic Set Translation functions if necessary */
  8192.         G[i].rtoi = xl_u[G[i].designation];
  8193.         G[i].itol = xl_tx[tcsl] ;
  8194.         G[i].ltoi = xl_u[tcsl] ;
  8195.         G[i].itor = xl_tx[G[i].designation];
  8196.         G[i].init = FALSE ;
  8197.     }
  8198. #endif /* COMMENT */
  8199. }
  8200.  
  8201.  
  8202. /*  D O K V E R B  --  Execute a keyboard verb  */
  8203.  
  8204. void
  8205. dokverb(int mode, int k) {                        /* 'k' is the kverbs[] table index. */
  8206.     extern int activecmd ;
  8207.     int x;
  8208.     con_event evt ;
  8209.     char escbuf[10];                    /* For building key escape sequences */
  8210. /*
  8211.   Items are grouped according to function, and checked approximately
  8212.   in order of how frequently they are used.
  8213. */
  8214.     k &= ~(F_KVERB);                    /* Clear KVERB flag */
  8215.  
  8216.     if (k >= K_ACT_MIN && k <= K_ACT_MAX) {
  8217.  
  8218.         switch (k) {                    /* Common Kermit actions first ... */
  8219.         case K_EXIT:  /* \Kexit: */
  8220.             if ( mode == VTERM ) {
  8221.                 if ( markmodeflag[mode] != notmarking ) {
  8222.                     markmode(mode,k);
  8223.                 }
  8224.                 else if ( tt_escape )
  8225.                     SetConnectMode(FALSE,CSX_ESCAPE);/*   Exit from terminal emulator */
  8226.             }
  8227.             else if ((mode == VCMD) && !(what & W_XFER)) {
  8228.                 if (
  8229. #ifndef NOSPL
  8230.                  cmdlvl == 0
  8231. #else
  8232.                  tlevel == -1
  8233. #endif /* NOSPL */
  8234.                    ) {
  8235.                     x = conect(1);
  8236. #ifdef KUI
  8237.                     KuiSetTerminalConnectButton(x);
  8238. #endif /* KUI */
  8239.                 } else
  8240.                     bleep(BP_WARN);
  8241.             }
  8242.             return;
  8243.  
  8244.         case K_QUIT:  /* \Kquit: */
  8245.             if ( markmodeflag[mode] != notmarking ) {
  8246.                 markmode(mode,k);
  8247.                 /* return ; */
  8248.             }
  8249.             if ( mode == VTERM ) {
  8250.                 quitnow = 1;
  8251.                 strcpy(termessage, "Hangup and quit.\n");
  8252.                 SetConnectMode(0,CSX_USERDISC);
  8253.             }
  8254.             else {
  8255.                 ttclos(0);
  8256.                 doexit(GOOD_EXIT,0);
  8257.             }
  8258.             return;
  8259.  
  8260.         case K_BREAK:                 /* \Kbreak */
  8261.             if (mode == VTERM && !kbdlocked()) {
  8262.                 int iosav = term_io;
  8263.                 term_io = FALSE;
  8264.                 msleep(750);               /* Allow term thread to notice */
  8265.                 ttsndb();
  8266.                 term_io = iosav;
  8267.             }
  8268.             return;
  8269.         case K_DOS:                   /* \Kdos or \Kos2 */
  8270.             os2push(); 
  8271.             return;                   /*   Push to system */
  8272.         case K_RESET:                 /* \Kreset */
  8273.             if ( mode == VTERM )
  8274.               doreset(1); 
  8275.             return;         /*   Reset terminal emulator */
  8276.         case K_HELP: {        /* \Khelp */
  8277.               enum helpscreen x = hlp_normal ;
  8278.               if ( markmodeflag[mode] != notmarking ) {
  8279.                   markmode(mode,k);
  8280.                   return ;
  8281.               }
  8282.               if ( scrollstatus[mode] ) {
  8283.                   scrollback(mode,k);
  8284.                   return ;
  8285.               }
  8286.               while ( popuphelp(mode,x) == ( F_KVERB | K_HELP ) )
  8287. #ifdef OS2MOUSE
  8288.                   switch ( x ) {
  8289.                   case hlp_normal:
  8290.                       x = hlp_rollback;
  8291.                       break;
  8292.                   case hlp_rollback:
  8293.                       x = hlp_mouse;
  8294.                       break;
  8295.                   case hlp_mouse:
  8296.                       x = hlp_normal;
  8297.                       break;
  8298.                   }
  8299. #else /* OS2MOUSE */
  8300.             switch ( x ) {
  8301.             case hlp_normal:
  8302.                 x = hlp_rollback;
  8303.                 break;
  8304.             case hlp_rollback:
  8305.                 x = hlp_normal;
  8306.                 break;
  8307.             }
  8308. #endif /* OS2MOUSE */
  8309.               return;   /*   Pop-up help message */
  8310.           }
  8311.           case K_PRTCTRL:               /* \Kprtscn,\Kprtctrl */
  8312.             if ( mode == VTERM )
  8313.               if ( xprint ) {               /*   Toggle Printer Ctrl mode on/off */
  8314.                   xprint = FALSE;         /*   It's on, turn it off */
  8315.                   if ( !cprint && !aprint )
  8316.                     printeroff();
  8317.                   else
  8318.                     ipadl25();
  8319.               } else {                    /*   vice versa ... */
  8320.                   xprint = TRUE ;
  8321.                   printeron();
  8322.               }
  8323.             return;
  8324.         case K_PRTAUTO:               /* \Kprtauto */
  8325.             if ( mode == VTERM )
  8326.               if ( aprint ) {         /*   Toggle printer auto mode on/off */
  8327.                   setaprint(FALSE);   /*   It's on, turn it off */
  8328.                   if ( !cprint && !xprint )
  8329.                     printeroff();
  8330.                   else
  8331.                     ipadl25();
  8332.               } else {                    /*   vice versa ... */
  8333.                   setaprint(TRUE);
  8334.                   printeron();
  8335.               }
  8336.             return;
  8337.         case K_PRTCOPY:               /* \Kprtcopy */
  8338.             if ( mode == VTERM )
  8339.               if ( cprint ) {     /*   Toggle printer copy mode on/off */
  8340.                   cprint = FALSE;         /*   It's on, turn it off */
  8341.                   if ( !aprint && !xprint )
  8342.                     printeroff();
  8343.                   else
  8344.                     ipadl25();
  8345.               } else {                    /*   vice versa ... */
  8346.                   cprint = TRUE ;
  8347.                   printeron();
  8348.               }
  8349.             return;
  8350.         case K_DUMP:                  /* \Kdump   */
  8351.             if ( markmodeflag[mode] != notmarking ) {
  8352.                 markmode(mode,k);
  8353.                 return ;
  8354.             }
  8355.             if ( scrollflag[mode] ) {
  8356.                 scrollback(mode,k);
  8357.                 return ;
  8358.             }
  8359.             x = xprintff; xprintff = 0; /*   Print/Dump current screen */
  8360.             prtscreen(mode,1,VscrnGetHeight(mode)-(tt_status[VTERM]?1:0));
  8361.             xprintff = x; 
  8362.             return;
  8363.         case K_PRINTFF:               /* \KprintFF - Print Form Feed */
  8364.             prtchar(FF); /* Send formfeed */
  8365.             return;
  8366.         case K_HANGUP:                /* \Khangup */
  8367.             {
  8368.                 debug( F110,"dokverb","K_HANGUP",0);
  8369.                 DialerSend( OPT_KERMIT_HANGUP, 0 ) ;
  8370. #ifndef NODIAL
  8371.                 if (mdmhup() < 1)
  8372. #endif /* NODIAL */
  8373.                     tthang();
  8374.             }
  8375.             return;
  8376.         case K_NULL:                  /* \Knull */
  8377.             if ( mode == VTERM ||
  8378.                  mode == VCMD && activecmd == XXOUT )
  8379.               if ( !kbdlocked() )
  8380.                 sendcharduplex('\0',TRUE); 
  8381.             return; /*   Send a NUL */
  8382.           case K_LBREAK:                /* \Klbreak: */
  8383.             if ( mode == VTERM ||
  8384.                  mode == VCMD && activecmd == XXOUT )
  8385.               if ( !kbdlocked() )
  8386.                 ttsndlb(); 
  8387.             return;          /*   Send a Long BREAK */
  8388.           case K_DEBUG:                 /* \Kdebug */
  8389.             flipdebug(); 
  8390.             return;        /*   Toggle debugging */
  8391.           case K_FLIPSCN:               /* \KflipScn */
  8392.             flipscreen(mode);
  8393.             VscrnIsDirty(mode);
  8394.             return;                     /* Toggle video */
  8395.         case K_HOLDSCRN:              /* \KholdScrn */
  8396.             if ( holdscreen ) {
  8397.                 holdscreen = FALSE ;
  8398.                 restore_status_line();      /* Restore status line */
  8399.                 VscrnIsDirty(mode) ;
  8400.             }
  8401.             else {
  8402.                 save_status_line();         /* Save current status line */
  8403.                 sprintf(usertext,
  8404.                          "SCROLL-LOCK      Press %s to unlock",
  8405.                          keyname(vik.holdscrn) );
  8406.                 helptext[0] = exittext[0] = hostname[0] = NUL;
  8407.                 VscrnIsDirty(mode);        /* Status line needs to be updated */
  8408.                 holdscreen = TRUE ;
  8409.             }
  8410.             return;
  8411.         case K_ANSWERBACK:
  8412.             if ( mode == VTERM ||
  8413.                  mode == VCMD && activecmd == XXOUT )
  8414.                 sendcharsduplex(answerback,strlen(answerback), FALSE) ;
  8415.             return ;
  8416.         case K_IGNORE:                /* \Kignore */
  8417.             return;
  8418. #ifdef NETCONN
  8419. #ifdef TCPSOCKET
  8420.         case K_TN_SAK:
  8421.             if ( mode == VTERM ||
  8422.                  mode == VCMD && activecmd == XXOUT )
  8423.               if ( !kbdlocked() )
  8424.                 do_tn_cmd((CHAR) TN_SAK);
  8425.             return;
  8426.         case K_TN_GA:                /* TELNET Go Ahead */
  8427.             if ( mode == VTERM ||
  8428.                  mode == VCMD && activecmd == XXOUT )
  8429.               if ( !kbdlocked() )
  8430.                 do_tn_cmd((CHAR) TN_GA);
  8431.             return;
  8432.         case K_TN_AO:                /* TELNET Abort Output */
  8433.             if ( mode == VTERM ||
  8434.                  mode == VCMD && activecmd == XXOUT )
  8435.               if ( !kbdlocked() )
  8436.                 do_tn_cmd((CHAR) TN_AO);
  8437.             return;
  8438.         case K_TN_EL:                /* TELNET Erase Line */
  8439.             if ( mode == VTERM ||
  8440.                  mode == VCMD && activecmd == XXOUT )
  8441.               if ( !kbdlocked() )
  8442.                 do_tn_cmd((CHAR) TN_EL);
  8443.             return;
  8444.         case K_TN_EC:                /* TELNET Erase Character */
  8445.             if ( mode == VTERM ||
  8446.                  mode == VCMD && activecmd == XXOUT )
  8447.               if ( !kbdlocked() )
  8448.                 do_tn_cmd((CHAR) TN_EC);
  8449.             return;
  8450.         case K_TN_AYT:                /* TELNET Are You There */
  8451.             if ( mode == VTERM ||
  8452.                  mode == VCMD && activecmd == XXOUT )
  8453.               if ( !kbdlocked() )
  8454.                 do_tn_cmd((CHAR) TN_AYT);
  8455.             return;
  8456.         case K_TN_IP:                 /* TELNET Interrupt Process */
  8457.             if ( mode == VTERM ||
  8458.                  mode == VCMD && activecmd == XXOUT )
  8459.               if ( !kbdlocked() )
  8460.                 do_tn_cmd((CHAR) TN_IP);
  8461.             return;
  8462.         case K_TN_LOGOUT:             /* TELNET LOGOUT */
  8463.             if ( mode == VTERM ||
  8464.                  mode == VCMD && activecmd == XXOUT )
  8465.                 if ( !kbdlocked() ) {
  8466.                     tn_sopt(DO,TELOPT_LOGOUT);
  8467.                     TELOPT_UNANSWERED_DO(TELOPT_LOGOUT) = 1;
  8468.                 }
  8469.             return;
  8470.         case K_TN_NAWS:               /* TELNET NAWS - Send Window Size */
  8471. #ifdef  CK_NAWS
  8472.             if ( mode == VTERM ||
  8473.                  mode == VCMD && activecmd == XXOUT )
  8474.                 if ( !kbdlocked() ) {
  8475.                     TELOPT_SB(TELOPT_NAWS).naws.x = 0;
  8476.                     TELOPT_SB(TELOPT_NAWS).naws.y = 0;
  8477.                     tn_snaws();
  8478. #ifdef RLOGCODE
  8479.                     rlog_naws();
  8480. #endif /* RLOGCODE */
  8481. #ifdef SSHBUILTIN
  8482.                     ssh_snaws();
  8483. #endif /* SSHBUILTIN */
  8484.                 }
  8485. #endif /* CK_NAWS */
  8486.             return;
  8487. #endif /* TCPSOCKET */
  8488. #endif /* NETCONN */
  8489.         case K_PASTE:                 /* Paste clipboard to Host */
  8490.             if ( !kbdlocked() )
  8491.               CopyClipboardToKbdBuffer(mode) ;
  8492.             return;
  8493.         case K_CLRSCRN:
  8494.             VscrnScroll( mode, UPWARD, 0,
  8495.                         VscrnGetHeight(mode)-(tt_status[mode]?2:1),
  8496.                         VscrnGetHeight(mode)-(tt_status[mode]?1:0),
  8497.                         TRUE,
  8498.                         SP );
  8499.             cleartermscreen(mode) ;    /* Clear the terminal screen */
  8500.             VscrnIsDirty(mode);
  8501.             return;
  8502.         case K_CLRSCROLL:
  8503.             clearscrollback(mode);
  8504.             VscrnIsDirty(mode);
  8505.             return;
  8506.         case K_SESSION:
  8507.             if ( !seslog ) {
  8508.                 if ( *sesfil )
  8509.                   setseslog(1);
  8510.                 else {
  8511. #ifdef KUI
  8512.                     char logfile[MAX_PATH+1];
  8513.                     if ( !KuiDownloadDialog("Create Session Log ...","session.log",
  8514.                                             logfile,MAX_PATH+1) )
  8515.                         return;
  8516.                     setseslog(sesopn( logfile, 0));
  8517. #else /* KUI */
  8518.                     setseslog(sesopn( "session.log", 0 )); /* create new */
  8519. #endif /* KUI */
  8520.                 }
  8521.                 if ( !seslog )
  8522.                   bleep( BP_FAIL ) ;
  8523.             } else {
  8524.                 setseslog(0);    /* session file.  Therefore, we can continue */
  8525.             }
  8526.             break;
  8527.         case K_LOGON:
  8528.             if ( !seslog ) {
  8529.                 if ( *sesfil )
  8530.                   setseslog(1);
  8531.                 else
  8532.                   setseslog(sesopn( "session.log", 0 )); /* create new */
  8533.                 if ( !seslog )
  8534.                   bleep( BP_FAIL ) ;
  8535.             } else {
  8536.                 bleep( BP_WARN ) ;
  8537.             }
  8538.             return ;
  8539.         case K_LOGOFF:
  8540.             if ( seslog ) {     /* Unlike CLOSE SESSION we do not close the  */
  8541.                 setseslog(0);    /* session file.  Therefore, we can continue */
  8542.             } else {            /* to append to the file later on.           */
  8543.                 bleep( BP_WARN ) ;
  8544.             }
  8545.             return ;
  8546.  
  8547. #ifdef PCTERM
  8548.         case K_PCTERM:
  8549.             setpcterm(!tt_pcterm);
  8550.             break;
  8551. #endif /* PCTERM */
  8552.  
  8553.         case K_AUTODOWN:
  8554. #ifndef NOXFER
  8555.             if ( !autodl )
  8556.                 setautodl(1,0);
  8557.             else if ( autodl && !adl_ask )
  8558.                 setautodl(1,1);
  8559.             else 
  8560.                 setautodl(0,0);
  8561. #else /* NOXFER */
  8562.             bleep( BP_WARN ) ;
  8563. #endif /* NOXFER */
  8564.             break;
  8565.  
  8566.         case K_URLHILT:
  8567.             seturlhl(!tt_url_hilite);
  8568.             break;
  8569.  
  8570.         case K_BYTESIZE:
  8571.             if ( cmask == 0177 )
  8572.                 setcmask(8);
  8573.             else
  8574.                 setcmask(7);
  8575.             if (IS97801(tt_type_mode))
  8576.                 SNI_bitmode((cmask == 0377) ? 8 : 7);
  8577.             break;
  8578.  
  8579.         case K_SET_BOOK:              /* Bookmark Kverbs */
  8580.             bookmarkset(mode);
  8581.             return ;
  8582.  
  8583.         case K_TERMTYPE:                /* Toggle Terminal Type */
  8584.             if ( mode == VTERM )
  8585.                   settermtype((tt_type+1)%(TT_MAX+1), 0);
  8586.             return ;
  8587.  
  8588.         case K_STATUS:          /* Toggle Status-Line Type */
  8589.             if ( mode == VTERM )
  8590.                 setdecssdt((decssdt+1)%3);
  8591.             return ;
  8592.  
  8593.  
  8594.         case K_KEYCLICK:                /* Toggle Keyclick */
  8595.             setkeyclick(!keyclick);
  8596.             return ;
  8597.  
  8598.         case K_LOGDEBUG:                /* Toggle Debug Log File */
  8599. #ifdef DEBUG
  8600.             {
  8601.                 extern int deblog ;
  8602.                 extern char debfil[] ;
  8603.                 char * tp ;
  8604.  
  8605.                 if ( deblog ) {
  8606. #ifdef COMMENT
  8607.                     doclslog(LOGD);
  8608. #else
  8609.                     ztime(&tp);
  8610.                     debug(F110,"Debug log suspended at",tp,0);
  8611.                     deblog = FALSE ;
  8612. #endif
  8613.                 }
  8614.                 else {
  8615.                     if ( debfil && *debfil ) {
  8616.                         deblog = TRUE ;
  8617.                         ztime(&tp);
  8618.                         debug(F110,"Debug log resumed at",tp,0);
  8619.                     }
  8620.                     else
  8621.                         deblog = debopn("debug.log",0);
  8622.                 }
  8623.             }
  8624. #endif /* DEBUG */
  8625.             return ;
  8626.  
  8627.         case K_FNKEYS:                  /* Display Function Key Labels */
  8628.             if ( mode == VTERM ) {
  8629.                 fkeypopup(mode);
  8630.             }
  8631.             return;
  8632.  
  8633.         case K_CURSOR_URL:
  8634.             mouseurl(mode,vscrn[mode].cursor.y,vscrn[mode].cursor.x);
  8635.             break;
  8636.  
  8637.         default:                        /* None of the above */
  8638.             return;                     /* Ignore this key and return. */
  8639.         }
  8640.     }
  8641.  
  8642.     /* Capture all kverbs that must go to mark mode */
  8643.  
  8644.     if (k >= K_MARK_MIN && k <= K_MARK_MAX ||
  8645.         ( markmodeflag[mode] != notmarking &&
  8646.             (k >= K_ROLLMIN && k <= K_ROLLMAX ||
  8647.             k >= K_ARR_MIN && k <= K_ARR_MAX ))) {
  8648.         /* mark mode goes here */
  8649.         markmode(mode,k);
  8650.         return ;
  8651.     }
  8652.     if (k >= K_ROLLMIN && k <= K_ROLLMAX ) { /* Screen rollback... */
  8653.         scrollback(mode,k);
  8654.         return;
  8655.     }
  8656.  
  8657.     if ( k >= K_LFONE && k <= K_RTALL ) {       /* Horizontal Scrolling */
  8658.         switch ( k ) {
  8659.         case K_LFONE:
  8660.             if ( vscrn[mode].hscroll == 0 )
  8661.                 bleep(BP_WARN);
  8662.             else if ( vscrn[mode].hscroll > 0 )
  8663.                 vscrn[mode].hscroll -= 1 ;
  8664.             break;
  8665.         case K_LFPAGE:
  8666.             if ( vscrn[mode].hscroll == 0 )
  8667.                 bleep(BP_WARN);
  8668.             else if ( vscrn[mode].hscroll > 8 )
  8669.                 vscrn[mode].hscroll -= 8 ;
  8670.             else
  8671.                 vscrn[mode].hscroll = 0 ;
  8672.             break;
  8673.         case K_LFALL:
  8674.             if ( vscrn[mode].hscroll == 0 )
  8675.                 bleep(BP_WARN);
  8676.             else if ( vscrn[mode].hscroll > 0 )
  8677.                 vscrn[mode].hscroll = 0 ;
  8678.             break;
  8679.         case K_RTONE:
  8680.             if ( vscrn[mode].hscroll == MAXTERMCOL-pwidth )
  8681.                 bleep(BP_WARN);
  8682.             else if ( vscrn[mode].hscroll < MAXTERMCOL-pwidth )
  8683.                 vscrn[mode].hscroll += 1 ;
  8684.             break;
  8685.         case K_RTPAGE:
  8686.             if ( vscrn[mode].hscroll == MAXTERMCOL-pwidth )
  8687.                 bleep(BP_WARN);
  8688.             else if ( vscrn[mode].hscroll < MAXTERMCOL-pwidth-8 )
  8689.                 vscrn[mode].hscroll += 8 ;
  8690.             else
  8691.                 vscrn[mode].hscroll = MAXTERMCOL-pwidth ;
  8692.             break;
  8693.         case K_RTALL:
  8694.             if ( vscrn[mode].hscroll == MAXTERMCOL-pwidth )
  8695.                 bleep(BP_WARN);
  8696.             else if ( vscrn[mode].hscroll < MAXTERMCOL-pwidth )
  8697.                 vscrn[mode].hscroll = MAXTERMCOL-pwidth ;
  8698.             break;
  8699.         }
  8700.         VscrnIsDirty(mode);
  8701.         return;
  8702.     }
  8703.  
  8704. #ifdef OS2MOUSE
  8705.     if (k >= K_MOUSE_MIN && k <= K_MOUSE_MAX) {
  8706.         /* mouse verbs cannot be assigned to keys */
  8707.         bleep(BP_FAIL);
  8708.         return ;
  8709.     }
  8710. #endif /* OS2MOUSE */
  8711.  
  8712.     if ( !kbdlocked() ) {
  8713.         if ( mode == VTERM ||
  8714.              mode == VCMD && activecmd == XXOUT ) {
  8715.             if (k >= K_ARR_MIN && k <= K_ARR_MAX) {
  8716.                 if ( ISDG200( tt_type_mode ) ) {
  8717.                     /* Data General */
  8718.                     extern int dgunix;
  8719.  
  8720.                     switch ( k ) {
  8721.                     case K_UPARR:
  8722.                         if ( dgunix ) {
  8723.                             if ( udkfkeys[K_DGUPARR-K_DGF01+25] )
  8724.                                 sendcharsduplex(udkfkeys[K_DGUPARR - K_DGF01+25],
  8725.                                                  strlen(udkfkeys[K_DGUPARR - K_DGF01+25]),
  8726.                                                  TRUE);
  8727.                             else
  8728.                                 sendcharsduplex("\036PA",3,TRUE);
  8729.                         }
  8730.                         else {
  8731.                             if ( udkfkeys[K_DGUPARR-K_DGF01] )
  8732.                                 sendcharsduplex(udkfkeys[K_DGUPARR - K_DGF01],
  8733.                                                  strlen(udkfkeys[K_DGUPARR - K_DGF01]),
  8734.                                                  TRUE);
  8735.                             else
  8736.                             sendcharduplex(ETB,TRUE);
  8737.                         }
  8738.                         break;
  8739.                     case K_RTARR:
  8740.                         if ( dgunix ) {
  8741.                             if ( udkfkeys[K_DGRTARR-K_DGF01+25] )
  8742.                                 sendcharsduplex(udkfkeys[K_DGRTARR - K_DGF01+25],
  8743.                                                  strlen(udkfkeys[K_DGRTARR - K_DGF01+25]),
  8744.                                                  TRUE);
  8745.                             else
  8746.                             sendcharsduplex("\036PC",3,TRUE);
  8747.                         }
  8748.                         else {
  8749.                             if ( udkfkeys[K_DGRTARR-K_DGF01] )
  8750.                                 sendcharsduplex(udkfkeys[K_DGRTARR - K_DGF01],
  8751.                                                  strlen(udkfkeys[K_DGRTARR - K_DGF01]),
  8752.                                                  TRUE);
  8753.                             else
  8754.                             sendcharduplex(CAN,TRUE);
  8755.                         }
  8756.                         break;
  8757.                     case K_LFARR:
  8758.                         if ( dgunix ) {
  8759.                             if ( udkfkeys[K_DGLFARR-K_DGF01+25] )
  8760.                                 sendcharsduplex(udkfkeys[K_DGLFARR - K_DGF01+25],
  8761.                                                  strlen(udkfkeys[K_DGLFARR - K_DGF01+25]),
  8762.                                                  TRUE);
  8763.                             else
  8764.                             sendcharsduplex("\036PD",3,TRUE);
  8765.                         }
  8766.                         else {
  8767.                             if ( udkfkeys[K_DGLFARR-K_DGF01] )
  8768.                                 sendcharsduplex(udkfkeys[K_DGLFARR - K_DGF01],
  8769.                                                  strlen(udkfkeys[K_DGLFARR - K_DGF01]),
  8770.                                                  TRUE);
  8771.                             else
  8772.                             sendcharduplex(XEM,TRUE);
  8773.                         }
  8774.                         break;
  8775.                     case K_DNARR:
  8776.                         if ( dgunix ) {
  8777.                             if ( udkfkeys[K_DGDNARR-K_DGF01+25] )
  8778.                                 sendcharsduplex(udkfkeys[K_DGDNARR - K_DGF01+25],
  8779.                                                  strlen(udkfkeys[K_DGDNARR - K_DGF01+25]),
  8780.                                                  TRUE);
  8781.                             else
  8782.                             sendcharsduplex("\036PB",3,TRUE);
  8783.                         }
  8784.                         else {
  8785.                             if ( udkfkeys[K_DGDNARR-K_DGF01] )
  8786.                                 sendcharsduplex(udkfkeys[K_DGDNARR - K_DGF01],
  8787.                                                  strlen(udkfkeys[K_DGDNARR - K_DGF01]),
  8788.                                                  TRUE);
  8789.                             else
  8790.                             sendcharduplex(SUB,TRUE);
  8791.                         }
  8792.                         break;
  8793.                     }
  8794.                 }
  8795.                 else if ( ISQNX( tt_type_mode ) ) {
  8796.                     /* QNX */
  8797.                     char buf[3] ;
  8798.                     switch ( k ) {
  8799.                     case K_UPARR:
  8800.                         sprintf(buf,"\377\241");
  8801.                         break;
  8802.                     case K_RTARR:
  8803.                         sprintf(buf,"\377\246");
  8804.                         break;
  8805.                     case K_LFARR:
  8806.                         sprintf(buf,"\377\244");
  8807.                         break;
  8808.                     case K_DNARR:
  8809.                         sprintf(buf,"\377\251");
  8810.                         break;
  8811.                     }
  8812.                     sendcharsduplex(buf,2,TRUE);
  8813.                 }
  8814.                 else if ( ISHP( tt_type_mode ) ||
  8815.                           ISIBM31(tt_type_mode)) {
  8816.                     /* HP2621A || IBM 31xx */
  8817.                     char buf[3] ;
  8818.                     switch ( k ) {
  8819.                     case K_UPARR:
  8820.                         sprintf(buf,"%cA",ESC);
  8821.                         break;
  8822.                     case K_RTARR:
  8823.                         sprintf(buf,"%cC",ESC);
  8824.                         break;
  8825.                     case K_LFARR:
  8826.                         sprintf(buf,"%cD",ESC);
  8827.                         break;
  8828.                     case K_DNARR:
  8829.                         sprintf(buf,"%cB",ESC);
  8830.                         break;
  8831.                     }
  8832.                     sendcharsduplex(buf,2,TRUE);
  8833.                 }
  8834.                 else if ( ISHZL( tt_type_mode ) ) {
  8835.                     /* Hazeltine */
  8836.                     switch ( k ) {
  8837.                     case K_UPARR:
  8838.                         sendcharsduplex("~\x0C",2,TRUE);
  8839.                         break;
  8840.                     case K_RTARR:
  8841.                         sendcharduplex(DLE,TRUE);
  8842.                         break;
  8843.                     case K_LFARR:
  8844.                         sendcharduplex(BS,TRUE);
  8845.                         break;
  8846.                     case K_DNARR:
  8847.                         sendcharsduplex("~\x0B",2,TRUE);
  8848.                         break;
  8849.                     }
  8850.                 }
  8851.                 else if ( ISVC( tt_type_mode ) ) {
  8852.                     /* Victor Craig */
  8853.                     switch ( k ) {
  8854.                     case K_UPARR:
  8855.                         sendcharduplex(SUB,TRUE);
  8856.                         break;
  8857.                     case K_RTARR:
  8858.                         sendcharduplex(NAK,TRUE);
  8859.                         break;
  8860.                     case K_LFARR:
  8861.                         sendcharduplex(BS,TRUE);
  8862.                         break;
  8863.                     case K_DNARR:
  8864.                         sendcharduplex(LF,TRUE);
  8865.                         break;
  8866.                     }
  8867.                 }
  8868.                 else if ( ISWYSE( tt_type_mode ) ) {
  8869.                     switch ( k ) {
  8870.                     case K_UPARR:
  8871.                         if ( udkfkeys[K_WYUPARR-K_WYF01] )
  8872.                             sendcharsduplex(udkfkeys[K_WYUPARR - K_WYF01],
  8873.                                        strlen(udkfkeys[K_WYUPARR - K_WYF01]),
  8874.                                              TRUE);
  8875.                         else
  8876.                             sendcharduplex(VT,TRUE);
  8877.                         break;
  8878.                     case K_RTARR:
  8879.                         if ( udkfkeys[K_WYRTARR-K_WYF01] )
  8880.                             sendcharsduplex(udkfkeys[K_WYRTARR - K_WYF01],
  8881.                                        strlen(udkfkeys[K_WYRTARR - K_WYF01]),
  8882.                                              TRUE);
  8883.                         else
  8884.                             sendcharduplex(FF,TRUE);
  8885.                         break;
  8886.                     case K_LFARR:
  8887.                         if ( udkfkeys[K_WYLFARR-K_WYF01] )
  8888.                             sendcharsduplex(udkfkeys[K_WYLFARR - K_WYF01],
  8889.                                        strlen(udkfkeys[K_WYLFARR - K_WYF01]),
  8890.                                              TRUE);
  8891.                         else
  8892.                             sendcharduplex(BS,TRUE);
  8893.                         break;
  8894.                     case K_DNARR:
  8895.                         if ( udkfkeys[K_WYDNARR-K_WYF01] )
  8896.                             sendcharsduplex(udkfkeys[K_WYDNARR - K_WYF01],
  8897.                                        strlen(udkfkeys[K_WYDNARR - K_WYF01]),
  8898.                                              TRUE);
  8899.                         else
  8900.                             sendcharduplex(LF,TRUE);
  8901.                         break;
  8902.                     }
  8903.                 }
  8904.                 else if ( ISTVI( tt_type_mode ) ) {
  8905.                     switch ( k ) {
  8906.                     case K_UPARR:
  8907.                         if ( udkfkeys[K_TVIUPARR-K_TVIF01] )
  8908.                             sendcharsduplex(udkfkeys[K_TVIUPARR - K_TVIF01],
  8909.                                        strlen(udkfkeys[K_TVIUPARR - K_TVIF01]),
  8910.                                              TRUE);
  8911.                         else
  8912.                             sendcharduplex(DLE,TRUE);
  8913.                         break;
  8914.                     case K_RTARR:
  8915.                         if ( udkfkeys[K_TVIRTARR-K_TVIF01] )
  8916.                             sendcharsduplex(udkfkeys[K_TVIRTARR - K_TVIF01],
  8917.                                        strlen(udkfkeys[K_TVIRTARR - K_TVIF01]),
  8918.                                              TRUE);
  8919.                         else
  8920.                             sendcharduplex(ACK,TRUE);
  8921.                         break;
  8922.                     case K_LFARR:
  8923.                         if ( udkfkeys[K_TVILFARR-K_TVIF01] )
  8924.                             sendcharsduplex(udkfkeys[K_TVILFARR - K_TVIF01],
  8925.                                        strlen(udkfkeys[K_TVILFARR - K_TVIF01]),
  8926.                                              TRUE);
  8927.                         else
  8928.                             sendcharduplex(STX,TRUE);
  8929.                         break;
  8930.                     case K_DNARR:
  8931.                         if ( udkfkeys[K_TVIDNARR-K_TVIF01] )
  8932.                             sendcharsduplex(udkfkeys[K_TVIDNARR - K_TVIF01],
  8933.                                        strlen(udkfkeys[K_TVIDNARR - K_TVIF01]),
  8934.                                              TRUE);
  8935.                         else
  8936.                             sendcharduplex(SO,TRUE);
  8937.                         break;
  8938.                     }
  8939.                 }
  8940.                 else if ( IS97801(tt_type_mode) ) {
  8941.                     switch ( k ) {
  8942.                     case K_UPARR:
  8943.                         if ( udkfkeys[K_SNI_CURSOR_UP-K_SNI_F01] )
  8944.                             sendcharsduplex(udkfkeys[K_SNI_CURSOR_UP - K_SNI_F01],
  8945.                                        strlen(udkfkeys[K_SNI_CURSOR_UP - K_SNI_F01]),
  8946.                                              TRUE);
  8947.                         else
  8948.                             sendcharsduplex("\033[A",3,TRUE);
  8949.                         break;
  8950.                     case K_RTARR:
  8951.                         if ( udkfkeys[K_SNI_CURSOR_RIGHT-K_SNI_F01] )
  8952.                             sendcharsduplex(udkfkeys[K_SNI_CURSOR_RIGHT - K_SNI_F01],
  8953.                                        strlen(udkfkeys[K_SNI_CURSOR_RIGHT - K_SNI_F01]),
  8954.                                              TRUE);
  8955.                         else
  8956.                             sendcharsduplex("\033[C",3,TRUE);
  8957.                         break;
  8958.                     case K_LFARR:
  8959.                         if ( udkfkeys[K_SNI_CURSOR_LEFT-K_SNI_F01] )
  8960.                             sendcharsduplex(udkfkeys[K_SNI_CURSOR_LEFT - K_SNI_F01],
  8961.                                        strlen(udkfkeys[K_SNI_CURSOR_LEFT - K_SNI_F01]),
  8962.                                              TRUE);
  8963.                         else
  8964.                             sendcharsduplex("\033[D",3,TRUE);
  8965.                         break;
  8966.                     case K_DNARR:
  8967.                         if ( udkfkeys[K_SNI_CURSOR_DOWN-K_SNI_F01] )
  8968.                             sendcharsduplex(udkfkeys[K_SNI_CURSOR_DOWN - K_SNI_F01],
  8969.                                        strlen(udkfkeys[K_SNI_CURSOR_DOWN - K_SNI_F01]),
  8970.                                              TRUE);
  8971.                         else
  8972.                             sendcharsduplex("\033[B",3,TRUE);
  8973.                         break;
  8974.                     }
  8975.                 }
  8976.                 else {
  8977.                     /* DEC arrow (cursor) keys */
  8978.                     if (ISVT100(tt_type_mode) ||
  8979.                          ISANSI(tt_type_mode) ||
  8980.                          ISQANSI(tt_type_mode) ||
  8981.                          ISBEOS(tt_type_mode) ||
  8982.                         ISHFT(tt_type_mode))
  8983.                         sprintf(escbuf,"%c%c",( (tt_arrow == TTK_APPL) ? 'O' : '[' ),
  8984.                                  'A' + (k - K_UPARR));
  8985.                     else
  8986.                         sprintf(escbuf,"%c", 'A' + (k - K_UPARR));
  8987.                     sendescseq(escbuf);
  8988.                 }
  8989.                 return;
  8990.             }
  8991.  
  8992.             if (k >= K_PF1 && k <= K_PF4) { /* DEC PF keys */
  8993.                 char *p = escbuf;
  8994.                 if (ISVT100(tt_type_mode)) /* SS3 P..S for VT100 & above */
  8995.                   *p++ = 'O';
  8996.                 *p++ = 'P' + (k - K_PF1);   /* or just ESC P..S for VT52 */
  8997.                 *p = NUL;
  8998.                 sendescseq(escbuf);
  8999.                 return;
  9000.             }
  9001.  
  9002.             if (k >= K_KP0 && k <= K_KP9) { /* DEC numeric keypad keys */
  9003.                 if (tt_keypad == TTK_NORM)  /* Keypad in numeric mode */
  9004.                   sendcharduplex((CHAR) ('0' + (CHAR) (k - K_KP0)),TRUE);
  9005.                 else {                      /* Application mode */
  9006.                     int dup_sav = duplex;
  9007.                     duplex = 0;
  9008.                     sprintf(escbuf,
  9009.                         "%c%c",
  9010.                         (ISVT100(tt_type_mode) ? 'O' : '?'),
  9011.                         ('p' + (k - K_KP0))
  9012.                         );
  9013.                     sendescseq(escbuf);
  9014.                     duplex = dup_sav;
  9015.                 }
  9016.                 return;
  9017.             }
  9018.  
  9019.             if (k >= K_KPCOMA && k <= K_KPDOT) { /* DEC keypad punctuation keys */
  9020.                 if (tt_keypad == TTK_NORM)  /* Keypad in numeric mode */
  9021.                   sendcharduplex((CHAR) (',' + (CHAR) (k - K_KPCOMA)),TRUE); /*  */
  9022.                 else {                      /* Keypad in application mode */
  9023.                     int dup_sav = duplex;
  9024.                     duplex = 0;
  9025.                     sprintf(escbuf,
  9026.                              "%c%c",
  9027.                              (ISVT100(tt_type_mode) ? 'O' : '?'),
  9028.                              ('l' + (k - K_KPCOMA))
  9029.                              );
  9030.                     sendescseq(escbuf);
  9031.                     duplex = dup_sav;
  9032.                 }
  9033.                 return;
  9034.             }
  9035.  
  9036.             if (k == K_KPENTER) {           /* DEC keypad Enter key */
  9037.                 if (tt_keypad == TTK_NORM) { /* Keypad in numeric mode */
  9038.                     sendcharduplex('\015',TRUE);  /* Send CR */
  9039.                     if (tnlm)
  9040.                       sendcharduplex('\012',TRUE); /* Newline mode, send LF too */
  9041.                 } else {                    /* Keypad in application mode */
  9042.                     int dup_sav = duplex;
  9043.                     duplex = 0;
  9044.                     sprintf(escbuf,
  9045.                              "%c%M",
  9046.                              (ISVT100(tt_type_mode) ? 'O' : '?')
  9047.                              );
  9048.                     sendescseq(escbuf);
  9049.                     duplex = dup_sav;
  9050.                 }
  9051.                 return;
  9052.             }
  9053.  
  9054.             if (k >= K_DECFIND && k <= K_DECHOME) { /* DEC editing keypad keys */
  9055.                 int dup_sav = duplex;
  9056.                 duplex = 0;
  9057.                 if (ISVT220(tt_type_mode)) /* VT220 and above */
  9058.                   sendescseq(ekeys[k - K_DECFIND]);
  9059.                 else bleep(BP_WARN);
  9060.                 duplex = dup_sav;
  9061.                 return;
  9062.             }
  9063.  
  9064.             if (k >= K_DECF1 && k <= K_DECF20) { /* DEC top-rank function keys */
  9065.                 if (ISVT220(tt_type_mode)) { /* VT220 and above */
  9066.                     int dup_sav = duplex;
  9067.                     duplex =0;
  9068.                     sendescseq(fkeys[k - K_DECF1]);
  9069.                     duplex = dup_sav;
  9070.                     return;
  9071.                 } else {                    /* VT102 or lower */
  9072.                     switch (k) {
  9073.                     case K_DECF11:
  9074.                         sendcharduplex(ESC,TRUE); return;
  9075.                     case K_DECF12:
  9076.                         sendcharduplex(BS,TRUE); return;
  9077.                     case K_DECF13:
  9078.                         sendcharduplex(LF,TRUE); return;
  9079.                     default:
  9080.                         bleep(BP_WARN);
  9081.                         return;
  9082.                     }
  9083.                 }
  9084.             }
  9085.  
  9086.             if (k >= K_UDKF1 && k <= K_UDKF20) { /* User-Defined Keys */
  9087.                 if (ISVT220(tt_type_mode)) { /* VT220 and above */
  9088.                     if ( udkfkeys[k-K_UDKF1] )
  9089.                       sendcharsduplex(udkfkeys[k - K_UDKF1],
  9090.                                  strlen(udkfkeys[k - K_UDKF1]),TRUE);
  9091.  
  9092.                 }
  9093.                 else {
  9094.                     bleep( BP_WARN );
  9095.                 }
  9096.                 return;
  9097.             }
  9098.  
  9099.             if ( k >= K_ANSIF01 && k <= K_ANSIF61 ) { /* ANSI FN Keys */
  9100.                 if ( ISUNIXCON(tt_type_mode) ) {
  9101.                     if ( udkfkeys[k-K_ANSIF01] )
  9102.                       sendcharsduplex(udkfkeys[k-K_ANSIF01],
  9103.                                  strlen(udkfkeys[k-K_ANSIF01]),TRUE) ;
  9104.                 }
  9105.                 else {
  9106.                     bleep( BP_WARN ) ;
  9107.                 }
  9108.                 return ;
  9109.             }
  9110.  
  9111.             if ( k >= K_WYF01 && k <= K_WYSSEND ) {    /* WYSE FN Keys */
  9112.                 if ( ISWYSE(tt_type_mode) ) {
  9113.                     if ( udkfkeys[k-K_WYF01] )
  9114.                         sendcharsduplex(udkfkeys[k-K_WYF01],
  9115.                                    strlen(udkfkeys[k-K_WYF01]),TRUE);
  9116.                 }
  9117.                 else
  9118.                     bleep( BP_WARN ) ;
  9119.                 return ;
  9120.             }
  9121.  
  9122.             if ( k >= K_TVIF01 && k <= K_TVIPRTSCN ||
  9123.                         k == K_TVISEND || k == K_TVISSEND) {    /* TVI FN Keys */
  9124.                 if ( ISTVI(tt_type_mode) ) {
  9125.                     if ( udkfkeys[k-K_TVIF01] )
  9126.                         sendcharsduplex(udkfkeys[k-K_TVIF01],
  9127.                                    strlen(udkfkeys[k-K_TVIF01]),TRUE);
  9128.                 }
  9129.                 else
  9130.                     bleep( BP_WARN ) ;
  9131.                 return ;
  9132.             }
  9133.  
  9134.             if ( k >= K_HPF01 && k <= K_HPENTER ) {     /* HP FN Keys */
  9135.                 if ( ISHP(tt_type_mode) ) {
  9136.                     if ( udkfkeys[k-K_HPF01] )
  9137.                         sendcharsduplex(udkfkeys[k-K_HPF01],
  9138.                                    strlen(udkfkeys[k-K_HPF01]),TRUE);
  9139.                 }
  9140.                 else
  9141.                     bleep( BP_WARN ) ;
  9142.                 return ;
  9143.             }
  9144.  
  9145.             if ( k >= K_DGF01 && k <= K_DGSHOME ) {     /* DG FN Keys */
  9146.                 if ( ISDG200(tt_type_mode) ) {
  9147.                     extern int dgunix;
  9148.                     if ( k <= K_DGCSF15 || ! dgunix ) {
  9149.                         if ( udkfkeys[k-K_DGF01] )
  9150.                         sendcharsduplex(udkfkeys[k-K_DGF01],
  9151.                                    strlen(udkfkeys[k-K_DGF01]),TRUE);
  9152.                     }
  9153.                     else {
  9154.                         if ( udkfkeys[k-K_DGF01+25] )
  9155.                         sendcharsduplex(udkfkeys[k-K_DGF01+25],
  9156.                                    strlen(udkfkeys[k-K_DGF01+25]),TRUE);
  9157.                     }
  9158.                 }
  9159.                 else
  9160.                     bleep( BP_WARN );
  9161.                 return;
  9162.             }
  9163.  
  9164.             if ( k >= K_SNI_MIN && k <= K_SNI_MAX ) {   /* SNI FN Keys */
  9165.                 if ( IS97801(tt_type_mode) ) {
  9166.                     if ( k == K_SNI_CH_CODE ) {
  9167.                         if ( sni_bitmode == 8 && !sni_chcode_8 ||
  9168.                              sni_bitmode == 7 && !sni_chcode_7 )
  9169.                             bleep(BP_WARN);
  9170.                         else {
  9171.                             SNI_chcode(!sni_chcode);
  9172.                             if ( sni_chcode )
  9173.                                 printf("SNI Ch.Code is ON\n");
  9174.                             else
  9175.                                 printf("SNI Ch.Code is OFF\n");
  9176.                         }
  9177.                     } else {
  9178.                         if ( udkfkeys[k-K_SNI_MIN] )
  9179.                             sendcharsduplex(udkfkeys[k-K_SNI_MIN],
  9180.                                              strlen(udkfkeys[k-K_SNI_MIN]),TRUE);
  9181.                     }
  9182.                 }
  9183.                 else
  9184.                     bleep( BP_WARN );
  9185.                 return;
  9186.             }
  9187.  
  9188.             if ( k >= K_BA80_MIN && k <= K_BA80_MAX ) { /* SNI FN Keys */
  9189.                 if ( ISBA80(tt_type_mode) ) {
  9190.                     if ( udkfkeys[k-K_BA80_MIN] )
  9191.                         sendcharsduplex(udkfkeys[k-K_BA80_MIN],
  9192.                                    strlen(udkfkeys[k-K_BA80_MIN]),TRUE);
  9193.                 }
  9194.                 else
  9195.                     bleep( BP_WARN );
  9196.                 return;
  9197.             }
  9198.  
  9199.             if ( k >= K_I31_MIN && k <= K_I31_MAX ) {   /* IBM 31xx FN Keys */
  9200.                 if ( ISIBM31(tt_type_mode) ) {
  9201.                     if ( udkfkeys[k-K_I31_MIN] )
  9202.                         sendcharsduplex(udkfkeys[k-K_I31_MIN],
  9203.                                    strlen(udkfkeys[k-K_I31_MIN]),TRUE);
  9204.                 }
  9205.                 else
  9206.                     bleep( BP_WARN );
  9207.                 return;
  9208.             }
  9209.  
  9210.             if ( k >= K_SUN_MIN && k <= K_SUN_MAX ) {   /* SUN Keys */
  9211.                 if ( ISSUN(tt_type_mode) ) {
  9212.                     if ( udkfkeys[k-K_SUN_MIN] )
  9213.                         sendcharsduplex(udkfkeys[k-K_SUN_MIN],
  9214.                                    strlen(udkfkeys[k-K_SUN_MIN]),TRUE);
  9215.                 }
  9216.                 else
  9217.                     bleep( BP_WARN );
  9218.                 return;
  9219.             }
  9220.  
  9221.             if ( k == K_EMACS_OVER && tt_kb_mode == KBM_EM )
  9222.                 sendescseq("Xoverwrite\r") ;
  9223.         }
  9224.  
  9225.         if (k == K_COMPOSE) {           /* Compose key */
  9226.             dokcompose(mode, 0) ;
  9227.             return;
  9228.         }
  9229.  
  9230.         if (k == K_C_UNI16) {           /* Compose key */
  9231.             dokcompose(mode, 1) ;
  9232.             return;
  9233.         }
  9234.  
  9235.         if ( mode == VTERM ) {
  9236.             if (k == K_KB_HEB) {            /* Hebrew keyboard support... */
  9237.                 if ( tt_kb_mode == KBM_HE )
  9238.                     set_kb_mode(KBM_EN) ;
  9239.                 else
  9240.                     set_kb_mode(KBM_HE) ;
  9241.                 ipadl25();                      /* Update the status line */
  9242.                 return;
  9243.             }
  9244.  
  9245.             if (k == K_KB_RUS) {            /* Russian keyboard support... */
  9246.                 if ( tt_kb_mode == KBM_RU )
  9247.                     set_kb_mode(KBM_EN) ;
  9248.                 else
  9249.                     set_kb_mode(KBM_RU) ;
  9250.                 ipadl25();                      /* Update the status line */
  9251.                 return;
  9252.             }
  9253.  
  9254.             if ( k == K_KB_EMA ) {      /* Emacs keyboard support */
  9255.                 if ( tt_kb_mode == KBM_EM )
  9256.                     set_kb_mode(KBM_EN) ;
  9257.                 else
  9258.                     set_kb_mode(KBM_EM) ;
  9259.                 ipadl25();                      /* Update the status line */
  9260.                 return ;
  9261.             }
  9262.  
  9263.             if ( k == K_KB_WP ) {       /* WP5.1 keyboard support */
  9264.                 if ( tt_kb_mode == KBM_WP )
  9265.                     set_kb_mode(KBM_EN);
  9266.                 else
  9267.                     set_kb_mode(KBM_WP);
  9268.                 ipadl25();                      /* Update the status line */
  9269.                 return ;
  9270.             }
  9271.             if (k == K_KB_ENG) {            /* English too... */
  9272.                 if ( tt_kb_mode != KBM_EN ) {
  9273.                     set_kb_mode(KBM_EN);
  9274.                     ipadl25();                  /* Update the status line */
  9275.                 }
  9276.                 return;
  9277.             }
  9278.         }
  9279.  
  9280.     } /* !kbdlocked() */
  9281. }
  9282. #endif /* NOKVERBS */
  9283.  
  9284. /*  S E N D K E Y D E F  --  Send key definition  */
  9285.  
  9286. void
  9287. sendkeydef(unsigned char *s, int no_xlate ) {
  9288. #ifndef NOKVERBS
  9289.     int x, y, brace = 0;
  9290.     char * p, * b;
  9291. #define K_BUFLEN 30
  9292.     char kbuf[K_BUFLEN + 1];            /* Key verb name buffer */
  9293. #define SEND_BUFLEN 255
  9294. #define sendbufd(x) { sendbuf[sendndx++] = x ; if (sendndx == SEND_BUFLEN) { sendcharsduplex(s,SEND_BUFLEN,no_xlate); sendndx = 0 ;}}
  9295.     char sendbuf[SEND_BUFLEN +1] ;
  9296.     int  sendndx = 0 ;
  9297. #endif /* NOKVERBS */
  9298.  
  9299. #ifdef NOKVERBS
  9300.     sendcharsduplex(s, strlen(s), no_xlate); /* Send the entire string literally. */
  9301. #else   /* \Kverb support ... */
  9302.     for ( ; *s; s++ ) {                 /* Go through the string */
  9303.  
  9304.         if (*s != CMDQ) {               /* Normal character */
  9305.             sendbufd(*s) ;
  9306.             continue;                   /* Get next, etc. */
  9307.         }
  9308.         b = s++;                        /* Get next character */
  9309.         if (!*s) {
  9310.             sendbufd(CMDQ) ;            /* Send the CMDQ char */
  9311.             goto exit_sendkeydef ;      /* and then exit */
  9312.         }
  9313.         if (*s == '{') {                /* Opening brace? */
  9314.             brace++;                    /* Remember */
  9315.             s++;                        /* Go to next character */
  9316.             if (!*s) {
  9317.                 goto exit_sendkeydef ;
  9318.             }
  9319.         }
  9320.         if (*s == 'K' || *s == 'k') {   /* Have K verb? */
  9321.             s++;
  9322.             if (*s == '{') {                /* Opening brace? */
  9323.                 brace++;                  /* Remember */
  9324.                 s++;                        /* Go to next character */
  9325.                 if (!*s) {
  9326.                     goto exit_sendkeydef ;
  9327.                 }
  9328.             } else if (!*s) {
  9329.                 goto exit_sendkeydef ;
  9330.             }
  9331.  
  9332. /*
  9333.   We assume that the verb name is {braced}, or it extends to the end of the
  9334.   string, s, or it ends with a space, control character, or backslash.
  9335. */
  9336.             p = kbuf;                   /* Copy verb name into local buffer */
  9337.             x = 0;
  9338.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  9339.                 if (brace && *s == '}') {
  9340.                     if (brace == 1)
  9341.                         break;
  9342.                     brace--;
  9343.                     s++;
  9344.                     continue;
  9345.                 }
  9346.                 *p++ = *s++;
  9347.             }
  9348.             if (*s && !brace)           /* If we broke because of \, etc, */
  9349.                 s--;                    /*  back up so we get another look. */
  9350.             brace = 0;
  9351.             *p = NUL;                   /* Terminate. */
  9352.             p = kbuf;                   /* Point back to beginning */
  9353.             debug(F110,"sendkeydef kverb",p,0);
  9354.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  9355.             debug(F101,"sendkeydef lookup",0,y);
  9356.             if (y > -1) {
  9357.                 if ( sendndx ) {
  9358.                     sendcharsduplex( sendbuf, sendndx, no_xlate ) ;
  9359.                     sendndx = 0 ;
  9360.                 }
  9361.                 dokverb(VTERM,y) ;
  9362. #ifndef NOSPL
  9363.             } else {                    /* Is it a macro? */
  9364.                 y = mxlook(mactab,p,nmac);
  9365.                 if (y > -1) {
  9366.                     keymac = 1;         /* Flag for key macro active */
  9367.                     keymacx = y;        /* Key macro index */
  9368.                     keydefptr = s;      /* Where to resume next time */
  9369.                     debug(F111,"sendkeydef mxlook",keydefptr,y);
  9370.                     SetConnectMode(0,CSX_MACRO); /* Leave CONNECT mode */
  9371.                 }
  9372. #endif /* NOSPL */
  9373.             }
  9374.         } else if (*s == 'V' || *s == 'v') { /* Have \v(xxx)? */
  9375.             s++;                        /* Next char */
  9376.             if (!*s)
  9377.                 goto exit_sendkeydef ;
  9378.             if (*s != '(') {            /* Should be left paren */
  9379.                 sendbufd(CMDQ) ;
  9380.                 sendbufd(*s) ;
  9381.                 continue;
  9382.             }
  9383.             b = s - 1;                  /* Save my place */
  9384.             s++;                        /* Point past paren */
  9385.             p = kbuf;                   /* Point to word buffer */
  9386.             x = 0;                      /* Copy verb into it */
  9387.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != ')'))
  9388.                 *p++ = *s++;
  9389.             *p = NUL;
  9390.             if (*s != ')') {            /* Have terminating paren? */
  9391.                                         /* No, send this literally */
  9392.                 sendbufd(CMDQ) ;
  9393.                 s = b;
  9394.                 continue;
  9395.             } else {
  9396.                 p = kbuf;               /* Point back to beginning */
  9397.                 debug(F110,"sendkeydef v(verb)",p,0);
  9398.                 p = nvlook(p);          /* Look it up. */
  9399.                 if (!p)                 /* Not found, */
  9400.                     continue;           /* continue silently. */
  9401.                 while (*p) {            /* Send it. */
  9402.                     sendbufd(*p++) ;
  9403.                 }
  9404.                 if (!*s)
  9405.                     goto exit_sendkeydef ;
  9406.             }
  9407.         } else if (*s == CMDQ) {        /* A Quoted CMDQ */
  9408.             sendbufd(CMDQ);
  9409.         } else {                        /* Not \K, \{K, \V, or \\ */
  9410.                                         /* Back up and send backslash, */
  9411.             sendbufd(CMDQ) ;
  9412.             if (brace) {                /* and maybe a left brace, */
  9413.                 sendbufd('{') ;
  9414.                 brace = 0;
  9415.             }
  9416.             if (*s) /* and this char literally. */
  9417.                 sendbufd(*s) ;
  9418.         }
  9419.         if (!*s) {
  9420.             keydefptr = NULL;
  9421.             return;
  9422.         }
  9423.     }
  9424.   exit_sendkeydef:
  9425.     if ( sendndx ) {
  9426.         sendcharsduplex( sendbuf, sendndx, no_xlate ) ;
  9427.         sendndx = 0 ;
  9428.     }
  9429.     keydefptr = NULL;
  9430. #undef sendbufd
  9431. #endif /* NOKVERBS */
  9432. }
  9433.  
  9434. void
  9435. scrollstatusline( void )
  9436. {
  9437. #ifndef NOKVERBS
  9438.     /* Build a special status line for scrollback mode */
  9439.     /* Usertext field updated dynamicly in line25()    */
  9440.  
  9441.     if ( markmodeflag[VTERM] == notmarking ) {
  9442.         if (vik.upscn > 255 && keyname(vik.upscn)) {
  9443.                 strncpy(helptext, keyname(vik.upscn), 20);
  9444.             if (vik.dnscn > 255 && keyname(vik.dnscn)) {
  9445.                 ckstrncat(helptext,"/",HLPTXTLEN);
  9446.                 ckstrncat(helptext,keyname(vik.dnscn),HLPTXTLEN);
  9447.             }
  9448.         }
  9449.         else
  9450.             ckstrncpy(helptext, "\\KupScn,\\KdnScn",HLPTXTLEN);
  9451.         }
  9452.     else {
  9453.         sprintf(helptext, "%c,%c,%c,%c\0",27,24,25,26);
  9454.     }
  9455.  
  9456.     if ((vik.help > 255) &&
  9457.          (keyname(vik.help)) &&
  9458.          ((HSTNAMLEN - 6 - (int)strlen(keyname(vik.help))) > 0)) {
  9459.         sprintf(hostname, "Help: %s", keyname(vik.help));
  9460.     }
  9461.     else if (vik.homscn > 255 && keyname(vik.homscn)) {
  9462.             strcpy(hostname, keyname(vik.homscn));
  9463.         if (vik.endscn > 255 && keyname(vik.endscn)) {
  9464.             ckstrncat(hostname,"/",HSTNAMLEN);
  9465.             ckstrncat(hostname,keyname(vik.endscn),HSTNAMLEN);
  9466.         }
  9467.     }
  9468.     else
  9469.         ckstrncpy(hostname, "\\KhomScn,\\KendScn",HSTNAMLEN);
  9470.  
  9471.     helptext[0] = '\0';
  9472.     exittext[0] = '\0';
  9473.     /* filetext[0] = '\0'; */
  9474. #endif /* NOKVERBS */
  9475. }
  9476.  
  9477. /* Mark mode - this replaces most of the Mouse Functions */
  9478.  
  9479. void
  9480. markmode( BYTE vmode, int k )
  9481. {
  9482. #ifndef NOKVERBS
  9483.     static int rollstate[VNUM]={0,0,0,0},
  9484.                scrollstate[VNUM]={0,0,0,0};
  9485.     static KEY savekeys[8]={0,0,0,0,0,0,0,0};
  9486.     static MACRO savemacros[8]={0,0,0,0,0,0,0,0};
  9487.     con_event evt ;
  9488.  
  9489.     if ( k != K_MARK_START && markmodeflag[vmode] == notmarking )
  9490.     {
  9491.        switch( k )
  9492.        {
  9493.        case K_BACKSRCH:
  9494.           markmode( vmode, K_MARK_START ) ;
  9495.           if ( search( vmode, FALSE, TRUE ) )
  9496.           {
  9497.              k = K_MARK_START ;
  9498.              break;
  9499.           }
  9500.           else
  9501.           {
  9502.              markmode( vmode, K_MARK_CANCEL ) ;
  9503.              bleep( BP_FAIL ) ;
  9504.              return;
  9505.           }
  9506.        case K_BACKNEXT:
  9507.           markmode( vmode, K_MARK_START ) ;
  9508.           if ( search( vmode, FALSE, FALSE ) )
  9509.           {
  9510.              k = K_MARK_START ;
  9511.              break;
  9512.           }
  9513.           else
  9514.           {
  9515.              markmode( vmode, K_MARK_CANCEL ) ;
  9516.              bleep( BP_FAIL ) ;
  9517.              return;
  9518.           }
  9519.        case K_FWDSRCH:
  9520.           markmode( vmode, K_MARK_START ) ;
  9521.           if ( search( vmode, TRUE, TRUE ) )
  9522.           {
  9523.              k = K_MARK_START ;
  9524.              break;
  9525.           }
  9526.           else
  9527.           {
  9528.              markmode( vmode, K_MARK_CANCEL ) ;
  9529.              bleep( BP_FAIL ) ;
  9530.              return;
  9531.           }
  9532.        case K_FWDNEXT:
  9533.           markmode( vmode, K_MARK_START ) ;
  9534.           if ( search( vmode, TRUE, FALSE ) )
  9535.           {
  9536.              k = K_MARK_START ;
  9537.              break;
  9538.           }
  9539.           else
  9540.           {
  9541.              markmode( vmode, K_MARK_CANCEL ) ;
  9542.              bleep( BP_FAIL ) ;
  9543.              return;
  9544.           }
  9545.  
  9546.        case K_MARK_CANCEL:
  9547.            return;
  9548.  
  9549.        default:
  9550.           bleep( BP_WARN ) ;
  9551.           return ;
  9552.        }
  9553.     }
  9554.  
  9555.     if ( markmodeflag[vmode] == notmarking ) {
  9556.         /* Save Macro and Keymap settings for Arrow keys */
  9557.         savemacros[0] = macrotab[KEY_SCAN | KEY_ENHANCED | 38] ;     /* Up Arrow    Gray */
  9558.         savemacros[1] = macrotab[KEY_SCAN | 38               ] ;     /* Up Arrow    Numeric */
  9559.         savemacros[2] = macrotab[KEY_SCAN | KEY_ENHANCED | 37] ;     /* Left Arrow  Gray */
  9560.         savemacros[3] = macrotab[KEY_SCAN | 37               ] ;     /* Left Arrow  Numeric*/
  9561.         savemacros[4] = macrotab[KEY_SCAN | KEY_ENHANCED | 39] ;     /* Right Arrow Gray */
  9562.         savemacros[5] = macrotab[KEY_SCAN | 39               ] ;     /* Right Arrow Numeric */
  9563.         savemacros[6] = macrotab[KEY_SCAN | KEY_ENHANCED | 40] ;     /* Down Arrow  Gray */
  9564.         savemacros[7] = macrotab[KEY_SCAN | 40               ] ;     /* Down Arrow  Numeric */
  9565.  
  9566.         savekeys[0] = keymap[KEY_SCAN | KEY_ENHANCED | 38] ;         /* Up Arrow    Gray */
  9567.         savekeys[1] = keymap[KEY_SCAN | 38               ] ;         /* Up Arrow    Numeric */
  9568.         savekeys[2] = keymap[KEY_SCAN | KEY_ENHANCED | 37] ;         /* Left Arrow  Gray */
  9569.         savekeys[3] = keymap[KEY_SCAN | 37               ] ;         /* Left Arrow  Numeric*/
  9570.         savekeys[4] = keymap[KEY_SCAN | KEY_ENHANCED | 39] ;         /* Right Arrow Gray */
  9571.         savekeys[5] = keymap[KEY_SCAN | 39               ] ;         /* Right Arrow Numeric */
  9572.         savekeys[6] = keymap[KEY_SCAN | KEY_ENHANCED | 40] ;         /* Down Arrow  Gray */
  9573.         savekeys[7] = keymap[KEY_SCAN | 40               ] ;         /* Down Arrow  Numeric */
  9574.  
  9575.         macrotab[KEY_SCAN | KEY_ENHANCED | 38] = NULL ;              /* Up Arrow    Gray */
  9576.         macrotab[KEY_SCAN | 38               ] = NULL ;              /* Up Arrow    Numeric */
  9577.         macrotab[KEY_SCAN | KEY_ENHANCED | 37] = NULL ;              /* Left Arrow  Gray */
  9578.         macrotab[KEY_SCAN | 37               ] = NULL ;              /* Left Arrow  Numeric*/
  9579.         macrotab[KEY_SCAN | KEY_ENHANCED | 39] = NULL ;              /* Right Arrow Gray */
  9580.         macrotab[KEY_SCAN | 39               ] = NULL ;              /* Right Arrow Numeric */
  9581.         macrotab[KEY_SCAN | KEY_ENHANCED | 40] = NULL ;              /* Down Arrow  Gray */
  9582.         macrotab[KEY_SCAN | 40               ] = NULL ;              /* Down Arrow  Numeric */
  9583.  
  9584.         keymap[KEY_SCAN | KEY_ENHANCED | 38] = F_KVERB | K_UPARR;       /* Up Arrow    Gray */
  9585.         keymap[KEY_SCAN | 38               ] = F_KVERB | K_UPARR;       /* Up Arrow    Numeric */
  9586.         keymap[KEY_SCAN | KEY_ENHANCED | 37] = F_KVERB | K_LFARR;       /* Left Arrow  Gray */
  9587.         keymap[KEY_SCAN | 37               ] = F_KVERB | K_LFARR;       /* Left Arrow  Numeric*/
  9588.         keymap[KEY_SCAN | KEY_ENHANCED | 39] = F_KVERB | K_RTARR;       /* Right Arrow Gray */
  9589.         keymap[KEY_SCAN | 39               ] = F_KVERB | K_RTARR;       /* Right Arrow Numeric */
  9590.         keymap[KEY_SCAN | KEY_ENHANCED | 40] = F_KVERB | K_DNARR;       /* Down Arrow  Gray */
  9591.         keymap[KEY_SCAN | 40               ] = F_KVERB | K_DNARR;       /* Down Arrow  Numeric */
  9592.  
  9593.         rollstate[vmode] = tt_roll[vmode] ;
  9594.         scrollstate[vmode] = scrollflag[vmode] ;
  9595.         markmodeflag[vmode] = inmarkmode ;
  9596.  
  9597.         if (!scrollstate[vmode]) {
  9598.             scrollstatus[vmode] = TRUE ;
  9599.             }
  9600.  
  9601.         scrollstatusline() ;
  9602.         scrollflag[vmode] = TRUE ;
  9603.         if ( !scrollstate[vmode] )
  9604.             VscrnSetScrollTop( vmode, VscrnGetTop(vmode) ) ;
  9605.         VscrnIsDirty(vmode) ;
  9606.         return ;
  9607.         }  /* if (markmode[vmode] == notmarking) */
  9608.  
  9609.         switch (k &= ~(F_KVERB)) {
  9610.         case K_MARK_START:
  9611.             scrollstatusline();
  9612.             markstart(vmode) ;
  9613.             break;
  9614.  
  9615.         case K_MARK_CANCEL:
  9616.             markcancel(vmode) ;
  9617.             break;
  9618.  
  9619.         case K_MARK_COPYCLIP:
  9620.             markcopyclip(vmode,0) ;
  9621.             break;
  9622.  
  9623.         case K_MARK_COPYHOST:
  9624.             markcopyhost(vmode,0) ;
  9625.             break;
  9626.  
  9627.        case K_MARK_SELECT:
  9628.             markselect(vmode,0);
  9629.             break;
  9630.  
  9631.         case K_MARK_COPYCLIP_NOEOL:
  9632.             markcopyclip(vmode,1) ;
  9633.             break;
  9634.  
  9635.         case K_MARK_COPYHOST_NOEOL:
  9636.             markcopyhost(vmode,1) ;
  9637.             break;
  9638.  
  9639.        case K_MARK_SELECT_NOEOL:
  9640.             markselect(vmode,1);
  9641.             break;
  9642.  
  9643.         case K_DNONE:
  9644.         case K_DNARR:
  9645.             markdownone(vmode) ;
  9646.             break;
  9647.  
  9648.         case K_UPONE:
  9649.         case K_UPARR:
  9650.             markupone(vmode) ;
  9651.             break;
  9652.  
  9653.         case K_LFONE:
  9654.         case K_LFARR:
  9655.             markleftone(vmode) ;
  9656.             break;
  9657.  
  9658.         case K_RTONE:
  9659.         case K_RTARR:
  9660.             markrightone(vmode) ;
  9661.             break;
  9662.  
  9663.         case K_DNSCN:
  9664.             markdownscreen(vmode) ;
  9665.             break;
  9666.  
  9667.         case K_UPSCN:
  9668.             markupscreen(vmode) ;
  9669.             break;
  9670.  
  9671.         case K_HOMSCN:
  9672.             markhomescreen(vmode) ;
  9673.             break;
  9674.  
  9675.         case K_ENDSCN:
  9676.             markendscreen(vmode) ;
  9677.             break;
  9678.  
  9679. #ifdef IN_PROGRESS  /* They just are not finished */
  9680.         case K_LFPAGE:
  9681.             markleftpage(vmode) ;
  9682.             break;
  9683.  
  9684.         case K_RTPAGE:
  9685.             markrightpage(vmode) ;
  9686.             break;
  9687. #endif /* IN_PROGRESS */
  9688.  
  9689.         case K_DUMP:
  9690.             markprint(vmode, 0);
  9691.             break;
  9692.  
  9693.         case K_HELP:                    /* Help */
  9694.             while ( popuphelp( vmode, hlp_markmode ) == ( F_KVERB | K_HELP ) ) ;
  9695.             return;
  9696.  
  9697.         case K_EXIT:            /* Exit terminal mode */
  9698.             markcancel(vmode);
  9699.             putkey( vmode, vik.exit ) ;
  9700.             return ;
  9701.  
  9702.     case K_QUIT:            /* Quit Kermit */
  9703.             markcancel(vmode);
  9704.             putkey( vmode, vik.quit ) ;
  9705.             return ;
  9706.  
  9707.     case K_BACKSRCH:
  9708.            if (!search( vmode, FALSE, TRUE ) )
  9709.            {
  9710.               markcancel(vmode);
  9711.               bleep(BP_FAIL);
  9712.            }
  9713.            break;
  9714.  
  9715.     case K_BACKNEXT:
  9716.            if (!search( vmode, FALSE, FALSE ))
  9717.            {
  9718.               markcancel(vmode);
  9719.               bleep(BP_FAIL);
  9720.            }
  9721.            break;
  9722.     case K_FWDSRCH:
  9723.            if (!search( vmode, TRUE, TRUE ))
  9724.            {
  9725.               markcancel(vmode);
  9726.               bleep(BP_FAIL);
  9727.            }
  9728.            break;
  9729.     case K_FWDNEXT:
  9730.            if (!search( vmode, TRUE, FALSE ))
  9731.            {
  9732.               markcancel(vmode);
  9733.               bleep(BP_FAIL);
  9734.            }
  9735.            break;
  9736.  
  9737.         default:
  9738.             bleep(BP_WARN);
  9739.         }
  9740.  
  9741.     if ( markmodeflag[vmode] == notmarking ) {
  9742.         if (scrollstate[vmode]) {
  9743.             scrollstatusline() ;
  9744.             }
  9745.         else {
  9746.             scrollstatus[vmode] = FALSE ;
  9747.             ipadl25() ;   /* put back the normal status line */
  9748.             }
  9749.  
  9750.         scrollflag[vmode] = scrollstate[vmode] ;
  9751.         tt_roll[vmode] = rollstate[vmode] ;
  9752.  
  9753.         VscrnSetCurPos( vmode, wherex[vmode] -1, wherey[vmode]-1 ) ;
  9754.  
  9755.         /* Restore Macro and KeyMap settings for Arrow keys */
  9756.  
  9757.         macrotab[KEY_SCAN | KEY_ENHANCED | 38] = savemacros[0] ;     /* Up Arrow    Gray */
  9758.         macrotab[KEY_SCAN | 38               ] = savemacros[1] ;     /* Up Arrow    Numeric */
  9759.         macrotab[KEY_SCAN | KEY_ENHANCED | 37] = savemacros[2] ;     /* Left Arrow  Gray */
  9760.         macrotab[KEY_SCAN | 37               ] = savemacros[3] ;     /* Left Arrow  Numeric*/
  9761.         macrotab[KEY_SCAN | KEY_ENHANCED | 39] = savemacros[4] ;     /* Right Arrow Gray */
  9762.         macrotab[KEY_SCAN | 39               ] = savemacros[5] ;     /* Right Arrow Numeric */
  9763.         macrotab[KEY_SCAN | KEY_ENHANCED | 40] = savemacros[6] ;     /* Down Arrow  Gray */
  9764.         macrotab[KEY_SCAN | 40               ] = savemacros[7] ;     /* Down Arrow  Numeric */
  9765.  
  9766.         keymap[KEY_SCAN | KEY_ENHANCED | 38] = savekeys[0] ;         /* Up Arrow    Gray */
  9767.         keymap[KEY_SCAN | 38               ] = savekeys[1] ;         /* Up Arrow    Numeric */
  9768.         keymap[KEY_SCAN | KEY_ENHANCED | 37] = savekeys[2] ;         /* Left Arrow  Gray */
  9769.         keymap[KEY_SCAN | 37               ] = savekeys[3] ;         /* Left Arrow  Numeric*/
  9770.         keymap[KEY_SCAN | KEY_ENHANCED | 39] = savekeys[4] ;         /* Right Arrow Gray */
  9771.         keymap[KEY_SCAN | 39               ] = savekeys[5] ;         /* Right Arrow Numeric */
  9772.         keymap[KEY_SCAN | KEY_ENHANCED | 40] = savekeys[6] ;         /* Down Arrow  Gray */
  9773.         keymap[KEY_SCAN | 40               ] = savekeys[7] ;         /* Down Arrow  Numeric */
  9774.         } /* if ( markmodeflag[vmode] == notmarking ) */
  9775.  
  9776.     os2settitle(NULL,1);
  9777.     VscrnIsDirty(vmode);
  9778. #endif /* NOKVERBS */
  9779. }
  9780.  
  9781. /* Scrollback handler */
  9782. /*
  9783.   Totally rewritten for edit 190 to allow TERMINAL ROLL options and to
  9784.   use new keymap  - fdc.
  9785.  
  9786.   And again for 191 - jaltman.
  9787. */
  9788.  
  9789. void
  9790. scrollback(BYTE vmode, int k) {                 /* Keycode */
  9791. #ifndef NOKVERBS
  9792.     con_event evt ;
  9793.  
  9794.     /* Initialization */
  9795.  
  9796. #ifdef DEBUG
  9797.     debug(F101,"scrollback key","",key);
  9798.     debug(F101,"scrollback tt_roll","",tt_roll[vmode]);
  9799. #endif /* DEBUG */
  9800.  
  9801.     if ( !tt_scroll ) {
  9802.         debug(F100,"scrollback disabled","",0);
  9803.         return;
  9804.     }
  9805. /*
  9806.   If TERMINAL ROLL OFF, we just process the argument key and return control of
  9807.   the keyboard to the user.  This lets the user type characters to the host
  9808.   while looking at rollback screens, as well as view new incoming characters
  9809.   on an old screen.  But it can result in some confusion by mixing new and old
  9810.   material in the rollback buffer.
  9811.  
  9812.   If TERMINAL ROLL ON, the user is held captive inside the rolled-back
  9813.   screens, allowed to type only rollback keys until reaching the bottom again,
  9814.   and no characters are read from the communication device while rolled back.
  9815.   This prevents transmission of characters to the host, and it prevents
  9816.   mixture of new and old material in the rollback buffer.
  9817.  
  9818.   This is not true in this code anymore.  We always fall through regardless
  9819.   of ROLL ON or OFF.
  9820. */
  9821.     switch (k &= ~(F_KVERB)) {  /* Handle the key... */
  9822.  
  9823.     case K_GO_BOOK:       /* Scroll to Bookmark location */
  9824.        bookmarkjump(vmode);
  9825.        break;
  9826.  
  9827.     case K_GOTO:
  9828.        gotojump(vmode);
  9829.        break;
  9830.  
  9831.     case K_HOMSCN:              /* Scrolling UP (backwards) ... */
  9832.         if (!tt_roll[vmode]) {
  9833.             if ( VscrnSetTop(vmode, VscrnGetBegin(vmode)) < 0 )
  9834.               bleep(BP_WARN) ;
  9835.         }
  9836.         else {
  9837.             if ( VscrnSetScrollTop(vmode,VscrnGetBegin(vmode)) < 0 )
  9838.               bleep(BP_WARN);
  9839.         }
  9840.         break;
  9841.  
  9842.     case K_UPSCN:
  9843.         if (!tt_roll[vmode]) {
  9844.             if ( VscrnMoveTop(vmode,-(VscrnGetHeight(vmode)-(tt_status[vmode]?1:0))) < 0 )
  9845.               if ( VscrnSetTop(vmode,VscrnGetBegin(vmode)) < 0 )
  9846.                 bleep(BP_WARN) ;
  9847.         }
  9848.         else {
  9849.             if ( VscrnMoveScrollTop(vmode,-(VscrnGetHeight(vmode)-(tt_status[vmode]?1:0))) < 0 )
  9850.               if ( VscrnSetScrollTop(vmode,VscrnGetBegin(vmode)) < 0 )
  9851.                 bleep(BP_WARN);
  9852.         }
  9853.         break;
  9854.  
  9855.     case K_UPONE:
  9856.         if (!tt_roll[vmode]) {
  9857.             if ( VscrnMoveTop(vmode,-1) < 0 )
  9858.               bleep(BP_WARN) ;
  9859.         }
  9860.         else {
  9861.             if ( VscrnMoveScrollTop(vmode,-1) < 0 )
  9862.               bleep(BP_WARN);
  9863.         }
  9864.         break;
  9865.  
  9866.     case K_DNSCN:                       /* Go down */
  9867.         if (!tt_roll[vmode]) {
  9868.             if ( VscrnMoveTop(vmode,VscrnGetHeight(vmode)-(tt_status[vmode]?1:0)) < 0 )
  9869.               if ( VscrnSetTop(vmode,VscrnGetEnd(vmode) - VscrnGetHeight(vmode)+1) < 0 )
  9870.                 bleep(BP_WARN);
  9871.         }
  9872.         else {
  9873.             if ( VscrnMoveScrollTop(vmode,VscrnGetHeight(vmode)-(tt_status[vmode]?1:0)) < 0 )
  9874.               if ( VscrnSetScrollTop(vmode,VscrnGetEnd(vmode)
  9875.                                       - (VscrnGetHeight(vmode)-(tt_status[vmode]?1:0))+1) < 0 )
  9876.                 bleep(BP_WARN);
  9877.         }
  9878.         break;
  9879.  
  9880.     case K_DNONE:
  9881.         if (!tt_roll[vmode]) {
  9882.             if ( VscrnMoveTop(vmode,1) < 0 )
  9883.               bleep(BP_WARN);
  9884.         }
  9885.         else {
  9886.             if ( VscrnMoveScrollTop(vmode,1) < 0 )
  9887.               bleep(BP_WARN);
  9888.         }
  9889.         break;
  9890.  
  9891.     case K_ENDSCN:              /* Scroll to bottom */
  9892.         if (!tt_roll[vmode]) {
  9893.             if ( VscrnSetTop(vmode,VscrnGetEnd(vmode) - VscrnGetHeight(vmode)-(tt_status[vmode]?1:0) + 1) < 0 )
  9894.               bleep(BP_WARN);
  9895.         }
  9896.         else {
  9897.             if ( VscrnSetScrollTop(vmode,VscrnGetTop(vmode)) < 0 )
  9898.               bleep(BP_WARN);
  9899.         }
  9900.         break;
  9901.  
  9902.     case K_DUMP: {              /* Print/Dump current screen */
  9903.         int x;
  9904.         x = xprintff; xprintff = 0;
  9905.         prtscreen(vmode,1,VscrnGetHeight(vmode)-(tt_status[vmode]?1:0));
  9906.         xprintff = x;
  9907.         break;
  9908.     }
  9909.  
  9910.     case K_HELP: {              /* Help */
  9911.         int x = hlp_rollback;
  9912.         while ( popuphelp(vmode,x) == ( F_KVERB | K_HELP ) )
  9913.             switch ( x ) {
  9914. #ifdef OS2MOUSE
  9915.             case hlp_rollback:
  9916.                 x = hlp_mouse;
  9917.                 break;
  9918.             case hlp_mouse:
  9919.                 x = hlp_rollback;
  9920.                 break;
  9921. #else /* OS2MOUSE */
  9922.             case hlp_rollback:
  9923.                 x = hlp_rollback;
  9924.                 break;
  9925. #endif /* OS2MOUSE */
  9926.             }
  9927.         killcursor(vmode);              /* Turn it back off */
  9928.         break;
  9929.     }
  9930.  
  9931.     case K_MARK_START:
  9932.         markmode(vmode,K_MARK_START);
  9933.         break;
  9934.  
  9935.     case K_EXIT:
  9936.         putkey( vmode, vik.endscn ) ;
  9937.         putkey( vmode, vik.exit ) ;
  9938.         break ;
  9939.  
  9940.     case K_QUIT:
  9941.         putkey( vmode, vik.endscn ) ;
  9942.         putkey( vmode, vik.quit ) ;
  9943.         break ;
  9944.  
  9945.     default:                    /* Not a rollback key. */
  9946.         bleep(BP_WARN);
  9947.         break;
  9948.  
  9949.     } /* switch (k) */
  9950.  
  9951.     scrollflag[vmode] = tt_roll[vmode] && ( VscrnGetTop(vmode) != VscrnGetScrollTop(vmode) ) ;
  9952.  
  9953.     if ( !scrollstatus[vmode] ) {
  9954.         scrollstatus[vmode] = TRUE ;
  9955.         scrollstatusline() ;
  9956.     }
  9957.  
  9958. /*
  9959.   Get here after processing one keystroke and TERMINAL ROLL is OFF,
  9960.   or when TERMINAL ROLL is ON, only when we've reached the bottom.
  9961.   Wrong.
  9962. */
  9963.     if ( !scrollflag[vmode] ) {
  9964.         if (tt_roll[vmode] ||
  9965.              (VscrnGetTop(vmode)+VscrnGetHeight(vmode)-(tt_status[vmode]?2:1))%VscrnGetBufferSize(vmode) == VscrnGetEnd(vmode))
  9966.         {
  9967.             scrollstatus[vmode] = FALSE ;
  9968.             ipadl25();                  /* Put back normal status line */
  9969.         }
  9970.     } /* if ( !scrollflag[vmode] ) */
  9971.  
  9972.     os2settitle(NULL,1);
  9973.     VscrnIsDirty(vmode) ;
  9974. #endif /* NOKVERBS */
  9975. }
  9976.  
  9977. void
  9978. vt100key(int key) {
  9979. #ifdef NOKVERBS
  9980.     char str[3];                        /* Not needed in simplified code */
  9981.     int prt, st;
  9982. #endif /* NOKVERBS */
  9983.  
  9984.     if ( keydefptr ) {                  /* First send any leftovers */
  9985.         sendkeydef( keydefptr,FALSE );  /* from previous session... */
  9986.         keydefptr = NULL;                   /* and then forget about it */
  9987.         return;
  9988.     }
  9989.  
  9990.     if (key < 0x100 && !kbdlocked()) {      /* If it's a regular key, */
  9991.         sendcharduplex((char) key,FALSE);/* just send it, */
  9992.         if (tt_pacing > 0)              /* taking care of pacing */
  9993.             msleep(tt_pacing);
  9994.         if (key == CR && tnlm) {        /* and newline mode */
  9995.             if (tt_pacing > 0)          /* and pacing */
  9996.                 msleep(tt_pacing);
  9997.         }
  9998.         return;
  9999.     }
  10000.  
  10001.     /* vt100key is only called from within conkbdhandler() */
  10002.     /* and all events are handled there, so how would this */
  10003.     /* get here */
  10004.     if ( IS_CSI(key) ) {
  10005.         char buf[3] ;
  10006.         buf[0] = '[' ;
  10007.         buf[1] = key & 0xFF ;
  10008.         buf[2] = NUL ;
  10009.         sendescseq(buf) ;
  10010.     }
  10011.     else if ( IS_ESC(key) ) {
  10012.         char buf[2] ;
  10013.         buf[0] = key & 0xFF ;
  10014.         buf[1] = NUL ;
  10015.         sendescseq(buf) ;
  10016.     }
  10017. #ifndef NOKVERBS
  10018.     else if (IS_KVERB(key)) {        /* Specially precoded keyboard verb */
  10019.         dokverb(VTERM,key) ;          /* We already know its index */
  10020.     }
  10021.     else
  10022.         bleep(BP_WARN);                         /* Extended key with no definition. */
  10023.     return;                             /* Just beep & return. */
  10024. #endif /* NOKVERBS */
  10025. }
  10026.  
  10027. #ifdef CK_APC
  10028. /* ------------------------------------------------------------------ */
  10029. /* doosc - process OSC sequences (VT320 and higher)                   */
  10030. /*         sequence of apclength in apcbuf                            */
  10031. /* ------------------------------------------------------------------ */
  10032.  
  10033. void
  10034. doosc( void ) {
  10035. /* at current we only process two SET WINDOW TITLE and SET ICON TITLE */
  10036. /* So let's not implement a full parser                               */
  10037.  
  10038.     /* AIXTERM */
  10039.     /*   0 - Set Icon and Title */
  10040.     /*   1 - Set Icon only      */
  10041.     /*   2 - Set Title only     */
  10042.  
  10043.     switch ( apcbuf[0] ) {
  10044.     case '0': { /* XTERM */
  10045.         /* the rest of the apcbuffer is the Window Title */
  10046.         char wtitle[31] ;
  10047.         int i ;
  10048.         for ( i=0;i<=30 && i+2 < apclength; i++ )
  10049.             wtitle[i] = apcbuf[i+2] ;
  10050.         if ( i > 0 && apcbuf[i-1] == 0x07 ) {
  10051.             /* XTERMs may append a Beep indicator at the end */
  10052.             wtitle[i-1] = NUL ;
  10053.             bleep(BP_NOTE);
  10054.         }
  10055.         else
  10056.             wtitle[i] = NUL ;
  10057.  
  10058.         if (!os2settitle(wtitle,1)) {
  10059.             bleep(BP_FAIL);
  10060.             debug(F110,"doosc os2settitle fails",wtitle,0);
  10061.         }
  10062.         break;
  10063.     }
  10064.     case '2': /* DEC VTxxx */
  10065.         switch ( apcbuf[1] ) {
  10066.         case 'L':       /* SET ICON TITLE - DECSIN */
  10067.             /* the rest of the apcbuffer is the Icon Title */
  10068.             break;
  10069.         case '1': {     /* SET WINDOW TITLE - DECSWT */
  10070.             /* the rest of the apcbuffer is the Window Title */
  10071.             char wtitle[31] ;
  10072.             int i ;
  10073.             for ( i=0;i<=30 && i+3<=apclength; i++ )
  10074.                 wtitle[i] = apcbuf[i+3] ;
  10075.             wtitle[i] = NUL ;
  10076.  
  10077.             if (!os2settitle(wtitle,1)) {
  10078.                 bleep(BP_FAIL);
  10079.                 debug(F110,"doosc os2settitle fails",wtitle,0);
  10080.             }
  10081.             break;
  10082.         }
  10083.         }
  10084.         break;
  10085.     }
  10086.     return;
  10087. }
  10088.  
  10089. /* dopu1 - process PU1 sequences (97801-5xx terminals) */
  10090. void
  10091. dopu1( void )
  10092. {
  10093.     debug(F111,"dopu1",apcbuf,apclength);
  10094. }
  10095.  
  10096. /* dopu2 - process PU2 sequences (97801-5xx terminals) */
  10097. void
  10098. dopu2( void )
  10099. {
  10100.     debug(F111,"dopu2",apcbuf,apclength);
  10101.     switch ( apcbuf[0] ) {
  10102.     case 'A':
  10103.         /* Load key assignment table */
  10104.         break;
  10105.     case 'B':
  10106.         /* Load one or more character generator addresses with a new */
  10107.         /* symbol ( ... = 3-byte address and 28/32-byte pattern in hex format ) */
  10108.         break;
  10109.     case 'C':
  10110.         if ( apcbuf[1] == NUL )
  10111.             ; /* Query load process for string key table */
  10112.         else
  10113.             ; /* Load string key table */
  10114.         break;
  10115.     case 'D':
  10116.         if ( apclength == 1 )
  10117.             ; /* Delete compose key table */
  10118.         else
  10119.             ; /* Load compose key table */
  10120.         break;
  10121.     case 'E':
  10122.         /* Load dead key table */
  10123.         break;
  10124.     case 'F':
  10125.         /* Load key assignment table */
  10126.         break;
  10127.     }
  10128. }
  10129.  
  10130. /* ------------------------------------------------------------------ */
  10131. /* dodcs - process DCS sequences (VT320 and higher)                   */
  10132. /*         sequence of apclength in apcbuf                            */
  10133. /* ------------------------------------------------------------------ */
  10134.  
  10135. void
  10136. dodcs( void )
  10137. {
  10138.     int pn[11];
  10139.     int i,k,l;
  10140.     int dcsnext = 0 ;
  10141.     char keydef[257] ; /* UDK defs can't be longer than 256 chars */
  10142.     char c, * p ;
  10143.  
  10144.     /*
  10145.     we haven't coded this yet
  10146.     but what would go here would be DECUDK, DECRSPS, DECRQSS, ....
  10147.     */
  10148.     debug( F111,"DCS string",apcbuf,apclength ) ;
  10149.  
  10150.     if ( debses )              /* If TERMINAL DEBUG ON */
  10151.       return ;                 /* don't do anything    */
  10152.     achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10153.     switch ( achar ) {
  10154.     case '$':  /* as in $q - DECRQSS */
  10155.         k = 0 ;
  10156.         goto LB4003;
  10157.     case '|':  /* DECUDK */
  10158.         pn[1] = pn[2] = 0;
  10159.         k = 2;
  10160.         goto LB4003;
  10161.     case ';':           /* As in DCS ; 7 m */
  10162.         pn[1] = 0;
  10163.         k = 1;
  10164.         goto LB4002;
  10165.     default:            /* Pn - got a number */
  10166.       LB4001:
  10167.         {               /* Esc [ Pn...Pn x   functions */
  10168.             pn[1] = 0 ;
  10169.             while (isdigit(achar)) {            /* Get number */
  10170.                 pn[1] = (pn[1] * 10) + achar - 48;
  10171.                 achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10172.             }
  10173.             k = 1;
  10174.           LB4002:
  10175.             while (achar == ';') { /* get Pn[k] */
  10176.                 achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10177.                 k++;
  10178.                 if (achar == '?')
  10179.                   achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10180.                                 pn[k] = 0 ;
  10181.                 while (isdigit(achar)) {                /* Get number */
  10182.                     pn[k] = (pn[k] * 10) + achar - 48;
  10183.                     achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10184.                 }
  10185.             }
  10186.             pn[k + 1] = 1;
  10187.           LB4003:
  10188.             switch (achar) { /* Third level */
  10189.             case '$': {
  10190.                 char decrpss[12] = "";
  10191.                 achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10192.                 switch ( achar ) {
  10193.                 case 'q':               /* DECRQSS */
  10194.                     /* The next set of characters are the D...D portion */
  10195.                     /* of the DECRQSS request */
  10196.                     achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10197.                     switch ( achar ) {
  10198.                     case '}':           /* DECPRO */
  10199.                         if ( send_c1 )
  10200.                             sprintf(decrpss,"%c0$r}%c",_DCS,_ST8);
  10201.                         else
  10202.                             sprintf(decrpss,"%cP0$r}%c\\",ESC,ESC);
  10203.                         break;
  10204.                     case '$':
  10205.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10206.                         switch ( achar ) {
  10207.                         case '}':       /* DECSASD */
  10208.                             if ( send_c1 )
  10209.                                 sprintf(decrpss,"%c0$r$}%c",_DCS,_ST8);
  10210.                             else
  10211.                                 sprintf(decrpss,"%cP0$r$}%c\\",ESC,ESC);
  10212.                             break;
  10213.                         case '|':       /* DECSCPP */
  10214.                             if ( send_c1 )
  10215.                                 sprintf(decrpss,"%c0$r$|%c",_DCS,_ST8);
  10216.                             else
  10217.                                 sprintf(decrpss,"%cP0$r$|%c\\",ESC,ESC);
  10218.                             break;
  10219.                         case '~':       /* DECSSDT */
  10220.                             if ( send_c1 )
  10221.                                 sprintf(decrpss,"%c0$r$~%c",_DCS,_ST8);
  10222.                             else
  10223.                                 sprintf(decrpss,"%cP0$r$~%c\\",ESC,ESC);
  10224.                             break;
  10225.                         }
  10226.                         break;
  10227.                     case '"':
  10228.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10229.                         switch ( achar ) {
  10230.                         case 'q':       /* DECSCA */
  10231.                             if ( send_c1 )
  10232.                                 sprintf(decrpss,"%c0$r\"q%c",_DCS,_ST8);
  10233.                             else
  10234.                                 sprintf(decrpss,"%cP0$r\"q%c\\",ESC,ESC);
  10235.                             break;
  10236.                         case 'p':       /* DECSCL */
  10237.                             if ( send_c1 )
  10238.                                 sprintf(decrpss,"%c0$r\"p%c",_DCS,_ST8);
  10239.                             else
  10240.                                 sprintf(decrpss,"%cP0$r\"p%c\\",ESC,ESC);
  10241.                             break;
  10242.                         }
  10243.                         break;
  10244.                     case 't':           /* DECSLPP */
  10245.                         if ( send_c1 )
  10246.                             sprintf(decrpss,"%c0$rt%c",_DCS,_ST8);
  10247.                         else
  10248.                             sprintf(decrpss,"%cP0$rt%c\\",ESC,ESC);
  10249.                         break;
  10250.                     case 'r':           /* DECSTBM */
  10251.                         if ( send_c1 )
  10252.                             sprintf(decrpss,"%c0$rr%c",_DCS,_ST8);
  10253.                         else
  10254.                             sprintf(decrpss,"%cP0$rr%c\\",ESC,ESC);
  10255.                         break;
  10256.                     case '|':           /* DECTTC */
  10257.                         if ( send_c1 )
  10258.                             sprintf(decrpss,"%c0$r|%c",_DCS,_ST8);
  10259.                         else
  10260.                             sprintf(decrpss,"%cP0$r|%c",ESC,ESC);
  10261.                         break;
  10262.                     case '\'':
  10263.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10264.                         switch ( achar ) {
  10265.                         case 's':       /* DECTLTC */
  10266.                             if ( send_c1 )
  10267.                                 sprintf(decrpss,"%c0$r\'s%c",_DCS,_ST8);
  10268.                             else
  10269.                                 sprintf(decrpss,"%cP0$r\'s%c\\",ESC,ESC);
  10270.                             break;
  10271.                         }
  10272.                         break;
  10273.                     case 'm':           /* SGR */
  10274.                         if ( send_c1 )
  10275.                             sprintf(decrpss,"%c0$rm%c",_DCS,_ST8);
  10276.                         else
  10277.                             sprintf(decrpss,"%cP0$rm%c\\",ESC,ESC);
  10278.                         break;
  10279.                     case 's':           /* DECSLRM - Set Left and Right Margins */
  10280.                         if ( send_c1 )
  10281.                             sprintf(decrpss,"%c1$rs%c",_DCS,_ST8);
  10282.                         else
  10283.                             sprintf(decrpss,"%cP1$rs%c\\",ESC,ESC);
  10284.                         break;
  10285.                     case '*':
  10286.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10287.                         switch ( achar ) {
  10288.                         case 'x':       /* DECSACE - Select Attrib Change Extent */
  10289.                             if ( send_c1 )
  10290.                                 sprintf(decrpss,"%c%d$r*x%c",_DCS,decsace?2:1,_ST8);
  10291.                             else
  10292.                                 sprintf(decrpss,"%cP%d$r*x%c\\",ESC,decsace?2:1,ESC);
  10293.                             break;
  10294.                         case '|':       /* DECSNLS - Set Num Lines Per Screen */
  10295.                             if ( send_c1 )
  10296.                                 sprintf(decrpss,"%c1$r*|%c",_DCS,_ST8);
  10297.                             else
  10298.                                 sprintf(decrpss,"%cP1$r*|%c\\",ESC,ESC);
  10299.                             break;
  10300.                         }
  10301.                         break;
  10302.                     case '+':
  10303.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10304.                         switch ( achar ) {
  10305.                         case 'q':       /* DECELF - Enable Local Functions */
  10306.                             if ( send_c1 )
  10307.                                 sprintf(decrpss,"%c1$r+q%c",_DCS,_ST8);
  10308.                             else
  10309.                                 sprintf(decrpss,"%cP1$r+q%c\\",ESC,ESC);
  10310.                             break;
  10311.                         case 'r':       /* DECSMKR - Select modifier key reporting */
  10312.                             if ( send_c1 )
  10313.                                 sprintf(decrpss,"%c1$r+r%c",_DCS,_ST8);
  10314.                             else
  10315.                                 sprintf(decrpss,"%cP1$r+r%c\\",ESC,ESC);
  10316.                             break;
  10317.                         }
  10318.                         break;
  10319.                     case '=':
  10320.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10321.                         switch ( achar ) {
  10322.                         case '}':       /* DECLFKC - Local Function Key Control */
  10323.                             if ( send_c1 )
  10324.                                 sprintf(decrpss,"%c1$r=}%c",_DCS,_ST8);
  10325.                             else
  10326.                                 sprintf(decrpss,"%cP1$r=}%c\\",ESC,ESC);
  10327.                             break;
  10328.                         }
  10329.                         break;
  10330.                     }
  10331.                     if ( decrpss[0] ) {
  10332.                         if ( send_c1 )
  10333.                             sprintf(decrpss,"%c1$r%c",_DCS,_ST8);
  10334.                         else
  10335.                             sprintf(decrpss,"%cP1$r%c\\",ESC,ESC);
  10336.                     }
  10337.                     if (decrpss[0])
  10338.                         sendchars(decrpss,strlen(decrpss));
  10339.                     break;
  10340.                 }
  10341.                 break;
  10342.             } /* $ */
  10343.             case '|': {    /* DECUDK */
  10344.                 int key = 0 ;
  10345.                 /* pn[1] - Clear keys: 0 All, 1 One */
  10346.                 /* pn[2] - Lock keys:  0 Lock, 1 no Lock */
  10347.                 if ( k<2 )
  10348.                     pn[2] = 1 ;
  10349.                 if ( k<1 )
  10350.                     pn[1] = 0 ;
  10351.  
  10352.                 if ( udklock )
  10353.                     return;  /* do nothing if the UDKs are locked */
  10354.  
  10355.                 if ( pn[1] == 0 ) { /* Clear all key defs */
  10356.                     udkreset() ;
  10357.                 }
  10358.  
  10359.                 while ( dcsnext < apclength ) {
  10360.                     /* look for patterns of XX/string; */
  10361.  
  10362.                     key=0;
  10363.                     /* which key to assign to? */
  10364.                     achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10365.                     if ( achar == ';' )
  10366.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10367.  
  10368.                     while (isdigit(achar)) {                /* Get number */
  10369.                         key = (key * 10) + achar - 48;
  10370.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10371.                     }
  10372.  
  10373.                     /* Check for proper separator */
  10374.                     if ( achar != '/') {
  10375.                         /* if error, call cwrite() on rest of DCS         */
  10376.                         /* including ST.  Actually, in a real VT terminal */
  10377.                         /* we wouldn't even wait until this point to      */
  10378.                         /* determine if there was an error.  We would do  */
  10379.                         /* this as the data is received.                  */
  10380.                         while ( achar ) {
  10381.                             cwrite(achar);
  10382.                             achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10383.                         }
  10384.                         cwrite(ESC);
  10385.                         cwrite('\\');
  10386.                         return ;
  10387.                     }
  10388.  
  10389.                     /* Get the key definition */
  10390.                     l = 0 ; /* characters in definition */
  10391.                     i = 0 ; /* which pass? */
  10392.                     while ( apcbuf[dcsnext] != ';' &&
  10393.                             dcsnext < apclength ) {
  10394.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10395.                         c = 0 ;
  10396.                         if ( isxdigit(achar) )
  10397.                         {
  10398.                             if ( isdigit(achar) )
  10399.                                 c = achar - '0' ;
  10400.                             else if ( islower(achar) )
  10401.                                 c = achar - 'a' + 10 ;
  10402.                             else
  10403.                                 c = achar - 'A' + 10 ;
  10404.                         }   
  10405.                         if ( i ) {
  10406.                             keydef[l] = (keydef[l]<<4)|c ;
  10407.                             l++ ;
  10408.                             keydef[l] = '\0' ;
  10409.                             i = 0 ;
  10410.                         }
  10411.                         else {
  10412.                             keydef[l] = c ;
  10413.                             i = 1 ;
  10414.                         }
  10415.                     }   
  10416.  
  10417.                     if ( i == 1 ||
  10418.                          apcbuf[dcsnext] != ';' &&
  10419.                          dcsnext < apclength ){
  10420.                         /* if error, call cwrite() on rest of DCS         */
  10421.                         /* including ST.  Actually, in a real VT terminal */
  10422.                         /* we wouldn't even wait until this point to      */
  10423.                         /* determine if there was an error.  We would do  */
  10424.                         /* this as the data is received.                  */
  10425.                         while ( achar ) {
  10426.                             cwrite(achar);
  10427.                             achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10428.                         }
  10429.                         cwrite(ESC);
  10430.                         cwrite('\\');
  10431.                         return ;
  10432.                     }
  10433.  
  10434.                     i = -1 ;
  10435.                     switch ( key ) {
  10436.                         /* DEC couldn't make it easy, could they */
  10437.                     case 11: i = 0 ; break ;
  10438.                     case 12: i = 1 ; break ;
  10439.                     case 13: i = 2 ; break ;
  10440.                     case 14: i = 3 ; break ;
  10441.                     case 15: i = 4 ; break ;
  10442.                     case 17: i = 5 ; break ;
  10443.                     case 18: i = 6 ; break ;
  10444.                     case 19: i = 7 ; break ;
  10445.                     case 20: i = 8 ; break ;
  10446.                     case 21: i = 9 ; break ;
  10447.                     case 23: i = 10 ; break ;
  10448.                     case 24: i = 11 ; break ;
  10449.                     case 25: i = 12 ; break ;
  10450.                     case 26: i = 13 ; break ;
  10451.                     case 28: i = 14 ; break ;
  10452.                     case 29: i = 15 ; break ;
  10453.                     case 31: i = 16 ; break ;
  10454.                     case 32: i = 17 ; break ;
  10455.                     case 33: i = 18 ; break ;
  10456.                     case 34: i = 19 ; break ;
  10457.                     }
  10458.                     if ( i>= 0 )
  10459.                     {
  10460.                         if ( udkfkeys[i] ) {
  10461.                             free( udkfkeys[i] ) ;
  10462.                             udkfkeys[i]=NULL;
  10463.                         }
  10464.                         if ( strlen(keydef) )
  10465.                             udkfkeys[i] = strdup(keydef) ;
  10466.                     }   
  10467.                     }   
  10468.  
  10469.                 if ( !pn[2] )
  10470.                     udklock = TRUE ;
  10471.                 break;
  10472.             }   /* | */
  10473.             case '+': {
  10474.                 achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10475.                 switch ( achar ) {
  10476.                 case 'm': {  /* URL or UNC attribute */
  10477.                     int  quote = 0;
  10478.                     char * link = NULL, *p;
  10479.  
  10480.                     if ( k < 1 )
  10481.                         pn[1] = 0;
  10482.  
  10483.                     switch ( pn[1] ) {
  10484.                     case 0:     /* End URL or UNC link */
  10485.                         debug(F100,"URL/UNC link attribute removed","",0);
  10486.                         if ( debses )
  10487.                             break;
  10488.                         attrib.hyperlink = FALSE;
  10489.                         attrib.linkid = 0;
  10490.                         break;
  10491.                     case 1:     /* Begin URL link */
  10492.                     case 2:     /* Begin UNC link */
  10493.                         link = (char *) malloc(apclength - dcsnext + 1);
  10494.                         if ( !link )
  10495.                             break;
  10496.                         
  10497.                         p = link;
  10498.                         achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10499.                         quote = (achar == '"');
  10500.                         if ( quote )
  10501.                             achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10502.  
  10503.                         while ( achar && (!quote || (quote && achar != '"') ))
  10504.                         {
  10505.                             *p++ = achar;
  10506.                              achar = (dcsnext<apclength)?apcbuf[dcsnext++]:0;
  10507.                         }
  10508.                         *p = '\0';
  10509.                         switch ( pn[1] ) {
  10510.                         case 1: 
  10511.                             debug(F110,"URL link assigned",link,0);
  10512.                             if ( debses ) {
  10513.                                 free(link);
  10514.                                 break;
  10515.                             }
  10516.                             attrib.hyperlink = TRUE;
  10517.                             attrib.linkid = hyperlink_add(HYPERLINK_URL, link);
  10518.                             break;
  10519.                         case 2:
  10520.                             debug(F110,"UNC link assigned",link,0);
  10521.                             if ( debses ) {
  10522.                                 free(link);
  10523.                                 break;
  10524.                             }
  10525.                             attrib.hyperlink = TRUE;
  10526.                             attrib.linkid = hyperlink_add(HYPERLINK_UNC, link);
  10527.                             break;
  10528.                         default:
  10529.                             debug(F110,"unknown link type",link,pn[1]);
  10530.                             free(link);
  10531.                         }
  10532.                         break;
  10533.                     }
  10534.                     break;
  10535.                 }   /* m */
  10536.                 }   /* achar */
  10537.                 break;
  10538.             }  /* + */
  10539.             }   /* third level */
  10540.         }
  10541.     }
  10542. }
  10543. #endif /* CK_APC */
  10544.  
  10545. /* ------------------------------------------------------------------ */
  10546. /* cwrite - check and process escape sequence                         */
  10547. /* ------------------------------------------------------------------ */
  10548.  
  10549.  
  10550. void
  10551. debugses( unsigned char ch )
  10552. {
  10553.     static char old_c = 0;
  10554.     static int  deb_wrap = 0;
  10555.  
  10556.     if (debses && !f_pushed) {          /* Session debugging */
  10557.         unsigned char ch8 = f_popped ? ((ch ^ 0x40) | 0x80) : ch;
  10558.         int tt_wrap_sav = tt_wrap;
  10559.         tt_wrap = 0;
  10560.  
  10561.         deb_wrap = wherex[VTERM] >= VscrnGetWidth(VTERM);
  10562.         if (ch8 < 32 && !literal_ch) {  /* C0 Control character */
  10563.             attribute = colordebug;     /* Use underline color */
  10564.             if (decscnm)                /* Handle flipped screen */
  10565.               attribute = swapcolors(attribute);
  10566.             wrtch((char)(ch8 | 64));    /* Write corresponding letter */
  10567.         } else if (ch8 == 127) {        /* DEL */
  10568.             attribute = colordebug;     /* Use underline color */
  10569.             if (decscnm)                /* Handle flipped screen */
  10570.               attribute = swapcolors(attribute);
  10571.             wrtch('?');                 /* question mark */
  10572.         } else if (ch8 > 127 && ch8 < 160 && !literal_ch) { /* C1 control */
  10573.             attribute = colordebug;     /* Use underline color */
  10574.             ch8 = (ch8 ^ 0x40) & 0x7F ;
  10575.             if (!decscnm)               /* Handle flipped screen */
  10576.               attribute = swapcolors(attribute);
  10577.             wrtch(ch8);                 /* The character itself */
  10578.         } else if (escstate != ES_NORMAL) { /* Part of Esc sequence */
  10579.             attribute = swapcolors(defaultattribute); /* Reverse video */
  10580.             wrtch(ch8);
  10581.         } else {                        /* Regular character */
  10582.             attribute = defaultattribute; /* Normal colors */
  10583.             if (tn_bold) attribute ^= 8; /* (only for TELNET debugging...) */
  10584.             wrtch(ch8);
  10585.         }
  10586.         if (deb_wrap ||
  10587.              ch8 == LF && old_c == CR) { /* Break lines for readability */
  10588.             attribute = defaultattribute;
  10589.             wrtch(CR);
  10590.             wrtch(LF);
  10591.         }
  10592.         old_c = ch8;                    /* Remember this character */
  10593.                                         /* for CRLF matching. */
  10594.         tt_wrap = tt_wrap_sav;
  10595.     }
  10596. }
  10597.  
  10598. void
  10599. cwrite(unsigned short ch) {             /* Used by ckcnet.c for */
  10600.                                         /* TELNET options debug display. */
  10601.     static vt52esclen = 0 ;
  10602. /*
  10603.    Edit 190.
  10604.    New code, supporting APC, and integrating escape sequence state switching
  10605.    that was formerly done, but not used to good advantage, in chkaes().  The
  10606.    additional complexity comes from the fact that ESC is not used only to
  10607.    commence escape sequences, but also, in the case of APC, OSC, PM, etc, to
  10608.    terminate them.  New code also supports session debugging.
  10609.  
  10610.    Edit 192.
  10611.    New code supporting auto-download for Zmodem and Kermit protocols.
  10612. */
  10613.  
  10614.     debugses( ch ) ;                    /* Session debugging */
  10615.  
  10616. #ifdef CKLEARN
  10617.     learnnet(ch);
  10618. #endif /* CKLEARN */
  10619.  
  10620. #ifndef NOXFER
  10621.     /* if Auto-download C0 conflicts are not being processed, stop now */
  10622.     if ( (!adl_kc0 && ch == stchr) || (!adl_zc0 && ch == CAN) )
  10623.          return;
  10624. #endif /* NOXFER */
  10625.  
  10626. #ifdef NOTERM
  10627.     if (!debses)
  10628.         wrtch(ch);
  10629.     return;
  10630. #else /* NOTERM */
  10631.     /* Unless we are parsing a terminal type based upon ANSI X3.64-1979 */
  10632.     /* this is as far as we go. */
  10633.  
  10634.     if (tt_type_mode == TT_NONE) {
  10635.         if (!debses)
  10636.             wrtch(ch);
  10637.         return;
  10638.     }
  10639.  
  10640.     if ( ISWYSE(tt_type_mode) )
  10641.     {
  10642.         wyseascii(ch) ;
  10643.         return ;
  10644.     }
  10645.  
  10646.     if ( ISDG200(tt_type_mode) )
  10647.     {
  10648.         dgascii(ch) ;
  10649.         return ;
  10650.     }
  10651.  
  10652.     if ( ISHP(tt_type_mode) )
  10653.     {
  10654.         hpascii(ch);
  10655.         return ;
  10656.     }
  10657.  
  10658.     if ( ISHZL(tt_type_mode) )
  10659.     {
  10660.         hzlascii(ch) ;
  10661.         return ;
  10662.     }
  10663.  
  10664.     if ( ISADM3A(tt_type_mode) || ISADM5(tt_type_mode) ) {
  10665.         admascii(ch);
  10666.         return;
  10667.     }
  10668.  
  10669.     if ( ISVC(tt_type_mode) )
  10670.     {
  10671.         vcascii(ch);
  10672.         return;
  10673.     }
  10674.  
  10675.     if ( ISIBM31(tt_type_mode) )
  10676.     {
  10677.         i31ascii(ch);
  10678.         return ;
  10679.     }
  10680.  
  10681.     if ( ISQNX(tt_type_mode) ) {
  10682.         qnxascii(ch);
  10683.         return;
  10684.     }
  10685.  
  10686.     if ( ISTVI(tt_type_mode) )
  10687.     {
  10688.         tviascii(ch);
  10689.         return ;
  10690.     }
  10691.  
  10692.     if ( ISBA80(tt_type_mode) && ba80_fkey_read ) {
  10693.         extern char fkeylabel[16][32];
  10694.         if ( ba80_fkey_read < 0 ) {
  10695.             int i=0;
  10696.             ba80_fkey_read = (ch - '0') * 10;
  10697.             ba80_fkey_ptr = NULL;
  10698.             for ( i=0;i<16;i++ )
  10699.                 fkeylabel[i][0] = NUL;
  10700.         }
  10701.         else if ( ba80_fkey_read % 10 == 0 ) {
  10702.             if ( ba80_fkey_ptr )
  10703.                 *ba80_fkey_ptr = NUL;
  10704.             if ( isdigit(ch) )
  10705.                 ba80_fkey_ptr = &fkeylabel[ch-'1'][0];
  10706.             ba80_fkey_read--;
  10707.         } else {
  10708.             if ( ba80_fkey_ptr ) {
  10709.                 *ba80_fkey_ptr = ch;
  10710.                 ba80_fkey_ptr++;
  10711.             }
  10712.             ba80_fkey_read--;
  10713.         }
  10714.         return;
  10715.     }
  10716.  
  10717.     if ( ISVTNT(tt_type_mode) && !debses && !tn_deb) {
  10718.         /* Microsoft VTNT does not start using raw WinCon structs until after */
  10719.         /* the IAC SB TERMINAL-TYPE IS VTNT IAC SE has been sent to the host. */
  10720.         /* Until that time we just treat the data as ANSI X3.64 based.        */
  10721.  
  10722.         if ( ttnum == -1 )
  10723.             vt100(ch);
  10724.         else {
  10725.             PCONSOLE_SCREEN_BUFFER_INFO pScrnBufInf = NULL;
  10726.             PCOORD pCursor = NULL;
  10727.             PCOORD pBufCoord = NULL;
  10728.             PCOORD pBufSz = NULL;
  10729.             PSMALL_RECT pWriteRegion = NULL;
  10730.             PCHAR_INFO pCharInfo = NULL;
  10731.  
  10732.             if ( vtnt_index < vtnt_read && vtnt_index < VTNT_BUFSZ) {
  10733.                 vtnt_buf[vtnt_index++] = ch;
  10734.                 if ( vtnt_index == VTNT_MIN_READ ) {
  10735.                     int szchng = 0, h_vtnt, w_vtnt;
  10736.  
  10737.                     hexdump("VTNT MIN_READ",vtnt_buf,VTNT_MIN_READ);
  10738.  
  10739.                     /* Figure out how much more data we need to read */
  10740.                     pScrnBufInf = (PCONSOLE_SCREEN_BUFFER_INFO) vtnt_buf;
  10741.                     pCursor = (PCOORD) ((PCHAR) pScrnBufInf
  10742.                                       + sizeof(CONSOLE_SCREEN_BUFFER_INFO));
  10743.                     pBufCoord = (PCOORD) ((PCHAR) pCursor + sizeof(COORD));
  10744.                     pBufSz = (PCOORD) ((PCHAR) pBufCoord + sizeof(COORD));
  10745.                     pWriteRegion = (PSMALL_RECT) ((PCHAR) pBufSz
  10746.                                                    + sizeof(COORD));
  10747.  
  10748. #ifdef COMMENT
  10749.                     debug(F100,"VTNT Using pBufSz for Dimensions","",0);
  10750.                     w_vtnt = pBufSz->X;
  10751.                     h_vtnt = pBufSz->Y;
  10752. #else /* COMMENT */
  10753. #ifndef COMMENT2
  10754.                     debug(F100,"VTNT Using pScrnBufInf for Dimensions","",0);
  10755.                     w_vtnt = pScrnBufInf->dwSize.X;
  10756.                     h_vtnt = pScrnBufInf->dwSize.Y;
  10757. #else /* COMMENT2 */
  10758.                     debug(F100,"VTNT Using WriteRegion for Dimensions","",0);
  10759.                     w_vtnt = pWriteRegion->Right - pWriteRegion->Left + 1;
  10760.                     h_vtnt = pWriteRegion->Bottom - pWriteRegion->Top + 1;
  10761. #endif /* COMMENT2 */
  10762. #endif /* COMMENT */
  10763.                     vtnt_read = pBufSz->X * pBufSz->Y * sizeof(CHAR_INFO) + VTNT_MIN_READ;
  10764.                     debug(F111,"VTNT char_info bytes","vtnt_read",vtnt_read);
  10765.  
  10766.                     if ( pBufSz->X > pScrnBufInf->dwSize.X )
  10767.                         debug(F101,"VTNT WARNING BufSz->X > ScrnBufInf->Size.X","",
  10768.                                pBufSz->X);
  10769.                     if ( pBufSz->Y > pScrnBufInf->dwSize.Y )
  10770.                         debug(F101,"VTNT WARNING BufSz->Y > ScrnBufInf->Size.Y","",
  10771.                                pBufSz->Y);
  10772.  
  10773.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO dwSize.X","",pScrnBufInf->dwSize.X);
  10774.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO dwSize.Y","",pScrnBufInf->dwSize.Y);
  10775.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO dwCursorPosition.X","",pScrnBufInf->dwCursorPosition.X);
  10776.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO dwCursorPosition.Y","",pScrnBufInf->dwCursorPosition.Y);
  10777.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO wAttributes","",pScrnBufInf->wAttributes);
  10778.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO srWindow.Left","",pScrnBufInf->srWindow.Left);
  10779.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO srWindow.Top","",pScrnBufInf->srWindow.Top);
  10780.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO srWindow.Right","",pScrnBufInf->srWindow.Right);
  10781.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO srWindow.Bottom","",pScrnBufInf->srWindow.Bottom);
  10782.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO dwMaximumWindowSize.X","",pScrnBufInf->dwMaximumWindowSize.X);
  10783.                     debug(F101,"VTNT CONSOLE_SCREEN_BUFFER_INFO dwMaximumWindowSize.Y","",pScrnBufInf->dwMaximumWindowSize.Y);
  10784.                     debug(F101,"VTNT CURSOR X","",pCursor->X);
  10785.                     debug(F101,"VTNT CURSOR Y","",pCursor->Y);
  10786.                     debug(F101,"VTNT BUFFER COORD X","",pBufCoord->X);
  10787.                     debug(F101,"VTNT BUFFER COORD Y","",pBufCoord->Y);
  10788.                     debug(F101,"VTNT BUFFER SIZE X","",pBufSz->X);
  10789.                     debug(F101,"VTNT BUFFER SIZE Y","",pBufSz->Y);
  10790.                     debug(F101,"VTNT WRITE REGION Left","",  pWriteRegion->Left);
  10791.                     debug(F101,"VTNT WRITE REGION Top","",   pWriteRegion->Top);
  10792.                     debug(F101,"VTNT WRITE REGION Right","", pWriteRegion->Right);
  10793.                     debug(F101,"VTNT WRITE REGION Bottom","",pWriteRegion->Bottom);
  10794.  
  10795. #ifdef COMMENT
  10796.                     /* Compare screen dimensions and switch if they do not match */
  10797.                     if ( VscrnGetWidth(VTERM) != w_vtnt ) {
  10798.                         if ( w_vtnt > 0 && w_vtnt <= MAXTERMROW) {
  10799.                             debug(F101,"VTNT Width Changed to","",w_vtnt);
  10800.                             VscrnSetWidth(VTERM,w_vtnt);
  10801.                             tt_rows[VTERM] = w_vtnt;
  10802. #ifndef KUI
  10803.                             vt100screen.mi.col = w_vtnt;
  10804. #endif /* KUI */
  10805.                             szchng = 1;
  10806.                         }
  10807.                     }
  10808.                     if ( VscrnGetHeight(VTERM) != (h_vtnt + (tt_status[VTERM]?1:0)) ) {
  10809.                         if ( h_vtnt > 0 && h_vtnt <= MAXTERMCOL) {
  10810.                             debug(F101,"VTNT Height Changed to","",h_vtnt);
  10811.                             VscrnSetHeight(VTERM,h_vtnt + (tt_status[VTERM]?1:0));
  10812.                             tt_cols[VTERM] = h_vtnt;
  10813. #ifndef KUI
  10814.                             vt100screen.mi.row = h_vtnt + (tt_status[VTERM]?1:0);
  10815. #endif /* KUI */
  10816.                             szchng = 1;
  10817.                         }
  10818.                     }
  10819.                     if ( szchng )
  10820.                         RestoreTermMode();
  10821. #endif /* COMMENT */
  10822.  
  10823.                     if (vtnt_index == vtnt_read) {
  10824.                         /* In other words, the size of the char info is 0 */
  10825.                         VscrnSetCurPos(VTERM,
  10826.                                         pCursor->X,
  10827.                                         pCursor->Y);
  10828.                         VscrnIsDirty(VTERM);
  10829.  
  10830.                         vtnt_index = 0;
  10831.                         vtnt_read = VTNT_MIN_READ;
  10832.                         memset(vtnt_buf,0,VTNT_BUFSZ);
  10833.                     }
  10834.                 }
  10835.                 else if (vtnt_index == vtnt_read) {
  10836.                     /* We should now have the complete set of struct data */
  10837.                     /* now to process it  */
  10838.                     USHORT Row, Col;
  10839.                     viocell  vio={0,0};
  10840.                     vtattrib vta={0,0,0,0,0,0,0,0,0,0};
  10841.  
  10842.                     pScrnBufInf = (PCONSOLE_SCREEN_BUFFER_INFO) vtnt_buf;
  10843.                     pCursor = (PCOORD) ((PCHAR) pScrnBufInf
  10844.                                          + sizeof(CONSOLE_SCREEN_BUFFER_INFO));
  10845.                     pBufCoord = (PCOORD) ((PCHAR) pCursor + sizeof(COORD));
  10846.                     pBufSz = (PCOORD) ((PCHAR) pBufCoord + sizeof(COORD));
  10847.                     pWriteRegion = (PSMALL_RECT) ((PCHAR) pBufSz
  10848.                                                    + sizeof(COORD));
  10849.                     pCharInfo = (PCHAR_INFO) ((PCHAR) pWriteRegion
  10850.                                                + sizeof(SMALL_RECT));
  10851.  
  10852.                     hexdump("VTNT CharInfo",pCharInfo,vtnt_read-VTNT_MIN_READ);
  10853.  
  10854.                     Row = pWriteRegion->Top;
  10855.                     Col = pWriteRegion->Left;
  10856.                     while ( (PCHAR) pCharInfo < &vtnt_buf[vtnt_index] &&
  10857.                             (Row < pWriteRegion->Bottom ||
  10858.                             Row == pWriteRegion->Bottom &&
  10859.                               Col <= pWriteRegion->Right)) {
  10860.                         if ( isunicode() )
  10861.                         {
  10862.                             vio.c = pCharInfo->Char.UnicodeChar;
  10863.                         }
  10864.                         else {
  10865.                             if (GNOW->itol)
  10866.                                 vio.c = (*GNOW->itol)(pCharInfo->Char.UnicodeChar);
  10867.                             else
  10868.                                 vio.c = (pCharInfo->Char.UnicodeChar & 0xFF);
  10869.                         }
  10870.                         vio.a = (pCharInfo->Attributes & 0xFF);
  10871.                         VscrnWrtCell(VTERM,
  10872.                                       vio,
  10873.                                       vta,
  10874.                                       Row,
  10875.                                       Col);
  10876.                         if ( ++Col > pWriteRegion->Right ) {
  10877.                             Row++;
  10878.                             Col = pWriteRegion->Left;
  10879.                         }
  10880.                         pCharInfo++;
  10881.                     }
  10882.                     VscrnSetCurPos(VTERM,
  10883.                                     pCursor->X,
  10884.                                     pCursor->Y);
  10885.                     VscrnIsDirty(VTERM);
  10886.  
  10887.                     vtnt_index = 0;
  10888.                     vtnt_read = VTNT_MIN_READ;
  10889.                     memset(vtnt_buf,0,VTNT_BUFSZ);
  10890.                 }
  10891.             }
  10892.         }
  10893.         return;
  10894.     }
  10895.  
  10896. /*
  10897.   Even if debugging, we still plow through the escape-sequence state table
  10898.   switcher, but we don't call any of the action routines.
  10899.   This lets us highlight text that appears inside an escape sequence.
  10900. */
  10901.  
  10902.     if (escstate == ES_NORMAL) {        /* Not in an escape sequence */
  10903.         if (ch == ESC &&
  10904.              !literal_ch) {             /* This character is an Escape */
  10905.             escstate = ES_GOTESC;       /* Change state to GOTESC */
  10906.             esclast = 0;                /* Reset buffer pointer */
  10907.             escbuffer[0] = ESC;
  10908.         }
  10909.         else if ( ch == _CSI && !literal_ch) {
  10910.             escstate = ES_GOTCSI;       /* Escape sequence was restarted */
  10911.             escbuffer[0] = _CSI;         /* Save in case we have to replay it */
  10912.             esclast = 1;                /* Reset buffer pointer, but */
  10913.             escbuffer[1] = '[';         /* But translate for vtescape() */
  10914.         } else {                        /* Not an ESC, stay in NORMAL state */
  10915.           if (!debses)
  10916.             vt100(ch);          /* and send to vt100() for display. */
  10917.         }
  10918.         return;                 /* Return in either case. */
  10919.     }
  10920.  
  10921. /* We are in an escape sequence... */
  10922.  
  10923.     if (ch < SP || (ch == _CSI)) {                 /* Control character? */
  10924.         if ( xprint ) {                            /* During a transparent print the */
  10925.             int i;                                 /* only sequence we care about is */
  10926.             if ( !debses && escstate != ES_NORMAL ) { /* CSI 4 i.                    */
  10927.                 switch ( escbuffer[0] ) {
  10928.                 case ESC:
  10929.                     i = 0;                         /* ESC is beginning of C0 sequence */
  10930.                     break;
  10931.                 case _CSI:
  10932.                     prtchar(_CSI);                    /* We really had a C1 sequence */
  10933.                     i = 2;
  10934.                     break;
  10935.                 default:
  10936.                     prtchar(ESC);                    /* it must have been C0, and we made */
  10937.                     i = 1;                         /* a coding mistake */
  10938.                 }
  10939.                 for ( ; i <= esclast; i++ )        /* Print what we've got. */
  10940.                     prtchar(escbuffer[i]);
  10941.             }
  10942.             esclast  = 0;               /* Reset the buffer */
  10943.             escbuffer[0] = 0;           /* And clear the first char, just in case */
  10944.             escstate = ES_NORMAL;       /* Go back to normal */
  10945.             cwrite(ch);                 /* And then restart */
  10946.         } else if ( escstate == ES_GOTESC && ISANSI(tt_type_mode) && crm ) {
  10947.             if ( !debses )
  10948.                 vt100(ch);
  10949.             escstate = ES_NORMAL;       /* Go back to normal */
  10950.         } else if (ch == CAN || ch == SUB) { /* These cancel an escape sequence  */
  10951.             /* According to the 97801-5xx manual.  SUB is different from CAN in  */
  10952.             /* that SUB outputs to the screen the characters received as part of */
  10953.             /* the escape sequence. However, the only noticeable difference on   */
  10954.             /* the VT320 is that a backwards question mark is printed whenever a */
  10955.             /* SUB is received.                                                  */
  10956.             escstate = ES_NORMAL;            /* Go back to normal. */
  10957. #ifdef CK_APC
  10958.             apclength = 0;
  10959.             apcbuf[0] = 0 ;
  10960.             apcactive = APC_INACTIVE ;
  10961.             apcrecv = FALSE ;
  10962.             dcsrecv = FALSE ;
  10963.             pmrecv  = FALSE ;
  10964.             oscrecv = FALSE ;
  10965.             pu1recv = FALSE ;
  10966.             pu2recv = FALSE ;
  10967.             c1strrecv = FALSE ;
  10968. #endif /* CK_APC */
  10969.         } else if (ch == BS) {  /* Erases previous */
  10970.             if ( escstate == ES_GOTCSI && esclast == 1 ) {
  10971.                 escstate = ES_GOTESC ;
  10972.                 esclast = 0 ;
  10973.             }
  10974.             else if ( escstate == ES_ESCSEQ && esclast == 1 ) {
  10975.                 escstate = ES_GOTESC ;
  10976.                 esclast = 0 ;
  10977.             }
  10978.             else if ( escstate == ES_GOTESC && esclast == 0 ) {
  10979.                 escstate = ES_NORMAL ;
  10980.             }
  10981.             else if ( escstate == ES_TERMIN ) {
  10982.                 escstate = ES_STRING ;
  10983.             }
  10984.             else if ( escstate == ES_STRING ) {
  10985. #ifdef CK_APC
  10986.                 if ( apclength > 0 )
  10987.                     apclength-- ;
  10988.                 else
  10989. #endif /* CK_APC */
  10990.                 {
  10991.                     escstate = ES_GOTESC ;
  10992.                 }
  10993.             }
  10994.             else if ( esclast > 0 ) {
  10995.                 esclast--;              /* escape sequence char (really?) */
  10996.             }
  10997.         } else if (ch == ESC) {
  10998.             if ( escstate == ES_STRING )
  10999.                 escstate = ES_TERMIN ;
  11000.             else {
  11001.                 escstate = ES_GOTESC;   /* Escape sequence was restarted */
  11002.                 esclast = 0;            /* Reset buffer pointer */
  11003.                 escbuffer[0] = ESC;     /* Save in case we have to replay it */
  11004.             }
  11005.         } else if (ch == _CSI) {
  11006.             escstate = ES_GOTCSI;       /* Escape sequence was restarted */
  11007.             escbuffer[0] = _CSI;         /* Save in case we have to replay it */
  11008.             esclast = 1;                /* Reset buffer pointer, but */
  11009.             escbuffer[1] = '[';         /* But translate for vtescape() */
  11010.         } else if (ch != NUL) {
  11011.             wrtch(ch);
  11012.         }
  11013.         return;
  11014.     }
  11015. /*
  11016.   Put this character in the escape sequence buffer.
  11017.   But we don't put "strings" in this buffer; either absorb them silently
  11018.   (as with Operating System Command), or handle them specially (as with APC).
  11019.   Note that indexing starts at 1, not 0.
  11020. */
  11021.     if ( escstate != ES_STRING && escstate != ES_TERMIN )
  11022.         if (esclast < ESCBUFLEN)
  11023.             escbuffer[++esclast] = ch;
  11024.  
  11025.  
  11026.    /* Note: vtescape() sets escstate back to ES_NORMAL. */
  11027.  
  11028.    if (ISVT52(tt_type_mode)) {          /* VT52 Emulation */
  11029.       switch (esclast) {
  11030.       case 1:                           /* First char after Esc */
  11031.           switch ( ch ) {
  11032.           case 'Y':
  11033.               vt52esclen = 3 ;
  11034.               break;
  11035.           case 'r':
  11036.           case 'x':
  11037.           case 'y':
  11038.               vt52esclen = 2 ;
  11039.               break;
  11040.           default:
  11041.               vtescape() ;
  11042.           }
  11043.           break;
  11044.       default:
  11045.           if ( esclast == vt52esclen )
  11046.               vtescape() ;              /* then it's a complete sequence */
  11047.           else if ( esclast > vt52esclen )
  11048.               escstate = ES_NORMAL;     /* Something unexpected, ignore */
  11049.           break;
  11050.       }
  11051.        return;                                /* Done with VT52 */
  11052.    }
  11053.  
  11054.    /* The rest of this routine handles ANSI/VT1xx/VT2xx/VT3xx/VT4xx/VT5xx emulation... */
  11055.  
  11056.     switch (escstate) {                 /* Enter esc sequence state switcher */
  11057.     case ES_GOTESC:                     /* GOTESC state, prev char was Esc */
  11058.         switch ( ch ) {
  11059.         case '[':                       /* Left bracket after ESC is CSI */
  11060.             escstate = ES_GOTCSI;       /* Change to GOTCSI state */
  11061.             break;
  11062.         case '_':                       /* Application Program Command (APC) */
  11063.             if ( !xprint ) {
  11064.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11065.                 if ( !savefiletext[0] )
  11066.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11067.                 ckstrncpy(filetext,"APC STRING",sizeof(filetext)) ;
  11068.                 VscrnIsDirty(VTERM);    /* Update status line */
  11069. #ifdef CK_APC
  11070.                 apcrecv = TRUE;         /* We are receiving an APC string */
  11071.                 apclength = 0;          /* and reset APC buffer pointer */
  11072. #endif /* CK_APC */
  11073.             } else {
  11074.                 vtescape();                               /* Go act on it. */
  11075.             }
  11076.         case 'P':                       /* Device Control String (DCS) Introducer */
  11077.             if ( !xprint ) {
  11078.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11079. #ifdef CK_APC
  11080.                 dcsrecv = TRUE ;        /* Set DCS-Active flag */
  11081.                 apclength = 0 ;         /* we use the same buffer as for APC */
  11082. #endif /* CK_APC */
  11083.                 if ( !savefiletext[0] )
  11084.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11085.                 ckstrncpy(filetext,"DCS STRING",sizeof(filetext)) ;
  11086.                 VscrnIsDirty(VTERM);    /* Update status line */
  11087.             } else {
  11088.                 vtescape();                               /* Go act on it. */
  11089.             }
  11090.             break;
  11091.         case 'Q':                       /* Private Use One (PU1) Introducer 97801-5xx */
  11092.             if ( !xprint && !ISANSI(tt_type_mode) ) {
  11093.                 /* 
  11094.                  * SCOANSI used ESC Q to prefix keyboard assignments
  11095.                  * so do not enter the string state
  11096.                  */
  11097.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11098. #ifdef CK_APC
  11099.                 pu1recv = TRUE ;        /* Set PU1-Active flag */
  11100.                 apclength = 0 ;         /* we use the same buffer as for APC */
  11101. #endif /* CK_APC */
  11102.                 if ( !savefiletext[0] )
  11103.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11104.                 ckstrncpy(filetext,"PU1 STRING",sizeof(filetext)) ;
  11105.                 VscrnIsDirty(VTERM);    /* Update status line */
  11106.             }
  11107.             else {
  11108.                 vtescape();                               /* Go act on it. */
  11109.             }
  11110.             break;
  11111.         case 'R':                       /* Private Use Two (PU2) Introducer 97801-5xx */
  11112.             if ( !xprint ) {
  11113.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11114. #ifdef CK_APC
  11115.                 pu2recv = TRUE ;        /* Set PU2-Active flag */
  11116.                 apclength = 0 ;         /* we use the same buffer as for APC */
  11117. #endif /* CK_APC */
  11118.                 if ( !savefiletext[0] )
  11119.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11120.                 ckstrncpy(filetext,"PU2 STRING",sizeof(filetext)) ;
  11121.                 VscrnIsDirty(VTERM);    /* Update status line */
  11122.             }
  11123.             else {
  11124.                 vtescape();                               /* Go act on it. */
  11125.             }
  11126.             break;
  11127.         case 'X':                       /* Start-Of-String (SOS) Ignored */
  11128.             if ( !xprint ) {
  11129.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11130. #ifdef CK_APC
  11131.                 c1strrecv = TRUE ;      /* Set Active flag */
  11132.                 apclength = 0 ;         /* we use the same buffer as for APC */
  11133. #endif /* CK_APC */
  11134.                 if ( !savefiletext[0] )
  11135.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11136.                 ckstrncpy(filetext,"SOS STRING",sizeof(filetext));
  11137.                 VscrnIsDirty(VTERM);    /* Update status line */
  11138.             }
  11139.             else {
  11140.                 vtescape();             /* Go act on it. */
  11141.             }
  11142.             break;
  11143.         case 'Z':                       /* DECID */
  11144.             if ( ISVT52(tt_type_mode) ) {
  11145.                 sendescseq(tt_info[TT_VT52].x_id);
  11146.             }
  11147.             else if ( ISVT220(tt_type) ) {
  11148.                 sendescseq(tt_info[tt_type].x_id);
  11149.             }
  11150.             break;
  11151.         case '^':                       /* Privacy Message (PM) */
  11152.             if ( !xprint ) {
  11153.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11154. #ifdef CK_APC
  11155.                 pmrecv = TRUE ;       /* Set PM-Active flag */
  11156.                 apclength = 0 ;         /* we use the same buffer as for APC */
  11157. #endif /* CK_APC */
  11158.                 if ( !savefiletext[0] )
  11159.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11160.                 ckstrncpy(filetext,"PM STRING",sizeof(filetext)) ;
  11161.                 VscrnIsDirty(VTERM);    /* Update status line */
  11162.                 break;
  11163.             }
  11164.         case ']':                       /* Operating System Command (OSC) */
  11165.             if ( !xprint ) {
  11166.                 escstate = ES_STRING;   /* Enter STRING-absorption state */
  11167. #ifdef CK_APC
  11168.                 oscrecv = TRUE ;      /* Set OSC-Active flag */
  11169.                 apclength = 0 ;         /* we use the same buffer as for APC */
  11170. #endif /* CK_APC */
  11171.                 if ( !savefiletext[0] )
  11172.                     ckstrncpy(savefiletext,filetext,sizeof(savefiletext));
  11173.                 ckstrncpy(filetext,"OSC STRING",sizeof(filetext)) ;
  11174.                 VscrnIsDirty(VTERM);    /* Update status line */
  11175.                 break;
  11176.             }
  11177.         default:
  11178.             if ((ch > 057) && (ch < 0177)) /* Or final char, '0' thru '~' */
  11179.                 vtescape();                               /* Go act on it. */
  11180.             else
  11181.                 escstate = ES_ESCSEQ;
  11182.          }
  11183.          break;
  11184.  
  11185.     case ES_ESCSEQ:                     /* ESCSEQ -- in an escape sequence */
  11186.         if (ch > 057 && ch < 0177)      /* Final character is '0' thru '~' */
  11187.           vtescape();                   /* Go handle it */
  11188.         break;
  11189.  
  11190.     case ES_GOTCSI:                     /* GOTCSI -- In a control sequence */
  11191.         if (ch > 077 && ch < 0177)      /* Final character is '@' thru '~' */
  11192.           vtescape();                   /* Go act on it. */
  11193.         break;
  11194.  
  11195.     case ES_STRING:                     /* Inside a string */
  11196.         if (ch == ESC)                  /* ESC may be 1st char of terminator */
  11197.           escstate = ES_TERMIN;         /* Change state to find out. */
  11198. #ifdef CK_APC
  11199.         else if ( ch == BEL && ISAIXTERM(tt_type_mode) && oscrecv ) {
  11200.             /* BEL terminates an OSC string in AIXTERM */
  11201.             escstate = ES_NORMAL;       /* If so, back to NORMAL */
  11202.             if (savefiletext[0]) {              /* Fix status line */
  11203.                 ckstrncpy(filetext,savefiletext,sizeof(filetext));
  11204.                 savefiletext[0] = NUL;
  11205.                 VscrnIsDirty(VTERM);  /* status line needs to be updated */
  11206.             }
  11207.             apcbuf[apclength] = NUL; /* terminate it */
  11208.                                        /* process it */
  11209.             if (!debses)
  11210.                 doosc() ;
  11211.             oscrecv = FALSE ;
  11212.         }
  11213.         else if (apcrecv || dcsrecv || oscrecv || pmrecv ||
  11214.                   pu1recv || pu2recv || c1strrecv) {
  11215.             if (apclength < apcbuflen)    /* If in APC string, */
  11216.               apcbuf[apclength++] = ch;   /* deposit this character */
  11217.             else {                        /* Buffer overrun */
  11218.                 apcrecv = FALSE ;         /* Discard what we got */
  11219.                 dcsrecv = FALSE ;
  11220.                 oscrecv = FALSE ;
  11221.                 pmrecv  = FALSE ;
  11222.                 pu1recv = FALSE ;
  11223.                 pu2recv = FALSE ;
  11224.                 c1strrecv = FALSE ;
  11225.                 apclength = 0;            /* and go back to normal */
  11226.                 apcbuf[0] = 0;            /* Not pretty, but what else */
  11227.                 escstate = ES_NORMAL ;
  11228.             }
  11229.         }
  11230. #endif /* CK_APC */
  11231.         break;                          /* Absorb all other characters. */
  11232.  
  11233.     case ES_TERMIN:                     /* May have a string terminator */
  11234.         if (ch == '\\') {               /* which must be backslash */
  11235.             escstate = ES_NORMAL;       /* If so, back to NORMAL */
  11236.             if (savefiletext[0]) {              /* Fix status line */
  11237.                 ckstrncpy(filetext,savefiletext,sizeof(filetext));
  11238.                 savefiletext[0] = NUL;
  11239.                 VscrnIsDirty(VTERM);  /* status line needs to be updated */
  11240.             }
  11241. #ifdef CK_APC
  11242.             if (apcrecv && apclength > 0)/* If it was an APC string, */
  11243.             {
  11244.                 apcbuf[apclength] = NUL; /* terminate it */
  11245.                 if ((apcstatus & APC_ON) && !debses) {
  11246.                     apc_command(APC_REMOTE,apcbuf);
  11247.                     return;             /* with the apcactive flag still set */
  11248.                 }
  11249.                 else apcactive = APC_INACTIVE;
  11250.             }
  11251.             else if ( dcsrecv ) /* it was a DCS string, */
  11252.             {
  11253.                 apcbuf[apclength] = NUL; /* terminate it */
  11254.                 if ( tt_type_mode >= TT_VT320 && /* and if we are a VT320 */
  11255.                      tt_type_mode <= TT_WY370 )
  11256.                 {                            /* process it */
  11257.                     if (!debses)
  11258.                       dodcs() ;
  11259.                 }
  11260.                 dcsrecv = FALSE ;
  11261.             }
  11262.             else if ( pu1recv ) /* it was a PU1 string, */
  11263.             {
  11264.                 apcbuf[apclength] = NUL; /* terminate it */
  11265.                 if ( IS97801(tt_type_mode) )
  11266.                 {                            /* process it */
  11267.                     if (!debses)
  11268.                       dopu1() ;
  11269.                 }
  11270.                 pu1recv = FALSE ;
  11271.             }
  11272.             else if ( pu2recv ) /* it was a PU2 string, */
  11273.             {
  11274.                 apcbuf[apclength] = NUL; /* terminate it */
  11275.                 if ( IS97801(tt_type_mode) )
  11276.                 {                            /* process it */
  11277.                     if (!debses)
  11278.                       dopu2() ;
  11279.                 }
  11280.                 pu2recv = FALSE ;
  11281.             }
  11282.             else if ( oscrecv ) /* it was a OSC string, */
  11283.             {
  11284.                 apcbuf[apclength] = NUL; /* terminate it */
  11285.                 if ( tt_type_mode >= TT_VT320 && /* and if we are a VT320 */
  11286.                      tt_type_mode <= TT_WY370 )
  11287.                 {                            /* process it */
  11288.                     if (!debses)
  11289.                       doosc() ;
  11290.                 }
  11291.                 oscrecv = FALSE ;
  11292.             }
  11293. #endif /* CK_APC */
  11294.         } else {
  11295. #ifdef CK_APC
  11296.             if ( dcsrecv ) {
  11297.                 dcsrecv = FALSE ;
  11298.                 apcbuf[0] = NUL ;
  11299.                 apclength = 0 ;
  11300.                 escstate = ES_GOTESC ;
  11301.                 if (savefiletext[0]) {          /* Fix status line */
  11302.                     ckstrncpy(filetext,savefiletext,sizeof(filetext));
  11303.                     savefiletext[0] = NUL;
  11304.                     VscrnIsDirty(VTERM);  /* status line needs to be updated */
  11305.                 }
  11306.                 cwrite(ch);
  11307.             }
  11308.             else {
  11309. #endif /* CK_APC */
  11310.                 if ( ch >= SP )         /* Just a stray Esc character. */
  11311.                     escstate = ES_STRING;       /* Return to string absorption. */
  11312. #ifdef CK_APC
  11313.                 if (apcrecv) {
  11314.                     if (apclength+1 < apcbuflen) { /* In APC string, */
  11315.                         apcbuf[apclength++] = ESC;   /* deposit the Esc character */
  11316.                         apcbuf[apclength++] = ch;    /* and this character too */
  11317.                     }
  11318.                 }
  11319.             }
  11320. #endif /* CK_APC */
  11321.         }
  11322.     }
  11323. #endif /* NOTERM */
  11324. }
  11325.  
  11326. /*---------------------------------------------------------------------------*/
  11327. /* scrninit                                                                  */
  11328. /*---------------------------------------------------------------------------*/
  11329. void
  11330. scrninit() {
  11331.     if (deccolm)
  11332.       Set132Cols(VTERM) ;
  11333.     else
  11334.       SetCols(VTERM) ;
  11335.  
  11336. #ifdef TCPSOCKET
  11337. #ifdef CK_NAWS
  11338.    if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0)
  11339.    {
  11340.        tn_snaws();
  11341. #ifdef RLOGCODE
  11342.        rlog_naws();
  11343. #endif /* RLOGCODE */
  11344. #ifdef SSHBUILTIN
  11345.        ssh_snaws();
  11346. #endif /* SSHBUILTIN */
  11347.    }
  11348. #endif /* CK_NAWS */
  11349. #endif /* TCPSOCKET */
  11350.  
  11351.     setborder();
  11352.     VscrnIsDirty(VTERM);
  11353. }
  11354.  
  11355. /*---------------------------------------------------------------------------*/
  11356. /* wrtch                                                                     */
  11357. /*---------------------------------------------------------------------------*/
  11358. void
  11359. wrtch(unsigned short ch) {
  11360.     viocell cell;
  11361.     vtattrib vta = {0,0,0,0,0,0,0,0,0,0};
  11362.     int vmode = decsasd == SASD_TERMINAL ? VTERM : VSTATUS ;
  11363.     extern int k95stdio,k95stdin,k95stdout;
  11364.  
  11365.     if (printon && xprint && !debses)   /* If transparent print active, */
  11366.       return;                           /*  we don't touch the screen. */
  11367.  
  11368.     if ( !IsConnectMode() && !interm )
  11369.         return;                         /* Don't touch screen if being */
  11370.                                         /* executed from an input cmd  */
  11371.  
  11372.     if ( k95stdout ) {
  11373. #ifdef putchar
  11374. #undef putchar
  11375. #endif
  11376.         putchar(ch);
  11377.         return;
  11378.     }
  11379.  
  11380.     prevchar = ch;                      /* save char for Repeat operations */
  11381.  
  11382.     if (ch >= SP || literal_ch || crm ||
  11383.          ((ISWYSE(tt_type_mode) || ISTVI(tt_type_mode)) &&
  11384.            (ch == STX || ch == ETX)))
  11385.     {                                   /* Treat as a Normal character */
  11386.         if (attrib.invisible)
  11387.           ch = SP;
  11388.  
  11389.         if ( isunicode() && crm && ch < SP ) {
  11390.             if ( ISANSI(tt_type_mode) )
  11391.                 ch = (*xl_u[TX_IBMC0GRPH])(ch) ;
  11392.             else
  11393.                 ch = (*xl_u[TX_C0PICT])(ch) ;
  11394.         }
  11395.         if ( (!tt_hidattr || ISHP(tt_type_mode)) &&
  11396.              (attrmode == ATTR_PAGE_MODE || attrmode == ATTR_LINE_MODE) )
  11397.         {
  11398.             /* Read the current attribute for wherex,wherey and */
  11399.             /* use it for the current location                  */
  11400.             vta = VscrnGetVtCharAttr( vmode,
  11401.                                       wherex[vmode]-1,
  11402.                                       wherey[vmode]-1 ) ;
  11403.             if ( !tt_hidattr )
  11404.                 vta.wyseattr = FALSE ;
  11405.             cell.c = ch;
  11406.             cell.a = attribute;
  11407.  
  11408.             if ( (ISWYSE(tt_type_mode) ||
  11409.                    ISTVI(tt_type_mode) ||
  11410.                    ISHZL(tt_type_mode) )
  11411.                  && protect ) {
  11412.                 /* If the current cursor is on a protected cell */
  11413.                 /* then we must advance the cursor to the first */
  11414.                 /* non-protected cell on the screen             */
  11415.                 int x = wherex[vmode];
  11416.                 int y = wherey[vmode];
  11417.                 int width = VscrnGetWidth(vmode);
  11418.  
  11419.                 while ( vta.unerasable ) {
  11420.                     if ( !vta.unerasable ) /* bug in MSVC 5.0 */
  11421.                         break;
  11422.                     x++;
  11423.                     if ( x > width ) {
  11424.                         y++;
  11425.                         if ( y >= marginbot ) {
  11426.                             x-- ;
  11427.                             y-- ;
  11428.                             return ;    /* Can't write this character */
  11429.                         }
  11430.                         x = 1 ;
  11431.                     }
  11432.  
  11433.                     lgotoxy(vmode,x,y); /* set wherex, wherey */
  11434.  
  11435.                     /* Retrieve the attributes of the new position */
  11436.                     vta = VscrnGetVtCharAttr( vmode,x-1,y-1 ) ;
  11437.                     if ( !tt_hidattr )
  11438.                         vta.wyseattr = FALSE ;
  11439.                 }
  11440.             }
  11441.  
  11442.             if (insertmode) {
  11443.                 VscrnScrollRt(vmode,
  11444.                                wherey[vmode] - 1,
  11445.                                wherex[vmode] - 1,
  11446.                                wherey[vmode] - 1,
  11447.                                VscrnGetWidth(vmode) - 1,
  11448.                                1, cell);
  11449.                 /* VscrnScrollRt() doesn't apply the current attribute */
  11450.                 VscrnWrtCell(vmode, cell, vta,
  11451.                           wherey[vmode] - 1,
  11452.                               wherex[vmode] - 1);
  11453.                 if ( vta.wyseattr ) {
  11454.                     /* the attribute is only assigned at one place */
  11455.                     vta.wyseattr = FALSE;
  11456.                     VscrnWrtCell(vmode, cell, vta,
  11457.                                   wherey[vmode] - 1,
  11458.                                   wherex[vmode]);
  11459.                 }
  11460.             }
  11461.             else {
  11462.                 vta.unerasable = attrib.unerasable ;    /* use current write protect */
  11463.  
  11464.                 VscrnWrtCell(vmode, cell, vta,
  11465.                           wherey[vmode] - 1,
  11466.                               wherex[vmode] - 1);
  11467.             }
  11468.  
  11469.             literal_ch = FALSE;
  11470.             /* don't wrap if autowrap is off */
  11471.             if ( tt_wrap || wherex[vmode] < VscrnGetWidth(vmode) ) {
  11472.                 if (++wherex[vmode] > VscrnGetWidth(vmode)) {
  11473.                     if ( autoscroll && !protect || wherey[vmode] < marginbot ) {
  11474.                         wherex[vmode] = 1;
  11475.                         wrtch((char) LF);
  11476.                     }
  11477.                 }
  11478.             }
  11479.         }
  11480.         else    /* We are in character attribute mode */
  11481.         {
  11482.             cell.c = ch;
  11483.             cell.a = attribute;
  11484.  
  11485.             if ( (ISWYSE(tt_type_mode) ||
  11486.                    ISTVI(tt_type_mode) ||
  11487.                    ISHZL(tt_type_mode) )
  11488.                  && protect ) {
  11489.                 int width = VscrnGetWidth(vmode);
  11490.                 /* If the current cursor is on a protected cell */
  11491.                 /* then we must advance the cursor to the first */
  11492.                 /* non-protected cell on the screen             */
  11493.  
  11494.                 vta = VscrnGetVtCharAttr( vmode,
  11495.                                           wherex[vmode]-1,
  11496.                                           wherey[vmode]-1 ) ;
  11497.  
  11498.                 while ( vta.unerasable ) {
  11499.                     if ( !vta.unerasable )  /* MSVC 5.0 bug */
  11500.                         break;
  11501.                     if ( ++wherex[vmode] > width ) {
  11502.                         if ( ++wherey[vmode] >= marginbot ) {
  11503.                             wherex[vmode]-- ;
  11504.                             wherey[vmode]-- ;
  11505.                             return ;    /* Can't write this character */
  11506.                         }
  11507.                         wherex[vmode] = 1 ;
  11508.                     }
  11509.  
  11510.                     lgotoxy(vmode,wherex[vmode],wherey[vmode]);
  11511.                 }
  11512.             }
  11513.  
  11514.             if (insertmode) {
  11515.                 VscrnScrollRt(vmode, wherey[vmode] - 1,
  11516.                                wherex[vmode] - 1, wherey[VTERM] - 1,
  11517.                                VscrnGetWidth(vmode) - 1, 1, cell);
  11518.                 /* VscrnScrollRt() doesn't apply the current attribute */
  11519.                 VscrnWrtCell(vmode, cell, attrib,
  11520.                           wherey[vmode] - 1,
  11521.                               wherex[vmode] - 1);
  11522.             }
  11523.             else {
  11524.                 VscrnWrtCell(vmode, cell, attrib,
  11525.                           wherey[vmode] - 1, wherex[vmode] - 1);
  11526.             }
  11527.  
  11528.             literal_ch = FALSE;
  11529.             /* don't wrap if autowrap is off */
  11530.             if ( tt_wrap || wherex[vmode] < VscrnGetWidth(vmode) ) {
  11531.                 if (++wherex[vmode] > VscrnGetWidth(vmode) && decsasd == SASD_TERMINAL) {
  11532.                     if ( IS97801(tt_type_mode) ) {
  11533.                         if ( !sni_pagemode ) {
  11534.                             wherex[vmode] = 1;
  11535.                             wrtch((char) LF);
  11536.                         }
  11537.                         else {  /* Page Mode */
  11538.                             lgotoxy(VTERM,1,margintop);
  11539.                         }
  11540.  
  11541.                     }
  11542.                     else if ( autoscroll && !protect || wherey[vmode] < marginbot ) {
  11543.                         wherex[vmode] = 1;
  11544.                         wrtch((char) LF);
  11545.                     }
  11546.                 }
  11547.             }
  11548.         }
  11549.  
  11550.     }
  11551.     else
  11552.     {   /* Control character */
  11553.         
  11554.         switch (ch) {
  11555.         case LF:
  11556.           dolf:
  11557.             if ( printon && is_aprint() ) {
  11558.                 prtline( wherey[VTERM], LF ) ;
  11559.             }
  11560.             if ( decsasd == SASD_TERMINAL ) {
  11561.                 if (wherey[vmode] == marginbot) {
  11562.                     if ( IS97801(tt_type_mode) ) {
  11563.                         if ( !sni_pagemode )
  11564.                             VscrnScroll(vmode,UPWARD, margintop - 1, marginbot - 1, 1,
  11565.                                          (margintop == 1), SP ) ;
  11566.                         else /* Page Mode */
  11567.                             wherex[VTERM] = 1;
  11568.                     } else if ( autoscroll && !protect ) {
  11569.                         VscrnScroll(vmode,UPWARD, margintop - 1, marginbot - 1, 1,
  11570.                                      (margintop == 1), SP ) ;
  11571.                     } else if ( wherex[vmode] > VscrnGetWidth(vmode) )
  11572.                         wherex[vmode] = VscrnGetWidth(vmode);
  11573.                 } else {
  11574.                     wherey[vmode]++;
  11575.                     if (wherey[vmode] >= VscrnGetHeight(vmode)+(tt_status[VTERM]?0:1)) {
  11576.                         if ( IS97801(tt_type_mode) ) {
  11577.                             if (wherey[vmode] == VscrnGetHeight(vmode)+(tt_status[VTERM]?0:1)
  11578.                                  && decssdt == SSDT_HOST_WRITABLE)
  11579.                                 setdecsasd(SASD_STATUS);
  11580.                             wherey[vmode] = margintop;
  11581.                         } else
  11582.                             wherey[vmode] = VscrnGetHeight(vmode)+(tt_status[VTERM]?0:1)-1;
  11583.                     }
  11584.                 }
  11585.             }
  11586.             break;
  11587.         case CR:
  11588.             if ( (IS97801(tt_type_mode) || ISHP(tt_type_mode)) &&
  11589.                  vmode == VTERM )
  11590.                 wherex[vmode] = marginleft;
  11591.             else
  11592.                 wherex[vmode] = 1;
  11593.             if ( !(ISANSI(tt_type_mode) || ISHFT(tt_type_mode)) )
  11594.                 wrapit = FALSE;
  11595.             break;
  11596.         case BS:
  11597.             if ( (IS97801(tt_type_mode) || ISHP(tt_type_mode)) &&
  11598.                  vmode == VTERM ) {
  11599.                 if (wherex[vmode] > marginleft)
  11600.                     wherex[vmode]--;
  11601.             }
  11602.             else if ( ISQNX(tt_type_mode) && vmode == VTERM ) {
  11603.                 if ( wherex[vmode] > 1 )
  11604.                     wherex[vmode]--;
  11605.                 else {
  11606.                     wherex[vmode] = VscrnGetWidth(vmode);
  11607.                     if ( wherey[vmode] > 1 ) {
  11608.                         wherey[vmode]--;
  11609.                     }
  11610.                     else {
  11611.                         wherey[vmode] = VscrnGetHeight(vmode)
  11612.                             -(tt_status[VTERM]?1:0) ;
  11613.                     }
  11614.                 }
  11615.             }
  11616.             else {
  11617.                 if (wherex[vmode] > 1)
  11618.                     wherex[vmode]--;
  11619.             }
  11620.             if ( !(ISANSI(tt_type_mode) || ISHFT(tt_type_mode)) )
  11621.                 wrapit = FALSE;
  11622.             break;
  11623.         case FF:
  11624.             if ( printon && is_aprint() ) {
  11625.                 prtline( wherey[VTERM], LF ) ;
  11626.             }
  11627.             if ( ISSUN(tt_type_mode) && vmode == VTERM) {
  11628.                 clrscreen(VTERM,SP);
  11629.                 lgotoxy(VTERM,1,1);       /* and home the cursor */
  11630.             } 
  11631.             else if ( (IS97801(tt_type_mode) || ISHP(tt_type_mode)) &&
  11632.                  vmode == VTERM ) {
  11633.                 if (wherex[vmode] < marginright)
  11634.                     wherex[vmode]++;
  11635.             }
  11636.             else {
  11637.                 goto dolf;
  11638.             }
  11639.             break;
  11640.         case BEL:
  11641.             bleep(BP_BEL);
  11642.             break;
  11643.         case NUL:                       /* represent it as a space */
  11644.             wrtch(SP);
  11645.             break;
  11646.         case VT:
  11647.             if ( printon && is_aprint() ) {
  11648.                 prtline( wherey[VTERM], LF ) ;
  11649.             }
  11650.             if ( ISWYSE(tt_type_mode) ||
  11651.                  ISTVI(tt_type_mode) ||
  11652.                  ISHZL(tt_type_mode) ) 
  11653.             {
  11654.                 if ( wherey[vmode] == margintop ) {
  11655.                     if ( autoscroll && !protect )
  11656.                         VscrnScroll(vmode,DOWNWARD, margintop - 1, marginbot - 1, 1,
  11657.                                      FALSE, SP ) ;
  11658.                 } else {
  11659.                     cursorup(0);
  11660.                 }
  11661.             } else if ( ISVT100(tt_type_mode) ) {
  11662.                 goto dolf;
  11663.             }
  11664.             break;
  11665.         case XFS:
  11666.             if ( IS97801(tt_type_mode) ) {
  11667.                 /* Abbreviated Cursor Position */
  11668.                 /* <FS> <line + 0x20> <col + 0x20>, 0-based */
  11669.                 debug(F110,"wrtch - 97801","Abbreviated Cursor Position - not implemented",0);
  11670.             }
  11671.             break;
  11672.         default:;                       /* Ignore */
  11673.         }
  11674.     }
  11675.     lgotoxy(vmode,wherex[vmode],wherey[vmode]);
  11676.     VscrnIsDirty(VTERM);  /* always mark the Terminal as requiring the update */
  11677. }
  11678.  
  11679. /*---------------------------------------------------------------------------*/
  11680. /* lgotoxy                                                                   */
  11681. /*---------------------------------------------------------------------------*/
  11682. void
  11683. lgotoxy(BYTE vmode, int x, int y) {
  11684.     if ( x < 1 ) x = 1;
  11685.     if ( y < 1 ) y = 1;
  11686.  
  11687.     if ( vmode == VTERM && decsasd == SASD_STATUS )
  11688.         vmode = VSTATUS ;
  11689.  
  11690.     if ( vmode == VSTATUS )
  11691.         y = 1 ;
  11692.  
  11693.     if ( vmode == VTERM && marginbell ) {
  11694.         position * cur = VscrnGetCurPos(VTERM) ;
  11695.         if ( cur->x+1 < marginbellcol && x >= marginbellcol )
  11696.             bleep(BP_BEL) ;
  11697.     }
  11698.  
  11699.     if ( vmode == VTERM &&
  11700.                 (ISWYSE(tt_type_mode) ||
  11701.            ISTVI(tt_type_mode) ||
  11702.            ISHZL(tt_type_mode) )
  11703.          && protect ) {
  11704.         /* If the current cursor is on a protected cell */
  11705.         /* then we must advance the cursor to the first */
  11706.         /* non-protected cell on the screen             */
  11707.         vtattrib vta = VscrnGetVtCharAttr( VTERM, x-1, y-1 ) ;
  11708.         int width    = VscrnGetWidth(VTERM);
  11709.         while ( vta.unerasable ) {
  11710.             if ( !vta.unerasable )      /* bug in MSVC 5.0 */
  11711.                 break;
  11712.             x++;
  11713.             if ( x > width ) {
  11714.                 y++;
  11715.                 if ( y > marginbot ) {
  11716.                     x=0 ;
  11717.                     y=margintop ;
  11718.                 }
  11719.                 x = 1 ;
  11720.             }
  11721.             /* Retrieve the attributes of the new position */
  11722.             vta = VscrnGetVtCharAttr( VTERM, x-1, y-1 ) ;
  11723.         }
  11724.     }
  11725.  
  11726.     wherex[vmode] = x;
  11727.     wherey[vmode] = y;
  11728.  
  11729.     wrapit = FALSE;
  11730.  
  11731.     if ( markmodeflag[vmode] == notmarking )
  11732.       VscrnSetCurPos( vmode, x - 1, y - 1 ) ;
  11733. #ifdef COMMENT
  11734.     debug(F111,"lgotoxy","vmode",vmode);
  11735.     debug(F111,"lgotoxy","x",x);
  11736.     debug(F111,"lgotoxy","y",y);
  11737. #endif /* COMMENT */
  11738.  
  11739. }
  11740.  
  11741. /*---------------------------------------------------------------------------*/
  11742. /* setmargins                                                                */
  11743. /*---------------------------------------------------------------------------*/
  11744. void
  11745. setmargins(int topmargin, int bottommargin) {
  11746.     margintop = topmargin;
  11747.     marginbot = bottommargin;
  11748. }
  11749.  
  11750. /*---------------------------------------------------------------------------*/
  11751. /* line25                                                                    */
  11752. /*---------------------------------------------------------------------------*/
  11753.  
  11754. #define STATUS_MAX 10
  11755. char *save_status[STATUS_MAX];
  11756. char *save_usertext[STATUS_MAX];
  11757. char *save_exittext[STATUS_MAX];
  11758. char *save_helptext[STATUS_MAX];
  11759. char *save_filetext[STATUS_MAX];
  11760. char *save_savefiletext[STATUS_MAX];
  11761. char *save_hostname[STATUS_MAX];
  11762.  
  11763. void
  11764. save_status_line() {
  11765.     if ((++status_saved >= (STATUS_MAX - 1)) || (status_saved < 0))
  11766.       return;
  11767.  
  11768.     if (!(save_status[status_saved] = malloc(MAXTERMCOL+1)))
  11769.       return;
  11770.     else
  11771.       strncpy(save_status[status_saved],statusline,MAXTERMCOL);
  11772.  
  11773.     if (!(save_usertext[status_saved] = malloc(MAXTERMCOL+1)))
  11774.       return;
  11775.     else
  11776.       strncpy(save_usertext[status_saved],usertext,MAXTERMCOL);
  11777.  
  11778.     if (!(save_exittext[status_saved] = malloc(MAXTERMCOL+1)))
  11779.       return;
  11780.     else
  11781.       strncpy(save_exittext[status_saved],exittext,MAXTERMCOL+1);
  11782.  
  11783.     if (!(save_helptext[status_saved] = malloc(MAXTERMCOL+1)))
  11784.       return;
  11785.     else
  11786.       strncpy(save_helptext[status_saved],helptext,MAXTERMCOL+1);
  11787.  
  11788.     if (!(save_filetext[status_saved] = malloc(MAXTERMCOL+1)))
  11789.       return;
  11790.     else
  11791.       strncpy(save_filetext[status_saved],filetext,MAXTERMCOL+1);
  11792.  
  11793.     if (!(save_savefiletext[status_saved] = malloc(MAXTERMCOL+1)))
  11794.       return;
  11795.     else
  11796.       strncpy(save_savefiletext[status_saved],savefiletext,MAXTERMCOL+1);
  11797.  
  11798.     if (!(save_hostname[status_saved] = malloc(MAXTERMCOL+1)))
  11799.       return;
  11800.     else
  11801.       strncpy(save_hostname[status_saved],hostname,MAXTERMCOL+1);
  11802. }
  11803.  
  11804. void
  11805. restore_status_line() {
  11806.     if ((status_saved >= (STATUS_MAX - 1)) || (status_saved < 0))
  11807.       return;
  11808.  
  11809.     if (save_status[status_saved]) {
  11810.         strncpy(statusline,save_status[status_saved],MAXTERMCOL);
  11811.         free(save_status[status_saved]);
  11812.     }
  11813.  
  11814.     if (save_usertext[status_saved]) {
  11815.         ckstrncpy(usertext,save_usertext[status_saved],sizeof(usertext));
  11816.         free(save_usertext[status_saved]);
  11817.     }
  11818.  
  11819.     if (save_exittext[status_saved]) {
  11820.         ckstrncpy(exittext,save_exittext[status_saved],sizeof(exittext));
  11821.         free(save_exittext[status_saved]);
  11822.     }
  11823.  
  11824.     if (save_helptext[status_saved]) {
  11825.         ckstrncpy(helptext,save_helptext[status_saved],sizeof(helptext));
  11826.         free(save_helptext[status_saved]);
  11827.     }
  11828.  
  11829.     if (save_filetext[status_saved]) {
  11830.         ckstrncpy(filetext,save_filetext[status_saved],sizeof(filetext));
  11831.         free(save_filetext[status_saved]);
  11832.     }
  11833.  
  11834.     if (save_savefiletext[status_saved]) {
  11835.         ckstrncpy(savefiletext,save_savefiletext[status_saved],sizeof(savefiletext));
  11836.         free(save_savefiletext[status_saved]);
  11837.     }
  11838.  
  11839.     if (save_hostname[status_saved]) {
  11840.         ckstrncpy(hostname,save_hostname[status_saved],sizeof(hostname));
  11841.         free(save_hostname[status_saved]);
  11842.     }
  11843.  
  11844.     status_saved--;
  11845.     VscrnIsDirty(VTERM);  /* status line needs to be updated */
  11846. }
  11847.  
  11848. void
  11849. strinsert(char *d, char *s) {
  11850.     while (*s)
  11851.       *d++ = *s++;
  11852. }
  11853.  
  11854. char *
  11855. line25(int vmode) {
  11856.     char *s = statusline, * mode = NULL;
  11857.     int  i;
  11858.     int numlines, linesleft ;
  11859.     int w = VscrnGetWidth(vmode);
  11860.  
  11861.     if ( scrollstatus[vmode] && !escapestatus[vmode] ) {
  11862.         /* we are in scrollback mode -- dynamicly update the status line */
  11863.         numlines = ( VscrnGetBegin(vmode) == 0 ) ?
  11864.             VscrnGetEnd(vmode) + 1 : VscrnGetBufferSize(vmode) ;
  11865.  
  11866.         if (tt_roll[vmode]) {
  11867.             linesleft = ( VscrnGetScrollTop(vmode) >= VscrnGetBegin(vmode) ) ?
  11868.                     VscrnGetScrollTop(vmode) - VscrnGetBegin(vmode) :
  11869.                     VscrnGetScrollTop(vmode) - VscrnGetBegin(vmode)
  11870.                         + VscrnGetBufferSize(vmode) ;
  11871.         }
  11872.         else {
  11873.             linesleft = ( VscrnGetTop(vmode) >= VscrnGetBegin(vmode) ) ?
  11874.                 VscrnGetTop(vmode) - VscrnGetBegin(vmode) :
  11875.                     VscrnGetTop(vmode) - VscrnGetBegin(vmode)
  11876.                         + VscrnGetBufferSize(vmode) ;
  11877.         }
  11878.  
  11879.        switch (markmodeflag[vmode]) {
  11880.        case notmarking:
  11881.            mode = "SCROLLBACK" ;
  11882.            break;
  11883.        case inmarkmode:
  11884.            mode = "MARK MODE " ;
  11885.            break;
  11886.        case marking:
  11887.            mode = "MARKING   " ;
  11888.            break;
  11889.        }
  11890.  
  11891.         /* Do special status line. */
  11892.         switch ( vmode ) {
  11893.         case VCMD:
  11894.             sprintf(usertext, "%s Top Line is %d out of %d | Help: Alt-H", mode, linesleft+1, numlines );
  11895.             break;
  11896.         default:
  11897.             sprintf(usertext, "%s Top Line is %d out of %d ", mode, linesleft+1, numlines );
  11898.         }
  11899.     }
  11900.  
  11901.     switch ( vmode ) {
  11902.     case VTERM:
  11903.         /* build the status line */
  11904.         for (i = 0; i < MAXTERMCOL; i++)
  11905.             s[i] = ' ';
  11906.         if (usertext[0])
  11907.             strinsert(&s[01], usertext);    /* Leftmost item */
  11908.         if (helptext[0])
  11909.             strinsert(&s[18], helptext);
  11910.         if (exittext[0])
  11911.             strinsert(&s[32], exittext);
  11912.         i = strlen(filetext);               /* How much needed for last item */
  11913.         if (i > 0) {
  11914.             strinsert(&s[78 - i], filetext); /* Right-justify it */
  11915.             if (hostname[0]) {
  11916.                 i = 31 - i;                 /* Space remaining for hostname */
  11917.                 if ((int) strlen(hostname) > (i - 1)) { /* Too long? */
  11918.                     int j;
  11919.                     for (j = i; j > 0 && hostname[j] != ':'; j--) ;
  11920.                     if (j > 0) {            /* Cut off ":service" if any */
  11921.                         hostname[j] = '\0';
  11922.                     }
  11923.                     else {          /* Or else ... */
  11924.                         hostname[i - 3] = '.'; /* show ellipsis */
  11925.                         hostname[i - 2] = '.';
  11926.                         hostname[i - 1] = '.';
  11927.                         hostname[i] = '\0';
  11928.                     }
  11929.                 }
  11930.             }
  11931.         }
  11932.         if (hostname[0])
  11933.             strinsert(&s[47], hostname);
  11934.  
  11935. #ifndef KUI
  11936.         s[0]=(vscrn[vmode].hscroll==0?0xFE:0x11);
  11937.         s[pwidth-1]=((pwidth!=w&&vscrn[vmode].hscroll<w-pwidth)?0x10:0xFE);
  11938. #endif /* KUI */
  11939.         break;
  11940.  
  11941.     case VCMD:
  11942.         for (i = 0; i < MAXTERMCOL; i++)
  11943.             s[i] = ' ';
  11944.         if ( scrollstatus[vmode] || escapestatus[vmode] )
  11945.             strinsert(&s[01],usertext);
  11946.         else
  11947.             strinsert(&s[01],
  11948.             "K95 Command Screen | Help: Alt-H | Terminal: CONNECT or Alt-X ");
  11949.         break;
  11950.     default:
  11951.         s = "";
  11952.     }
  11953.     return s ;
  11954. }
  11955.  
  11956. /* CHSTR  --  Make a printable string out of a character  */
  11957.  
  11958. char*
  11959. chstr(int c) {
  11960.     char s[8];
  11961.     char *cp = s;
  11962.  
  11963.     if (c < SP || c == DEL)
  11964.       sprintf(cp, "CTRL-%c", ctl(c));
  11965.     else
  11966.       sprintf(cp, "'%c'\n", c);
  11967.     cp = s;
  11968.     return (cp);
  11969. }
  11970.  
  11971. /* DOESC  --  Process an escape character argument  */
  11972.  
  11973. void
  11974. esc25(int h) {
  11975.     strcpy(usertext, " ESCAPE");
  11976.     if (vik.help > 255 && keyname(vik.help))
  11977.         sprintf(helptext, "Help: %s", keyname(vik.help));
  11978.     else
  11979.         strcpy(helptext, "No Help");
  11980.     strcpy(exittext, h ? "" : (esc_exit ? "Exit: c" : "Prompt: c"));
  11981.     strcpy(hostname, "" );
  11982.     strcpy(filetext, "" ) ;
  11983.     VscrnIsDirty(VTERM);  /* status line needs to be updated */
  11984. }
  11985.  
  11986. void
  11987. settermstatus( int y )
  11988. {
  11989.     if ( y != tt_status[VTERM] ) {
  11990.         /* might need to fixup the margins */
  11991.         if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  11992.             if ( y ) {
  11993.                 marginbot-- ;
  11994.             }
  11995.             else {
  11996.                 marginbot++ ;
  11997.             }
  11998.         tt_status[VTERM] = y;
  11999.         if ( y ){
  12000.             tt_szchng[VTERM] = 2 ;
  12001.             tt_rows[VTERM]--;
  12002.             VscrnInit( VTERM ) ;  /* Height set here */
  12003. #ifdef TCPSOCKET
  12004. #ifdef CK_NAWS
  12005.             if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  12006.                 tn_snaws();
  12007. #ifdef RLOGCODE
  12008.                 rlog_naws();
  12009. #endif /* RLOGCODE */
  12010. #ifdef SSHBUILTIN
  12011.                 ssh_snaws();
  12012. #endif /* SSHBUILTIN */
  12013.             }
  12014. #endif /* CK_NAWS */
  12015. #endif /* TCPSOCKET */
  12016.         }
  12017.         else {
  12018.             tt_szchng[VTERM] = 1 ;
  12019.             tt_rows[VTERM]++;
  12020.             VscrnInit( VTERM ) ;  /* Height set here */
  12021. #ifdef TCPSOCKET
  12022. #ifdef CK_NAWS
  12023.             if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  12024.                 tn_snaws();
  12025. #ifdef RLOGCODE
  12026.                 rlog_naws();
  12027. #endif /* RLOGCODE */
  12028. #ifdef SSHBUILTIN
  12029.                 ssh_snaws();
  12030. #endif /* SSHBUILTIN */
  12031.             }
  12032. #endif /* CK_NAWS */
  12033. #endif /* TCPSOCKET */
  12034.         }
  12035.     }
  12036. }
  12037.  
  12038. /* ttmacro - allow users to specify a particular macro to be executed when */
  12039. /*           a terminal type is chosen.                                    */
  12040. void
  12041. ttmacro( int tt )
  12042. {
  12043.     extern int maclvl;                  /* Macro invocation level */
  12044.     extern CHAR sstate ;
  12045. #ifdef DCMDBUF
  12046.     extern struct cmdptr *cmdstk;
  12047. #else
  12048.     extern struct cmdptr cmdstk[];
  12049. #endif /* DCMDBUF */
  12050.  
  12051.     extern struct keytab ttyptab[] ;
  12052.     extern int nttyp ;
  12053.     char macroname[24] ;
  12054.     int i, m, l, z ;
  12055.     int szo = sizeof(struct keytab) ;
  12056.     int term_io_sav = term_io;
  12057.     term_io = 0;                        /* Disable Terminal Emulator I/O */
  12058.  
  12059.     /* Compute the macroname */
  12060.     for ( i=0;i<nttyp;i++ )
  12061.         if ( tt == ttyptab[i].kwval )
  12062.             break;
  12063.     sprintf( macroname, "tt_%s", ttyptab[i].kwd ) ;
  12064.  
  12065.     /* Lookup the macroname */
  12066.  
  12067.     l = maclvl ;
  12068.     m = mxlook(mactab, macroname, nmac);
  12069.     if (m > -1) {
  12070.         debug(F111,"zzstring mxlook",macroname,m);
  12071.         if ( IsConnectMode() ) {
  12072.             apc_command(APC_LOCAL,macroname);
  12073.         } else {
  12074.             if ((z = dodo(m,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  12075.                 while (maclvl > l) {                /* Keep going till done with it, */
  12076.                     debug(F101,"ttmacro loop maclvl 1","",maclvl);
  12077.                     sstate = (CHAR) parser(1);      /* parsing & executing each command, */
  12078.                     debug(F101,"ttmacro loop maclvl 2","",maclvl);
  12079.                     if (sstate) proto();    /* including protocol commands. */
  12080.                 }
  12081.                 debug(F101,"ttmacro loop exit maclvl","",maclvl);
  12082.             }
  12083.         }
  12084.     }
  12085.     term_io = term_io_sav;
  12086. }
  12087.  
  12088. void
  12089. settermtype( int x, int prompts )
  12090. {
  12091.     static int savresetcol = 0;
  12092.     static int savtcsr = -1, savtcsl = -1, savfcs = -1, savcp = -1;
  12093.     static int savcolor = 0;            /* Terminal color */
  12094.     static int savgrcol = 0;            /* Graphics color */
  12095.     static int savulcol = 0;            /* Underline color */
  12096.     static int savulatt = 0;            /* Underline attribute */
  12097.     static int savrvatt = 0;            /* Reverse attribute */
  12098.     static int savblatt = 0;            /* Blink attribute */
  12099.     static int savcmask = 0;            /* For saving terminal bytesize */
  12100.     static int savedGset[VNUM] = {FALSE,FALSE,FALSE,FALSE};
  12101. #ifndef KUI
  12102.     static int savstatus = TRUE ;
  12103. #else
  12104.     static int savstatus = FALSE ;
  12105. #endif
  12106.     extern int fcharset, pflag, initvik, SysInited ;
  12107.     int i,y ;
  12108.  
  12109.     tt_type_mode = tt_type = x;
  12110.  
  12111.     if (savcolor) {             /* Restore this stuff if we */
  12112.         colorreset = savresetcol ;
  12113.         colornormal = savcolor; /* were ANSI before... */
  12114.         colorgraphic = savgrcol;
  12115.         colorunderline = savulcol;
  12116.  
  12117.         trueblink     = savblatt ;
  12118.         truereverse   = savrvatt ;
  12119.         trueunderline = savulatt ;
  12120.  
  12121.         savcolor = 0;
  12122.         savgrcol = 0 ;
  12123.         savulcol = 0 ;
  12124.         scrninitialized[VTERM] = 0;
  12125.         tt_status_usr[VTERM] = savstatus ;
  12126.         settermstatus(tt_status_usr[VTERM]) ;
  12127.     }
  12128.  
  12129.     if (savcmask) {             /* Restore terminal bytesize */
  12130.         cmask = savcmask;
  12131.         savcmask = 0;
  12132.     }
  12133.     if (savtcsl > -1) {         /* Restore character sets */
  12134.         tcsl = savtcsl;
  12135.         tcsr = savtcsr;
  12136.         fcharset = savfcs;
  12137.         savtcsl = -1;
  12138.     }
  12139.     if ( savedGset[VTERM] ) {
  12140.         for ( i = 0 ; i < 4 ; i++ )
  12141.             G[i] = savedG[VTERM][i] ;
  12142.         savedGset[VTERM] = FALSE ;
  12143.     }
  12144. #ifdef COMMENT
  12145.     if (savcp > 0) {            /* Restore code page */
  12146.         os2setcp(savcp);
  12147.         savcp = -1;
  12148.     }
  12149. #endif /* COMMENT */
  12150.  
  12151.     if (ISANSI(tt_type) || ISLINUX(tt_type)) {
  12152.         if (parity && prompts) {
  12153.  printf("WARNING, ANSI terminal emulation works right only if PARITY is NONE.\n");
  12154.  printf("HELP SET PARITY for further information.\n");
  12155.         }
  12156.         if ( !savcolor ) {
  12157.             savcolor = colornormal;     /* Save coloration */
  12158.             savgrcol = colorgraphic ;
  12159.             savulcol = colorunderline ;
  12160.  
  12161.             savulatt = trueunderline ;
  12162.             savblatt = trueblink ;
  12163.             savrvatt = truereverse ;
  12164.  
  12165.             colornormal = 0x07;         /* Light gray on black */
  12166.             colorgraphic = 0x07;        /* Light gray on black */
  12167.             colorunderline = 0x47;      /* Light gray on Red */
  12168.  
  12169. #ifndef KUI
  12170.             trueunderline = FALSE ;     /* Simulate underline */
  12171. #endif /* KUI */
  12172.  
  12173.             savresetcol = colorreset;     /* Save Reset Color mode */
  12174.  
  12175.             if (ISLINUX(tt_type) )
  12176.                 colorreset = FALSE ;
  12177.             else
  12178.                 colorreset = TRUE ;     /* Turn Reset color mode on */
  12179.             scrninitialized[VTERM] = 0; /* To make it take effect */
  12180.  
  12181.             savstatus = tt_status_usr[VTERM] ;
  12182.             if ( ISUNIXCON(tt_type) ) {
  12183.                 tt_status_usr[VTERM] = FALSE ;
  12184.                 settermstatus( tt_status_usr[VTERM] ) ;
  12185.             }
  12186.  
  12187.             VscrnInit(VTERM);           /* Reinit the screen buffer */
  12188.  
  12189.             savcmask = cmask;           /* Go to 8 bits */
  12190.             cmask = 0xFF;
  12191.  
  12192.             savtcsl = tcsl;             /* Save terminal charset */
  12193.             savtcsr = tcsr;
  12194.             savfcs  = fcharset;
  12195.  
  12196.             if ( ISLINUX(tt_type) ) {
  12197.                 G[0].def_designation = G[0].designation = TX_ASCII;
  12198.                 G[0].init = TRUE;
  12199.                 G[0].def_c1 = G[0].c1 = FALSE;
  12200.                 G[0].size = cs94;
  12201.                 G[0].national = FALSE;
  12202.  
  12203.                 G[1].def_designation = G[1].designation = TX_8859_1;
  12204.                 G[1].init = TRUE;
  12205.                 G[1].def_c1 = G[1].c1 = FALSE;
  12206.                 G[1].size = cs94;
  12207.                 G[1].national = FALSE;
  12208.  
  12209.                 G[2].def_designation = G[2].designation = TX_8859_1;
  12210.                 G[2].init = TRUE;
  12211.                 G[2].def_c1 = G[2].c1 = FALSE;
  12212.                 G[2].size = cs94;
  12213.                 G[2].national = FALSE;
  12214.  
  12215.                 G[3].def_designation = G[3].designation = TX_DECSPEC;
  12216.                 G[3].init = TRUE;
  12217.                 G[3].def_c1 = G[3].c1 = FALSE;
  12218.                 G[3].size = cs94;
  12219.                 G[3].national = FALSE;
  12220.             } else {
  12221.                 tcsr = tcsl = TX_ASCII;     /* Make them both the same */
  12222.                 y = os2getcp();             /* Default is current code page */
  12223.                 switch (y) {
  12224. #ifdef COMMENT
  12225.                     /* These do not support box drawing characters */
  12226.                 case 1250: setremcharset(TX_CP1250,4); break;
  12227.                 case 1251: setremcharset(TX_CP1251,4); break;
  12228.                 case 1252: setremcharset(TX_CP1252,4); break;
  12229.                 case 1253: setremcharset(TX_CP1253,4); break;
  12230.                 case 1254: setremcharset(TX_CP1254,4); break;
  12231.                 case 1257: setremcharset(TX_CP1257,4); break;
  12232. #endif /* COMMENT */
  12233.                 case 850:  setremcharset(TX_CP850,4); break;
  12234.                 case 852:  setremcharset(TX_CP852,4); break;
  12235.                 case 857:  setremcharset(TX_CP857,4); break;
  12236.                 case 862:  setremcharset(TX_CP862,4); break;
  12237.                 case 866:  setremcharset(TX_CP866,4); break;
  12238.                 case 869:  setremcharset(TX_CP869,4); break;
  12239.                 case 437: 
  12240.                 default:   setremcharset(TX_CP437,4); break;
  12241.                 }
  12242. #ifdef COMMENT
  12243.                 /* These should no longer be necessary with the above */
  12244.                 if (!cs_is_nrc(tcsl)) {
  12245.                     G[0].def_designation = G[0].designation = TX_ASCII;
  12246.                     G[0].init = TRUE;
  12247.                     G[0].def_c1 = G[0].c1 = FALSE;
  12248.                     G[0].size = cs94;
  12249.                     G[0].national = FALSE;
  12250.                 }
  12251.                 for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  12252.                     G[i].def_designation = G[i].designation = tcsl;
  12253.                     G[i].init = TRUE;
  12254.                     G[i].def_c1 = G[i].c1 = FALSE;
  12255.                     switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  12256.                     case 128:
  12257.                     case 96:
  12258.                         G[i].size = G[i].def_size = cs96;
  12259.                         break;
  12260.                     case 94:
  12261.                         G[i].size = G[i].def_size = cs94;
  12262.                         break;
  12263.                     default:
  12264.                         G[i].size = G[i].def_size = csmb;
  12265.                         break;
  12266.                     }
  12267.                     G[i].national = cs_is_nrc(tcsl);
  12268.                 }
  12269. #endif /* COMMENT */
  12270.             }
  12271.         }
  12272.     }
  12273.     else if ( ISAAA(tt_type) ) {
  12274.         savtcsl = tcsl;         /* Save terminal charset */
  12275.         savtcsr = tcsr;
  12276.         savfcs  = fcharset;
  12277.  
  12278.         /* Default Character-set is ASCII */
  12279.         for ( i = 0 ; i < 4 ; i++ ) {
  12280.             savedG[VTERM][i] = G[i] ;
  12281.         }
  12282.         savedGset[VTERM] = TRUE ;
  12283.  
  12284.         G[0].def_designation = G[0].designation = TX_ASCII;
  12285.         G[0].init = TRUE;
  12286.         G[0].def_c1 = G[0].c1 = FALSE;
  12287.         G[0].size = cs94;
  12288.         G[0].national = TRUE;
  12289.  
  12290.         G[1].def_designation = G[1].designation = TX_ASCII;
  12291.         G[1].init = TRUE;
  12292.         G[1].def_c1 = G[1].c1 = FALSE;
  12293.         G[1].size = cs94;
  12294.         G[1].national = TRUE;
  12295.  
  12296.         G[2].def_designation = G[2].designation = TX_ASCII;
  12297.         G[2].init = TRUE;
  12298.         G[2].def_c1 = G[2].c1 = FALSE;
  12299.         G[2].size = cs94;
  12300.         G[2].national = TRUE;
  12301.  
  12302.         G[3].def_designation = G[3].designation = TX_ASCII;
  12303.         G[3].init = TRUE;
  12304.         G[3].def_c1 = G[3].c1 = FALSE;
  12305.         G[3].size = cs94;
  12306.         G[3].national = TRUE;
  12307.     } 
  12308.     else if ( ISHP(tt_type) ) {
  12309.         savtcsl = tcsl;         /* Save terminal charset */
  12310.         savtcsr = tcsr;
  12311.         savfcs  = fcharset;
  12312.  
  12313.         /* Default Character-set is HP-ROMAN8 */
  12314.         G[0].designation = G[0].def_designation = TX_ASCII ;
  12315.         G[0].size = G[0].def_size = cs94 ;
  12316.         G[0].c1   = G[0].def_c1 = FALSE ;
  12317.         G[0].national = CSisNRC(G[0].designation) ;
  12318.         G[0].init = TRUE ;
  12319.         for ( i=1; i<4; i++ ) {
  12320.             G[i].designation = G[i].def_designation =
  12321.                 (i == 1) ? TX_HPR8 : TX_HPLINE;
  12322.             G[i].size = G[i].def_size = cs96 ;
  12323.             G[i].c1   = G[i].def_c1 = TRUE ;
  12324.             G[i].init = TRUE ;
  12325.         }
  12326.         savedGset[VTERM] = TRUE ;
  12327.     }
  12328.     else if ( ISQNX(tt_type) ) {
  12329.         savcmask = cmask;               /* Go to 8 bits */
  12330.         cmask = 0xFF;
  12331.  
  12332.         savtcsl = tcsl;         /* Save terminal charset */
  12333.         savtcsr = tcsr;
  12334.         savfcs  = fcharset;
  12335.  
  12336.         /* Default Character-set is CP437 */
  12337.         for ( i = 0 ; i < 4 ; i++ ) {
  12338.             savedG[VTERM][i] = G[i] ;
  12339.         }
  12340.             G[0].designation = G[0].def_designation = TX_ASCII ;
  12341.             G[0].size = G[0].def_size = cs94 ;
  12342.             G[0].c1   = G[0].def_c1 = FALSE ;
  12343.             G[0].national = CSisNRC(G[0].designation) ;
  12344.             G[0].init = TRUE ;
  12345.             for ( i=1; i<4; i++ ) {
  12346.                 G[i].designation = G[i].def_designation =
  12347.                     TX_CP437;
  12348.                 G[i].size = G[i].def_size = cs96 ;
  12349.                 G[i].c1   = G[i].def_c1 = TRUE ;
  12350.                 G[i].init = TRUE ;
  12351.             }
  12352.             savedGset[VTERM] = TRUE ;
  12353.     }
  12354.     else if ( ISQANSI(tt_type) ) {
  12355.         if ( !savcolor ) {
  12356.             savcolor = colornormal;     /* Save coloration */
  12357.             savgrcol = colorgraphic ;
  12358.             savulcol = colorunderline ;
  12359.  
  12360.             savulatt = trueunderline ;
  12361.             savblatt = trueblink ;
  12362.             savrvatt = truereverse ;
  12363.  
  12364.             colornormal = 0x07;         /* Light gray on black */
  12365.             colorgraphic = 0x07;        /* Light gray on black */
  12366.             colorunderline = 0x47;      /* Light gray on Red */
  12367.  
  12368. #ifndef KUI
  12369.             trueunderline = FALSE ;     /* Simulate underline */
  12370. #endif /* KUI */
  12371.  
  12372.             savresetcol = colorreset;     /* Save Reset Color mode */
  12373.  
  12374.             colorreset = FALSE ;
  12375.             scrninitialized[VTERM] = 0; /* To make it take effect */
  12376.  
  12377.             savstatus = tt_status_usr[VTERM] ;
  12378.         }
  12379.  
  12380.         savcmask = cmask;               /* Go to 8 bits */
  12381.         cmask = 0xFF;
  12382.  
  12383.         savtcsl = tcsl;         /* Save terminal charset */
  12384.         savtcsr = tcsr;
  12385.         savfcs  = fcharset;
  12386.  
  12387.         /* Default Character-set is ASCII/CP437 */
  12388.         for ( i = 0 ; i < 4 ; i++ ) {
  12389.             savedG[VTERM][i] = G[i] ;
  12390.         }
  12391.         /* Set G0 */
  12392.         G[0].designation = G[0].def_designation = TX_ASCII ;
  12393.         G[0].size = G[0].def_size = cs94 ;
  12394.         G[0].c1   = G[0].def_c1 = FALSE ;
  12395.         G[0].national = CSisNRC(G[0].designation) ;
  12396.         G[0].init = TRUE ;
  12397.  
  12398.         /* Set G1 */
  12399.         G[1].designation = G[1].def_designation = TX_DECSPEC ;
  12400.         G[1].size = G[1].def_size = cs94 ;
  12401.         G[1].c1   = G[1].def_c1 = FALSE ;
  12402.         G[1].national = CSisNRC(G[1].designation) ;
  12403.         G[1].init = TRUE ;
  12404.  
  12405.         /* Set G2 */
  12406.         G[2].designation = G[2].def_designation = TX_8859_2 ;
  12407.         G[2].size = G[2].def_size = cs96 ;
  12408.         G[2].c1   = G[2].def_c1 = FALSE ;
  12409.         G[2].national = CSisNRC(G[2].designation) ;
  12410.         G[2].init = TRUE ;
  12411.  
  12412.         /* Set G3 */
  12413.         G[3].designation = G[3].def_designation = TX_DECSPEC ;
  12414.         G[3].size = G[3].def_size = cs94 ;
  12415.         G[3].c1   = G[3].def_c1 = FALSE ;
  12416.         G[3].national = CSisNRC(G[3].designation) ;
  12417.         G[3].init = TRUE ;
  12418.         savedGset[VTERM] = TRUE ;
  12419.     }
  12420.  
  12421.     GNOW = GL = &G[0] ;
  12422.     GR = ISLINUX(tt_type_mode) ? &G[1] : ISVT220(tt_type_mode) ? &G[2] : &G[1];
  12423.     SSGL = NULL ;
  12424.  
  12425.     if ( ISQNX(tt_type) ) {
  12426.         user_erasemode = TRUE;
  12427.     }
  12428.     else {
  12429.         user_erasemode = FALSE;
  12430.     }
  12431.  
  12432.     if ( IS97801(tt_type_mode) ) {
  12433.         dec_lang = VTL_GERMAN;
  12434.         dec_nrc = TX_GERMAN;
  12435.         dec_kbd = TX_8859_1;
  12436.         SNI_bitmode((cmask == 0377) ? 8 : 7);
  12437.     }
  12438.  
  12439.     if ( ISHFT(tt_type) || ISSCO(tt_type) )
  12440.         colorreset = FALSE;
  12441.     else
  12442.         colorreset = TRUE;
  12443.  
  12444.     updanswerbk() ;
  12445.  
  12446.     VscrnInit(VTERM);
  12447.     initvik = TRUE;     /* Tell doreset() to initialize the vik table */
  12448.     doreset(1);         /* Clear screen and home the cursor */
  12449.  
  12450.     ttmacro(x) ;        /* Execute any user defined terminal type macros */
  12451.  
  12452. #ifdef KUI
  12453.     KuiSetProperty( KUI_TERM_TYPE, (long) tt_type, (long) 0 ) ;
  12454. #endif /* KUI */
  12455.     ipadl25() ;
  12456.     VscrnIsDirty(VTERM);
  12457.     msleep(10);
  12458. }
  12459.  
  12460. unsigned char
  12461. ComputeColorFromAttr( int mode, unsigned char colorattr, USHORT vtattr )
  12462. {
  12463.     static unsigned char colorval= 0x00;
  12464.     static unsigned char _colorattr=0x00;
  12465.     static USHORT _vtattr=0x00;
  12466.  
  12467.     if ( _colorattr == colorattr && vtattr == _vtattr )
  12468.         goto done;
  12469.  
  12470.     colorval = _colorattr = colorattr;
  12471.     _vtattr = vtattr;
  12472.  
  12473.     if (vtattr == VT_CHAR_ATTR_NORMAL)
  12474.         goto done;
  12475.  
  12476.     if (!(vtattr & WY_CHAR_ATTR) || tt_hidattr)
  12477.     {
  12478.         if ( (ISWYSE(tt_type_mode) ||
  12479.               ISTVI(tt_type_mode) ||
  12480.               ISHZL(tt_type_mode))
  12481.             && (vtattr & VT_CHAR_ATTR_PROTECTED) ) {
  12482.             vtattr = VT_CHAR_ATTR_NORMAL |
  12483.            (WPattrib.bold       ? VT_CHAR_ATTR_BOLD      : 0) |
  12484.            (WPattrib.dim        ? VT_CHAR_ATTR_DIM       : 0) |
  12485.            (WPattrib.underlined ? VT_CHAR_ATTR_UNDERLINE : 0) |
  12486.            (WPattrib.blinking   ? VT_CHAR_ATTR_BLINK     : 0) |
  12487.            (WPattrib.italic     ? VT_CHAR_ATTR_ITALIC    : 0) |
  12488.            (WPattrib.reversed   ? VT_CHAR_ATTR_REVERSE   : 0) |
  12489.            (WPattrib.invisible  ? VT_CHAR_ATTR_INVISIBLE : 0) |
  12490.            (WPattrib.unerasable ? VT_CHAR_ATTR_PROTECTED : 0) |
  12491.            (WPattrib.graphic    ? VT_CHAR_ATTR_GRAPHIC   : 0) |
  12492.            (WPattrib.hyperlink  ? VT_CHAR_ATTR_HYPERLINK : 0) |
  12493.            (WPattrib.wyseattr   ? WY_CHAR_ATTR           : 0) ;
  12494.         }
  12495.  
  12496.         if (vtattr & VT_CHAR_ATTR_HYPERLINK)
  12497.             vtattr |= tt_url_hilite_attr;
  12498.  
  12499.         if ((vtattr & VT_CHAR_ATTR_UNDERLINE) &&
  12500.             !trueunderline /* underline simulated by color */ )
  12501.             colorval = underlineattribute ;
  12502.         else if ((vtattr & VT_CHAR_ATTR_REVERSE) &&
  12503.                  !truereverse /* reverse simulated by color */ )
  12504.             colorval = reverseattribute ;
  12505.         else if ((vtattr & VT_CHAR_ATTR_ITALIC) &&
  12506.                  !trueitalic /* italic simulated by color */ )
  12507.             colorval = italicattribute;
  12508.         else if ((vtattr & VT_CHAR_ATTR_GRAPHIC))
  12509.             /* a graphic character */
  12510.             colorval = graphicattribute ;
  12511.         else
  12512.             colorval = colorattr ;
  12513.  
  12514.  
  12515.         if ((vtattr & VT_CHAR_ATTR_BLINK) &&
  12516.             !trueblink /* blink simulated by BGI */
  12517. #ifndef KUI
  12518.             || (vtattr & VT_CHAR_ATTR_UNDERLINE) &&
  12519.             trueunderline /* underline simulated by BGI */
  12520. #endif /* KUI */
  12521.              )
  12522.         {
  12523.             if (decscnm) {
  12524.                 if ( fgi )
  12525.                     colorval &= 0xF7 ;  /* Toggle FGI */
  12526.                 else
  12527.                     colorval |= 0x08 ;
  12528.             } else {
  12529.                 if (bgi)
  12530.                     colorval &= 0x7F ;  /* Toggle BGI */
  12531.                 else
  12532.                     colorval |= 0x80 ;
  12533.             }
  12534.         }
  12535.  
  12536.         if ( vtattr & VT_CHAR_ATTR_BOLD ||
  12537.              ( vtattr & VT_CHAR_ATTR_DIM 
  12538. #ifdef KUI
  12539.                && !truedim
  12540. #endif /* KUI */
  12541.                )
  12542.              ) {
  12543.             if (decscnm) {
  12544.                 if (bgi)
  12545.                     colorval &= 0x7F ;  /* Toggle BGI */
  12546.                 else
  12547.                     colorval |= 0x80 ;
  12548.             } else {
  12549.                 if ( fgi )
  12550.                     colorval &= 0xF7 ;  /* Toggle FGI */
  12551.                 else
  12552.                     colorval |= 0x08 ;
  12553.             }
  12554.         }
  12555.  
  12556.         if ( vtattr & VT_CHAR_ATTR_REVERSE &&
  12557.             truereverse /* not being simulated */ )
  12558.             colorval = byteswapcolors(colorval);
  12559.  
  12560.         if ( vtattr & VT_CHAR_ATTR_INVISIBLE )
  12561.             colorval = (colorval&0xF0)|((colorval&0xF0)>>4) ;
  12562.     }
  12563.  
  12564.   done:
  12565.     if ( flipscrnflag[mode] )
  12566.         return byteswapcolors(colorval);
  12567.     else
  12568.         return colorval;
  12569. }
  12570.  
  12571. #ifndef NOTERM
  12572. /*  V T E S C A P E  --  Interpret a VT52/100/102/220/320 escape sequence  */
  12573. /*
  12574.   Called after an escape sequence has been received and collected
  12575.   into escbuffer[]. To be added:
  12576.  
  12577.   Soft character sets (DRCS)
  12578.   Request Presentation State Report (DECRQPSR)
  12579.   Cursor Information Report (DECCIR)
  12580.   Tab Stop Report (DECTABSR)
  12581.   Restore Presentation State (DECRSPS)
  12582.   Restore Terminal State (DECRSTS)
  12583.   many more VT320 specific stuff
  12584. */
  12585.  
  12586. static int   pn[11]={0,0,0,0,0,0,0,0,0,0,0};
  12587. static bool  private=FALSE;
  12588. static bool  ansiext=FALSE;
  12589. static bool  zdsext=FALSE;
  12590. static bool  kermext=FALSE;
  12591. static vtattrib blankattrib={0,0,0,0,0,0,0,0,0,0};
  12592.  
  12593. void
  12594. vtcsi(void)
  12595. {
  12596.     unsigned short  j;
  12597.     unsigned short  k;
  12598.     unsigned short  l;
  12599.     unsigned char   blankcell[2];
  12600.     viocell         blankvcell ;
  12601.     int             i;
  12602.     char            tempstr[20];
  12603.     int             fore, back;
  12604.     int             tcs ;
  12605.     unsigned char   des ;
  12606.  
  12607.     if ( ISH19(tt_type_mode) ) {
  12608.         /* Hold Screen Mode On */
  12609.         /* They must have been drunk when they did this one */
  12610.         ;
  12611.     }
  12612.     else
  12613.     {
  12614.         achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12615.      LB2000:
  12616.         switch (achar) {        /* Second level */
  12617.         case 'A':               /* Cursor up one line */
  12618.             if ( IS97801(tt_type_mode) ) {
  12619.                 /* ignored if outside scroll region */
  12620.                 if ( wherey[VTERM] < margintop ||
  12621.                     wherey[VTERM] > marginbot )
  12622.                     break;
  12623.             }
  12624.             cursorup(0);
  12625.             if ( !ISANSI(tt_type_mode) || ISLINUX(tt_type_mode))
  12626.                 wrapit = FALSE;
  12627.             break;
  12628.         case 'B':               /* Cursor down one line */
  12629.             if ( IS97801(tt_type_mode) ) {
  12630.                 /* ignored if outside scroll region */
  12631.                 if ( wherey[VTERM] < margintop ||
  12632.                     wherey[VTERM] > marginbot )
  12633.                     break;
  12634.             }
  12635.             cursordown(0);
  12636.             if ( !ISANSI(tt_type_mode) || ISLINUX(tt_type_mode) )
  12637.                 wrapit = FALSE;
  12638.             break;
  12639.         case 'C':               /* Cursor forward, stay on same line */
  12640.             cursorright(0);
  12641.             break;
  12642.         case 'D':               /* Cursor back, stay on same line */
  12643.             cursorleft(0);
  12644.             break;
  12645.         case 'E':
  12646.             if ( ansiext && ISBA80(tt_type_mode) ) {
  12647.                 /* Window Status Request */
  12648.                 char buf[64];
  12649.                 sprintf(buf,"%c[=D%3d:%3d;001:001;Lohn    D",
  12650.                          27,VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0),
  12651.                          VscrnGetWidth(VTERM));
  12652.                 ttol(buf,strlen(buf));
  12653.  
  12654.             }
  12655.             else if ( private && ISAIXTERM(tt_type_mode) ) {
  12656.                 /* Erase Status Line */
  12657.                 clrscreen(VSTATUS,SP);
  12658.                 break;
  12659.             }
  12660.             else {
  12661.                 /* Cursor Next Line */
  12662.                 cursornextline();
  12663.             }
  12664.             break;
  12665.         case 'F':
  12666.             if ( private && ISAIXTERM(tt_type_mode) ) {
  12667.                 /* Return from Status Line */
  12668.                 setdecssdt(SASD_TERMINAL);
  12669.                 break;
  12670.             }
  12671.             else {
  12672.                 /* Cursor Previous Line */
  12673.                 cursorprevline();
  12674.             }
  12675.             break;
  12676.         case 'J': /* Erase from cursor to end of scrn */
  12677.             if (private)
  12678.                 selclreoscr_escape(VTERM,SP);
  12679.             else {
  12680.                 if ( IS97801(tt_type_mode) ) {
  12681.                     /* ignored if outside scroll region */
  12682.                     if ( wherey[VTERM] < margintop ||
  12683.                         wherey[VTERM] > marginbot )
  12684.                         break;
  12685.                 }
  12686.                 clreoscr_escape(VTERM,SP);
  12687.             }
  12688.             break;
  12689.         case 'V': /* Erase from cursor to end of region */
  12690.             if ( ISSCO(tt_type_mode) )
  12691.                 clreoreg_escape(VTERM,SP);
  12692.             break;
  12693.         case 'K':
  12694.             if ( ansiext && ISBA80(tt_type_mode) ) {
  12695.                 /* Begin Reading Function Labels */
  12696.                 ba80_fkey_read = -1;
  12697.             }
  12698.                 /* Erase from cursor to end of line */
  12699.             else if ( private == TRUE )
  12700.                 selclrtoeoln(VTERM,SP);
  12701.             else
  12702.                 clrtoeoln(VTERM,SP);
  12703.             break;
  12704.         case '?':               /* DEC private */
  12705.             private = TRUE;
  12706.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12707.             goto LB2000;
  12708.         case '=':               /* SCO,Unixware,ANSI,Nixdorf ext. */
  12709.             ansiext = TRUE ;
  12710.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12711.             goto LB2000;
  12712.         case '>':               /* Heath/Zenith/AnnArbor extension */
  12713.             zdsext = TRUE ;
  12714.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12715.             goto LB2000;
  12716.         case '<':               /* Kermit extension */
  12717.             kermext = TRUE ;
  12718.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12719.             goto LB2000;
  12720.         case 'H':
  12721.             if ( private && ISHFT(tt_type_mode) ) {
  12722.                 /* Hide Status Line */
  12723.                 setdecssdt( SSDT_INDICATOR );
  12724.                 break;
  12725.             }
  12726.             /* (no break) Cursor Home */
  12727.         case 'f':
  12728.             if ( IS97801(tt_type_mode) && decsasd == SASD_STATUS )
  12729.                 setdecsasd(SASD_TERMINAL);
  12730.             lgotoxy(VTERM, 1, relcursor ? margintop : 1);
  12731.             break;
  12732.         case 'g':
  12733.             if ( !ISSCO(tt_type_mode) ) {
  12734.                 /* Tab Clear at this position */
  12735.                 htab[wherex[VTERM]] = '0';
  12736.             }
  12737.             break;
  12738.         case 'm':       /* Normal Video - Exit all attribute modes */
  12739.             if (colorreset)
  12740.                 resetcolors(0) ;
  12741.  
  12742.             attrib.blinking = FALSE;
  12743.             attrib.italic = FALSE;              /* No italic */
  12744.             attrib.bold = FALSE;
  12745.             attrib.invisible = FALSE;
  12746.             attrib.underlined = FALSE;
  12747.             attrib.reversed = FALSE;
  12748.             attrib.dim = FALSE ;
  12749.             attrib.graphic = FALSE ;
  12750.             attrib.wyseattr = FALSE ;
  12751.             attrib.hyperlink = FALSE;
  12752.             attrib.linkid = 0;
  12753.  
  12754.             sco8bit = FALSE ;
  12755.  
  12756.             if ( ISANSI(tt_type_mode) )
  12757.                 crm = FALSE ;
  12758.             break;
  12759.         case 'M':
  12760.             if ( ansiext && ISBA80(tt_type_mode) ) {
  12761.                 /* Goto Status Line */
  12762.                 setdecssdt( SSDT_HOST_WRITABLE );
  12763.                 setdecsasd( SASD_STATUS );
  12764.                 break;
  12765.             }
  12766.             else {
  12767.                 pn[1] = 1;
  12768.                 k = 1;
  12769.                 goto LB2003;
  12770.             }
  12771.             break;
  12772.         case 'r': 
  12773. #ifdef COMMENT
  12774.             /* Reset Margin */
  12775.             setmargins(1, VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));
  12776.             if ( decsasd == SASD_STATUS )
  12777.                 lgotoxy( VSTATUS, 1, 1 );
  12778.             else
  12779.                 lgotoxy(VTERM, 1, 1);
  12780. #else /* COMMENT */
  12781.             if ( ISSUN(tt_type_mode) ) {
  12782.                 pn[1] = 0;
  12783.                 k = 1;
  12784.             } else {
  12785.                 pn[1] = pn[2] = 1;
  12786.                 k = 2;
  12787.             }
  12788.             goto LB2003;
  12789. #endif /* COMMENT */
  12790.             break;
  12791.         case 's': 
  12792.             if ( ISSUN(tt_type_mode) ) {
  12793.                 doreset(1);
  12794.             } else 
  12795.             /* ANSI.SYS save cursor position */
  12796.             if ( ISANSI(tt_type_mode) ||
  12797.                 IS97801(tt_type_mode))
  12798.                 savecurpos(VTERM,0);
  12799.             break;
  12800.         case 'u': /* ANSI.SYS restore cursor position */
  12801.             if ( ISANSI(tt_type_mode) ||
  12802.                 IS97801(tt_type_mode))
  12803.                 restorecurpos(VTERM,0);
  12804.             break;
  12805.         case 'U': /* SCO ANSI Reset Initial Screen */
  12806.             if ( ISSCO(tt_type_mode) )
  12807.                 doreset(1);   /* Hard Reset */
  12808.             break;
  12809.         case '!':
  12810.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12811.             switch (achar) {
  12812.             case 'p':
  12813.                 doreset(0);   /* DECSTR - Soft Reset */
  12814.                 break;
  12815.             }
  12816.             break;
  12817.         case '$':
  12818.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12819.             switch (achar) {
  12820.             case '}':
  12821.                 /* DECSASD - Select Active Status Display */
  12822.                 setdecsasd( SASD_TERMINAL );
  12823.                 break;
  12824.             case '-':   /* VT320 */
  12825.             case '~':   /* WY370 */
  12826.                 /* DECSSDT - Select Status Line Type */
  12827.                 setdecssdt( SSDT_BLANK );
  12828.                 break;
  12829.             }
  12830.             break;
  12831.         case 'S':
  12832.             if ( private && ISAIXTERM(tt_type_mode) ) {
  12833.                 /* Show Status Line */
  12834.                 setdecssdt( SSDT_HOST_WRITABLE );
  12835.                 break;
  12836.             } else if ( ansiext && ISBA80(tt_type_mode) ) {
  12837.                 /* Return from Status Line */
  12838.                 setdecsasd(SASD_TERMINAL);
  12839.                 break;
  12840.             }
  12841.             else {
  12842.                 pn[1] = 1;
  12843.                 k = 1;
  12844.                 goto LB2003;
  12845.             }
  12846.             break;
  12847.         case 'a':
  12848.         case 'e':
  12849.         case 'T':
  12850.         case 'L':
  12851.         case '@':
  12852.         case 'P':
  12853.         case 'Z':
  12854.         case SP:
  12855.             pn[1] = 1;
  12856.             k = 1;
  12857.             goto LB2003;
  12858.         case 'c':
  12859.         case 'h':
  12860.         case 'l':
  12861.         case 'n':
  12862.         case 'x':
  12863.             pn[1] = 0;
  12864.             k = 1;
  12865.             goto LB2003;
  12866.         case ';':               /* As in ESC [ ; 7 m */
  12867.             pn[1] = 0;
  12868.             k = 1;
  12869.             goto LB2002;
  12870.         default:  {             /* Pn - got a number */
  12871.           LB2001:
  12872.             /* Esc [ Pn...Pn x   functions */
  12873.             pn[1] = pnumber(&achar);
  12874.             k = 1;
  12875.           LB2002:
  12876.             while (achar == ';') { /* get Pn[k] */
  12877.                 achar = (escnext<=esclast)?
  12878.                     escbuffer[escnext++]:0;
  12879.                 k++;
  12880.                 /* If there is a '?' at this point it is a protocol */
  12881.                 /* error.  We will skip over it since this appears  */
  12882.                 /* to be a frequent mistake that people make when   */
  12883.                 /* combining private parameters.                    */
  12884.                 if (achar == '?')
  12885.                     achar = (escnext<=esclast)?
  12886.                         escbuffer[escnext++]:0;
  12887.                 pn[k] = pnumber(&achar);
  12888.             }
  12889.             pn[k + 1] = 1;
  12890.           LB2003:
  12891.             switch (achar) { /* Third level */
  12892.             case '"':
  12893.                 achar = (escnext<=esclast)?
  12894.                     escbuffer[escnext++]:0;
  12895.                 switch (achar) {
  12896.                 case 'p': /* COMPATIBILITY LEVEL (DECSCL) */
  12897.                     setdecsasd(SASD_TERMINAL);
  12898.                     switch ( pn[1] ) {
  12899.                     case 61:
  12900.                         switch ( tt_type ) {
  12901.                         case TT_VT100:
  12902.                             tt_type_mode = TT_VT100 ;
  12903.                             break;
  12904.                         case TT_VT102:
  12905.                         case TT_VT220:
  12906.                         case TT_VT220PC:
  12907.                         case TT_VT320:
  12908.                         case TT_VT320PC:
  12909.                         case TT_WY370:
  12910.                             tt_type_mode = TT_VT102 ;
  12911.                             break;
  12912.                         }
  12913.                         break;
  12914.                     case 62:
  12915.                         switch ( tt_type ) {
  12916.                         case TT_VT220:
  12917.                         case TT_VT220PC:
  12918.                         case TT_VT320:
  12919.                         case TT_VT320PC:
  12920.                         case TT_WY370:
  12921.                             tt_type_mode = tt_type;
  12922.                             break;
  12923.                         }
  12924.                         if ( k > 1 && pn[2] == 1 )
  12925.                             send_c1 = FALSE ; /* 7-bit cntrols */
  12926.                         else
  12927.                             send_c1 = TRUE ; /* 8-bit controls */
  12928.                         break;
  12929.                     case 63:
  12930.                         switch (tt_type) {
  12931.                         case TT_VT320:
  12932.                         case TT_VT320PC:
  12933.                         case TT_WY370:
  12934.                             tt_type_mode = tt_type ;
  12935.                             if ( k > 1 && pn[2] == 1 )
  12936.                                 send_c1 = FALSE ; /* 7-bit */
  12937.                             else
  12938.                                 send_c1 = TRUE ; /* 8-bit */
  12939.                         }
  12940.                         break;
  12941.                     }
  12942.                     ipadl25();
  12943.                     break;
  12944.                 case 'q':
  12945.                     /* DECSCA - Select Character Attributes */
  12946.                     if ( ISVT220(tt_type_mode) ) {
  12947.                         switch (pn[1]) {
  12948.                         case 0:  /* Reset all attributes */
  12949.                         case 2:  /* Designate character erasable */
  12950.                             attrib.unerasable = FALSE ;
  12951.                             break;
  12952.                         case 1:  /* Designate character unerasable */
  12953.                             attrib.unerasable = TRUE ;
  12954.                             break;
  12955.                         default:
  12956.                             break;
  12957.                         }
  12958.                     }
  12959.                     break;
  12960.                 case 'v':
  12961.                     if ( ISVT220(tt_type_mode) ) {
  12962.                         /* DECRQDE - Windows Reports */
  12963.                         char decrpde[32] ;
  12964.                         sprintf(decrpde,"[%d;%d;%d;%d;%d\"w",
  12965.                                  VscrnGetHeight(VTERM),
  12966.                                  VscrnGetWidth(VTERM),
  12967.                                  1,
  12968.                                  1,
  12969.                                  1);
  12970.                         sendescseq(decrpde);
  12971.                     }
  12972.                     break;
  12973.                 default:
  12974.                     break;
  12975.                 }
  12976.                 break;
  12977.             case '$':
  12978.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  12979.                 switch (achar) {
  12980.                 case '}':
  12981.                     /* DECSASD - Select Active Status Display */
  12982.                     setdecsasd( pn[1] );
  12983.                     break;
  12984.                 case '-': /* DEC VT320 */
  12985.                 case '~': /* WYSE 370  */
  12986.                     /* DECSSDT - Select Status Line Type */
  12987.                     setdecssdt( pn[1] );
  12988.                     break;
  12989.                 case '|':
  12990.                     /* DECSCPP - Set Columns Per Page */
  12991.                     tt_cols[VTERM] = pn[1];
  12992.                     VscrnSetWidth( VTERM, pn[1]);
  12993. #ifdef TCPSOCKET
  12994.                     if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  12995.                         tn_snaws();
  12996. #ifdef RLOGCODE
  12997.                         rlog_naws();
  12998. #endif /* RLOGCODE */
  12999. #ifdef SSHBUILTIN
  13000.                         ssh_snaws();
  13001. #endif /* SSHBUILTIN */
  13002.                     }
  13003. #endif /* TCPSOCKET */
  13004.                     break;
  13005.                 case 'p': {     /* DECRQM (from host) */
  13006.                     char buf[16] ;
  13007.                     if ( private ) {
  13008.                         switch ( pn[1] ) {
  13009.                         case 1: /* DECCKM */
  13010.                             pn[2] = (tt_arrow == TTK_APPL) ? 1 : 2 ;
  13011.                             break;
  13012.                         case 2: /* DECANM */
  13013.                             pn[2] = (tt_type_mode == tt_type_vt52) ?
  13014.                                 1 : 2 ;
  13015.                             break;
  13016.                         case 3: /* DECCOLM */
  13017.                             pn[2] = deccolm ? 1 : 2 ;
  13018.                             break;
  13019.                         case 4: /* DECSCLM */
  13020.                             pn[2] = (updmode == TTU_SMOOTH) ? 1 : 2 ;
  13021.                             break;
  13022.                         case 5: /* DECSCNM */
  13023.                             pn[2] = decscnm ? 1 : 2 ;
  13024.                             break;
  13025.                         case 6: /* DECOM */
  13026.                             pn[2] = relcursor ? 1 : 2 ;
  13027.                             break;
  13028.                         case 7: /* DECAWM */
  13029.                             pn[2] = tt_wrap ? 1 : 2 ;
  13030.                             break;
  13031.                         case 8: /* DECARM */
  13032.                             pn[2] = 3 ; /* permanently set */
  13033.                             break;
  13034.                         case 18: /* DECPFF */
  13035.                             pn[2] = xprintff ? 1 : 2 ;
  13036.                             break;
  13037.                         case 19: /* DECPEX */
  13038.                             pn[2] = !printregion ? 1 : 2 ;
  13039.                             break;
  13040.                         case 25: /* DECTCEM */
  13041.                             pn[2] = cursorena[VTERM] ? 1 : 2 ;
  13042.                             break;
  13043.                         case 42: /* DECNRCM */
  13044.                             pn[2] = decnrcm ? 1 : 2 ;
  13045.                             break;
  13046.                         case 66: /* DECNKM */
  13047.                             pn[2] = tt_keypad == TTK_APPL ? 1 : 2 ;
  13048.                             break;
  13049.                         case 67: /* DECBKM */
  13050.                             pn[2] = keymap[KEY_SCAN|8] == BS ? 1 : 2 ;
  13051.                             break;
  13052.                         case 68: /* DECKBUM */
  13053.                             pn[2] = 3 ; /* permanently set */
  13054.                             break;
  13055.                         default:
  13056.                             pn[2] = 0 ; /* Unrecognized mode */
  13057.                             break;
  13058.                         }
  13059.                         sprintf(buf,"[?%d;%d$y",pn[1],pn[2]);
  13060.                     }
  13061.                     else {
  13062.                         switch ( pn[1] ) {
  13063.                         case 2: /* KAM */
  13064.                             pn[2] = keylock ? 1 : 2 ;
  13065.                             break;
  13066.                         case 3: /* CRM */
  13067.                             pn[2] = crm ? 1 : 2 ;
  13068.                             break;
  13069.                         case 4: /* IRM */
  13070.                             pn[2] = insertmode ? 1 : 2 ;
  13071.                             break;
  13072.                         case 10: /* HEM */
  13073.                             pn[2] = 4 ; /* permanently reset */
  13074.                             break;
  13075.                         case 12: /* SRM */
  13076.                             pn[2] = !duplex ? 1 : 2 ;
  13077.                             break;
  13078.                         case 20: /* LNM */
  13079.                             pn[2] = tt_crd && tnlm ? 1 : 2 ;
  13080.                             break;
  13081.                         default:
  13082.                             pn[2] = 0 ; /* unrecognized mode */
  13083.                             break;
  13084.                         }
  13085.                         sprintf(buf,"[%d;%d$y",pn[1],pn[2]);
  13086.                     }
  13087.                     sendescseq(buf);
  13088.                 }
  13089.                 case 'R':
  13090.                     if ( ISBA80(tt_type_mode) && ansiext ) {
  13091.                         /* Reset virtual window to the background */
  13092.                     } else if ( ISSCO(tt_type_mode)) {
  13093.                         /* Delete lines - Alternate form of (CSI P1 M) */
  13094.                         for (i = 1; i <= pn[1]; ++i) {
  13095.                             VscrnScroll(VTERM,
  13096.                                          UPWARD,
  13097.                                          wherey[ VTERM] - 1,
  13098.                                          marginbot - 1,
  13099.                                          1,
  13100.                                          FALSE,
  13101.                                          SP);
  13102.                         }
  13103.                         VscrnIsDirty(VTERM);
  13104.                     }
  13105.                     break;
  13106.                 case 'r':       /* DECCARA - Change Attr in Rect Area */
  13107.                     if ( ISVT420(tt_type_mode) )
  13108.                     {
  13109.                         int w, h, x, y, z;
  13110.                         /*
  13111.                          * pn[1] - top-line border      default=1
  13112.                          * pn[2] - left-col border      default=1
  13113.                          * pn[3] - bottom-line border   default=last line
  13114.                          * pn[4] - right col border     default=last column
  13115.                          * pn[5] -> pn[k] attributes to change - default=0
  13116.                          *
  13117.                          *  0 - attributes off
  13118.                          *  1 - bold
  13119.                          *  4 - underline
  13120.                          *  5 - blink
  13121.                          *  7 - negative image
  13122.                          * 22 - no bold
  13123.                          * 24 - no underline
  13124.                          * 25 - no blink
  13125.                          * 27 - positive image
  13126.                          *
  13127.                          * decsace == FALSE, stream else rectangle
  13128.                          */
  13129.                         if ( k < 1 ) pn[1] = 1;
  13130.                         if ( k < 2 ) pn[2] = 1;
  13131.                         if ( k < 3 ) pn[3] = VscrnGetHeight(VTERM)
  13132.                              -(tt_status[VTERM]?1:0);
  13133.                         if ( k < 4 ) pn[4] = VscrnGetWidth(VTERM);
  13134.                         if ( k < 5 ) {
  13135.                             pn[5] = 0;
  13136.                             k = 5;
  13137.                         }
  13138.  
  13139.                         if ( pn[3] < pn[1] || pn[4] < pn[2] )
  13140.                             break;
  13141.  
  13142.                         w = pn[4] - pn[2] + 1;
  13143.                         h = pn[3] - pn[1] + 1;
  13144.  
  13145.                         if ( decsace ) {        /* rectangle */
  13146.                             for ( y=0; y<h; y++ ) {
  13147.                                 videoline * line = VscrnGetLineFromTop(VTERM,pn[1]+y-1);
  13148.                                 for ( x=0; x<w; x++ ) {
  13149.                                     for ( z=5; z<=k; z++ ) {
  13150.                                         USHORT a = line->vt_char_attrs[pn[2]+x-1];
  13151.                                         switch ( pn[z] ) {
  13152.                                         case 0:
  13153.                                             a = VT_CHAR_ATTR_NORMAL;
  13154.                                             break;
  13155.                                         case 1:
  13156.                                             a |= VT_CHAR_ATTR_BOLD;
  13157.                                             break;
  13158.                                         case 4:
  13159.                                             a |= VT_CHAR_ATTR_UNDERLINE;
  13160.                                             break;
  13161.                                         case 5:
  13162.                                             a |= VT_CHAR_ATTR_BLINK;
  13163.                                             break;
  13164.                                         case 7:
  13165.                                             a |= VT_CHAR_ATTR_REVERSE;
  13166.                                             break;
  13167.                                         case 22:
  13168.                                             a &= ~VT_CHAR_ATTR_BOLD;
  13169.                                             break;
  13170.                                         case 24:
  13171.                                             a &= ~VT_CHAR_ATTR_UNDERLINE;
  13172.                                             break;
  13173.                                         case 25:
  13174.                                             a &= ~VT_CHAR_ATTR_BLINK;
  13175.                                             break;
  13176.                                         case 27:
  13177.                                             a &= ~VT_CHAR_ATTR_REVERSE;
  13178.                                             break;
  13179.                                         }
  13180.                                         line->vt_char_attrs[pn[2]+x-1] = a;
  13181.                                     }
  13182.                                 }
  13183.                             }
  13184.                         } else {                /* stream */
  13185.                             for ( y=0; y<h; y++ ) {
  13186.                                 videoline * line = VscrnGetLineFromTop(VTERM,pn[1]+y-1);
  13187.                                 for ( x = (y==0 ? pn[2] - 1 : 0);
  13188.                                       x < ((y==h-1) ? pn[4] : VscrnGetWidth(VTERM));
  13189.                                       x++ ) {
  13190.                                     for ( z=5; z<=k; z++ ) {
  13191.                                         USHORT a = line->vt_char_attrs[x];
  13192.                                         switch ( pn[z] ) {
  13193.                                         case 0:
  13194.                                             a = VT_CHAR_ATTR_NORMAL;
  13195.                                             break;
  13196.                                         case 1:
  13197.                                             a |= VT_CHAR_ATTR_BOLD;
  13198.                                             break;
  13199.                                         case 4:
  13200.                                             a |= VT_CHAR_ATTR_UNDERLINE;
  13201.                                             break;
  13202.                                         case 5:
  13203.                                             a |= VT_CHAR_ATTR_BLINK;
  13204.                                             break;
  13205.                                         case 7:
  13206.                                             a |= VT_CHAR_ATTR_REVERSE;
  13207.                                             break;
  13208.                                         case 22:
  13209.                                             a &= ~VT_CHAR_ATTR_BOLD;
  13210.                                             break;
  13211.                                         case 24:
  13212.                                             a &= ~VT_CHAR_ATTR_UNDERLINE;
  13213.                                             break;
  13214.                                         case 25:
  13215.                                             a &= ~VT_CHAR_ATTR_BLINK;
  13216.                                             break;
  13217.                                         case 27:
  13218.                                             a &= ~VT_CHAR_ATTR_REVERSE;
  13219.                                             break;
  13220.                                         }
  13221.                                         line->vt_char_attrs[x] = a;
  13222.                                     }
  13223.                                 }
  13224.                             }
  13225.                         }
  13226.                         VscrnIsDirty(VTERM);
  13227.                     }
  13228.                     break;
  13229.                 case 't':       /* DECRARA - Reverse Attr in Rect Area */
  13230.                     if ( ISVT420(tt_type_mode) )
  13231.                     {
  13232.                         int w, h, x, y, z;
  13233.                         /*
  13234.                          * pn[1] - top-line border      default=1
  13235.                          * pn[2] - left-col border      default=1
  13236.                          * pn[3] - bottom-line border   default=last line
  13237.                          * pn[4] - right col border     default=last column
  13238.                          * pn[5] -> pn[k] attributes to change - default=0
  13239.                          *
  13240.                          *  0 - reverse all attributes
  13241.                          *  1 - reverse bold
  13242.                          *  4 - reverse underline
  13243.                          *  5 - reverse blink
  13244.                          *  7 - reverse negative image
  13245.                          *
  13246.                          * decsace == FALSE, stream else rectangle
  13247.                          */
  13248.  
  13249.                         if ( k < 1 ) pn[1] = 1;
  13250.                         if ( k < 2 ) pn[2] = 1;
  13251.                         if ( k < 3 ) pn[3] = VscrnGetHeight(VTERM)
  13252.                              -(tt_status[VTERM]?1:0);
  13253.                         if ( k < 4 ) pn[4] = VscrnGetWidth(VTERM);
  13254.                         if ( k < 5 ) {
  13255.                             pn[5] = 0;
  13256.                             k = 5;
  13257.                         }
  13258.  
  13259.                         if ( pn[3] < pn[1] || pn[4] < pn[2] )
  13260.                             break;
  13261.  
  13262.                         w = pn[4] - pn[2] + 1;
  13263.                         h = pn[3] - pn[1] + 1;
  13264.  
  13265.                         if ( decsace ) {        /* rectangle */
  13266.                             for ( y=0; y<h; y++ ) {
  13267.                                 videoline * line = VscrnGetLineFromTop(VTERM,pn[1]+y-1);
  13268.                                 for ( x=0; x<w; x++ ) {
  13269.                                     for ( z=5; z<=k; z++ ) {
  13270.                                         USHORT a = line->vt_char_attrs[pn[2]+x-1];
  13271.                                         if (pn[z] == 0 || pn[z] == 1) {
  13272.                                             if ( a & VT_CHAR_ATTR_BOLD )
  13273.                                                 a &= ~VT_CHAR_ATTR_BOLD;
  13274.                                             else
  13275.                                                 a |= VT_CHAR_ATTR_BOLD;
  13276.                                         }
  13277.                                         if (pn[z] == 0 || pn[z] == 4) {
  13278.                                             if ( a & VT_CHAR_ATTR_UNDERLINE )
  13279.                                                 a &= ~VT_CHAR_ATTR_UNDERLINE;
  13280.                                             else
  13281.                                                 a |= VT_CHAR_ATTR_UNDERLINE;
  13282.                                         }
  13283.                                         if (pn[z] == 0 || pn[z] == 5) {
  13284.                                             if ( a & VT_CHAR_ATTR_BLINK )
  13285.                                                 a &= ~VT_CHAR_ATTR_BLINK;
  13286.                                             else
  13287.                                                 a |= VT_CHAR_ATTR_BLINK;
  13288.                                         }
  13289.                                         if (pn[z] == 0 || pn[z] == 7) {
  13290.                                             if ( a & VT_CHAR_ATTR_REVERSE )
  13291.                                                 a &= ~VT_CHAR_ATTR_REVERSE;
  13292.                                             else
  13293.                                                 a |= VT_CHAR_ATTR_REVERSE;
  13294.                                         }
  13295.                                         line->vt_char_attrs[pn[2]+x-1] = a;
  13296.                                     }
  13297.                                 }
  13298.                             }
  13299.                         } else {                /* stream */
  13300.                             for ( y=0; y<h; y++ ) {
  13301.                                 videoline * line = VscrnGetLineFromTop(VTERM,pn[1]+y-1);
  13302.                                 for ( x = (y==0 ? pn[2] - 1 : 0);
  13303.                                       x < ((y==h-1) ? pn[4] : VscrnGetWidth(VTERM));
  13304.                                       x++ ) {
  13305.                                     for ( z=5; z<=k; z++ ) {
  13306.                                         USHORT a = line->vt_char_attrs[x];
  13307.                                         if (pn[z] == 0 || pn[z] == 1) {
  13308.                                             if ( a & VT_CHAR_ATTR_BOLD )
  13309.                                                 a &= ~VT_CHAR_ATTR_BOLD;
  13310.                                             else
  13311.                                                 a |= VT_CHAR_ATTR_BOLD;
  13312.                                         }
  13313.                                         if (pn[z] == 0 || pn[z] == 4) {
  13314.                                             if ( a & VT_CHAR_ATTR_UNDERLINE )
  13315.                                                 a &= ~VT_CHAR_ATTR_UNDERLINE;
  13316.                                             else
  13317.                                                 a |= VT_CHAR_ATTR_UNDERLINE;
  13318.                                         }
  13319.                                         if (pn[z] == 0 || pn[z] == 5) {
  13320.                                             if ( a & VT_CHAR_ATTR_BLINK )
  13321.                                                 a &= ~VT_CHAR_ATTR_BLINK;
  13322.                                             else
  13323.                                                 a |= VT_CHAR_ATTR_BLINK;
  13324.                                         }
  13325.                                         if (pn[z] == 0 || pn[z] == 7) {
  13326.                                             if ( a & VT_CHAR_ATTR_REVERSE )
  13327.                                                 a &= ~VT_CHAR_ATTR_REVERSE;
  13328.                                             else
  13329.                                                 a |= VT_CHAR_ATTR_REVERSE;
  13330.                                         }
  13331.                                         line->vt_char_attrs[x] = a;
  13332.                                     }
  13333.                                 }
  13334.                             }
  13335.                         }
  13336.                         VscrnIsDirty(VTERM);
  13337.                     }
  13338.                     break;
  13339.                 case 'v':       /* DECCRA - Copy Rect Area */
  13340.                     if ( ISVT420( tt_type_mode) )
  13341.                     {
  13342.                         USHORT * data = NULL;
  13343.                         int w, h, x, y;
  13344.  
  13345.                         /* Area to be copied:
  13346.                          * pn[1] - top-line border      default=1
  13347.                          * pn[2] - left-col border      default=1
  13348.                          * pn[3] - bottom-line border   default=last line
  13349.                          * pn[4] - right col border     default=last column
  13350.                          * pn[5] - page number          default=1
  13351.                          * Destination
  13352.                          * pn[6] - top-line border      default=1
  13353.                          * pn[7] - left-col border      default=1
  13354.                          * pn[8] - page number          default=1
  13355.                          *
  13356.                          * if pn[3] > pn[1] or pn[2] > pn[4] ignore
  13357.                          * coordinates are relative to DECOM setting
  13358.                          * not affected by page margins
  13359.                          * copy text, not attributes, destination attributes remain
  13360.                          * page becomes last available page if too large
  13361.                          * if destination is off page, clip off page data
  13362.                          */
  13363.                         if ( k < 1 ) pn[1] = 1;
  13364.                         if ( k < 2 ) pn[2] = 1;
  13365.                         if ( k < 3 ) pn[3] = VscrnGetHeight(VTERM)
  13366.                              -(tt_status[VTERM]?1:0);
  13367.                         if ( k < 4 ) pn[4] = VscrnGetWidth(VTERM);
  13368.                         if ( k < 5 ) pn[5] = 1;
  13369.                         if ( k < 6 ) pn[6] = 1;
  13370.                         if ( k < 7 ) pn[7] = 1;
  13371.                         if ( k < 8 ) pn[8] = 1;
  13372.                         k = 8;
  13373.  
  13374.                         if ( pn[3] < pn[1] || pn[4] < pn[2] )
  13375.                             break;
  13376.  
  13377.                         /* we ignore pages, since we only support one */
  13378.  
  13379.                         w = pn[4] - pn[2] + 1;
  13380.                         h = pn[3] - pn[1] + 1;
  13381.                         data = malloc(sizeof(USHORT) * w * h);
  13382.                         if ( !data )
  13383.                             break;
  13384.                         for ( y=0; y<h; y++ ) {
  13385.                             videoline * line = VscrnGetLineFromTop(VTERM,pn[1]+y-1);
  13386.                             for ( x=0; x<w; x++ ) {
  13387.                                 data[y*w + x] = line->cells[pn[2]+x-1].c;
  13388.                             }
  13389.                         }
  13390.  
  13391.                         for ( y=0; y<h; y++ ) {
  13392.                             videoline * line = VscrnGetLineFromTop(VTERM,pn[6]+y-1);
  13393.                             for ( x=0; x<w && (pn[7]+x <= VscrnGetWidth(VTERM)); x++ ) {
  13394.                                 line->cells[pn[7]+x-1].c = data[y*w + x];
  13395.                             }
  13396.                         }
  13397.                         free(data);
  13398.                         VscrnIsDirty(VTERM);
  13399.                     }
  13400.                     break;
  13401.                 case 'x':       /* DECFRA - Fill Rect Area */
  13402.                     if ( ISVT420(tt_type_mode) ) {
  13403.                         /* pn[1] - fill char                 */
  13404.                         /* pn[2] - top-line border default=1 */
  13405.                         /* pn[3] - left-col border default=1 */
  13406.                         /* pn[4] - bot-line border default=Height */
  13407.                         /* pn[5] - Right border    default=Width */
  13408.                         if ( k < 5 || pn[5] > VscrnGetWidth(VTERM) ||
  13409.                              pn[5] < 1 )
  13410.                             pn[4] = VscrnGetWidth(VTERM);
  13411.                         if ( k < 4 || pn[4] > VscrnGetHeight(VTERM)
  13412.                              -(tt_status[VTERM]?1:0) || pn[4] < 1 )
  13413.                             pn[4] = VscrnGetHeight(VTERM)
  13414.                                 -(tt_status[VTERM]?1:0);
  13415.                         if ( k < 3 || pn[3] < 1 )
  13416.                             pn[3] = 1 ;
  13417.                         if ( k < 2 || pn[2] < 1 )
  13418.                             pn[2] = 1 ;
  13419.                         if ( k < 1 )
  13420.                             pn[1] = SP ;
  13421.                         clrrect_escape( VTERM, pn[2], pn[3],
  13422.                                         pn[4], pn[5], pn[1] ) ;
  13423.                         VscrnIsDirty(VTERM);
  13424.                     }
  13425.                     break;
  13426.                 case 'z':       /* DECERA - Erase Rect Area */
  13427.                     if ( ISVT420(tt_type_mode) ) {
  13428.                         /* pn[1] - top-line border default=1 */
  13429.                         /* pn[2] - left-col border default=1 */
  13430.                         /* pn[3] - bot-line border default=Height */
  13431.                         /* pn[4] - Right border    default=Width */
  13432.                         if ( k < 4 || pn[4] > VscrnGetWidth(VTERM) ||
  13433.                              pn[4] < 1 )
  13434.                             pn[4] = VscrnGetWidth(VTERM);
  13435.                         if ( k < 3 || pn[3] > VscrnGetHeight(VTERM)
  13436.                              -(tt_status[VTERM]?1:0) || pn[3] < 1 )
  13437.                             pn[3] = VscrnGetHeight(VTERM)
  13438.                                 -(tt_status[VTERM]?1:0);
  13439.                         if ( k < 2 || pn[2] < 1 )
  13440.                             pn[2] = 1 ;
  13441.                         if ( k < 1 || pn[1] < 1 )
  13442.                             pn[1] = 1 ;
  13443.                         clrrect_escape( VTERM, pn[1], pn[2],
  13444.                                         pn[3], pn[4], SP ) ;
  13445.                         VscrnIsDirty(VTERM);
  13446.                     }
  13447.                     break;
  13448.                 case '{':       /* DECSERA - Selective Erase Rect Area */
  13449.                     if ( ISVT420(tt_type_mode) ) {
  13450.                         /* pn[1] - top-line border default=1 */
  13451.                         /* pn[2] - left-col border default=1 */
  13452.                         /* pn[3] - bot-line border default=Height */
  13453.                         /* pn[4] - Right border    default=Width */
  13454.                         if ( k < 4 || pn[4] > VscrnGetWidth(VTERM) ||
  13455.                              pn[4] < 1 )
  13456.                             pn[4] = VscrnGetWidth(VTERM);
  13457.                         if ( k < 3 || pn[3] > VscrnGetHeight(VTERM)
  13458.                              -(tt_status[VTERM]?1:0) || pn[3] < 1 )
  13459.                             pn[3] = VscrnGetHeight(VTERM)
  13460.                                 -(tt_status[VTERM]?1:0);
  13461.                         if ( k < 2 || pn[2] < 1 )
  13462.                             pn[2] = 1 ;
  13463.                         if ( k < 1 || pn[1] < 1 )
  13464.                             pn[1] = 1 ;
  13465.                         selclrrect_escape( VTERM, pn[1], pn[2],
  13466.                                         pn[3], pn[4], SP ) ;
  13467.                         VscrnIsDirty(VTERM);
  13468.                     }
  13469.                     break;
  13470.                 }
  13471.                 break;
  13472.             case '*':
  13473.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  13474.                 switch (achar) {
  13475.                 case 'x':       /* DECSACE - Select Attribute Change Extent */
  13476.                     if ( ISVT420(tt_type_mode) )
  13477.                     {
  13478.                         /*
  13479.                          * 0 - DECCARA or DECRARA affect the stream of character
  13480.                                positions that begins with the first position specified
  13481.                                in the DECCARA or DECRARA command, and ends with the
  13482.                                second character position specified. (default)
  13483.                          * 1 - Same as 0.
  13484.                          * 2 - DECCARA or DECRARA affect all characters positions in
  13485.                                the rectangular area.  The DECCARA or DECRARA command
  13486.                                specifies the top-left and bottom-right corners.
  13487.                          */
  13488.                         if ( pn[1] == 0 || pn[1] == 1 )
  13489.                             decsace = FALSE;
  13490.                         else if ( pn[1] == 2 )
  13491.                             decsace = TRUE;
  13492.                     }
  13493.                     break;
  13494.                 }
  13495.                 break;
  13496.             case '`':
  13497.                 /* Horizontal Position Absolute (HPA) */
  13498.                 /* moves active position to column pn[1] */
  13499.                 if ( decsasd == SASD_STATUS )
  13500.                     lgotoxy( VSTATUS, pn[1], 1 );
  13501.                 else
  13502.                     lgotoxy( VTERM, pn[1], wherey[VTERM] ) ;
  13503.                 break;
  13504.             case 'A':
  13505.                 /* ANSI - Set Border Color */
  13506.                 if ( ansiext ) {
  13507.                     if (ISANSI(tt_type_mode)) {
  13508.                         /* pn[1] contains new color */
  13509.                         if ( !sgrcolors )
  13510.                             break;
  13511.                         borderattribute = sgrcols[pn[1]%10];
  13512.                         setborder();
  13513.                     }
  13514.                     else if ( ISBA80(tt_type_mode) ) {
  13515.                         switch ( pn[1] ) {
  13516.                         case 0:
  13517.                             /* Dead Key Mode Off */
  13518.                             break;
  13519.                         case 1:
  13520.                             /* Dead Key Mode On */
  13521.                             break;
  13522.                         case 2:
  13523.                             /* Block Start */
  13524.                             break;
  13525.                         case 3:
  13526.                             /* Block End */
  13527.                             break;
  13528.                         }
  13529.                     }
  13530.                 }
  13531.                 else { /* CUU - Cursor up Pn lines */
  13532.                     if ( IS97801(tt_type_mode) ) {
  13533.                         /* ignored if outside scroll region */
  13534.                         if ( wherey[VTERM] < margintop ||
  13535.                              wherey[VTERM] > marginbot )
  13536.                             break;
  13537.                     }
  13538.                     do {
  13539.                         cursorup(0);
  13540.                         if ( tt_type_mode != TT_ANSI &&
  13541.                              tt_type_mode != TT_SCOANSI &&
  13542.                              tt_type_mode != TT_AT386 )
  13543.                             wrapit = FALSE;
  13544.                         pn[1] = pn[1] - 1;
  13545.                     } while (!(pn[1] <= 0));
  13546.                 }
  13547.                 break;
  13548.             case 'a':
  13549.                 /* Horizontal Position Relative */
  13550.                 /* moves active position pn[1] characters */
  13551.                 /* to the right */
  13552.                 do {
  13553.                     cursorright(0);
  13554.                     pn[1] = pn[1] - 1;
  13555.                 } while (pn[1] > 0);
  13556.                 break;
  13557.             case 'B':
  13558.                 if ( ansiext ) {
  13559.                     /* ANSI - Set Beep Freq/Duration */
  13560.                     if ( ISANSI( tt_type_mode ) ) {
  13561.                         beepfreq = pn[1] ; /* ??? this isn't correct */
  13562.                         beeptime = pn[2] * 100 ;
  13563.                     }
  13564.                     else if ( ISBA80(tt_type_mode) ) {
  13565.                         switch ( pn[1] ) {
  13566.                         case 0:
  13567.                             /* Cursor Off */
  13568.                             cursorena[VTERM] = TRUE;
  13569.                             break;
  13570.                         case 1:
  13571.                             /* Cursor On */
  13572.                             cursorena[VTERM] = FALSE;
  13573.                             break;
  13574.                         case 2:
  13575.                             /* Alternate Cursor */
  13576.                             tt_cursor = TTC_BLOCK ;
  13577.                             setcursormode();
  13578.                             cursorena[VTERM] = TRUE ;
  13579.                             break;
  13580.                         case 3:
  13581.                             /* Normal Cursor */
  13582.                             tt_cursor = TTC_ULINE ;
  13583.                             setcursormode();
  13584.                             cursorena[VTERM] = TRUE ;
  13585.                             break;
  13586.                         }
  13587.                     }
  13588.                 }
  13589.                 else {  /* CUD - Cursor down pn lines */
  13590.                     if ( IS97801(tt_type_mode) ) {
  13591.                         /* ignored if outside scroll region */
  13592.                         if ( wherey[VTERM] < margintop ||
  13593.                              wherey[VTERM] > marginbot )
  13594.                             break;
  13595.                     }
  13596.                     do {
  13597.                         cursordown(0);
  13598.                         if ( !ISANSI( tt_type_mode ) ||
  13599.                              ISLINUX(tt_type_mode))
  13600.                             wrapit = FALSE;
  13601.                         pn[1] = pn[1] - 1;
  13602.                     } while (!(pn[1] <= 0));
  13603.                 }
  13604.                 break;
  13605.             case 'b':
  13606.                 /* QANSI - Repeat previous character Pn times */
  13607.                 if ( ISQANSI(tt_type_mode) ) {
  13608.                     while ( pn[1] ) {
  13609.                         wrtch(prevchar);
  13610.                         pn[1] = pn[1] - 1;
  13611.                     }
  13612.                 } else if ( ISSCO(tt_type_mode) ||
  13613.                             ISAAA(tt_type_mode)) {
  13614.                     /* HPR - Horizontal Position Relative */
  13615.                     while ( pn[2] ) {
  13616.                         wrtch(pn[1]);
  13617.                         pn[2] = pn[2] - 1;
  13618.                     }
  13619.                 }
  13620.                 break;
  13621.             case 'C':
  13622.                 if ( ISBA80(tt_type_mode) && ansiext ) {
  13623.                     /* Close Virtual Window */
  13624.                     /* close the current virtual window */
  13625.                 }
  13626.                 /* ANSI - Set Cursor Height */
  13627.                 if ( ISANSI( tt_type_mode ) &&
  13628.                      ansiext ) {
  13629.                     debug(F111,"ANSI-SetCursor","start",pn[1]);
  13630.                     debug(F111,"ANSI-SetCursor","end",pn[2]);
  13631.                     if ( pn[1] > pn[2] ) {
  13632.                         cursorena[VTERM] = FALSE ;
  13633.                     }
  13634.                     else {
  13635.                         if ( pn[2]-pn[1] <= 1 )
  13636.                             tt_cursor = TTC_ULINE ;
  13637.                         else if ( pn[2]-pn[1] < 10 )
  13638.                             tt_cursor = TTC_HALF ;
  13639.                         else
  13640.                             tt_cursor = TTC_BLOCK ;
  13641.                         setcursormode();
  13642.                         cursorena[VTERM] = TRUE ;
  13643.                     }
  13644.                 }
  13645.                 else  /* CUF - Cursor right pn chars */
  13646.                     do {
  13647.                         cursorright(0);
  13648.                         pn[1] = pn[1] - 1;
  13649.                     } while (pn[1] > 0);
  13650.                 break;
  13651.             case 'c':
  13652.                 if ( zdsext && ISVT220(tt_type) ) {
  13653.                     /* Secondary Device Attributes Report Request */
  13654.                     if (pn[1] == 0) {
  13655.                         sendescseq("[>24;0;0c");
  13656.                     }
  13657.                 }
  13658.                 else if ( ansiext && ISVT220(tt_type) ) {
  13659.                     /* Tertiary Device Attributes Report Request */
  13660.                     if (pn[1] == 0) {
  13661.                         char DECRPTUI[24] ;
  13662.                         sprintf(DECRPTUI,"P!|00000000%c\\",ESC);
  13663.                         sendescseq(DECRPTUI);
  13664.                     }
  13665.                 }
  13666.                 else if ( IS97801(tt_type_mode) ) {
  13667.                     /* Reset to Initial State */
  13668.                     if ( debses )
  13669.                         break;
  13670.                     doreset(1);
  13671.                 }
  13672.                 else if ( ansiext && ISSCO(tt_type_mode) ||
  13673.                           ISANSI( tt_type_mode ) ) {
  13674.                     /* Set Cursor Type */
  13675.                     /* pn[1] = 0 - underline */
  13676.                     /* pn[1] = 1 - block     */
  13677.                     /* pn[1] = 2 - no cursor */
  13678.                     debug(F111,"CSI c","SetCursorType",pn[1]);
  13679.                     switch ( pn[1] ) {
  13680.                     case 0:
  13681.                         tt_cursor = TTC_ULINE ;
  13682.                         cursorena[VTERM] = TRUE;
  13683.                         break;
  13684.                     case 1:
  13685.                         tt_cursor = TTC_BLOCK ;
  13686.                         cursorena[VTERM] = TRUE ;
  13687.                         break;
  13688.                     case 2:
  13689.                         cursorena[VTERM] = FALSE ;
  13690.                         break;
  13691.                     }
  13692.                     setcursormode() ;
  13693.                 }
  13694.                 else if ( private && ISLINUX(tt_type_mode) ) {
  13695.                     /* Set Cursor Type */
  13696. #ifdef COMMENT
  13697.   VGA-softcursor.txt, from the 2.2 kernel
  13698.  
  13699.   Software cursor for VGA    by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>
  13700.   =======================    and Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  13701.  
  13702.      Linux now has some ability to manipulate cursor appearance. Normally, you
  13703.   can set the size of hardware cursor (and also work around some ugly bugs in
  13704.   those miserable Trident cards--see #define TRIDENT_GLITCH in drivers/video/
  13705.   vgacon.c). You can now play a few new tricks:  you can make your cursor look
  13706.   like a non-blinking red block, make it inverse background of the character it's
  13707.   over or to highlight that character and still choose whether the original
  13708.   hardware cursor should remain visible or not.  There may be other things I have
  13709.   never thought of.
  13710.  
  13711.      The cursor appearance is controlled by a "<ESC>[?1;2;3c" escape sequence
  13712.   where 1, 2 and 3 are parameters described below. If you omit any of them,
  13713.   they will default to zeroes.
  13714.  
  13715.      Parameter 1 specifies cursor size (0=default, 1=invisible, 2=underline, ...,
  13716.   8=full block) + 16 if you want the software cursor to be applied + 32 if you
  13717.   want to always change the background color + 64 if you dislike having the
  13718.   background the same as the foreground.  Highlights are ignored for the last two
  13719.   flags.
  13720.  
  13721.      The second parameter selects character attribute bits you want to change
  13722.   (by simply XORing them with the value of this parameter). On standard VGA,
  13723.   the high four bits specify background and the low four the foreground. In both
  13724.   groups, low three bits set color (as in normal color codes used by the console)
  13725.   and the most significant one turns on highlight (or sometimes blinking--it
  13726.   depends on the configuration of your VGA).
  13727.  
  13728.      The third parameter consists of character attribute bits you want to set.
  13729.   Bit setting takes place before bit toggling, so you can simply clear a bit by
  13730.   including it in both the set mask and the toggle mask.
  13731.  
  13732.   Examples:
  13733.   =========
  13734.  
  13735.   To get normal blinking underline, use: echo -e '\033[?2c'
  13736.   To get blinking block, use:            echo -e '\033[?6c'
  13737.   To get red non-blinking block, use:    echo -e '\033[?17;0;64c'
  13738. #endif /* COMMENT */
  13739.                     debug(F111,"CSI ? c","SetCursorType pn[1]",pn[1]);
  13740.                     debug(F111,"CSI ? c","SetCursorType pn[2]",pn[2]);
  13741.                     debug(F111,"CSI ? c","SetCursorType pn[3]",pn[3]);
  13742.                     switch ( pn[1] & 0x0F ) {
  13743.                     case 0:
  13744.                     case 2:
  13745.                         tt_cursor = TTC_ULINE ;
  13746.                         cursorena[VTERM] = TRUE;
  13747.                         break;
  13748.                     case 3:
  13749.                     case 4:
  13750.                     case 5:
  13751.                     case 6:
  13752.                     case 7:
  13753.                         tt_cursor = TTC_HALF ;
  13754.                         cursorena[VTERM] = TRUE ;
  13755.                         break;
  13756.                     case 8:
  13757.                         tt_cursor = TTC_BLOCK ;
  13758.                         cursorena[VTERM] = TRUE ;
  13759.                         break;
  13760.                     case 1:
  13761.                         cursorena[VTERM] = FALSE ;
  13762.                         break;
  13763.                     }
  13764.                     setcursormode() ;
  13765.                     break;
  13766.                 } else { /* DA - Device Attributes */
  13767.                     if (pn[1] == 0)
  13768.                         if (tt_type >= 0 &&
  13769.                              tt_type <= max_tt) {
  13770.                             sendescseq(tt_info[tt_type].x_id);
  13771.                         }
  13772.                     }
  13773.                     break;
  13774.             case 'D':
  13775.                 /* ANSI - Turn on/off Background Intensity */
  13776.                 if ( ISANSI( tt_type_mode ) &&
  13777.                      ansiext ) {
  13778.                     if ( !pn[1] && !bgi ||
  13779.                          pn[1] && bgi ) {
  13780.                         attribute |= 0x80 ;
  13781.                         defaultattribute |= 0x80 ;
  13782.                     }
  13783.                     else
  13784.                     {
  13785.                         attribute &= 0x7F ;
  13786.                         defaultattribute &= 0x7F ;
  13787.                     }
  13788.                 }
  13789.                 else  /* CUB - Cursor Left pn characters */
  13790.                     do {
  13791.                         cursorleft(0);
  13792.                         pn[1] = pn[1] - 1;
  13793.                     } while (pn[1] > 0);
  13794.                 break;
  13795.             case 'd':
  13796.                 /* VPA - Vertical Position Absolute */
  13797.                 /* moves active position to row pn[1] */
  13798.                 if ( decsasd == SASD_TERMINAL )
  13799.                     lgotoxy( VTERM, wherex[VTERM], pn[1] ) ;
  13800.                 break;
  13801.             case 'E':
  13802.                 if ( ISBA80(tt_type_mode) && ansiext ) {
  13803.                     /* Window Status Request */
  13804.                     char buf[64];
  13805.                     sprintf(buf,"%c[=D%3d:%3d;001:001;Lohn    D",
  13806.                              27,VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0),
  13807.                              VscrnGetWidth(VTERM));
  13808.                         ttol(buf,strlen(buf));
  13809.                 }
  13810.                 /* ANSI - TRUE BLINK vs Bold Background Intensity */
  13811.                 if ( ISANSI( tt_type_mode ) &&
  13812.                      ansiext ) {
  13813.                     if ( !pn[1] )
  13814.                     {
  13815.                         /* use TRUE BLINK - default */
  13816.                         trueblink = TRUE ;
  13817.                     }
  13818.                     else
  13819.                     {
  13820.                         /* use Bold Background Intensity */
  13821.                         trueblink = FALSE ;
  13822.                     }
  13823.                 }
  13824.                 else {
  13825.                     /* CNL - Cursor next line */
  13826.                     /* moves active position pn[1] rows down */
  13827.                     do {
  13828.                         cursornextline();
  13829.                         pn[1] = pn[1] - 1;
  13830.                     } while (pn[1] > 0);
  13831.                 }
  13832.                 break;
  13833.             case 'e':
  13834.                 /* VPR - Vertical Position Relative */
  13835.                 /* moves active position pn[1] rows down */
  13836.                 do {
  13837.                     cursordown(0);
  13838.                     pn[1] = pn[1] - 1;
  13839.                 } while (pn[1] > 0);
  13840.                 break;
  13841.             case 'F':
  13842.                 if ( ISBA80(tt_type_mode) && ansiext ) {
  13843.                     /* Fetch virtual window from the background */
  13844.                 }
  13845.                 /* ANSI - Set Normal Foreground Color */
  13846.                 if (( ISANSI( tt_type_mode ) ||
  13847.                       ISQANSI(tt_type_mode)) &&
  13848.                      ansiext ) {
  13849.                     /* pn[1] contains new color */
  13850.                     l = pn[1];
  13851.                     if (decscnm
  13852. #ifdef COMMENT
  13853.                          && !attrib.reversed ||
  13854.                          !decscnm && attrib.reversed
  13855. #endif
  13856.                          ) {
  13857.                         i = (defaultattribute & 0xF0);
  13858.                         attribute = defaultattribute = (i | (l << 4));
  13859.  
  13860.                     }
  13861.                     else {
  13862.                         i = (defaultattribute & 0xF0);
  13863.                         attribute = defaultattribute = (i | l);
  13864.                     }
  13865.                 }
  13866.                 else {
  13867.                     /* CPL - Cursor Previous Line */
  13868.                     /* moves active position pn[1] rows up */
  13869.                     /* in the first column */
  13870.                     do {
  13871.                         cursorprevline();
  13872.                         pn[1] = pn[1] - 1;
  13873.                     } while (pn[1] > 0);
  13874.                 }
  13875.                 break;
  13876.             case 'G':
  13877.                 /* ANSI - Set Normal Background Color */
  13878.                 if ( ansiext &&
  13879.                      (ISANSI( tt_type_mode ) || ISQANSI(tt_type_mode)) ) {
  13880.                     /* pn[1] contains new color */
  13881.                     l = pn[1];
  13882.                     if (!decscnm
  13883. #ifdef COMMENT
  13884.                          && !attrib.reversed ||
  13885.                          decscnm && attrib.reversed
  13886. #endif
  13887.                          ) {
  13888.                         i = (defaultattribute & 0x0F);
  13889.                         attribute = defaultattribute = (i | (l << 4));
  13890.                     }
  13891.                     else {
  13892.                         i = (defaultattribute & 0x0F);
  13893.                         attribute = defaultattribute = (i | l);
  13894.                     }
  13895.                 }
  13896.                 else {
  13897.                     /* CHA - Cursor Horizontal Absolute */
  13898.                     if ( ISHFT(tt_type_mode) ||
  13899.                          ISLINUX(tt_type_mode) ||
  13900.                          ISQANSI(tt_type_mode) ||
  13901.                          ISANSI(tt_type_mode)) {
  13902.                         if ( pn[1] < 1 || pn[1] > VscrnGetWidth(VTERM) )
  13903.                             break;
  13904.                         lgotoxy(VTERM,pn[1],wherey[VTERM]);
  13905.                     }
  13906.                 }
  13907.                 break;
  13908.             case 'H':
  13909.                 /* ANSI - Set Reverse Foreground Color */
  13910.                 if ( ISANSI( tt_type_mode ) &&
  13911.                      ansiext ) {
  13912.                     /* pn[1] contains new color */
  13913.                     l = pn[1];
  13914.                     i = (reverseattribute & 0xF0);
  13915.                     reverseattribute = (i | l);
  13916.                     break;
  13917.                 }
  13918.                 /* 'H' is also CUP - Direct cursor address for */
  13919.                 /* !ansiext, so don't put a break here   */
  13920.             case 'f':   /* HVP - Direct cursor address */
  13921.                 if ( IS97801(tt_type_mode) && decsasd == SASD_STATUS )
  13922.                     setdecsasd(SASD_TERMINAL);
  13923.  
  13924.                 if (pn[1] == 0)
  13925.                     pn[1] = 1;
  13926.                 if (relcursor)
  13927.                     pn[1] += margintop - 1;
  13928.                 if (pn[1] > VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0))
  13929.                     pn[1] = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  13930.                 if (pn[2] == 0)
  13931.                     pn[2] = 1;
  13932.                 if (isdoublewidth(pn[1])) {
  13933.                     if (pn[2] > VscrnGetWidth(VTERM)/2)
  13934.                         pn[2] = VscrnGetWidth(VTERM)/2;
  13935.                     }
  13936.                     else if (pn[2] > VscrnGetWidth(VTERM))
  13937.                         pn[2] = VscrnGetWidth(VTERM);
  13938.                     wrapit = FALSE;
  13939.  
  13940.                 /* SNI 97801 - If the cursor is addressed to the */
  13941.                 /* status line when SSDT_HOST_WRITABLE, we must  */
  13942.                 /* enter SASD_STATUS mode                        */
  13943.                 if ( IS97801(tt_type_mode) ) {
  13944.                     if ( pn[1] == VscrnGetHeight(VTERM) &&
  13945.                          decsasd != SASD_STATUS ) {
  13946.                         if ( decssdt == SSDT_INDICATOR )
  13947.                             setdecssdt(SSDT_HOST_WRITABLE);
  13948.                         setdecsasd(SASD_STATUS);
  13949.                     }
  13950.                 }
  13951.  
  13952.                 if ( decsasd == SASD_STATUS )
  13953.                     lgotoxy( VSTATUS, pn[2], 1 );
  13954.                 else
  13955.                     lgotoxy(VTERM, pn[2], pn[1]);
  13956.                 break;
  13957.             case 'I':
  13958.                 if ( ansiext && private ) {
  13959.                     if ( ISBA80(tt_type_mode) ) {
  13960.                         /* Screen Saver Off */
  13961.                     }
  13962.                 }
  13963.                 else if ( ansiext ) {
  13964.                     if ( ISBA80(tt_type_mode) ) {
  13965.                         /* Input */
  13966.                     }
  13967.                     /* ANSI - Set Reverse Background Color */
  13968.                     if ( ISANSI( tt_type_mode ) )
  13969.                     {
  13970.                         /* pn[1] contains new color */
  13971.                         l = pn[1];
  13972.                         i = (reverseattribute & 0x0F);
  13973.                         reverseattribute = (i | (l << 4));
  13974.                     }
  13975.                 }
  13976.                 else {
  13977.                     /* CHT - Cursor Horizontal Tab */
  13978.                     if ( k < 1 )
  13979.                         pn[1] = 1;
  13980.                     i = wherex[VTERM];
  13981.                     while ( pn[1] ) {
  13982.                         if (i < VscrnGetWidth(VTERM))
  13983.                         {
  13984.                             do {
  13985.                                 i++;
  13986.                                 cursorright(0);
  13987.                             } while ((htab[i] != 'T') &&
  13988.                                       (i <= VscrnGetWidth(VTERM)-1));
  13989.                         }
  13990.                         pn[1]--;
  13991.                     }
  13992.                     VscrnIsDirty(VTERM);
  13993.                 }
  13994.                 break;
  13995.             case 'g':
  13996.                 /* ANSI - Display Graphic Character */
  13997.                 if ( ISSCO(tt_type_mode) && !scoBCS2 ||
  13998.                      ISANSI( tt_type_mode ) &&
  13999.                      ansiext ) {
  14000.                     /* pn[1] contains a graphic Character
  14001.                     to display */
  14002.                     unsigned char a = attribute ;
  14003.                     int eight = sco8bit ;
  14004.                     int c = crm ;
  14005.                     struct _vtG * g = GR ;
  14006.  
  14007.                     attribute = graphicattribute ;
  14008.                     sco8bit = FALSE ;
  14009.                     crm = TRUE;
  14010.                     GR = &G[2];
  14011.  
  14012.                     wrtch( pn[1] ) ;
  14013.  
  14014.                     attribute = a ;
  14015.                     sco8bit = eight ;
  14016.                     crm = c;
  14017.                     GR = g;
  14018.                 }
  14019.                 else {
  14020.                     /* TBC - Tabulation Clear */
  14021.                     /* VT terminals only support 0 and 3 */
  14022.                     /* HFT (begin) */
  14023.                     /*  0 - clear horizontal tab stop at active position */
  14024.                     /*  1 - vertical tab at line indicated by cursor     */
  14025.                     /*  2 - horizontal tabs on line                      */
  14026.                     /*  3 - all horizontal tabs                          */
  14027.                     /*  4 - all vertical tabs                            */
  14028.                     /* HFT (end)                                         */
  14029.                     /* SCO BCS2 mode supports this functionality */
  14030.                     if (pn[1] == 3 || 
  14031.                         (pn[1] == 2 && !ISVT100(tt_type_mode)))
  14032.                     {
  14033.                         /* clear all tabs */
  14034.                         for (j = 1; j <=MAXTERMCOL; ++j)
  14035.                             htab[j] = '0';
  14036.                     } else if (pn[1] == 0) {
  14037.                         /* clear tab at current position */
  14038.                         htab[wherex[VTERM]] = '0';
  14039.                     }
  14040.                 }
  14041.                 break;
  14042.             case 'h':   /* Set Mode */
  14043.                 for (j = 1; j <= k; ++j) {
  14044.                     if (private) {
  14045.                         switch (pn[j]) {        /* Field specs */
  14046.                         case 1: /* DECCKM  */
  14047.                             tt_arrow = TTK_APPL;
  14048.                             break;
  14049.                         case 2:
  14050.                             /* DECANM : ANSI/VT52 */
  14051.                             /* XTERM - Designate US_ASCII into G0-G3 */
  14052.                             if ( ISH19(tt_type) ) {
  14053.                                 tt_type_mode = tt_type ;
  14054.                                 vt52graphics = FALSE;
  14055.                             }
  14056.                             else if ( decsasd == SASD_TERMINAL ){
  14057.                                 if ( ISVT52(tt_type_mode) ) {
  14058.                                     tt_type_mode = tt_type_vt52 ;
  14059.                                     vt52graphics = FALSE;
  14060.                                     ipadl25();
  14061.                                 }
  14062.                             }
  14063.                             break;
  14064.                         case 3: /* DECCOLM = 132 Columns */
  14065.                             RequestScreenMutex(SEM_INDEFINITE_WAIT);
  14066.                             killcursor(VTERM);
  14067.                             deccolm = TRUE;
  14068.                             Set132Cols(VTERM);
  14069. #ifdef TCPSOCKET
  14070. #ifdef CK_NAWS
  14071.                             if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  14072.                                 tn_snaws();
  14073. #ifdef RLOGCODE
  14074.                                 rlog_naws();
  14075. #endif /* RLOGCODE */
  14076. #ifdef SSHBUILTIN
  14077.                                 ssh_snaws();
  14078. #endif /* SSHBUILTIN */
  14079.                             }
  14080. #endif /* CK_NAWS */
  14081. #endif /* TCPSOCKET */
  14082.                             setborder();
  14083.                             newcursor(VTERM);
  14084.                             clrscreen(VTERM,SP);
  14085.                             lgotoxy(VTERM,1,1);       /* and home the cursor */
  14086.                             ipadl25();
  14087.                             ReleaseScreenMutex();
  14088.                             break;
  14089.                         case 4: /* DECSCLM - Smooth scroll */
  14090.                             SmoothScroll();
  14091.                             break;
  14092.                         case 5: /* DECSCNM - Reverse screen */
  14093.                             if (decscnm) /* Already reverse */
  14094.                                 break;
  14095.                             else {
  14096.                                 flipscreen(VTERM);
  14097.                                 VscrnIsDirty(VTERM) ;
  14098.                             }
  14099.                             break;
  14100.                         case 6: /* DECOM - Relative origin */
  14101.                             relcursor = TRUE;
  14102.                             if ( decsasd == SASD_STATUS )
  14103.                                 lgotoxy( VSTATUS, 1, 1 );
  14104.                             else
  14105.                                 lgotoxy(VTERM, 1, margintop);
  14106.                             break;
  14107.                         case 7: /* DECAWM - Auto Wrap mode */
  14108.                             tt_wrap = TRUE;
  14109.                             break;
  14110.                         case 8: /* DECARM - Autorepeat */
  14111.                             break;
  14112.                         case 9: /* DECINLM - Interlace */
  14113.                             /* XTERM - Send Mouse X & Y on button press */
  14114.                             break;
  14115.                         case 10:        /* DECEDM - Block Mode On */
  14116.                             break;
  14117.                         case 18:  /* DECPFF - Print Form Feed */
  14118.                             xprintff = TRUE;
  14119.                             break;
  14120.                         case 19:        /* DECPEX - Printer extent */
  14121.                             printregion = FALSE; /* Full screen */
  14122.                             break;
  14123.                         case 25:   /* DECTCEM - Cursor On */
  14124.                             cursorena[VTERM] = TRUE;
  14125.                             break;
  14126.                         case 34:    /* DECRLM - Right to Left Mode */
  14127.                             debug(F111,"VT","DECRLM - Right to Left Mode",1);
  14128.                             break;
  14129.                         case 35: /* DECHEBM */
  14130.                             /* Enter Hebrew keyboard mode */
  14131.                             tt_kb_mode = KBM_HE ;
  14132.                             break;
  14133.                         case 36:    /* DECHEM - Hebrew Encoding Mode */
  14134.                             debug(F111,"VT","DECHEM - Hebrew Encoding Mode",1);
  14135.                             break;
  14136.                         case 38: /* DECTEK */
  14137.                             /* Enter Tektronix 4010/4014 mode */
  14138.                             settekmode();
  14139.                             break;
  14140.                         case 40: /* XTERM - Allow 80 - 132 Mode */
  14141.                             break;
  14142.                         case 41: /* XTERM - more(1) fix */
  14143.                             break;
  14144.                         case 42: { /* DECNRCM */
  14145.                             /* Use 7-bit NRC */
  14146.                             int tcs ;
  14147.                             decnrcm = TRUE ;
  14148. #ifdef COMMENT
  14149.                             if ( G[0].national )
  14150.                             {
  14151.                                 for ( i = 1 ; i < 4 ; i++ ) {
  14152.                                     G[i].designation =
  14153.                                         G[0].def_designation ;
  14154.                                     G[i].size = G[0].def_size ;
  14155.                                     G[i].c1   = G[0].def_c1 ;
  14156.                                     G[i].national = G[0].national;
  14157.                                     G[i].rtoi = xl_u[G[0].def_designation];
  14158.                                     if ( isunicode() ) {
  14159.                                         G[i].itol = NULL ;
  14160.                                         G[i].ltoi = NULL ;
  14161.                                     }
  14162.                                     else {
  14163.                                         G[i].itol = xl_tx[tcsl] ;
  14164.                                         G[i].ltoi = xl_u[tcsl] ;
  14165.                                     }
  14166.                                     G[i].itor = xl_tx[G[0].def_designation] ;
  14167.                                 }
  14168.                             }
  14169.                             else {
  14170.                                 for ( i = 1 ; i < 4 ; i++ ) {
  14171.                                     G[i].designation = TX_ASCII;
  14172.                                     G[i].size = cs94 ;
  14173.                                     G[i].c1 = TRUE ;
  14174.                                     G[i].national = CSisNRC(G[i].designation);
  14175.                                     G[i].rtoi = xl_u[TX_ASCII];
  14176.                                     if ( isunicode() ) {
  14177.                                         G[i].itol = NULL ;
  14178.                                         G[i].ltoi = NULL ;
  14179.                                     }
  14180.                                     else {
  14181.                                         G[i].itol = xl_tx[tcsl] ;
  14182.                                         G[i].ltoi = xl_u[tcsl] ;
  14183.                                     }
  14184.                                     G[i].itor = xl_tx[TX_ASCII];
  14185.                                 }
  14186.                             }
  14187. #else /* COMMENT */
  14188.                             for ( i = 1 ; i < 4 ; i++ ) {
  14189.                                 G[i].designation = dec_nrc;
  14190.                                 G[i].size = cs94 ;
  14191.                                 G[i].c1 = TRUE ;
  14192.                                 G[i].national = CSisNRC(dec_nrc);
  14193.                                 G[i].rtoi = xl_u[dec_nrc];
  14194.                                 if ( isunicode() ) {
  14195.                                     G[i].itol = NULL ;
  14196.                                     G[i].ltoi = NULL ;
  14197.                                 }
  14198.                                 else {
  14199.                                     G[i].itol = xl_tx[tcsl] ;
  14200.                                     G[i].ltoi = xl_u[tcsl] ;
  14201.                                 }
  14202.                                 G[i].itor = xl_tx[dec_nrc];
  14203.                             }
  14204. #endif /* COMMENT */
  14205.                         }
  14206.                             break;
  14207.                         case 43: /* DECGEPM */
  14208.                             /* Graphics Expanded Print mode */
  14209.                             break;
  14210.                         case 44: /* DECGPCM */
  14211.                             /* Graphics Print Color mode */
  14212.                             /* XTERM - Turn on Margin Bell */
  14213.                             break;
  14214.                         case 45: /* DECGPCS */
  14215.                             /* Graphics Print Color syntax = RGB */
  14216.                             /* XTERM - Reverse-wraparound mode */
  14217.                             break;
  14218.                         case 46: /* DECGPBM */
  14219.                             /* Graphics Print Background mode */
  14220.                             /* XTERM - Start Logging */
  14221.                             break;
  14222.                         case 47: /* DECGRCM */
  14223.                             /* Graphics Rotated Print mode */
  14224.                             /* XTERM - Use Alternate Screen Buffer */
  14225.                             break;
  14226.                         case 53: /* DEC131TM */
  14227.                             /* VT131 Transmit */
  14228.                             break;
  14229.                         case 60: /* DECHCCM */
  14230.                             /* Horizontal cursor coupling */
  14231.                             break;
  14232.                         case 61: /* DECVCCM */
  14233.                             /* Vertical cursor coupling */
  14234.                             break;
  14235.                         case 64: /* DECPCCM */
  14236.                             /* Page cursor coupling */
  14237.                             break;
  14238.                         case 66: /* DECNKM */
  14239.                             /* Numeric Keyboard - Application */
  14240.                             tt_keypad = TTK_APPL ;
  14241.                             break;
  14242.                         case 67: /* DECBKM */
  14243.                             /* Backarrow key sends BS */
  14244.                             if ( !savdecbkm )
  14245.                                 savdecbkm = keymap[KEY_SCAN | 8];
  14246.                             keymap[KEY_SCAN | 8] = BS ;
  14247.                             break;
  14248.                         case 68: /* DECKBUM */
  14249.                             /* Keyboard Usage - Data Processing */
  14250.                             deckbum = 1;
  14251.                             break;
  14252.                         case 73: /* DECXRLM */
  14253.                             /* Transmit rate limiting */
  14254.                             break;
  14255.                         case 80:        /* WY161 - 161-column mode */
  14256.                             if ( ISWY370(tt_type_mode) )
  14257.                             {
  14258.                                 tt_szchng[VTERM] = 1 ;
  14259.                                 tt_cols[VTERM] = 161 ;
  14260.                                 VscrnInit( VTERM ) ;  /* Height set here */
  14261. #ifdef TCPSOCKET
  14262. #ifdef CK_NAWS
  14263.                                 if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  14264.                                     tn_snaws();
  14265. #ifdef RLOGCODE
  14266.                                     rlog_naws();
  14267. #endif /* RLOGCODE */
  14268. #ifdef SSHBUILTIN
  14269.                                     ssh_snaws();
  14270. #endif /* SSHBUILTIN */
  14271.                                 }
  14272. #endif /* TCPSOCKET */
  14273. #endif /* CK_NAWS */
  14274.                             }
  14275.                             break;
  14276.                             case 83:    /* WY52 - 52 line mode */
  14277.                             if ( ISWY370(tt_type_mode)
  14278.                                  && tt_modechg == TVC_ENA) {
  14279.                                 tt_szchng[VTERM] = 1 ;
  14280.                                 tt_rows[VTERM] = 52 ;
  14281.                                 VscrnInit( VTERM ) ;          /* Height set here */
  14282. #ifdef TCPSOCKET
  14283. #ifdef CK_NAWS
  14284.                                 if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  14285.                                     tn_snaws();
  14286. #ifdef RLOGCODE
  14287.                                     rlog_naws();
  14288. #endif /* RLOGCODE */
  14289. #ifdef SSHBUILTIN
  14290.                                     ssh_snaws();
  14291. #endif /* SSHBUILTIN */
  14292.                                 }
  14293. #endif /* CK_NAWS */
  14294. #endif /* TCPSOCKET */
  14295.                             }
  14296.                             break;
  14297.                         case 84:        /* WYENAT */
  14298.                             if ( ISWY370(tt_type_mode) )
  14299.                                 /* Enable separate assignment of */
  14300.                                 /* attributes (SGR) to erasable  */
  14301.                                 /* and nonerasable characters    */
  14302.                                 ;
  14303.                             break;
  14304.                         case 85:        /* WYREPL */
  14305.                             if ( ISWY370(tt_type_mode) )
  14306.                                 /* Set replacement character to */
  14307.                                 /* current character background */
  14308.                                 /* color */
  14309.                                 ;
  14310.                             break;
  14311.                         case 1000:
  14312.                             /* XTERM - Send Mouse X&Y on button press and release */
  14313.                             break;
  14314.                         case 1001:
  14315.                             /* XTERM - Use Hilite Mouse Tracking */
  14316.                             break;
  14317.                         default:
  14318.                             break;
  14319.                         }
  14320.                     } else if ( zdsext ) {
  14321.                         switch (pn[j]) {
  14322.                         /* Zenith/Heath values */
  14323.                         case 1: /* Enable 25th line */
  14324.                             if ( !tt_status[VTERM] )
  14325.                                 break;
  14326.                             settermstatus(FALSE);
  14327.                             break;
  14328.                         case 2: /* No Key Click */
  14329.                             setkeyclick(FALSE);
  14330.                             break;
  14331.                         case 3: /* Hold Screen Mode */
  14332.                             break;
  14333.                         case 4: /* Block Cursor */
  14334.                             tt_cursor = TTC_BLOCK ;
  14335.                             setcursormode() ;
  14336.                             break;
  14337.                         case 5: /* Cursor Off */
  14338.                             cursorena[VTERM] = FALSE ;
  14339.                             break;
  14340.                         case 6: /* Keypad Shifted */
  14341.                             tt_shift_keypad = TRUE ;
  14342.                             break;
  14343.                         case 7: /* Alternate keypad mode */
  14344.                             tt_keypad = TTK_APPL ;
  14345.                             break;
  14346.                         case 8: /* Auto Line Feed on receipt of CR */
  14347.                             tt_crd = TRUE ;
  14348.                             break;
  14349.                         case 9: /* Auto CR on receipt of LF */
  14350.                             tnlm = TRUE ;
  14351.                             break;
  14352.  
  14353.                         /* AnnArbor values */
  14354.                         case 25:        /* zMDM - Margin Bell Mode */
  14355.                             break;
  14356.                         case 26:        /* zKCM - Key Click Mode */
  14357.                             break;
  14358.                         case 27:        /* zKPCM - Key Pad Control Mode */
  14359.                             break;
  14360.                         case 28:        /* zKRM - Key Repeat Mode */
  14361.                             break;
  14362.                         case 29:        /* zRLM - Return Line Feed Mode */
  14363.                             break;
  14364.                         case 30:        /* zDBM - Destructive Backspace Mode */
  14365.                             break;
  14366.                         case 31:        /* zBKCM - Block Cursor Mode */
  14367.                             break;
  14368.                         case 32:        /* zBNCM - Blinking Cursor Mode */
  14369.                             break;
  14370.                         case 33:        /* zWFM - Wrap Forward Mode */
  14371.                             break;
  14372.                         case 34:        /* zWBM - Wrap Backward Mode */
  14373.                             break;
  14374.                         case 35:        /* zDDM - DEL character Display Mode */
  14375.                             break;
  14376.                         case 36:        /* zSPM - Scroll Page Mode */
  14377.                             break;
  14378.                         case 37:        /* zAXM - Auto Xoff/Xon Mode */
  14379.                             break;
  14380.                         case 38:        /* zAPM - Auto Pause Mode */
  14381.                             break;
  14382.                         case 39:        /* zSSM - Slow Scroll Mode */
  14383.                             break;
  14384.                         case 40:        /* zHDM - Half-Duplex Mode */
  14385.                             break;
  14386.                         case 41:        /* zTPDM - Transfer Pointer Display Mode */
  14387.                             break;
  14388.                         case 42:        /* zLTM - Line Transfer Mode */
  14389.                             break;
  14390.                         case 43:        /* zCSTM - Column Separator Transfer Mode */
  14391.                             break;
  14392.                         case 44:        /* zFSTM - Field Separator Transfer Mode */
  14393.                             break;
  14394.                         case 45:        /* zGRTM - Graphic Rendition Transfer Mode */
  14395.                             break;
  14396.                         case 46:        /* zAKDM - Auto Keyboard Disable Mode */
  14397.                             break;
  14398.                         case 47:        /* zFRM - Fast Repeat Mode */
  14399.                             break;
  14400.                         case 48:        /* zHAM - Hold in Area Mode */
  14401.                             break;
  14402.                         case 49:        /* zGAPM - Guarded Area Print Mode */
  14403.                             break;
  14404.                         case 51:        /* zACM - Alternate Cursor Mode */
  14405.                             break;
  14406.                         case 52:        /* zMKM - Meta Key Mode */
  14407.                             break;
  14408.                         case 53:        /* zCLIM - Caps Lock Invert Mode */
  14409.                             break;
  14410.                         case 54:        /* zINM - Ignore NUL Mode */
  14411.                             break;
  14412.                         case 55:        /* zCNM - CR New-Line Mode */
  14413.                             break;
  14414.                         case 56:        /* zICM - Invisible Cursor Mode */
  14415.                             break;
  14416.                         case 57:        /* zMMM - Meta Monitor Mode */
  14417.                             break;
  14418.                         case 59:        /* zIVM - Inverse Video Mode */
  14419.                             break;
  14420.                         case 61:        /* Z8RCM - 8-bit Remote Copy Mode */
  14421.                             break;
  14422.                         }
  14423.                     } else {      /* Not private */
  14424.                         if ( ISSCO(tt_type_mode) ) {
  14425.                             switch ( pn[j] ) {
  14426.                             case 2: /* Keyboard locked */
  14427.                                 keylock = TRUE;
  14428.                                 break;
  14429.                             case 3: /* 132 Columns */
  14430.                                 RequestScreenMutex(SEM_INDEFINITE_WAIT);
  14431.                                 killcursor(VTERM);
  14432.                                 deccolm = TRUE;
  14433.                                 Set132Cols(VTERM);
  14434. #ifdef TCPSOCKET
  14435. #ifdef CK_NAWS
  14436.                                 if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  14437.                                     tn_snaws();
  14438. #ifdef RLOGCODE
  14439.                                     rlog_naws();
  14440. #endif /* RLOGCODE */
  14441. #ifdef SSHBUILTIN
  14442.                                     ssh_snaws();
  14443. #endif /* SSHBUILTIN */
  14444.                                 }
  14445. #endif /* CK_NAWS */
  14446. #endif /* TCPSOCKET */
  14447.                                 setborder();
  14448.                                 newcursor(VTERM);
  14449.                                 clrscreen(VTERM,SP);
  14450.                                 lgotoxy(VTERM,1,1);       /* and home the cursor */
  14451.                                 ipadl25();
  14452.                                 ReleaseScreenMutex();
  14453.                                 break;
  14454.                             case 4: /* Smooth scroll */
  14455.                                 SmoothScroll();
  14456.                                 break;
  14457.  
  14458.                             case 6: /* Relative origin */
  14459.                                 relcursor = TRUE;
  14460.                                 if ( decsasd == SASD_STATUS )
  14461.                                     lgotoxy( VSTATUS, 1, 1 );
  14462.                                 else
  14463.                                     lgotoxy(VTERM, 1, margintop);
  14464.                                 break;
  14465.                             case 7: /* Auto Wrap mode */
  14466.                                 tt_wrap = TRUE;
  14467.                                 break;
  14468.                             case 25:   /* Cursor On */
  14469.                             case 48:
  14470.                             case 1048:
  14471.                                 cursorena[VTERM] = TRUE;
  14472.                                 break;
  14473.                             case 30:    /* Scrollbars On */
  14474.                                 break;
  14475.                             case 44:    /* Margin Bell On */
  14476.                                 marginbell = TRUE;
  14477.                                 break;
  14478.                             }
  14479.                         } else {
  14480.                             switch (pn[j]) {
  14481.                             case 2: /* Keyboard locked */
  14482.                                 keylock = TRUE;
  14483.                                 break;
  14484.                             case 3: /* CRM - Controls Mode On */
  14485.                                 crm = TRUE ;
  14486.                                 break;
  14487.                             case 4: /* ANSI insert mode */
  14488.                                 if (ISVT102(tt_type_mode) ||
  14489.                                      ISANSI(tt_type_mode))
  14490.                                     insertmode = TRUE;
  14491.                                 break;
  14492.                             case 6: /* Erasure Mode (ERM) Set */
  14493.                                 erm = 1 ;
  14494.                                 break;
  14495.                             case 12:        /* SRM - Send Receive ON */
  14496.                                 if ( duplex_sav < 0 )
  14497.                                     duplex_sav = duplex ;
  14498.                                 duplex = 0; /* Remote echo */
  14499.                                 break;
  14500.                             case 13:        /* FEAM - Control execution off */
  14501.                                 /* Display control codes */
  14502.                                 break;
  14503.                             case 16:        /* TTM - Send through cursor position */
  14504.                                 break;
  14505.                             case 20:
  14506.                                 /* LNM - linefeed / newline mode */
  14507.                                 tt_crd = tnlm = TRUE;
  14508.                                 break;
  14509.                             case 30:        /* WYDSCM - Turn display off */
  14510.                                 if ( ISWY370(tt_type_mode) ) {
  14511.                                     screenon = FALSE;
  14512.                                     if ( !savefiletext[0] )
  14513.                                         strcpy(savefiletext,filetext);
  14514.                                     strcpy(filetext,"SCREEN OFF") ;
  14515.                                     VscrnIsDirty(VTERM);
  14516.                                 }
  14517.                                 break;
  14518.                             case 31:        /* WYSTLINM - Display status line */
  14519.                                 break;
  14520.                             case 32:        /* WYCTRSAVM - Screen Saver off */
  14521.                                 break;
  14522.                             case 33:        /* WYSTCURM - Cursor steady */
  14523.                                 break;
  14524.                             case 34:        /* WYULCURM - Underline cursor */
  14525.                                 if ( ISWY370(tt_type_mode) ) {
  14526.                                     tt_cursor = TTC_ULINE ;
  14527.                                     setcursormode();
  14528.                                 }
  14529.                                 break;
  14530.                             case 35:        /* WYCLRM - Width change clear off */
  14531.                                 break;
  14532.                             case 36:        /* WYDELKM - Set delete key to BS/DEL */
  14533.                                 break;
  14534.                             case 37:        /* WYGATM - Send all characters */
  14535.                                 break;
  14536.                             case 38:        /* WYTEXM - Send full page */
  14537.                                 break;
  14538.                             case 40:        /* WYEXTDM - Extra data line */
  14539.                                 break;
  14540.                             case 42:        /* WYASCII - Select Wyse 350 personality */
  14541.                                 break;
  14542.                             case 50:    /* 97801-5XX - Compose key table on */
  14543.                                 if ( IS97801(tt_type_mode) ) {
  14544.                                     break;
  14545.                                 }
  14546.                                 break;
  14547.                             case 51:    /* 97801-5XX - Dead key table on */
  14548.                                 if ( IS97801(tt_type_mode) ) {
  14549.                                     break;
  14550.                                 }
  14551.                                 break;
  14552.                             case 53:    /* 97801-5XX - 132-character mode */
  14553.                                 if ( IS97801(tt_type_mode) ) {
  14554.                                     RequestScreenMutex(SEM_INDEFINITE_WAIT);
  14555.                                     killcursor(VTERM);
  14556.                                     deccolm = TRUE;
  14557.                                     Set132Cols(VTERM);
  14558. #ifdef TCPSOCKET            
  14559. #ifdef CK_NAWS              
  14560.                                     if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  14561.                                         tn_snaws();
  14562. #ifdef RLOGCODE             
  14563.                                         rlog_naws();
  14564. #endif /* RLOGCODE */       
  14565. #ifdef SSHBUILTIN           
  14566.                                         ssh_snaws();
  14567. #endif /* SSHBUILTIN */     
  14568.                                     }
  14569. #endif /* CK_NAWS */        
  14570. #endif /* TCPSOCKET */      
  14571.                                     setborder();
  14572.                                     newcursor(VTERM);
  14573.                                     clrscreen(VTERM,SP);
  14574.                                     lgotoxy(VTERM,1,1);       /* and home the cursor */
  14575.                                     ipadl25();
  14576.                                     ReleaseScreenMutex();
  14577.                                 }
  14578.                                 break;
  14579.                             default:
  14580.                                 break;
  14581.                             }
  14582.                         }
  14583.                     }
  14584.                 } /* for */
  14585.                 break;
  14586.             case 'l':
  14587.                 if ( ansiext && private ) {
  14588.                     /* Insert Line Up */
  14589.                     VscrnScroll(VTERM,
  14590.                                  UPWARD,
  14591.                                  0,
  14592.                                  wherey[VTERM] - 1,
  14593.                                  1,
  14594.                                  FALSE,
  14595.                                  SP);
  14596.                     break;
  14597.                 }
  14598.                 else if (ansiext && ISSCO(tt_type_mode)) {
  14599.                     /* SCO - Clear and Home Cursor */
  14600.                     clrscreen(VTERM,SP);
  14601.                     lgotoxy(VTERM,1,1);
  14602.                     VscrnIsDirty(VTERM);
  14603.                 }
  14604.                 else {/* Reset Mode */
  14605.                     for (j = 1; j <= k; ++j) {/* Go thru all pn's */
  14606.                         if (private) {
  14607.                             switch ((pn[j])) {      /* Field specs */
  14608.                             case 1: /* DECCKM - Cursor key mode */
  14609.                                 tt_arrow = TTK_NORM;
  14610.                                 break;
  14611.                             case 2: /* DECANM : ANSI/VT52 */
  14612.                                 if ( decsasd == SASD_TERMINAL ) {
  14613.                                     tt_type_vt52 = tt_type_mode ;
  14614.                                     tt_type_mode = TT_VT52;
  14615.                                     vt52graphics = FALSE;
  14616.                                     ipadl25();
  14617.                                 }
  14618.                                 break;
  14619.                             case 3: /* DECCOLM - 80 Columns */
  14620.                                 RequestScreenMutex(SEM_INDEFINITE_WAIT);
  14621.                                 killcursor(VTERM);
  14622.                                 deccolm = FALSE;
  14623.                                 Set80Cols(VTERM);
  14624. #ifdef TCPSOCKET
  14625. #ifdef CK_NAWS
  14626.                                 if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  14627.                                     tn_snaws();
  14628. #ifdef RLOGCODE
  14629.                                     rlog_naws();
  14630. #endif /* RLOGCODE */
  14631. #ifdef SSHBUILTIN
  14632.                                    ssh_snaws();
  14633. #endif /* SSHBUILTIN */
  14634.                                }
  14635. #endif /* CK_NAWS */
  14636. #endif /* TCPSOCKET */
  14637.                                setborder();
  14638.                                newcursor(VTERM);
  14639.                                clrscreen(VTERM,SP);
  14640.                                lgotoxy(VTERM,1,1);       /* and home the cursor */
  14641.                                ipadl25();
  14642.                                ReleaseScreenMutex();
  14643.                                break;
  14644.                            case 4: /* DECSCLM - Jump scrolling */
  14645.                                JumpScroll() ;
  14646.                                break;
  14647.                            case 5: /* DECSCNM - Normal screen */
  14648.                                if (!decscnm) /* Already normal? */
  14649.                                    break;
  14650.                                else {
  14651.                                    flipscreen(VTERM);
  14652.                                    VscrnIsDirty(VTERM);
  14653.                                }
  14654.                                break;
  14655.                            case 6: /* DECOM - Absolute origin */
  14656.                                relcursor = FALSE;
  14657.                                if ( decsasd == SASD_STATUS )
  14658.                                    lgotoxy( VSTATUS, 1, 1 );
  14659.                                else
  14660.                                    lgotoxy(VTERM,1, 1);
  14661.                                break;
  14662.                            case 7: /* DECAWM - Auto wrap */
  14663.                                tt_wrap = FALSE;
  14664.                                break;
  14665.                            case 8: /* DECARM - Auto repeat */
  14666.                                break;
  14667.                            case 9: /* DECINLM - Interlace */
  14668.                                /* XTERM - Don't Send Mouse X&Y on button press */
  14669.                                break;
  14670.                            case 10:        /* DECEDM - Block mode off */
  14671.                                break;
  14672.                            case 18: /* DECPFF - Print Form Feed */
  14673.                                xprintff = FALSE;
  14674.                                break;
  14675.                            case 19:        /* DECPEX - Print extent */
  14676.                                printregion = TRUE; /* Region */
  14677.                                break;
  14678.                            case 25: /* DECTCEM - Cursor Off */
  14679.                                cursorena[VTERM] = FALSE;
  14680.                                break;
  14681.                            case 34:    /* DECRLM - Right to Left Mode */
  14682.                                debug(F111,"VT","DECRLM - Right to Left Mode",0);
  14683.                                break;
  14684.                            case 35: /* DECHEBM */
  14685.                                /* Enter English keyboard mode */
  14686.                                tt_kb_mode = KBM_EN ;
  14687.                                break;
  14688.                            case 36:    /* DECHEM - Hebrew Encoding Mode */
  14689.                                debug(F111,"VT","DECHEM - Hebrew Encoding Mode",0);
  14690.                                break;
  14691.                            case 38: /* DECTEK */
  14692.                                /* Exit Tektronix 4010/4014 mode */
  14693.                                resettekmode();
  14694.                                break;
  14695.                            case 40:
  14696.                                /* XTERM - Disallow 80 - 132 mode switch */
  14697.                                break;
  14698.                            case 41:
  14699.                                /* XTERM - No more(1) fix */
  14700.                                break;
  14701.                            case 42: { /* DECNRCM */
  14702.                                /* 8-bit multinational char set */
  14703.                                int tcs ;
  14704.                                decnrcm = FALSE ;
  14705.                                for ( i = 0 ; i < 4 ; i++ ) {
  14706.                                    G[i].designation = G[i].def_designation ;
  14707.                                    G[i].size = G[i].def_size ;
  14708.                                    G[i].c1   = G[i].def_c1 ;
  14709.                                    G[i].national = CSisNRC(G[i].designation);
  14710.                                    if ( G[i].def_designation == FC_TRANSP ) {
  14711.                                        G[i].rtoi = NULL ;
  14712.                                        G[i].itol = NULL ;
  14713.                                        G[i].itor = NULL ;
  14714.                                        G[i].ltoi = NULL;
  14715.                                    }
  14716.                                    else {
  14717.                                        G[i].rtoi = xl_u[G[i].def_designation];
  14718.                                        if ( isunicode() ) {
  14719.                                            G[i].itol = NULL ;
  14720.                                            G[i].ltoi = NULL;
  14721.                                        }
  14722.                                        else {
  14723.                                            G[i].itol = xl_tx[tcsl] ;
  14724.                                            G[i].ltoi = xl_u[tcsl] ;
  14725.                                        }
  14726.                                        G[i].itor = xl_tx[G[i].def_designation];
  14727.                                    }
  14728.                                }
  14729.                            }
  14730.                                break;
  14731.                            case 43: /* DECGEPM */
  14732.                                /* Graphics Normal Print mode */
  14733.                                break;
  14734.                            case 44: /* DECGPCM */
  14735.                                /* Graphics Print Monochrome mode */
  14736.                                /* XTERM - Turn off margin bell */
  14737.                                break;
  14738.                            case 45: /* DECGPCS */
  14739.                                /* Graphics Print Color syntax = HLS */
  14740.                                /* XTERM - No Reverse-wraparound mode */
  14741.                                break;
  14742.                            case 46: /* DECGPBM */
  14743.                                /* Graphics Print No-Background mode */
  14744.                                /* XTERM - Stop Logging */
  14745.                                break;
  14746.                            case 47: /* DECGRCM */
  14747.                                /* Graphics Unrotated Print mode */
  14748.                                /* XTERM - Use Normal Screen Buffer */
  14749.                                break;
  14750.                            case 53: /* DEC131TM */
  14751.                                /* VT131 Transmit */
  14752.                                break;
  14753.                            case 60: /* DECHCCM */
  14754.                                /* Horizontal cursor coupling */
  14755.                                break;
  14756.                            case 61: /* DECVCCM */
  14757.                                /* Vertical cursor coupling */
  14758.                                break;
  14759.                            case 64: /* DECPCCM */
  14760.                                /* Page cursor coupling */
  14761.                                break;
  14762.                            case 66: /* DECNKM */
  14763.                                /* Numeric Keyboard - Numeric */
  14764.                                tt_keypad = TTK_NORM;
  14765.                                break;
  14766.                            case 67: /* DECBKM */
  14767.                                /* Backarrow key sends DEL */
  14768.                                if ( !savdecbkm )
  14769.                                    savdecbkm = keymap[KEY_SCAN | 8];
  14770.                                keymap[KEY_SCAN | 8] = DEL ;
  14771.                                break;
  14772.                            case 68: /* DECKBUM */
  14773.                                /* Keyboard Usage - Typewriter mode */
  14774.                                deckbum = 0 ;
  14775.                                break;
  14776.                            case 73: /* DECXRLM */
  14777.                                /* Transmit rate limiting */
  14778.                                break;
  14779.                            case 80:        /* WY161 - 80-column mode */
  14780.                                if ( ISWY370(tt_type_mode) )
  14781.                                {
  14782.                                    tt_szchng[VTERM] = 1 ;
  14783.                                    tt_cols[VTERM] = 80 ;
  14784.                                    VscrnInit( VTERM ) ;  /* Height set here */
  14785. #ifdef TCPSOCKET
  14786. #ifdef CK_NAWS
  14787.                                    if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  14788.                                        tn_snaws();
  14789. #ifdef RLOGCODE
  14790.                                        rlog_naws();
  14791. #endif /* RLOGCODE */
  14792. #ifdef SSHBUILTIN
  14793.                                        ssh_snaws();
  14794. #endif /* SSHBUILTIN */
  14795.                                    }
  14796. #endif /* CK_NAWS */
  14797. #endif /* TCPSOCKET */
  14798.                                }
  14799.                                break;
  14800.                            case 83:        /* WY52 - 24 line mode */
  14801.                                if ( ISWY370(tt_type_mode)
  14802.                                    && tt_modechg == TVC_ENA )
  14803.                                {
  14804.                                    tt_szchng[VTERM] = 1 ;
  14805.                                    tt_rows[VTERM] = 24 ;
  14806.                                    VscrnInit( VTERM ) ;  /* Height set here */
  14807. #ifdef TCPSOCKET
  14808. #ifdef CK_NAWS
  14809.                                    if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  14810.                                        tn_snaws();
  14811. #ifdef RLOGCODE
  14812.                                        rlog_naws();
  14813. #endif /* RLOGCODE */
  14814. #ifdef SSHBUILTIN
  14815.                                        ssh_snaws();
  14816. #endif /* SSHBUILTIN */
  14817.                                    }
  14818. #endif /* CK_NAWS */
  14819. #endif /* TCPSOCKET */
  14820.                                }
  14821.                                break;
  14822.                            case 84:        /* WYENAT */
  14823.                                if ( ISWY370(tt_type_mode) )
  14824.                                    /* Enable attribute assignment (SGR) */
  14825.                                    /* to extend to both eraseable and   */
  14826.                                    /* nonerasable characters            */
  14827.                                    ;
  14828.                                break;
  14829.                            case 85:        /* WYREPL */
  14830.                                if ( ISWY370(tt_type_mode) )
  14831.                                    /* Set replacement character to */
  14832.                                    /* color map background color   */
  14833.                                    ;
  14834.                                break;
  14835.                            case 1000:
  14836.                                /* XTERM - Don't Send Mouse X&Y on button press and release */
  14837.                                break;
  14838.                            case 1001:
  14839.                                /* XTERM - Don't use Hilite Mouse Tracking */
  14840.                                break;
  14841.                            default:
  14842.                                break;
  14843.                            }
  14844.                         } else if ( zdsext ) {
  14845.                            switch (pn[j]) {
  14846.                            /* Zenith/Heath */
  14847.                            case 1: /* Disable 25th line */
  14848.                                if ( tt_status[VTERM] )
  14849.                                    break;
  14850.                                settermstatus(TRUE);
  14851.                                break;
  14852.                            case 2: /* Key Click */
  14853.                                setkeyclick(TRUE);
  14854.                                break;
  14855.                            case 3: /* Exit Hold Screen Mode */
  14856.                                break;
  14857.                            case 4: /* Underline Cursor */
  14858.                                tt_cursor = TTC_ULINE ;
  14859.                                setcursormode() ;
  14860.                                break;
  14861.                            case 5: /* Cursor On */
  14862.                                cursorena[VTERM] = TRUE ;
  14863.                                break;
  14864.                            case 6: /* Keypad Unshifted */
  14865.                                tt_shift_keypad = FALSE ;
  14866.                                break;
  14867.                            case 7: /* Exit Alternate keypad mode */
  14868.                                tt_keypad = TTK_NORM ;
  14869.                                break;
  14870.                            case 8: /* No Auto Line Feed on receipt of CR */
  14871.                                tt_crd = FALSE ;
  14872.                                break;
  14873.                            case 9: /* No Auto CR on receipt of LF */
  14874.                                tnlm = FALSE ;
  14875.                                break;
  14876.  
  14877.                                /* AnnArbor values */
  14878.                            case 25:        /* zMDM - Margin Bell Mode */
  14879.                                break;
  14880.                            case 26:        /* zKCM - Key Click Mode */
  14881.                                break;
  14882.                            case 27:        /* zKPCM - Key Pad Control Mode */
  14883.                                break;
  14884.                            case 28:        /* zKRM - Key Repeat Mode */
  14885.                                break;
  14886.                            case 29:        /* zRLM - Return Line Feed Mode */
  14887.                                break;
  14888.                            case 30:        /* zDBM - Destructive Backspace Mode */
  14889.                                break;
  14890.                            case 31:        /* zBKCM - Block Cursor Mode */
  14891.                                break;
  14892.                            case 32:        /* zBNCM - Blinking Cursor Mode */
  14893.                                break;
  14894.                            case 33:        /* zWFM - Wrap Forward Mode */
  14895.                                break;
  14896.                            case 34:        /* zWBM - Wrap Backward Mode */
  14897.                                break;
  14898.                            case 35:        /* zDDM - DEL character Display Mode */
  14899.                                break;
  14900.                            case 36:        /* zSPM - Scroll Page Mode */
  14901.                                break;
  14902.                            case 37:        /* zAXM - Auto Xoff/Xon Mode */
  14903.                                break;
  14904.                            case 38:        /* zAPM - Auto Pause Mode */
  14905.                                break;
  14906.                            case 39:        /* zSSM - Slow Scroll Mode */
  14907.                                break;
  14908.                            case 40:        /* zHDM - Half-Duplex Mode */
  14909.                                break;
  14910.                            case 41:        /* zTPDM - Transfer Pointer Display Mode */
  14911.                                break;
  14912.                            case 42:        /* zLTM - Line Transfer Mode */
  14913.                                break;
  14914.                            case 43:        /* zCSTM - Column Separator Transfer Mode */
  14915.                                break;
  14916.                            case 44:        /* zFSTM - Field Separator Transfer Mode */
  14917.                                break;
  14918.                            case 45:        /* zGRTM - Graphic Rendition Transfer Mode */
  14919.                                break;
  14920.                            case 46:        /* zAKDM - Auto Keyboard Disable Mode */
  14921.                                break;
  14922.                            case 47:        /* zFRM - Fast Repeat Mode */
  14923.                                break;
  14924.                            case 48:        /* zHAM - Hold in Area Mode */
  14925.                                break;
  14926.                            case 49:        /* zGAPM - Guarded Area Print Mode */
  14927.                                break;
  14928.                            case 51:        /* zACM - Alternate Cursor Mode */
  14929.                                break;
  14930.                            case 52:        /* zMKM - Meta Key Mode */
  14931.                                break;
  14932.                            case 53:        /* zCLIM - Caps Lock Invert Mode */
  14933.                                break;
  14934.                            case 54:        /* zINM - Ignore NUL Mode */
  14935.                                break;
  14936.                            case 55:        /* zCNM - CR New-Line Mode */
  14937.                                break;
  14938.                            case 56:        /* zICM - Invisible Cursor Mode */
  14939.                                break;
  14940.                            case 57:        /* zMMM - Meta Monitor Mode */
  14941.                                break;
  14942.                            case 59:        /* zIVM - Inverse Video Mode */
  14943.                                break;
  14944.                            case 61:        /* Z8RCM - 8-bit Remote Copy Mode */
  14945.                                break;
  14946.                            }
  14947.                        } else { /* Not private */
  14948.                            if ( ISSCO(tt_type_mode) ) {
  14949.                                switch ( pn[j] ) {
  14950.                                case 2: /* Keyboard unlocked */
  14951.                                    keylock = FALSE;
  14952.                                    break;
  14953.                                case 3: /* 80 Columns */
  14954.                                    RequestScreenMutex(SEM_INDEFINITE_WAIT);
  14955.                                    killcursor(VTERM);
  14956.                                    deccolm = FALSE;
  14957.                                    Set80Cols(VTERM);
  14958. #ifdef TCPSOCKET
  14959. #ifdef CK_NAWS
  14960.                                    if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  14961.                                        tn_snaws();
  14962. #ifdef RLOGCODE
  14963.                                        rlog_naws();
  14964. #endif /* RLOGCODE */
  14965. #ifdef SSHBUILTIN
  14966.                                        ssh_snaws();
  14967. #endif /* SSHBUILTIN */
  14968.                                    }
  14969. #endif /* CK_NAWS */
  14970. #endif /* TCPSOCKET */
  14971.                                    setborder();
  14972.                                    newcursor(VTERM);
  14973.                                    clrscreen(VTERM,SP);
  14974.                                    lgotoxy(VTERM,1,1);       /* and home the cursor */
  14975.                                    ipadl25();
  14976.                                    ReleaseScreenMutex();
  14977.                                    break;
  14978.                                case 4: /* Jump scroll */
  14979.                                    JumpScroll();
  14980.                                    break;
  14981.                                case 6: /* Absolute origin */
  14982.                                    relcursor = FALSE;
  14983.                                    if ( decsasd == SASD_STATUS )
  14984.                                        lgotoxy( VSTATUS, 1, 1 );
  14985.                                    else
  14986.                                        lgotoxy(VTERM,1, 1);
  14987.                                    break;
  14988.                                case 7: /* Auto wrap */
  14989.                                    tt_wrap = FALSE;
  14990.                                    break;
  14991.                                case 25:   /* Cursor Off */
  14992.                                case 48:
  14993.                                case 1048:
  14994.                                    cursorena[VTERM] = FALSE;
  14995.                                    break;
  14996.                                case 30:    /* Scrollbars Off */
  14997.                                    break;
  14998.                                case 44:    /* Margin Bell Off */
  14999.                                    marginbell = FALSE;
  15000.                                    break;
  15001.                                }
  15002.                            }
  15003.                            else switch (pn[j])
  15004.                            {
  15005.                            case 2: /* Keyboard unlocked */
  15006.                                keylock = FALSE;
  15007.                                break;
  15008.                            case 3: /* CRM - Controls Mode Off */
  15009.                                crm = FALSE ;
  15010.                                break;
  15011.                            case 4: /* ANSI insert mode */
  15012.                                if (ISVT102(tt_type_mode) ||
  15013.                                    ISANSI(tt_type_mode))
  15014.                                    insertmode = FALSE;
  15015.                                break;
  15016.                            case 6: /* Erasure Mode (ERM) Reset */
  15017.                                erm = 0 ;
  15018.                                break;
  15019.                            case 12: /* SRM - Send Receive OFF */
  15020.                                if ( duplex_sav < 0 )
  15021.                                    duplex_sav = duplex ;
  15022.                                duplex = 1; /* Local echo */
  15023.                                break;
  15024.                            case 13:        /* FEAM - Control execution on */
  15025.                                break;
  15026.                            case 16:        /* TTM - Send through EOL or EOS */
  15027.                                break;
  15028.                            case 20:
  15029.                                /* LNM - linefeed / newline mode */
  15030.                                tt_crd = tnlm = FALSE;
  15031.                                break;
  15032.                            case 30:        /* WYDSCM - Turn display on */
  15033.                                if ( ISWY370(tt_type_mode) ) {
  15034.                                    screenon = TRUE;
  15035.                                    if ( savefiletext[0] ) {
  15036.                                        strcpy(filetext,savefiletext);
  15037.                                        savefiletext[0] = NUL ;
  15038.                                        /* Update status line */
  15039.                                        VscrnIsDirty(VTERM);
  15040.                                    }
  15041.                                }
  15042.                                break;
  15043.                            case 31:        /* WYSTLINM - Turn off status line */
  15044.                                break;
  15045.                            case 32:        /* WYCTRSAVM - Screen Saver on */
  15046.                                break;
  15047.                            case 33:        /* WYSTCURM - Cursor blinking */
  15048.                                break;
  15049.                            case 34:        /* WYULCURM - Block cursor */
  15050.                                if ( ISWY370(tt_type_mode) ) {
  15051.                                    tt_cursor = TTC_BLOCK ;
  15052.                                    setcursormode() ;
  15053.                                }
  15054.                                break;
  15055.                            case 35:        /* WYCLRM - Width change clear on */
  15056.                                break;
  15057.                            case 36:        /* WYDELKM - Set delete key to DEL/CAN */
  15058.                                break;
  15059.                            case 37:        /* WHGATM - Send erasable characters */
  15060.                                break;
  15061.                            case 38:        /* WYTEXM - Send scrolling region */
  15062.                                break;
  15063.                            case 40:        /* WYEXTDM - Extra data line */
  15064.                                break;
  15065.                            case 50:    /* 97801-5XX - Compose key table off */
  15066.                                if ( IS97801(tt_type_mode) ) {
  15067.                                    /* Make compose key send Compose Key String */
  15068.                                    break;
  15069.                                }
  15070.                                break;
  15071.                            case 51:    /* 97801-5XX - Dead key table off */
  15072.                                if ( IS97801(tt_type_mode) ) {
  15073.                                    break;
  15074.                                }
  15075.                                break;
  15076.                            case 53:    /* 97801-5XX - 80-character mode */
  15077.                                if ( IS97801(tt_type_mode) ) {
  15078.                                    RequestScreenMutex(SEM_INDEFINITE_WAIT);
  15079.                                    killcursor(VTERM);
  15080.                                    deccolm = FALSE;
  15081.                                    Set80Cols(VTERM);
  15082. #ifdef TCPSOCKET
  15083. #ifdef CK_NAWS
  15084.                                    if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0) {
  15085.                                        tn_snaws();
  15086. #ifdef RLOGCODE
  15087.                                        rlog_naws();
  15088. #endif /* RLOGCODE */
  15089. #ifdef SSHBUILTIN
  15090.                                        ssh_snaws();
  15091. #endif /* SSHBUILTIN */
  15092.                                    }
  15093. #endif /* CK_NAWS */
  15094. #endif /* TCPSOCKET */
  15095.                                    setborder();
  15096.                                    newcursor(VTERM);
  15097.                                    clrscreen(VTERM,SP);
  15098.                                    lgotoxy(VTERM,1,1);       /* and home the cursor */
  15099.                                    ipadl25();
  15100.                                    ReleaseScreenMutex();
  15101.                                }
  15102.                                break;
  15103.                            default:
  15104.                                break;
  15105.                            }
  15106.                        }
  15107.                     }
  15108.                 } /* for */
  15109.                 break;
  15110.             case 'i':       /* Media Copy */
  15111.                 /*
  15112.                   This code crashes the 16-bit version with Stack Overflow.
  15113.                   Print-Whole-Screen & Print-Cursor-Line support added in edit 190, fdc.
  15114.                 */
  15115.                 if (pn[1] == 0)  /* Print whole screen */
  15116.                     prtscreen(VTERM,
  15117.                                printregion ?
  15118.                                margintop :
  15119.                                1,
  15120.                                printregion ?
  15121.                                marginbot :
  15122.                                VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0)
  15123.                                );
  15124.                 else if (pn[1] == 1 &&  /* Print cursor line */
  15125.                           /* Only if ESC [?1i */
  15126.                           private == TRUE)
  15127.                     prtscreen(VTERM,wherey[VTERM],wherey[VTERM]);
  15128.                 /*
  15129.                 Send Screen to Host computer
  15130.                 #******************************************************************************#
  15131.                 #                                                                              #
  15132.                 #       Copyright (c) 1991-1993 Maximum Computer Technologies, Inc.            #
  15133.                 #                           All Rights Reserved.                               #
  15134.                 #       Version 1.2.0                                       09/15/93           #
  15135.                 #                                                                              #
  15136.                 #******************************************************************************#
  15137.                 NAME        = ansi
  15138.                 DESCRIPTION = Ansi standard console.
  15139.                 ALIASES     = li|ansi|ansic|ansi80x25|scoansi|scoansic
  15140.  
  15141.                 BEGIN_SCREEN_READ_CAPABILITIES
  15142.  
  15143.                 Send_screen         = \E[2i
  15144.                 End_send_screen     = \010
  15145.                 Rcflowcntrloff      = NO
  15146.                 Rsflowcntrloff      = NO
  15147.                 Mustreposition      = NO
  15148.                 Passthrough         = YES
  15149.                 Mustpruneattribute  = NO
  15150.  
  15151.                 END_SCREEN_READ_CAPABILITIES
  15152.                 */
  15153.                 else if ( pn[1] == 2 && !private ) {
  15154.                     int x,y,ch,
  15155.                     w=VscrnGetWidth(VTERM),
  15156.                     h=VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0),
  15157.                     xs=0,
  15158.                     ys=0,
  15159.                     xe=w-1,
  15160.                     ye=h-1;
  15161.  
  15162.                     /* Now send the data */
  15163.                     for ( y=ys;y<=ye; y++ ) {
  15164.                         for ( x=(y==ys)?xs:0 ; x <= (y==ye?xe:w-1) ; x++ ) {
  15165.                             ch = VscrnGetCell( VTERM, x, y )->c;
  15166.                             if ( tt_senddata ) {
  15167.                                     unsigned char * bytes;
  15168.                                 int nbytes;
  15169.                                 if ( isunicode() )
  15170.                                     nbytes = utorxlat(ch,&bytes);
  15171.                                 else
  15172.                                     nbytes = utorxlat(ch,&bytes);
  15173.                                 while ( nbytes-- > 0 )
  15174.                                     sendchar(*bytes++) ;
  15175.                             } else
  15176.                                 sendchar(SP);
  15177.                             }   
  15178.                         if ( y < ye ) {
  15179.                             sendchar(CR);
  15180.                             sendchar(LF);
  15181.                         }
  15182.                     }
  15183.                     sendchar(BS);
  15184.                 }
  15185.                 /* For pn = 4 or 5, we should differentiate here between transparent print  */
  15186.                 /* (private == FALSE) and autoprint (private == TRUE).  As presently coded, */
  15187.                 /* we always do transparent print.  Autoprint means that the current screen */
  15188.                 /* line is printed as soon as the cursor leaves it, i.e. when the terminal  */
  15189.                 /* receives a linefeed, form feed, or vertical tab, or when it wraps.       */
  15190.                 /* Edit 191.  Now we distinguish between auto-print and transparent print.  */
  15191.                 else if (pn[1] == 4) {
  15192.                     if ( private == TRUE ) {
  15193.                         setaprint(FALSE);
  15194.                     } else {
  15195.                         xprint = FALSE;
  15196.                     }
  15197.                     if ( is_noprint() )
  15198.                         turnoffprinter = TRUE;
  15199.                 } else if (pn[1] == 5) {
  15200.                     if ( private == TRUE ) {
  15201.                         setaprint(TRUE);
  15202.                     } else {
  15203.                         xprint = TRUE ;
  15204.                     }
  15205.                     if ( !printon )
  15206.                         turnonprinter = TRUE;
  15207.                     }   
  15208.  
  15209.                     /*  6 and 7 are in the VT125 manual.*/
  15210.                     /* These are really ANSI Media Copy */
  15211.                     /* sequences which should control   */
  15212.                     /* the flow of data from the printer */
  15213.                     /* port to the host */
  15214.                 else if (pn[1] == 6) {
  15215.                     if ( private == FALSE ) {
  15216.                         /* Turn off screen display */
  15217.                         screenon = FALSE;
  15218.                         if ( !savefiletext[0] )
  15219.                             strcpy(savefiletext,filetext);
  15220.                         strcpy(filetext,"SCREEN OFF") ;
  15221.                         VscrnIsDirty(VTERM);
  15222.                     }
  15223.                 } else if (pn[1] == 7) {
  15224.                     if ( private == FALSE ) {
  15225.                         /* Turn on screen display */
  15226.                         screenon = TRUE;
  15227.                         if ( savefiletext[0] ) {
  15228.                             strcpy(filetext,savefiletext);
  15229.                             savefiletext[0] = NUL ;
  15230.                             /* Update status line */
  15231.                             VscrnIsDirty(VTERM);
  15232.                         }
  15233.                     }
  15234.                 }
  15235.                 break;
  15236.             case 'k':       /* Keyclick */
  15237.             if ( pn[1] == 1 )
  15238.                     setkeyclick(FALSE);
  15239.                 else if ( pn[1] == 0 )
  15240.                     setkeyclick(TRUE);
  15241.                 break;
  15242.             case 'n':
  15243.                 switch ( pn[1] ) {
  15244.                 case 0:
  15245.                     /* SCO - Transmit Cursor Position */
  15246.                     if (ISSCO(tt_type_mode)) {
  15247.                         position * pos = VscrnGetCurPos(VTERM);
  15248.                         sprintf(tempstr,
  15249.                                  "%d %d\n",
  15250.                                  pos->y+1,
  15251.                                  pos->x+1
  15252.                                  );
  15253.                         sendchars(tempstr,strlen(tempstr));
  15254.                     }
  15255.                     break;
  15256.                 case 5: /* Terminal Status Report */
  15257.                     /* Pages 103-104, VT220 manual */
  15258.                     sendescseq("[0n"); /* Terminal is OK */
  15259.                     break;
  15260.                 case 6: {
  15261.                     /* Cursor position report (CPR/DECXCPR) */
  15262.                     /* Pages 103-104, VT220 manual */
  15263.                     position * pos = VscrnGetCurPos(VTERM);
  15264.                     if (private)
  15265.                         sprintf(tempstr,
  15266.                                 "[%d;%d;%dR",
  15267.                                 pos->y+1,
  15268.                                 pos->x+1,
  15269.                                 1
  15270.                                 );
  15271.                     else
  15272.                         sprintf(tempstr,"[%d;%dR",
  15273.                                 pos->y+1,
  15274.                                 pos->x+1
  15275.                                 );
  15276.                     sendescseq(tempstr);
  15277.                     break;
  15278.                 }
  15279. #ifdef COMMENT
  15280.                 case 7:
  15281.                     if ( private ) {
  15282.                         /* Request Time ("HH:MM:SS"<CR>) */
  15283.                         char response[32];
  15284.                         sprintf(response,"\"%2d:%2d:%2d\"\r",
  15285.                                 0,0,0);
  15286.                         sendchars(response,strlen(response));
  15287.                     }
  15288.                     break;
  15289.                 case 8: /* Request Date ("mmdddyy"<CR>) */
  15290.                     if ( private ) {
  15291.                         char response[32];
  15292.                         sprintf(response,"\"%2d%3s%2d\"\r",
  15293.                                 1,"jan",80);
  15294.                         sendchars(response,strlen(response));
  15295.                     }
  15296.                     break;
  15297. #endif /* COMMENT */
  15298.                 case 15: {
  15299.                     /* DECDSR Printer status */
  15300.                     sendescseq("[?10n"); /* Printer is ready */
  15301.                     break;
  15302.                 }
  15303.                 case 25: {
  15304.                     /*
  15305.                       DECDSR UDK status;
  15306.                       20=unlocked, 21=locked
  15307.                       */
  15308.                     if ( udklock )
  15309.                         sendescseq("[?21n");
  15310.                     else
  15311.                         sendescseq("[?20n");
  15312.                     break;
  15313.                 }
  15314.                 case 26: {
  15315.                     /*
  15316.                       DECDSR Keyboard language, UK or US
  15317.                       */
  15318.                     sendescseq((G[0].designation == TX_BRITISH) ?
  15319.                                "[?27;2n" :
  15320.                                "[?27;1n" );
  15321.                     break;
  15322.                 }
  15323.                 }
  15324.                 break;
  15325.             case 'o': 
  15326.                 if ( ISSCO(tt_type_mode) ) {
  15327.                     /* SCO - Transmit Margin Position */
  15328.  
  15329.                     switch ( pn[1] ) {
  15330.                     case '0': /* all margins */
  15331.                         sprintf(tempstr,
  15332.                                  "%d %d %d %d\n",
  15333.                                  margintop,
  15334.                                  marginbot,
  15335.                                  marginleft,
  15336.                                  marginright
  15337.                                  );
  15338.                         sendchars(tempstr,strlen(tempstr));
  15339.                         break;
  15340.                     case '1':
  15341.                         sprintf(tempstr,
  15342.                                  "%d\n",
  15343.                                  margintop
  15344.                                  );
  15345.                         sendchars(tempstr,strlen(tempstr));
  15346.                         break;
  15347.                     case '2':
  15348.                         sprintf(tempstr,
  15349.                                  "%d\n",
  15350.                                  marginbot
  15351.                                  );
  15352.                         sendchars(tempstr,strlen(tempstr));
  15353.                         break;
  15354.                     case '3':
  15355.                         sprintf(tempstr,
  15356.                                  "%d\n",
  15357.                                  marginleft
  15358.                                  );
  15359.                         sendchars(tempstr,strlen(tempstr));
  15360.                         break;
  15361.                     case '4':
  15362.                         sprintf(tempstr,
  15363.                                  "%d\n",
  15364.                                  marginright
  15365.                                  );
  15366.                         sendchars(tempstr,strlen(tempstr));
  15367.                         break;
  15368.                     }
  15369.                 } else if (ISAAA(tt_type_mode)) {
  15370.                     /* DAQ - Define Area Qualification */
  15371.  
  15372.                 }
  15373.                 break;
  15374.             case 'p':   /* Proprietary */
  15375.                 if ( ISH19(tt_type) ) {
  15376.                     /* Transmit Page to host */
  15377.                     break;
  15378.                 } else if ( ISAAA(tt_type_mode) ) {
  15379.                     /* zSDP - Set Display Parameters Pn1;Pn2;...;Pn6 
  15380.                      *
  15381.                      * Pn1 - Active Memory Lines 
  15382.                      * Pn2 - Upper Host Area Lines
  15383.                      * Pn3 - Lower Host Area Lines
  15384.                      * Pn4 - Screen Lines 
  15385.                      * Pn5 - Screen Columns
  15386.                      * Pn6 - Active Memory Columns
  15387.                      */
  15388.                     if ( pn[1] <= pn[2] + pn[3] ||
  15389.                          pn[4] <= pn[2] + pn[3] + 1 ||
  15390.                          (k > 4) && (pn[6] <= pn[5]))
  15391.                         break;
  15392.  
  15393.             /* Kermit is not going to do the right thing 
  15394.              * Since we do not support memory pages different
  15395.              * than the actual screen size, we ignore everything
  15396.              * but the memory lines
  15397.              */
  15398. #ifdef KUI
  15399.                     tt_linespacing[VTERM] = (CKFLOAT)pn[1] / (CKFLOAT)pn[4];
  15400.                     gui_resize_mode(0);
  15401. #endif /* KUI */
  15402.                     tt_szchng[VTERM] = 1 ;
  15403. #ifdef COMMENT
  15404.                     tt_rows[VTERM] = pn[4];
  15405. #else
  15406.                     tt_rows[VTERM] = pn[1];
  15407.                     marginbot = pn[4];
  15408. #endif /* COMMENT */
  15409.                     if (k > 4)
  15410.                         tt_cols[VTERM] = pn[5];
  15411.                     VscrnInit( VTERM ) ;  /* Height set here */
  15412.                     VscrnSetDisplayHeight(VTERM, pn[1] != pn[4] ? pn[4] : 0);
  15413. #ifdef TCPSOCKET
  15414. #ifdef CK_NAWS
  15415.                     if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  15416.                         tn_snaws();
  15417. #ifdef RLOGCODE
  15418.                         rlog_naws();
  15419. #endif /* RLOGCODE */
  15420. #ifdef SSHBUILTIN
  15421.                         ssh_snaws();
  15422. #endif /* SSHBUILTIN */
  15423.                     }
  15424. #endif /* TCPSOCKET */
  15425. #endif /* CK_NAWS */
  15426.                     break;
  15427.                 } else if ( ISSUN(tt_type_mode) ) {
  15428.                     /* 
  15429.                     ESC[p       Black On White (SUNBOW)
  15430.                     Takes no parameters.  Sets the screen  mode  to  black-
  15431.                     on-white.   If  the  screen  mode  is already black-on-
  15432.                     white, has no effect.  In this mode spaces  display  as
  15433.                     solid  white,  other characters as black-on-white.  The
  15434.                     cursor is a solid black block.  Characters displayed in
  15435.                     negative  image  rendition  (see `Select Graphic Rendi-
  15436.                     tion' above) is white-on-black in this mode.   This  is
  15437.                     the initial setting of the screen mode on reset.
  15438.                     */
  15439.                 }
  15440.                 else if ( IS97801(tt_type_mode) ) {
  15441.                     switch ( pn[1] ) {
  15442.                     case 0: /* Blinking on, lines 1-25 or 1-24 */
  15443.                         break;
  15444.                     case 1: /* Blinking off, lines 1-25 or 1-24 */
  15445.                         break;
  15446.                     case 2: /* Blinking on, line 25 */
  15447.                         break;
  15448.                     case 3: /* Blinking off, line 25 */
  15449.                         break;
  15450.                     case 5: /* Request abbreviated cursor position */
  15451.                         {
  15452.                             /* Respond with <FS> <line + 0x20> <col + 0x20>, 0 based */
  15453.                             char buf[4];
  15454.                             buf[0] = XFS;
  15455.                             buf[1] = wherey[1] + SP - 1;
  15456.                             buf[2] = wherex[1] + SP - 1;
  15457.                             buf[3] = NUL;
  15458.                             sendchars(buf,3);
  15459.                         }
  15460.                         break;
  15461.                     case 6: /* Cursor not visible */
  15462.                         cursorena[VTERM] = FALSE;
  15463.                         break;
  15464.                     case 7: /* Activate cursor */
  15465.                         cursorena[VTERM] = TRUE;
  15466.                         break;
  15467.                     case 8: /* Display off */
  15468.                         /* This is supposed to fill the viewable      */
  15469.                         /* screen with blanks but continue processing */
  15470.                         /* additional chars into the display buffer   */
  15471.                         screenon = FALSE;
  15472.                         if ( !savefiletext[0] )
  15473.                             strcpy(savefiletext,filetext);
  15474.                         strcpy(filetext,"SCREEN OFF") ;
  15475.                         VscrnIsDirty(VTERM);
  15476.                         break;
  15477.                     case 9: /* Display on */
  15478.                         /* Re-enable viewing the display buffer with  */
  15479.                         /* real data.                                 */
  15480.                         screenon = TRUE;
  15481.                         if ( savefiletext[0] ) {
  15482.                             strcpy(filetext,savefiletext);
  15483.                             savefiletext[0] = NUL ;
  15484.                             /* Update status line */
  15485.                             VscrnIsDirty(VTERM);
  15486.                         }
  15487.                         break;
  15488.                     case 10: /* Single inverting block cursor */
  15489.                         tt_cursor = TTC_HALF;
  15490.                         setcursormode();
  15491.                         cursorena[VTERM] = TRUE;
  15492.                         break;
  15493.                     case 11: /* Activate block cursor */
  15494.                         tt_cursor = TTC_BLOCK;
  15495.                         setcursormode();
  15496.                         cursorena[VTERM] = TRUE;
  15497.                         break;
  15498.                     case 12: /* Activate underscore cursor */
  15499.                         tt_cursor = TTC_ULINE;
  15500.                         setcursormode();
  15501.                         cursorena[VTERM] = TRUE;
  15502.                         break;
  15503.                     case 13: /* Activate cursor blinking */
  15504.                         break;
  15505.                     case 14: /* Deactivate cursor blinking */
  15506.                         break;
  15507.                     }
  15508.                 }
  15509.                 break;
  15510.             case 'q':   /* Proprietary */
  15511.                 if ( ISH19(tt_type) ) {
  15512.                     /* Transmit 25th line to host */
  15513.                     break;
  15514.                 } else if ( ISSUN(tt_type_mode) ) {
  15515.                     /*
  15516.                     ESC[q       White On Black (SUNWOB)
  15517.                     Takes no parameters.  Sets the screen  mode  to  white-
  15518.                     on-black.   If  the  screen  mode  is already white-on-
  15519.                     black, has no effect.  In this mode spaces  display  as
  15520.                     solid  black,  other characters as white-on-black.  The
  15521.                     cursor is a solid white block.  Characters displayed in
  15522.                     negative  image  rendition  (see `Select Graphic Rendi-
  15523.                     tion' above) is black-on-white in this mode.  The  ini-
  15524.                     tial  setting of the screen mode on reset is the alter-
  15525.                     native mode, black on white.
  15526.                     */
  15527.                 }
  15528.                 else if ( IS97801(tt_type_mode) ) {
  15529.                     switch ( pn[1] ) {
  15530.                     case 0: /* CH.CODE LED off */
  15531.                         /* does not affect actual mode */
  15532.                         break;
  15533.                     case 6: /* CH.CODE LED on */
  15534.                         /* does not affect actual mode */
  15535.                         break;
  15536.                     }
  15537.                     break;
  15538.                 }
  15539.                 else {
  15540.                     /* Load LEDs */
  15541.                     for ( i=1 ; i<=k ; i++ ) {
  15542.                         switch ( pn[i] ) {
  15543.                         case 0:
  15544.                             decled[0] = decled[1] =
  15545.                                 decled[2] = decled[3] = FALSE ;
  15546.                             break;
  15547.                         case 1:
  15548.                         case 2:
  15549.                         case 3:
  15550.                         case 4:
  15551.                             decled[ pn[i]-1 ] = TRUE ;
  15552.                             break;
  15553.                         case 21:
  15554.                         case 22:
  15555.                         case 23:
  15556.                         case 24:
  15557.                             decled[ pn[i]-21 ] = FALSE ;
  15558.                             break;
  15559.                         }
  15560.                     }
  15561.                     ipadl25() ;
  15562.                 }
  15563.                 break;
  15564.             case 'x':   /* Proprietary */
  15565.                 if ( ISWY370(tt_type_mode) ) {
  15566.                     /* Set Color and Attribute */
  15567.                     /* pn[1] - 64 color palette - fg */
  15568.                     /* pn[2] - 64 color palette - bg */
  15569.                     /* pn[3] - attribute             */
  15570.                     switch ((pn[3])) {   /* This one... */
  15571.                     case 0: /* Set all attributes to normal */
  15572.                         if (colorreset)
  15573.                             resetcolors(0);
  15574.  
  15575.                         attrib.blinking = FALSE;
  15576.                         attrib.italic = FALSE;              /* No italic */
  15577.                         attrib.bold = FALSE;
  15578.                         attrib.invisible = FALSE;
  15579.                         attrib.underlined = FALSE;
  15580.                         attrib.reversed = FALSE;
  15581.                         attrib.graphic = FALSE ;
  15582.                         attrib.dim = FALSE ;
  15583.                         attrib.wyseattr = FALSE ;
  15584.                         attrib.hyperlink = FALSE;
  15585.                         attrib.linkid = 0;
  15586.  
  15587.                         sco8bit = FALSE ;
  15588.  
  15589.                         if ( ISANSI(tt_type_mode) )
  15590.                             crm = FALSE ;
  15591.                         break;
  15592.                     case 1: /* Turn on BOLD */
  15593.                         /* No colors involved. */
  15594.                         if (attrib.bold) /* Already bold? */
  15595.                             break;
  15596.                         attrib.bold = TRUE; /* Remember */
  15597.                         break;
  15598.                     case 2: /* Turn on DIM (QANSI) */
  15599.                         /* No colors involved. */
  15600.                         if (attrib.dim) /* Already dim? */
  15601.                             break;
  15602.                         attrib.dim = TRUE; /* Remember */
  15603.                         break;
  15604.                     case 3: /* Turn on ITALIC (ANSI X3.64) */
  15605.                         if ( tt_type_mode == TT_AT386 &&
  15606.                              !trueitalic ) {
  15607.                             if ( colorreset )
  15608.                                 resetcolors(0);
  15609.                             attribute = italicattribute;
  15610.                         }
  15611.                         else {
  15612.                             if (attrib.italic)
  15613.                                 break;
  15614.                             attrib.italic = TRUE;
  15615.                         }
  15616.                         break;
  15617.                     case 4: /* Turn on UNDERLINE */
  15618.                         if ( tt_type_mode == TT_AT386 &&
  15619.                              !trueunderline ) {
  15620.                             if ( colorreset )
  15621.                                 resetcolors(0);
  15622.                             attribute = underlineattribute;
  15623.                         }
  15624.                         else {
  15625.                             if (attrib.underlined)
  15626.                                 break;
  15627.                             attrib.underlined = TRUE;
  15628.                         }
  15629.                         break;
  15630.                     case 5: /* Turn on Slow BLINK */
  15631.                         /* Simulated by background intensity) */
  15632.                         if ( attrib.blinking )
  15633.                             break;
  15634.                         attrib.blinking = TRUE;
  15635.                         break;
  15636.                     case 6: /* Turn on Fast BLINK */
  15637.                         if ( attrib.blinking )
  15638.                             break;
  15639.                         attrib.blinking = TRUE ;
  15640.                         break;
  15641.                     case 7: /* Turn on REVERSE VIDEO */
  15642.                         if ( tt_type_mode == TT_AT386 ) {
  15643.                             if ( colorreset )
  15644.                                 resetcolors(0);
  15645.                             attribute = swapcolors(attribute);
  15646.                         }
  15647.                         else {
  15648.                             if (attrib.reversed)
  15649.                                 break;
  15650.                             attrib.reversed = TRUE;
  15651.                         }
  15652.                         break;
  15653.  
  15654.                         /* 8 - 12 are ANSI X3.64 */
  15655.                     case 8: /* Turn on INVISIBLE */
  15656.                     case 9: /* Turn on INVISIBLE (QANSI) */
  15657.                         attrib.invisible = TRUE; /* see wrtch */
  15658.                         break;
  15659.                     }
  15660.                     if ( !sgrcolors )
  15661.                         break;
  15662.                     l = sgrcols[(decscnm?pn[2]:pn[1])%8];
  15663.                     i = (attribute & 0x8F);
  15664.                     attribute = (i | ((l << 4)));
  15665.                     l = sgrcols[(decscnm?pn[1]:pn[2])%8];
  15666.                     i = (attribute & 0xF8);
  15667.                     attribute = (i | l);
  15668.                     break;
  15669.                 }
  15670.  
  15671.                 /* DECREQTPARM Request Terminal Parameters */
  15672.                 if (pn[1] > 1)
  15673.                     break;
  15674.                 tempstr[0] = '[';
  15675.                 tempstr[1] = (pn[1] == 0) ? '2' : '3';
  15676.                 tempstr[2] = ';';
  15677.                 tempstr[5] = '2'; /* Nbits = 7 */
  15678.                 switch (parity) {
  15679.                 case 0:
  15680.                     tempstr[3] = '1'; /* Parity = None */
  15681.                     /* Nbits depends on TERMINAL BYTESIZE */
  15682.                     if (cmask == 0xFF)
  15683.                         tempstr[5] = '1'; /* Nbits = 8 */
  15684.                     break;
  15685.                 case 'e':
  15686.                     tempstr[3] = '5'; /* Parity = Even */
  15687.                     break;
  15688.                 case 'o':
  15689.                     tempstr[3] = '4'; /* Parity = Odd */
  15690.                     break;
  15691.                 case 'm':
  15692.                     tempstr[3] = '3'; /* Parity = Mark */
  15693.                     break;
  15694.                 default:
  15695.                     tempstr[3] = '2'; /* Parity = Space */
  15696.                     break;
  15697.                 }
  15698.                 tempstr[4] = ';';
  15699.                 switch (speed) {
  15700.                 case 50:
  15701.                     i = 0;
  15702.                     break;
  15703.                 case 75:
  15704.                     i = 8;
  15705.                     break;
  15706.                 case 110:
  15707.                     i = 16;
  15708.                     break;
  15709.                 case 133:
  15710.                     i = 14;
  15711.                     break;
  15712.                 case 150:
  15713.                     i = 32;
  15714.                     break;
  15715.                 case 200:
  15716.                     i = 40;
  15717.                     break;
  15718.                 case 300:
  15719.                     i = 48;
  15720.                     break;
  15721.                 case 600:
  15722.                     i = 56;
  15723.                     break;
  15724.                 case 1200:
  15725.                     i = 64;
  15726.                     break;
  15727.                 case 1800:
  15728.                     i = 72;
  15729.                     break;
  15730.                 case 2000:
  15731.                     i = 80;
  15732.                     break;
  15733.                 case 2400:
  15734.                     i = 88;
  15735.                     break;
  15736.                 case 3600:
  15737.                     i = 96;
  15738.                     break;
  15739.                 case 4800:
  15740.                     i = 104;
  15741.                     break;
  15742.                 case 9600:
  15743.                     i = 112;
  15744.                     break;
  15745.                 case 19200: /* Really the 19200 value */
  15746.                     i=120;
  15747.                     break;
  15748.                 case 38400: /* but it's the highest one */
  15749.                     i=128;
  15750.                     break;
  15751.                 case 57600:
  15752.                 case 115200:
  15753.                 case 230400:
  15754.                 case -1: /*  Lie about networks too */
  15755.                     i = 128;
  15756.                     break;
  15757.                 default: /* UNKNOWN speed - not true */
  15758.                     i = 128;
  15759.                     break;
  15760.                 }
  15761.                 sprintf(&tempstr[6], ";%d;%d;1;0x", i, i);
  15762.                 sendescseq(tempstr);
  15763.                 break;
  15764.             case '}':       /* (Why this?) */
  15765.             case 'm':
  15766.                 if ( ansiext && private ) {
  15767.                     /* Delete Line Up */
  15768.                     VscrnScroll(VTERM,
  15769.                                 DOWNWARD,
  15770.                                 0,
  15771.                                 wherey[VTERM] - 1,
  15772.                                 1,
  15773.                                 FALSE,
  15774.                                 SP);
  15775.                     break;
  15776.                 } else if ( ansiext && ISSCO(tt_type_mode) ) {
  15777.                     switch ( pn[1] ) {
  15778.                     case 0: /* top margin */
  15779.                         margintop = pn[2];
  15780.                         break;
  15781.                     case 1: /* bottom margin */
  15782.                         marginbot = pn[2];
  15783.                         break;
  15784.                     case 2: /* left margin */
  15785.                         marginleft = pn[2];
  15786.                         break;
  15787.                     case 3: /* right margin */
  15788.                         marginright = pn[2];
  15789.                         break;
  15790.                     }
  15791.                 } else { /* Select Graphic Rendition (SGR) */
  15792.                     for (j = 1; j <= k; ++j) /* Go thru all Pn's */
  15793.                         switch ((pn[j])) {   /* This one... */
  15794.                         case 0: /* Set all attributes to normal */
  15795.                             if (colorreset)
  15796.                                 resetcolors(0);
  15797.  
  15798.                             attrib.blinking = FALSE;
  15799.                             attrib.italic = FALSE;              /* No italic */
  15800.                             attrib.bold = FALSE;
  15801.                             attrib.invisible = FALSE;
  15802.                             attrib.underlined = FALSE;
  15803.                             attrib.reversed = FALSE;
  15804.                             attrib.graphic = FALSE ;
  15805.                             attrib.dim = FALSE ;
  15806.                             attrib.wyseattr = FALSE ;
  15807.                             attrib.hyperlink = FALSE;
  15808.                             attrib.linkid = 0;
  15809.  
  15810.                             sco8bit = FALSE ;
  15811.  
  15812.                             if ( ISANSI(tt_type_mode) )
  15813.                                 crm = FALSE ;
  15814.                             break;
  15815.                         case 1:     /* Turn on BOLD */
  15816.                             /* No colors involved. */
  15817.                             if (attrib.bold) /* Already bold? */
  15818.                                 break;
  15819.                             attrib.bold = TRUE; /* Remember */
  15820.                             break;
  15821.                         case 2:
  15822.                             if ( ISSCO(tt_type_mode) ) {
  15823.                                 /* Select fg/bg iso colors */
  15824.                                 if ( !sgrcolors )
  15825.                                     break;
  15826.                                 if (decscnm) {
  15827.                                     i = (attribute & 0x88);
  15828.                                     attribute = (i | (((pn[j+1] & 0x07) << 4)) | (pn[j+2] & 0x07));
  15829.                                     defaultattribute = attribute;
  15830.                                     graphicattribute = attribute;
  15831.                                     reverseattribute = (i | (((pn[j+2] & 0x07) << 4)) | (pn[j+1] & 0x07));
  15832.                                     /* reverseattribute = attribute; */
  15833.                                 } else {
  15834.                                     i = (attribute & 0x88);
  15835.                                     attribute = (i | (((pn[j+2] & 0x07) << 4)) | (pn[j+1] & 0x07));
  15836.                                     defaultattribute = attribute;
  15837.                                     graphicattribute = attribute;
  15838.                                     reverseattribute = (i | (((pn[j+1] & 0x07) << 4)) | (pn[j+2] & 0x07));
  15839.                                     /* reverseattribute = attribute; */
  15840.                                 }
  15841.                                 j += 2;
  15842.                             } else {
  15843.                                 /* Turn on DIM (QANSI) */
  15844.                                 /* No colors involved. */
  15845.                                 if (attrib.dim) /* Already dim? */
  15846.                                     break;
  15847.                                 attrib.dim = TRUE; /* Remember */
  15848.                             }
  15849.                             break;
  15850.                         case 3:
  15851.                             if ( ISSCO(tt_type_mode) ) {
  15852.                                 /* Turn on Italic */
  15853.                                 /* pn[j+1] determines blink or bold background*/
  15854.                                 if (attrib.italic)
  15855.                                     break;
  15856.                                 attrib.italic = TRUE;
  15857.                                 j++;
  15858.                                 break;
  15859.                             } else {
  15860.                                 /* Turn on ITALIC (ANSI X3.64) */
  15861.                                 if (attrib.italic)
  15862.                                     break;
  15863.                                 attrib.italic = TRUE;
  15864.                             }
  15865.                             break;
  15866.                         case 4:     /* Turn on UNDERLINE */
  15867.                             if ( tt_type_mode == TT_AT386 &&
  15868.                                 !trueunderline ) {
  15869.                                 if ( colorreset )
  15870.                                     resetcolors(0);
  15871.                                 attribute = underlineattribute;
  15872.                             }
  15873.                             else {
  15874.                                 if (attrib.underlined)
  15875.                                     break;
  15876.                                 attrib.underlined = TRUE;
  15877.                             }
  15878.                             break;
  15879.                         case 5:
  15880.                             if ( ISSCO(tt_type_mode) ) {
  15881.                                 /* Turn on Blink Mode */
  15882.                                 if ( attrib.blinking )
  15883.                                     break;
  15884.                                 attrib.blinking = TRUE;
  15885.                             } else {
  15886.                                 /* Turn on Slow BLINK */
  15887.                                 /* Simulated by background intensity) */
  15888.                                 if ( attrib.blinking )
  15889.                                     break;
  15890.                                 attrib.blinking = TRUE;
  15891.                             }
  15892.                             break;
  15893.                         case 6:
  15894.                             if ( ISSCO(tt_type_mode) ) {
  15895.                                 /* Turn off Blink Mode */
  15896.                                 if ( !attrib.blinking )
  15897.                                     break;
  15898.                                 attrib.blinking = FALSE;
  15899.                             } else {
  15900.                                 /* Turn on Fast BLINK */
  15901.                                 if ( attrib.blinking )
  15902.                                     break;
  15903.                                 attrib.blinking = TRUE ;
  15904.                             }
  15905.                             break;
  15906.                         case 7: /* Turn on REVERSE VIDEO */
  15907.                             if ( tt_type_mode == TT_AT386 ) {
  15908.                                 if ( colorreset )
  15909.                                     resetcolors(0);
  15910.                                 attribute = swapcolors(attribute);
  15911.                             }
  15912.                             else {
  15913.                                 if (attrib.reversed)
  15914.                                     break;
  15915.                                 attrib.reversed = TRUE;
  15916.                             }
  15917.                             break;
  15918.  
  15919.                             /* 8 - 12 are ANSI X3.64 */
  15920.                         case 8: /* Turn on INVISIBLE */
  15921.                         case 9: /* Turn on INVISIBLE (QANSI) */
  15922.                             attrib.invisible = TRUE; /* see wrtch */
  15923.                             break;
  15924.  
  15925.                         case 10:  /* Select Primary font */
  15926.                             if (ISANSI(tt_type_mode) ||
  15927.                                 ISBEOS(tt_type_mode))
  15928.                             {
  15929.                                 sco8bit = FALSE;
  15930.                                 crm = FALSE ;
  15931.                                 attrib.graphic = FALSE ;
  15932.                                 GR = &G[1];
  15933.                                 if ( tt_type_mode == TT_AT386 && colorreset ||
  15934.                                      ISSCO(tt_type_mode) && scocompat )
  15935.                                     resetcolors(0);
  15936.                             } else if (ISLINUX(tt_type_mode) ||
  15937.                                        ISQANSI(tt_type_mode)) {
  15938.                                 sco8bit = FALSE;
  15939.                                 crm = FALSE;
  15940.                                 if ( Qsaved ) {
  15941.                                     int i;
  15942.                                     Qsaved = FALSE;
  15943.                                     for ( i=0;i<4;i++ )
  15944.                                         G[i] = QsavedG[i];
  15945.                                 }
  15946.                             }
  15947.                             break;
  15948.  
  15949.                         case 11:  /* Display GL Control Characters */
  15950.                             /* as Graphic Characters */
  15951.                             if ( ISANSI(tt_type_mode) )
  15952.                             {
  15953.                                 sco8bit = FALSE ;
  15954.                                 crm = TRUE;
  15955.                                 GR = &G[2];
  15956.                                 if ( tt_type_mode == TT_AT386 && colorreset ||
  15957.                                      ISSCO(tt_type_mode) && scocompat )
  15958.                                     resetcolors(0);
  15959.                                 attribute = graphicattribute ;
  15960.                             }
  15961.                             else if (ISLINUX(tt_type_mode)) {
  15962.                                 int i;
  15963.                                 sco8bit = TRUE ;
  15964.                                 crm = TRUE;
  15965.                                 if ( !Qsaved ) {
  15966.                                     Qsaved = TRUE;
  15967.                                     for ( i=0;i<4;i++ )
  15968.                                         QsavedG[i] = G[i];
  15969.                                 }
  15970.                                 for ( i=1;i<4;i++ )
  15971.                                     charset(cs94,'U',&G[i]);
  15972.                             }
  15973.                             else if (ISQANSI(tt_type_mode)) {
  15974.                                 int i;
  15975.                                 sco8bit = TRUE ;
  15976.                                 crm = TRUE;
  15977.                                 if ( !Qsaved ) {
  15978.                                     Qsaved = TRUE;
  15979.                                     for ( i=0;i<4;i++ )
  15980.                                         QsavedG[i] = G[i];
  15981.                                 }
  15982.                                 for ( i=1;i<3;i++ )
  15983.                                     charset(cs94,'*',&G[i]);
  15984.                             }
  15985.                             break;
  15986.  
  15987.                         case 12:
  15988.                             if (ISLINUX(tt_type_mode)) {
  15989.                                 /*
  15990.                                 select null mapping (CP437),
  15991.                                 set display control flag,
  15992.                                 set toggle meta flag. (The toggle meta flag
  15993.                                 causes the high bit of a byte to be toggled
  15994.                                 before the mapping table translation is done.)
  15995.                                 */
  15996.                                 int i;
  15997.                                 sco8bit = TRUE ;
  15998.                                 crm = TRUE ;
  15999.                                 attrib.graphic = FALSE ;
  16000.                                 if ( !Qsaved ) {
  16001.                                     Qsaved = TRUE;
  16002.                                     for ( i=0;i<4;i++ )
  16003.                                         QsavedG[i] = G[i];
  16004.                                 }
  16005.                                 for ( i=1;i<4;i++ )
  16006.                                     charset(cs94,'U',&G[i]);
  16007.                                 break;
  16008.                             }
  16009.                         case 13: /* IBM HFT */
  16010.                         case 14: /* IBM HFT */
  16011.                         case 15: /* IBM HFT */
  16012.                         case 16: /* IBM HFT */
  16013.                         case 17: /* IBM HFT */
  16014.                             /* Shift High Bit on before displaying */
  16015.                             /* Characters */
  16016.                             if ( ISANSI(tt_type_mode) ||
  16017.                                 ISBEOS(tt_type_mode))
  16018.                             {
  16019.                                 sco8bit = TRUE ;
  16020.                                 crm = FALSE ;
  16021.                                 attrib.graphic = FALSE ;
  16022.                                 GR = &G[3];
  16023.  
  16024.                                 if ( tt_type_mode == TT_AT386 &&
  16025.                                     colorreset )
  16026.                                     resetcolors(0);
  16027.                             } else if (ISQANSI(tt_type_mode)) {
  16028.                                 int i;
  16029.                                 sco8bit = TRUE ;
  16030.                                 crm = FALSE;
  16031.                                 if ( !Qsaved ) {
  16032.                                     Qsaved = TRUE;
  16033.                                     for ( i=0;i<4;i++ )
  16034.                                         QsavedG[i] = G[i];
  16035.                                 }
  16036.                                 for ( i=1;i<3;i++ )
  16037.                                     charset(cs94,'U',&G[i]);
  16038.                             }
  16039.  
  16040.                         case 21: /* Set Normal Intensity */
  16041.                             if (attrib.bold)
  16042.                                 attrib.bold = FALSE;
  16043.                             if (attrib.dim)
  16044.                                 attrib.dim = FALSE;
  16045.                             break;
  16046.                         case 22: /* Turn BOLD Off */
  16047.                             if (attrib.bold)
  16048.                                 attrib.bold = FALSE;
  16049.                             if (attrib.dim)
  16050.                                 attrib.dim = FALSE;
  16051.                             break;
  16052.                         case 23: /* Turn ITALIC off */
  16053.                             if (!attrib.italic)
  16054.                                 break;
  16055.                             attrib.italic = FALSE;
  16056.                             break;
  16057.  
  16058.                         case 24: /* Turn UNDERLINE Off */
  16059.                             if (!attrib.underlined)
  16060.                                 break;
  16061.                             attrib.underlined = FALSE;
  16062.                             /* Go back to normal coloring */
  16063.                             break;
  16064.                         case 25: /* Turn BLINK Off */
  16065.                             if (!attrib.blinking)
  16066.                                 break;
  16067.                             attrib.blinking = FALSE;
  16068.                             break;
  16069.                         case 26: /* Turn BLINK On */
  16070.                             if ( ISSCO(tt_type_mode)) {
  16071.                                 if (attrib.blinking)
  16072.                                     break;
  16073.                                 attrib.blinking = TRUE;
  16074.                             } else {
  16075.                                 if (!attrib.blinking)
  16076.                                     break;
  16077.                                 attrib.blinking = FALSE;
  16078.                             }
  16079.                             break;
  16080.                         case 27: /* Turn REVERSE VIDEO Off */
  16081.                             if (!attrib.reversed)
  16082.                                 break;
  16083.                             attrib.reversed = FALSE;
  16084.                             break;
  16085.                         case 28:/* Turn INVISIBLE Off */
  16086.                         case 29:/* QANSI */
  16087.                             if (!attrib.invisible)
  16088.                                 break;
  16089.                             attrib.invisible = FALSE;
  16090.                             break;
  16091.  
  16092.                         case 30: /* Colors */
  16093.                         case 31:
  16094.                         case 32:
  16095.                         case 33:
  16096.                         case 34:
  16097.                         case 35:
  16098.                         case 36:
  16099.                         case 37:
  16100.                             /* Select foreground color */
  16101.                             if ( !sgrcolors )
  16102.                                 break;
  16103.                             if ( 0 && ISQANSI(tt_type_mode) )
  16104.                                 l = pn[j] - 30;
  16105.                             else
  16106.                                 l = sgrcols[pn[j] - 30];
  16107.                             if (decscnm) {
  16108.                                 i = (attribute & 0x8F);
  16109.                                 attribute = (i | ((l << 4)));
  16110.  
  16111.                                 if ( ISSCO(tt_type_mode) ) {
  16112.                                     /* set the default attribute as well */
  16113.                                     i = (defaultattribute & 0x8F);
  16114.                                     defaultattribute = (i | (l << 4));
  16115.                                     i = (graphicattribute & 0x8F);
  16116.                                     graphicattribute = (i | (l << 4));
  16117. #ifdef COMMENT
  16118.                                     i = (reverseattribute & 0x8F);
  16119.                                     reverseattribute = (i | (l << 4));
  16120. #else
  16121.                                     i = (reverseattribute & 0xF8);
  16122.                                     reverseattribute = (i | l);
  16123. #endif
  16124.                                 }
  16125.                             } else {
  16126.                                 i = (attribute & 0xF8);
  16127.                                 attribute = (i | l);
  16128.  
  16129.                                 if ( ISSCO(tt_type_mode) ) {
  16130.                                     /* set the default attribute as well */
  16131.                                     i = (defaultattribute & 0xF8);
  16132.                                     defaultattribute = (i | l);
  16133.                                     i = (graphicattribute & 0xF8);
  16134.                                     graphicattribute = (i | l);
  16135. #ifdef COMMENT
  16136.                                     i = (reverseattribute & 0xF8);
  16137.                                     reverseattribute = (i | l);
  16138. #else
  16139.                                     i = (reverseattribute & 0x8F);
  16140.                                     reverseattribute = (i | (l << 4));
  16141. #endif
  16142.                                 }
  16143.                             }
  16144.                             break;
  16145.                         case 38:  /* enable underline option */
  16146.                             break;
  16147.                         case 39:  /* disable underline option */
  16148.                             /* Supported by SCO ANSI */
  16149.                             /* QANSI - restore fg color saved with */
  16150.                             /* CSI = Pn F                          */
  16151.                             if ( !sgrcolors )
  16152.                                 break;
  16153.  
  16154.                             if (decscnm) {
  16155.                                 l = (defaultattribute & 0x70);
  16156.                                 i = (attribute & 0x8F);
  16157.                                 attribute = (i | l);
  16158.                             } else {
  16159.                                 l = defaultattribute & 0x07;
  16160.                                 i = (attribute & 0xF8);
  16161.                                 attribute = (i | l);
  16162.                             }
  16163.                             break;
  16164.                         case 40:
  16165.                         case 41:
  16166.                         case 42:
  16167.                         case 43:
  16168.                         case 44:
  16169.                         case 45:
  16170.                         case 46:
  16171.                         case 47:
  16172.                             /* Select background color */
  16173.                             if ( !sgrcolors )
  16174.                                 break;
  16175.  
  16176.                             if ( 0 && ISQANSI(tt_type_mode) )
  16177.                                 l = pn[j] - 40;
  16178.                             else
  16179.                                 l = sgrcols[pn[j] - 40];
  16180.                             if (!decscnm) {
  16181.                                 i = (attribute & 0x8F);
  16182.                                 attribute = (i | ((l << 4)));
  16183.  
  16184.                                 if ( tt_type_mode == TT_SCOANSI ) {
  16185.                                     /* set the default attribute as well */
  16186.                                     i = (defaultattribute & 0x8F);
  16187.                                     defaultattribute = (i | (l << 4));
  16188.                                     i = (graphicattribute & 0x8F);
  16189.                                     graphicattribute = (i | (l << 4));
  16190. #ifdef COMMENT
  16191.                                     i = (reverseattribute & 0x8F);
  16192.                                     reverseattribute = (i | (l << 4));
  16193. #else
  16194.                                     i = (reverseattribute & 0xF8);
  16195.                                     reverseattribute = (i | l);
  16196. #endif
  16197.                                 }
  16198.                             } else {
  16199.                                 i = (attribute & 0xF8);
  16200.                                 attribute = (i | l);
  16201.  
  16202.                                 if ( tt_type_mode == TT_SCOANSI ) {
  16203.                                     /* set the default attribute as well */
  16204.                                     i = (defaultattribute & 0xF8);
  16205.                                     defaultattribute = (i | l);
  16206.                                     i = (graphicattribute & 0xF8);
  16207.                                     graphicattribute = (i | l);
  16208. #ifdef COMMENT
  16209.                                     i = (reverseattribute & 0xF8);
  16210.                                     reverseattribute = (i | l);
  16211. #else
  16212.                                     i = (reverseattribute & 0x8F);
  16213.                                     reverseattribute = (i | (l << 4));
  16214. #endif
  16215.                                 }
  16216.                             }
  16217.                             break;
  16218.                         case 49:
  16219.                             /* Supported by SCO ANSI */
  16220.                             /* QANSI - restore bg color saved with */
  16221.                             /* CSI = Pn G                          */
  16222.                             if ( !sgrcolors )
  16223.                                 break;
  16224.  
  16225.                             if (!decscnm) {
  16226.                                 l = defaultattribute & 0x70;
  16227.                                 i = (attribute & 0x8F);
  16228.                                 attribute = (i | l);
  16229.                             } else {
  16230.                                 l = defaultattribute & 0x07;
  16231.                                 i = (attribute & 0xF8);
  16232.                                 attribute = (i | l);
  16233.                             }
  16234.                             break;
  16235.                         case 50:
  16236.                             if ( IS97801(tt_type_mode) ) {
  16237.                                 /* Save Attributes */
  16238.                                 /* When the "save attributes" command is issued,  */
  16239.                                 /* all attributes then in effect for the entire   */
  16240.                                 /* screen are stored.  These attributes will then */
  16241.                                 /* apply to any new display data (without SGR com-*/
  16242.                                 /* mand sequences) output to the screen.          */
  16243.                                 /* The stored attributes can be returned to normal*/
  16244.                                 /* by commands such as "erase in display with     */
  16245.                                 /* blanks/NULs; clear attributes". */
  16246.                                 break;
  16247.                             } else if ( ISSCO(tt_type_mode) ) {
  16248.                                 /*
  16249.                                 Reset to the original color pair. In backwards
  16250.                                 compatibility mode, set the normal attribute to white
  16251.                                 text on a black background, and reverse video to black
  16252.                                 text on a white background.  In the default (new) mode,
  16253.                                 set the current attribute according to the current mode
  16254.                                 and the current values for reverse, normal or graphics
  16255.                                 */
  16256.                             }
  16257.                             break;
  16258.                         case 51:
  16259.                             if ( ISSCO(tt_type_mode) ) {
  16260.                                 /*
  16261.                                 Resets all colors to the system default of gray for the
  16262.                                 foreground and reverse background, and black for the
  16263.                                 background and reverse foreground.  Only valid in new
  16264.                                 mode.
  16265.                                 */
  16266.                                 break;
  16267.                             }
  16268.                         case 90: /* Colors */
  16269.                         case 91:
  16270.                         case 92:
  16271.                         case 93:
  16272.                         case 94:
  16273.                         case 95:
  16274.                         case 96:
  16275.                         case 97:
  16276.                             /* Select foreground color (8-bit high) */
  16277.                             if ( !sgrcolors )
  16278.                                 break;
  16279.                             if ( 0 && ISQANSI(tt_type_mode) )
  16280.                                 l = pn[j] - 90;
  16281.                             else
  16282.                                 l = sgrcols[pn[j] - 90];
  16283.                             l += 8;     /* 8th bit high */
  16284.                             if (decscnm
  16285. #ifdef COMMENT
  16286.                                  && !attrib.reversed ||
  16287.                                  !decscnm && attrib.reversed
  16288. #endif
  16289.                                  ) {
  16290.                                 i = (attribute & 0x8F);
  16291.                                 attribute = (i | ((l << 4)));
  16292.  
  16293.                                 if ( tt_type_mode == TT_SCOANSI ) {
  16294.                                     /* set the default attribute as well */
  16295.                                     i = (defaultattribute & 0x8F);
  16296.                                     defaultattribute = (i | (l << 4));
  16297.                                     i = (graphicattribute & 0x8F);
  16298.                                     graphicattribute = (i | (l << 4));
  16299. #ifdef COMMENT
  16300.                                     i = (reverseattribute & 0x8F);
  16301.                                     reverseattribute = (i | (l << 4));
  16302. #else
  16303.                                     i = (reverseattribute & 0xF8);
  16304.                                     reverseattribute = (i | l);
  16305. #endif
  16306.                                 }
  16307.                                 } else {
  16308.                                     i = (attribute & 0xF8);
  16309.                                     attribute = (i | l);
  16310.  
  16311.                                     if ( tt_type_mode == TT_SCOANSI ) {
  16312.                                         /* set the default attribute as well */
  16313.                                         i = (defaultattribute & 0xF8);
  16314.                                         defaultattribute = (i | l);
  16315.                                         i = (graphicattribute & 0xF8);
  16316.                                         graphicattribute = (i | l);
  16317. #ifdef COMMENT
  16318.                                         i = (reverseattribute & 0xF8);
  16319.                                         reverseattribute = (i | l);
  16320. #else
  16321.                                         i = (reverseattribute & 0x8F);
  16322.                                         reverseattribute = (i | (l << 4));
  16323. #endif
  16324.                                     }
  16325.                                 }
  16326.                             break;
  16327.                         case 100:
  16328.                         case 101:
  16329.                         case 102:
  16330.                         case 103:
  16331.                         case 104:
  16332.                         case 105:
  16333.                         case 106:
  16334.                         case 107:
  16335.                             /* Select background color (8-bit high) */
  16336.                             if ( !sgrcolors )
  16337.                                 break;
  16338.  
  16339.                             if ( 0 && ISQANSI(tt_type_mode) )
  16340.                                 l = pn[j] - 100;
  16341.                             else
  16342.                                 l = sgrcols[pn[j] - 100];
  16343.                             l += 8;     /* 8th bit high */
  16344.                             if (!decscnm
  16345. #ifdef COMMENT
  16346.                                  && !attrib.reversed ||
  16347.                                  decscnm && attrib.reversed
  16348. #endif
  16349.                                 ) {
  16350.                                 i = (attribute & 0x8F);
  16351.                                 attribute = (i | ((l << 4)));
  16352.  
  16353.                                 if ( tt_type_mode == TT_SCOANSI ) {
  16354.                                     /* set the default attribute as well */
  16355.                                     i = (defaultattribute & 0x8F);
  16356.                                     defaultattribute = (i | (l << 4));
  16357.                                     i = (graphicattribute & 0x8F);
  16358.                                     graphicattribute = (i | (l << 4));
  16359. #ifdef COMMENT
  16360.                                     i = (reverseattribute & 0x8F);
  16361.                                     reverseattribute = (i | (l << 4));
  16362. #else
  16363.                                     i = (reverseattribute & 0xF8);
  16364.                                     reverseattribute = (i | l);
  16365. #endif
  16366.                                 }
  16367.                                 } else {
  16368.                                     i = (attribute & 0xF8);
  16369.                                     attribute = (i | l);
  16370.  
  16371.                                     if ( tt_type_mode == TT_SCOANSI ) {
  16372.                                         /* set the default attribute as well */
  16373.                                         i = (defaultattribute & 0xF8);
  16374.                                         defaultattribute = (i | l);
  16375.                                         i = (graphicattribute & 0xF8);
  16376.                                         graphicattribute = (i | l);
  16377. #ifdef COMMENT
  16378.                                         i = (reverseattribute & 0xF8);
  16379.                                         reverseattribute = (i | l);
  16380. #else
  16381.                                         i = (reverseattribute & 0x8F);
  16382.                                         reverseattribute = (i | (l << 4));
  16383. #endif 
  16384.                                     }
  16385.                                 }
  16386.                             break;
  16387.                         default:
  16388.                             break;
  16389.                         }
  16390.                 }
  16391.                 break;
  16392.             case 'r':   /* Proprietary */
  16393.                 if ( ISH19(tt_type) ) {
  16394.                     /* Set Baud Rate to pn[1] */
  16395.                     break;
  16396.                 }
  16397.                 else if ( ISSUN(tt_type_mode) ) {
  16398.                     /* 
  16399.                     ESC[#r      Set scrolling (SUNSCRL)
  16400.                     Takes one parameter, #  (default  0).   Sets  to  #  an
  16401.                     internal  register  which determines how many lines the
  16402.                     screen scrolls up when a  line-feed  function  is  per-
  16403.                     formed with the cursor on the bottom line.  A parameter
  16404.                     of 2 or 3 introduces a small amount of ``jump'' when  a
  16405.                     scroll  occurs.   A  parameter  of 34 clears the screen
  16406.                     rather than scrolling.  The initial  setting  is  1  on
  16407.                     reset.
  16408.  
  16409.                     A parameter of zero initiates ``wrap mode'' instead  of
  16410.                     scrolling.   In  wrap mode, if a linefeed occurs on the
  16411.                     bottom line, the cursor  goes  to  the  same  character
  16412.                     position  in  the  top  line  of  the screen.  When any
  16413.                     linefeed occurs, the line that the cursor moves  to  is
  16414.                     cleared.   This  means  that  no scrolling ever occurs.
  16415.                     `ESC [ 1 r' exits back to scroll mode.
  16416.  
  16417.                     For more information, see the description of the  Line-
  16418.                     feed (CTRL-J) control function above.
  16419.                     */
  16420.                 }
  16421.                 else if ( ansiext && ISSCO(tt_type_mode) ) {
  16422.                     margintop = 1;
  16423.                     marginbot = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  16424.                     marginleft = 1;
  16425.                     marginright = VscrnGetWidth(VTERM);
  16426.                     break;
  16427.                 } else if ( private ) {
  16428.                     /* Restore Modes */
  16429.                     if ( ISHFT(tt_type_mode) ) {
  16430.                         for (j = 1; j <= k; ++j) /* Go thru all Pn's */
  16431.                             switch ((pn[j])) {   /* This one... */
  16432.                             default:
  16433.                                 break;
  16434.                             }
  16435.                     }
  16436.                 }
  16437.                 else {
  16438.                     /* Set margin (scrolling region) */
  16439.                     int h = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  16440.                     int w = VscrnGetWidth(VTERM);
  16441.  
  16442.                     if ((k < 2) || (pn[2] == 0))
  16443.                         pn[2] = h;
  16444.  
  16445.                     /* for SCO */
  16446.                     if ((k < 3) || (pn[3] == 0))
  16447.                         pn[3] = 1;
  16448.  
  16449.                     if ((k < 4) || (pn[4] == 0))
  16450.                         pn[4] = w;
  16451.  
  16452.                     if (pn[1] == 0)
  16453.                         pn[1] = 1;
  16454.  
  16455.                     /* The 97801 allows the bottom margin include the */
  16456.                     /* status line even when it is separated from the */
  16457.                     /* main display area.                             */
  16458.                     if ( IS97801(tt_type_mode) &&
  16459.                          decssdt == SSDT_HOST_WRITABLE )
  16460.                         h++;
  16461.  
  16462.                     if  ((pn[1] > 0) &&
  16463.                          (pn[1] < pn[2]) &&
  16464.                          (pn[2] <= h) &&
  16465.                          (pn[3] < pn[4]) &&
  16466.                          (pn[4] <= w))
  16467.                     {
  16468.                         setmargins(pn[1], pn[2]);
  16469.                         if ( ISSCO(tt_type_mode) ) {
  16470.                             marginleft = pn[3];
  16471.                             marginright = pn[4];
  16472.                             lgotoxy(VTERM, relcursor ? marginleft : 1,
  16473.                                      relcursor ? marginbot : 1);
  16474.                         } else if ( !IS97801(tt_type_mode) ) {
  16475.                             if ( decsasd == SASD_STATUS )
  16476.                                 lgotoxy( VSTATUS, 1, 1 );
  16477.                             else
  16478.                                 lgotoxy(VTERM, 1, relcursor ? margintop : 1);
  16479.                         }
  16480.                     }
  16481.                     else if (!ISSCO(tt_type_mode)) {
  16482.                         if ( pn[1] > 0 &&
  16483.                             pn[1] <= VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  16484.                             pn[2] = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) ;
  16485.                         setmargins(pn[1], pn[2]);
  16486.                         if ( !IS97801(tt_type_mode) ) {
  16487.                             if ( decsasd == SASD_STATUS )
  16488.                                 lgotoxy( VSTATUS, 1, 1 );
  16489.                             else
  16490.                                 lgotoxy(VTERM, 1, relcursor ?
  16491.                                         margintop : 1);
  16492.                         }
  16493.                     }
  16494.                     break;
  16495.                 }
  16496.                 break;
  16497.             case 'J':
  16498.                 if ( ansiext && private ) {
  16499.                     if ( ISBA80(tt_type_mode) ) {
  16500.                         /* Screen Saver On */
  16501.                     }
  16502.                 }
  16503.                 else if ( ansiext ) {
  16504.                     /* ANSI - Set Graphic Foreground Color */
  16505.                     if ( ISANSI(tt_type_mode) ) {
  16506.                         /* pn[1] contains new color */
  16507.                         l = pn[1];
  16508.                         i = (graphicattribute & 0xF0);
  16509.                         graphicattribute = (i | l);
  16510.                     }
  16511.                 }
  16512.                 else if ( private == TRUE ) {
  16513.                     /* Selective clear screen - DECSED */
  16514.                     if ( ISVT220(tt_type_mode) ) {
  16515.                         switch ((pn[1])) {
  16516.                             /* Selective clear to end of screen */
  16517.                         case 0:
  16518.                             selclreoscr_escape(VTERM,SP);
  16519.                             break;
  16520.                             /* Selective clear to beginning */
  16521.                         case 1:
  16522.                             selclrboscr_escape(VTERM,SP);
  16523.                             break;
  16524.                             /* Selective clear whole screen */
  16525.                         case 2:
  16526.                             {
  16527.                                 /* Cursor does not move */
  16528.                                 if ( decsasd == SASD_STATUS ) {
  16529.                                     selclrscreen(VSTATUS,SP);
  16530.                                 }
  16531.                                 else {
  16532.                                     selclrscreen(VTERM,SP);
  16533.                                 }
  16534.                             }
  16535.                             break;
  16536.                         default:
  16537.                             break;
  16538.                         }
  16539.                     }
  16540.                 } else {
  16541.                     /* Erase in Display (ED) */
  16542.                     /* ??? For the 97801, the called functions must be */
  16543.                     /* recoded to only clear the current scroll region */
  16544.                     /* with both vertical and horizontal boundaries.   */
  16545.                     if ( IS97801(tt_type_mode) ) {
  16546.                         /* ignored if outside scroll region */
  16547.                         if ( wherey[VTERM] < margintop ||
  16548.                             wherey[VTERM] > marginbot )
  16549.                             break;
  16550.                     }
  16551.                     switch ((pn[1])) {
  16552.                     case 0:
  16553.                         /* Clear to end of screen w/SP */
  16554.                         /* Clear Attributes */
  16555.                         if ( IS97801(tt_type_mode) )
  16556.                             clreoreg_escape(VTERM,SP);
  16557.                         else
  16558.                             clreoscr_escape(VTERM,SP);
  16559.                         break;
  16560.                     case 1:
  16561.                         /* Clear to beginning w/SP */
  16562.                         /* Clear Attributes */
  16563.                         if ( IS97801(tt_type_mode) )
  16564.                             clrboreg_escape(VTERM,SP);
  16565.                         else
  16566.                             clrboscr_escape(VTERM,SP);
  16567.                         break;
  16568.                     case 2:
  16569.                         /* Clear whole screen w/SP */
  16570.                         /* Clear Attributes */
  16571.                         /* DEC ... */
  16572.                         if ( !ISANSI(tt_type_mode) ) {
  16573.                             /* Cursor does not move */
  16574.                             if ( decsasd == SASD_STATUS ) {
  16575.                                 clrscreen(VSTATUS,SP);
  16576.                             }
  16577.                             else {
  16578.                                 if ( IS97801(tt_type_mode) )
  16579.                                     clrregion(VTERM,SP);
  16580.                                 else
  16581.                                     clrscreen(VTERM,SP);
  16582.                             }
  16583.                         } else { /* ANSI homes the cursor */
  16584.                             clrscreen(VTERM,SP);
  16585.                             lgotoxy(VTERM,1,1);       /* and home the cursor */
  16586.                         }
  16587.                         break;
  16588.                     case 3:
  16589.                         /* Clear to end of screen w/NUL */
  16590.                         /* Clear Attributes */
  16591.                         if ( IS97801(tt_type_mode) ) {
  16592.                             clreoreg_escape(VTERM,NUL);
  16593.                         }
  16594.                         break;
  16595.                     case 4:
  16596.                         /* Clear to beginning w/NUL */
  16597.                         /* Clear Attributes */
  16598.                         if ( IS97801(tt_type_mode) ) {
  16599.                             clrboreg_escape(VTERM,NUL);
  16600.                         }
  16601.                         break;
  16602.                     case 5:
  16603.                         /* Clear whole screen w/NUL */
  16604.                         /* Clear Attributes */
  16605.                         /* DEC ... */
  16606.                         /* Cursor does not move */
  16607.                         if ( IS97801(tt_type_mode) ) {
  16608.                             if ( decsasd == SASD_STATUS ) {
  16609.                                 clrscreen(VSTATUS,NUL);
  16610.                             }
  16611.                             else {
  16612.                                 clrregion(VTERM,NUL);
  16613.                             }
  16614.                         }
  16615.                         break;
  16616.                     case 6:
  16617.                         /* Clear to end of screen w/SP */
  16618.                         /* Preset with the last valid attribute */
  16619.                         /* (if attributes are not stored) */
  16620.                         if ( IS97801(tt_type_mode) ) {
  16621.                             clreoreg_escape(VTERM,SP);
  16622.                         }
  16623.                         break;
  16624.                     case 7:
  16625.                         /* Clear to beginning w/SP */
  16626.                         /* Preset with the last valid attribute */
  16627.                         /* (if attributes are not stored) */
  16628.                         if ( IS97801(tt_type_mode) ) {
  16629.                             clrboreg_escape(VTERM,SP);
  16630.                         }
  16631.                         break;
  16632.                     case 8:
  16633.                         /* Clear whole screen w/SP */
  16634.                         /* Preset with the last valid attribute */
  16635.                         /* (if attributes are not stored) */
  16636.                         if ( IS97801(tt_type_mode) ) {
  16637.                             if ( decsasd == SASD_STATUS ) {
  16638.                                 clrscreen(VSTATUS,SP);
  16639.                             }
  16640.                             else {
  16641.                                 clrregion(VTERM,SP);
  16642.                             }
  16643.                         }
  16644.                         break;
  16645.                     case 9:
  16646.                         /* Clear to end of screen w/NUL */
  16647.                         /* Preset with the last valid attribute */
  16648.                         /* (if attributes are not stored) */
  16649.                         if ( IS97801(tt_type_mode) ) {
  16650.                             clreoreg_escape(VTERM,NUL);
  16651.                         }
  16652.                         break;
  16653.                     case 10:
  16654.                         /* Clear to beginning w/NUL */
  16655.                         /* Preset with the last valid attribute */
  16656.                         /* (if attributes are not stored) */
  16657.                         if ( IS97801(tt_type_mode) ) {
  16658.                             clrboreg_escape(VTERM,NUL);
  16659.                         }
  16660.                         break;
  16661.                     case 11:
  16662.                         /* Clear whole screen w/NUL */
  16663.                         /* Preset with the last valid attribute */
  16664.                         /* (if attributes are not stored) */
  16665.                         if ( IS97801(tt_type_mode) ) {
  16666.                             if ( decsasd == SASD_STATUS ) {
  16667.                                 clrscreen(VSTATUS,NUL);
  16668.                             }
  16669.                             else {
  16670.                                 clrregion(VTERM,NUL);
  16671.                             }
  16672.                         }
  16673.                         break;
  16674.                     case 12:
  16675.                         /* Clear to end of screen w/SP */
  16676.                         /* Preserve attributes */
  16677.                         if ( IS97801(tt_type_mode) ) {
  16678.                             clreoreg_escape(VTERM,SP);
  16679.                         }
  16680.                         break;
  16681.                     case 13:
  16682.                         /* Clear to beginning w/SP */
  16683.                         /* Preserve attributes */
  16684.                         if ( IS97801(tt_type_mode) ) {
  16685.                             clrboreg_escape(VTERM,SP);
  16686.                         }
  16687.                         break;
  16688.                     case 14:
  16689.                         /* Clear whole screen w/SP */
  16690.                         /* Preserve attributes */
  16691.                         if ( IS97801(tt_type_mode) ) {
  16692.                             if ( decsasd == SASD_STATUS ) {
  16693.                                 clrscreen(VSTATUS,SP);
  16694.                             }
  16695.                             else {
  16696.                                 clrregion(VTERM,SP);
  16697.                             }
  16698.                         }
  16699.                         break;
  16700.                     case 15:
  16701.                         /* Clear to end of screen w/NUL */
  16702.                         /* Preserve attributes */
  16703.                         if ( IS97801(tt_type_mode) ) {
  16704.                             clreoreg_escape(VTERM,NUL);
  16705.                         }
  16706.                         break;
  16707.                     case 16:
  16708.                         /* Clear to beginning w/NUL */
  16709.                         /* Preserve attributes */
  16710.                         if ( IS97801(tt_type_mode) ) {
  16711.                             clrboreg_escape(VTERM,NUL);
  16712.                         }
  16713.                         break;
  16714.                     case 17:
  16715.                         /* Clear whole screen w/NUL */
  16716.                         /* Preserve attributes */
  16717.                         if ( IS97801(tt_type_mode) ) {
  16718.                             if ( decsasd == SASD_STATUS ) {
  16719.                                 clrscreen(VSTATUS,NUL);
  16720.                             }
  16721.                             else {
  16722.                                 clrregion(VTERM,NUL);
  16723.                             }
  16724.                         }
  16725.                         break;
  16726.                     default:
  16727.                         break;
  16728.                     }
  16729.                 }
  16730.                 break;
  16731.             case 'V':
  16732.                 if (ISSCO(tt_type_mode)) {
  16733.                     /* Erase in Region (ER) */
  16734.                     switch ((pn[1])) {
  16735.                     case 0:
  16736.                         /* Clear to end of screen w/SP */
  16737.                         /* Clear Attributes */
  16738.                         clreoreg_escape(VTERM,SP);
  16739.                         break;
  16740.                     case 1:
  16741.                         /* Clear to beginning w/SP */
  16742.                         /* Clear Attributes */
  16743.                         clrboreg_escape(VTERM,SP);
  16744.                         break;
  16745.                     case 2:
  16746.                         /* Clear whole region w/SP */
  16747.                         /* Clear Attributes */
  16748.                         /* DEC ... */
  16749.                         clrregion(VTERM,SP);
  16750.                         break;
  16751.                     default:
  16752.                         break;
  16753.                     }
  16754.                 }
  16755.                 break;
  16756.             case 'v':   /* Proprietary */
  16757.                 if ( ISAAA(tt_type_mode) ) {
  16758.                     /* zSRC - Start Remote Copy */
  16759.                     break;
  16760.                 } else if ( IS97801(tt_type_mode) ) {
  16761.                     switch ( pn[1] ) {
  16762.                     case 5:
  16763.                         /* Switch within G0 (national/international, 7-bit mode) */
  16764.                         if ( sni_bitmode == 7 )
  16765.                             SNI_chcode(!sni_chcode);
  16766.                         break;
  16767.                     case 7:
  16768.                         /* Full screen mode off */
  16769.                         break;
  16770.                     case 8:
  16771.                         /* Fill scroll area with chracters (diagnostics) */
  16772.                         break;
  16773.                     case 9:
  16774.                         /* Output entire character generator */
  16775.                         break;
  16776.                     case 10:
  16777.                         /* Disable CH.CODE key (7-bit mode) */
  16778.                         sni_chcode_7 = 0;
  16779.                         break;
  16780.                     case 11:
  16781.                         /* Enable CH.CODE key (7-bit mode) */
  16782.                         sni_chcode_7 = 1;
  16783.                         break;
  16784.                     case 13: {
  16785.                         /* Query current code table */
  16786.                         /* 0 - SI: G0FEST active */
  16787.                         /* 1 - SI: G0 active     */
  16788.                         /* 2 - SO: G0FEST activ  */
  16789.                         /* 3 - SO: G0 active     */
  16790.  
  16791.                         char chtable[9];
  16792.                         char status;
  16793.                         if ( GL == &G[0] )
  16794.                             status = sni_chcode ? '1' : '0';
  16795.                         else
  16796.                             status = sni_chcode ? '3' : '2';
  16797.                         if ( send_c1 )
  16798.                             sprintf(chtable,"%c13v%c%c",_DCS,status,_ST8);
  16799.                         else
  16800.                             sprintf(chtable,"%cP13v%c%c\\",ESC,status,ESC);
  16801.                         sendchars(chtable,strlen(chtable));
  16802.                         break;
  16803.                     }
  16804.                     case 20:
  16805.                         /* Switch to alternative key assignment table (8-bit CH.CODE) */
  16806.                         if ( sni_bitmode == 8 )
  16807.                             SNI_chcode(!sni_chcode);
  16808.                         break;
  16809.                     case 21: {
  16810.                         /* Query current key assignment table (CH.CODE status, 8-bit mode) */
  16811.                         char chtable[9];
  16812.                         char status;
  16813.                         status = sni_chcode ? '1' : '0';
  16814.                         if ( send_c1 )
  16815.                             sprintf(chtable,"%c21v%c%c",_DCS,status,_ST8);
  16816.                         else
  16817.                             sprintf(chtable,"%cP21v%c%c\\",ESC,status,ESC);
  16818.                         sendchars(chtable,strlen(chtable));
  16819.                         break;
  16820.                     }
  16821.                     case 22:
  16822.                         /* Disable CH.CODE key (8-bit mode) */
  16823.                         sni_chcode_8 = 0;
  16824.                         break;
  16825.                     case 23:
  16826.                         /* Enable CH.CODE key (8-bit mode) */
  16827.                         sni_chcode_8 = 1;
  16828.                         break;
  16829.                     }
  16830.                 }
  16831.                 break;
  16832.             case 'w': /* Proprietary */
  16833.                 if ( ISAAA(tt_type_mode) ) {
  16834.                     /* zSPF - Set Print Format Pn1;Pn2;Pn3
  16835.                      * Pn1 - Printed Lines (per page) 1 - 126
  16836.                      * Pn2 - Total Lines (per page) 1 - 126
  16837.                      * Pn3 - Left Margin 0 - 254
  16838.                      */
  16839.                 } 
  16840.                 else if ( ISHFT(tt_type_mode) ) {
  16841.                     /* vt raw keyboard input */
  16842.                     ;
  16843.                 }
  16844.                 else if ( IS97801(tt_type_mode) ) {
  16845.                     switch ( pn[1] ) {
  16846.                     case 0:     /* Transmit keylock switch status */
  16847.                         break;
  16848.                     case 1:     /* Reinitialize character generator */
  16849.                         break;
  16850.                     }
  16851.                 }
  16852.                 else if ( ISWY370(tt_type_mode) )
  16853.                 {
  16854.                     /* All sorts of color controls */
  16855.                     switch ( pn[1] ) {
  16856.                         /* 0-47 - Defining Color Associations */
  16857.                     case 48:
  16858.                         /* Select Foreground Color */
  16859.                         break;
  16860.                     case 49:
  16861.                         /* Select Background Color */
  16862.                         /* Sets border color to Bg Color */
  16863.                         break;
  16864.                     case 50:
  16865.                         /* Restore Foreground and Background colors */
  16866.                         /* sets border color to bg color */
  16867.                         break;
  16868.                     case 51:
  16869.                         /* Select border color */
  16870.                         break;
  16871.                     case 52:
  16872.                         /* Select cursor color */
  16873.                         break;
  16874.                     case 54:
  16875.                         /* Select user status line attrs/colors */
  16876.                         break;
  16877.                     case 55:
  16878.                         /* Select system status line attrs/colors */
  16879.                         break;
  16880.                     case 56:
  16881.                         /* Select replacement chars attrs/colors */
  16882.                         break;
  16883.                     case 57:
  16884.                         /* Select nonerasable chars attrs/colors */
  16885.                         break;
  16886.                     case 60:
  16887.                         /* Restore default color index values */
  16888.                         break;
  16889.                     case 61:
  16890.                         /* Assign current char fg color */
  16891.                         /* Turns on color index mode    */
  16892.                         break;
  16893.                     case 62:
  16894.                         /* Assign current char bg color */
  16895.                         /* sets border color to bg color */
  16896.                         break;
  16897.                     case 63:
  16898.                         /* Turn color index mode on/off */
  16899.                         break;
  16900.                     case 64:
  16901.                         /* Change current nonerasable char */
  16902.                         /* foreground color                */
  16903.                         break;
  16904.                     case 65:
  16905.                         /* Change current nonerasable char */
  16906.                         /* background color                */
  16907.                         break;
  16908.                     case 66:
  16909.                         /* Redefine color index value */
  16910.                         break;
  16911.                     default:
  16912.                         break;
  16913.                     }
  16914.                 }
  16915.                 break;
  16916.             case 'K':
  16917.                 if ( ansiext )
  16918.                 {
  16919.                     /* ANSI - Set Graphic Background Color */
  16920.                     if ( ISANSI(tt_type_mode) ) {
  16921.                         /* pn[1] contains new color */
  16922.                         l = pn[1];
  16923.                         i = (graphicattribute & 0x0F);
  16924.                         graphicattribute = (i | (l << 4));
  16925.                     }
  16926.                     else if ( ISBA80(tt_type_mode) ) {
  16927.                         /* Begin Reading Function Labels */
  16928.                         ba80_fkey_read = -1;
  16929.                     }
  16930.                 }
  16931.                 else if ( private == TRUE ) {
  16932.                     /* Selective clear line - DECSEL */
  16933.                     if ( ISVT220(tt_type_mode) ) {
  16934.                         switch ((pn[1])) {
  16935.                             /* Selective clear to end of line; clear attributes */
  16936.                         case 0:
  16937.                             selclrtoeoln(VTERM,SP);
  16938.                             break;
  16939.                             /* Selective clear to beginning; clear attributes */
  16940.                         case 1:
  16941.                             selclrbol_escape(VTERM,SP);
  16942.                             break;
  16943.                             /* Selective clear whole cursor line; clear attributes */
  16944.                         case 2:
  16945.                             selclrline_escape(VTERM,SP);
  16946.                             break;
  16947.                         default:
  16948.                             break;
  16949.                         }
  16950.                     }
  16951.                 } else {
  16952.                     /* Erase line (EL) */
  16953.                     switch ((pn[1])) {
  16954.                     case 0:
  16955.                         /* Clear to end of line; clear attributes */
  16956.                         clrtoeoln(VTERM,SP);
  16957.                         break;
  16958.                     case 1:
  16959.                         /* Clear to beginning; clear attributes */
  16960.                         clrbol_escape(VTERM,SP);
  16961.                         break;
  16962.                     case 2:
  16963.                         /* Clear whole cursor line; clear attributes */
  16964.                         clrline_escape(VTERM,SP);
  16965.                         break;
  16966.                     case 3:
  16967.                         /* SNI 97801 */
  16968.                         /* Erase with NULs to EOL */
  16969.                         /* Clear attributes */
  16970.                         clrtoeoln(VTERM,NUL);
  16971.                         break;
  16972.                     case 4:
  16973.                         /* SNI 97801 */
  16974.                         /* Erase with NULs to BOL */
  16975.                         /* Clear attributes */
  16976.                         clrbol_escape(VTERM,NUL);
  16977.                         break;
  16978.                     case 5:
  16979.                         /* SNI 97801 */
  16980.                         /* Erase with NULs entire line */
  16981.                         /* Clear attributes */
  16982.                         clrline_escape(VTERM,NUL);
  16983.                         break;
  16984.                     case 6:
  16985.                         /* SNI 97801 */
  16986.                         /* Erase with SP to EOL */
  16987.                         /* Preset with the last valid SGR attribute */
  16988.                         /* (if attributes are not stored) */
  16989.                         clrtoeoln(VTERM,SP);
  16990.                         break;
  16991.                     case 7:
  16992.                         /* SNI 97801 */
  16993.                         /* Erase with SP to BOL */
  16994.                         /* Preset with the last valid SGR attribute */
  16995.                         /* (if attributes are not stored) */
  16996.                         clrbol_escape(VTERM,SP);
  16997.                         break;
  16998.                     case 8:
  16999.                         /* SNI 97801 */
  17000.                         /* Erase with SP entire line */
  17001.                         /* Preset with the last valid SGR attribute */
  17002.                         /* (if attributes are not stored) */
  17003.                         clrline_escape(VTERM,SP);
  17004.                         break;
  17005.                     case 9:
  17006.                         /* SNI 97801 */
  17007.                         /* Erase with NUL to EOL */
  17008.                         /* Preset with the last valid SGR attribute */
  17009.                         /* (if attributes are not stored) */
  17010.                         clrtoeoln(VTERM,NUL);
  17011.                         break;
  17012.                     case 10:
  17013.                         /* SNI 97801 */
  17014.                         /* Erase with NUL to BOL */
  17015.                         /* Preset with the last valid SGR attribute */
  17016.                         /* (if attributes are not stored) */
  17017.                         clrbol_escape(VTERM,NUL);
  17018.                         break;
  17019.                     case 11:
  17020.                         /* SNI 97801 */
  17021.                         /* Erase with NUL entire line */
  17022.                         /* Preset with the last valid SGR attribute */
  17023.                         /* (if attributes are not stored) */
  17024.                         clrline_escape(VTERM,NUL);
  17025.                         break;
  17026.                     case 12:
  17027.                         /* SNI 97801 */
  17028.                         /* Erase with SP to EOL */
  17029.                         /* Preserve attributes */
  17030.                         clrtoeoln(VTERM,SP);
  17031.                         break;
  17032.                     case 13:
  17033.                         /* SNI 97801 */
  17034.                         /* Erase with SP to BOL */
  17035.                         /* Preserve attributes */
  17036.                         clrbol_escape(VTERM,SP);
  17037.                         break;
  17038.                     case 14:
  17039.                         /* SNI 97801 */
  17040.                         /* Erase with SP entire line */
  17041.                         /* Preserve attributes */
  17042.                         clrline_escape(VTERM,SP);
  17043.                         break;
  17044.                     case 15:
  17045.                         /* SNI 97801 */
  17046.                         /* Erase with NUL to EOL */
  17047.                         /* Preserve attributes */
  17048.                         clrtoeoln(VTERM,NUL);
  17049.                         break;
  17050.                     case 16:
  17051.                         /* SNI 97801 */
  17052.                         /* Erase with NUL to BOL */
  17053.                         /* Preserve attributes */
  17054.                         clrbol_escape(VTERM,NUL);
  17055.                         break;
  17056.                     case 17:
  17057.                         /* SNI 97801 */
  17058.                         /* Erase with NUL entire line */
  17059.                         /* Preserve attributes */
  17060.                         clrline_escape(VTERM,NUL);
  17061.                         break;
  17062.                     default:
  17063.                         break;
  17064.                     }
  17065.                 }
  17066.                 break;
  17067.             case 'L':
  17068.                 if ( ISSCO(tt_type_mode) && ansiext ) {
  17069.                     /* SCO - Set Emulation Feature */
  17070.                     switch ( pn[1] ) {
  17071.                     case 0: /* New regions filled with the current attribute (default) */
  17072.                         break;
  17073.                     case 1: /* New regions filled with the normal attribute */
  17074.                         break;
  17075.                     case 2: /* Disable iBCS2 compliance (default) */
  17076.                         break;
  17077.                     case 3: /* Enable iBCS2 compliance */
  17078.                         break;
  17079.                     case 4: /* Disable ANSI SGR0 interpretation (default) */
  17080.                         break;
  17081.                     case 5: /* Enable ANSI SGR0 interpretation */
  17082.                         break;
  17083.                     case 6: /* Disable backwards compatibility mode (default) */
  17084.                         scocompat = FALSE;
  17085.                         break;
  17086.                     case 7: /* Enable backwards compatibility mode (resets margins too) */
  17087.                         scocompat = TRUE;
  17088.                         break;
  17089.                     case 8: /* Cursor motion bound by region (default) */
  17090.                         break;
  17091.                     case 9: /* Cursor motion unbound */
  17092.                         break;
  17093.                     case 10: /* Enable 8-bit keyboard meta mode (default) */
  17094.                         break;
  17095.                     case 11: /* Disable 8-bit keyboard meta mode */
  17096.                         break;
  17097.                     case 12: /* Disable debugging for this screen (default) */
  17098.                         break;
  17099.                     case 13: /* Enable debugging for this screen (do not use) */
  17100.                         break;
  17101.                     case 14: /* Disable global video loop debugging (default) */
  17102.                         break;
  17103.                     case 15: /* Enable global video loop debugging (do not use) */
  17104.                         break;
  17105.                     case 16: /* Enable M6845 frame buffer optimization (default) */
  17106.                         break;
  17107.                     case 17: /* Disable M6845 frame buffer optimization (debugging only) */
  17108.                         break;
  17109.                     case 20: /* Disable using ESC for meta (high) bit. */
  17110.                         break;
  17111.                     case 21: /* Enable using ESC for meta (high) bit. */
  17112.                         break;
  17113.                     default:
  17114.                         break;
  17115.                     }
  17116.                 } else if ( ISANSI(tt_type_mode) && ansiext ) {
  17117.                     /* ANSI - Set Fill (Erase?) mode */
  17118.                     if ( !pn[1] )
  17119.                         /* use current color */
  17120.                         erasemode = FALSE ;
  17121.                     else
  17122.                         /* use normal color */
  17123.                         erasemode = TRUE ;
  17124.                 }
  17125.                 else {
  17126.                     if ( ISVT102(tt_type_mode) ||
  17127.                          ISANSI(tt_type_mode)) {
  17128.                         /* IL - Insert lines */
  17129.                         if ( IS97801(tt_type_mode) ) {
  17130.                             /* ignored if outside scroll region */
  17131.                             if ( wherey[VTERM] < margintop ||
  17132.                                  wherey[VTERM] > marginbot )
  17133.                                 break;
  17134.                         }
  17135.                         for (i = 1; i <= pn[1]; ++i) {
  17136.                             VscrnScroll(VTERM,
  17137.                                          DOWNWARD,
  17138.                                          wherey[VTERM] - 1,
  17139.                                          marginbot - 1,
  17140.                                          1,
  17141.                                          FALSE,
  17142.                                          SP);
  17143.                         }
  17144.                     }
  17145.                 }
  17146.                 break;
  17147.             case 'M':
  17148.                 if ( ansiext ) {
  17149.                     /* ANSI - Report Color Attributes */
  17150.                     if ( ISANSI(tt_type_mode) )
  17151.                     {
  17152.                         char buf[32] ;
  17153.  
  17154.                         switch ( pn[1] ) {
  17155.                         case 0: /* Normal */
  17156.                         case 2: /* Graphic - ??? */
  17157.                             sprintf(buf,"%d %d\n",defaultattribute&0x0F,
  17158.                                      (defaultattribute&0xF0)>>4);
  17159.                             break;
  17160.                         case 1: /* Reverse */
  17161.                             sprintf(buf,"%d %d\n",
  17162.                                      (defaultattribute&0xF0)>>4,
  17163.                                      defaultattribute&0x0F);
  17164.                             break;
  17165.                         default:
  17166.                             *buf = '\0';
  17167.                         }
  17168.  
  17169.                         if ( *buf )
  17170.                             sendcharsduplex( buf, strlen(buf), FALSE);
  17171.                     } else if ( ISBA80(tt_type_mode) ) {
  17172.                         /* Move to Status Line */
  17173.                         setdecssdt( SSDT_HOST_WRITABLE );
  17174.                         setdecsasd( SASD_STATUS );
  17175.                     }
  17176.                 }
  17177.                 else {
  17178.                     if ( ISVT102(tt_type_mode) ||
  17179.                          ISANSI(tt_type_mode)) {
  17180.                         /* DL - Delete lines */
  17181.                         for (i = 1; i <= pn[1]; ++i) {
  17182.                             VscrnScroll(VTERM,
  17183.                                          UPWARD,
  17184.                                          wherey[VTERM] - 1,
  17185.                                          marginbot - 1,
  17186.                                          1,
  17187.                                          FALSE,
  17188.                                          SP);
  17189.                         }
  17190.                     }
  17191.                 }
  17192.                 break;
  17193.             case '@':   /* (ICH) Insert characters */
  17194.                 if ( ISVT102(tt_type_mode) ||
  17195.                      ISANSI(tt_type_mode) &&
  17196.                      private == FALSE &&
  17197.                      ansiext == FALSE ) {
  17198.                     blankvcell.c = SP;
  17199.                     blankvcell.a = attribute;
  17200.                     if (pn[1] > VscrnGetWidth(VTERM) + 1 -
  17201.                          wherex[VTERM])
  17202.                         pn[1] = VscrnGetWidth(VTERM) + 1 -
  17203.                             wherex[VTERM];
  17204.                     VscrnScrollRt(VTERM, wherey[VTERM] - 1,
  17205.                                    wherex[VTERM] - 1,
  17206.                                    wherey[VTERM] - 1,
  17207.                                    VscrnGetWidth(VTERM) - 1,
  17208.                                    pn[1],
  17209.                                    blankvcell
  17210.                                    );
  17211.                 }
  17212.                 break;
  17213.             case 'N':
  17214.                 if ( ISHFT(tt_type_mode) || ISLINUX(tt_type_mode) || 
  17215.                      ISAAA(tt_type_mode)) {
  17216.                     /* EF - Erase Field */
  17217.                     int start, end, width;
  17218.                     blankvcell.c = ' ' ;
  17219.                     blankvcell.a = geterasecolor(VTERM) ;
  17220.                     start = end = wherex[VTERM];
  17221.                     width = VscrnGetWidth(VTERM);
  17222.                     if (start > 1) {
  17223.                         do {
  17224.                             start--;
  17225.                         } while ((htab[start] != 'T') &&
  17226.                                   (start >= 2));
  17227.                     }
  17228.                     if (end < width) {
  17229.                         do {
  17230.                             end++;
  17231.                         } while ((htab[end] != 'T') &&
  17232.                                   (end < width));
  17233.                     }
  17234.                     switch ( pn[1] ) {
  17235.                     case 0: /* Erase to End of Field (cursor to tab stop) */
  17236.                         for ( i = wherex[VTERM] ; i < end ; i++ ) {
  17237.                             VscrnWrtCell(VTERM,
  17238.                                           blankvcell,
  17239.                                           attrib,
  17240.                                           wherey[VTERM]-1,
  17241.                                           i);
  17242.                         }
  17243.                         break;
  17244.                     case 1: /* Erase From Field Start (tab stop to cursor) */
  17245.                         for ( i = start ; i <= wherex[VTERM] ; i++ ) {
  17246.                             VscrnWrtCell(VTERM,
  17247.                                           blankvcell,
  17248.                                           attrib,
  17249.                                           wherey[VTERM]-1,
  17250.                                           i);
  17251.                         }
  17252.                         break;
  17253.                     case 2: /* Erase All of Field (tab stop to tab stop) */
  17254.                         for ( i = start ; i <= end ; i++ ) {
  17255.                             VscrnWrtCell(VTERM,
  17256.                                           blankvcell,
  17257.                                           attrib,
  17258.                                           wherey[VTERM]-1,
  17259.                                           i);
  17260.                         }
  17261.                         break;
  17262.                     }
  17263.                 }
  17264.                 break;
  17265.             case 'O':
  17266.                 if ( ISBA80(tt_type_mode) && ansiext ) {
  17267.                     /* Open Virtual Window */
  17268.                     /* Format is CSI = O Pa Pn1[:Pn2][;Pa Pn1[:Pn2]][...] O */
  17269.                     /* Pa = 1 - Set Height:Width of virtual window */
  17270.                     /* Pa = 2 - Set Row:Column of virtual window in relation to */
  17271.                     /*          physical window */
  17272.                     /* Pa = 4 - Name of the virtual Window (8 chars) */
  17273.                     /*          default are 24:80, name is "Lohn    " */
  17274.                 }
  17275.                 else if ( ISHFT(tt_type_mode) ||
  17276.                           ISLINUX(tt_type_mode) ||
  17277.                           ISAAA(tt_type_mode)) {
  17278.                     /* EA - Erase Area */
  17279.                     switch ( pn[1] ) {
  17280.                     case 0: /* Erase to end of area (line) */
  17281.                         clrtoeoln(VTERM,SP);
  17282.                         break;
  17283.                     case 1: /* Erase from area start (line) */
  17284.                         clrbol_escape(VTERM,SP);
  17285.                         break;
  17286.                     case 2: /* Erase all of area (line) */
  17287.                         clrline_escape(VTERM,SP);
  17288.                         break;
  17289.                     }
  17290.                 }
  17291.                 break;
  17292.             case 'P':   /* (DCH) DeleteChar */
  17293.                 if ( (ISVT102(tt_type_mode) ||
  17294.                        ISANSI(tt_type_mode)) &&
  17295.                      private == FALSE &&
  17296.                      ansiext == FALSE ) {
  17297.                     blankvcell.c = SP;
  17298.                     blankvcell.a = geterasecolor(VTERM);
  17299.                     if (pn[1] > VscrnGetWidth(VTERM) + 1 -
  17300.                          wherex[VTERM])
  17301.                         pn[1] = VscrnGetWidth(VTERM) + 1 -
  17302.                             wherex[VTERM];
  17303.                     VscrnScrollLf(VTERM, wherey[VTERM] - 1,
  17304.                                    wherex[VTERM] - 1,
  17305.                                    wherey[VTERM] - 1,
  17306.                                    VscrnGetWidth(VTERM) - 1,
  17307.                                    pn[1],
  17308.                                    blankvcell
  17309.                                    ) ;
  17310.                 }
  17311.                 break;
  17312.             case 'Q':   /* SEE - Select Editing Extent */
  17313.                 if ( ISAAA(tt_type_mode) ) {
  17314.                     switch ( pn[1] ) {
  17315.                     case 0:     /* Edit in Page (default) */
  17316.                         break;
  17317.                     case 1:     /* Edit in Line */
  17318.                         break;
  17319.                     case 2:     /* Edit in Field (between Tab Stops */
  17320.                         break;
  17321.                     case 3:     /* Edit in Qualified Area (see DAQ, SPA, EPA) */
  17322.                         break;
  17323.                     }
  17324.                 }
  17325.                 break;
  17326.             case 'R':   /* CPR - Cursor Position Report */
  17327.                 /* Sent to host (see DSR), not processed by terminal */
  17328.                 break;
  17329.             case 'S':
  17330.                 if ( ansiext ) {
  17331.                     if (ISBA80(tt_type_mode)) {
  17332.                         /* Return from Status Line */
  17333.                         setdecsasd(SASD_TERMINAL);
  17334.                     }
  17335.                 } else {
  17336.                     /* (SU) Scroll up-scrolls the characters up */
  17337.                     /* n lines.  The bottom n lines are    */
  17338.                     /* cleared to blanks (default: n=1). */
  17339.                     /* Also (RU) Roll up with SNI 97801 */
  17340.                     if ( IS97801(tt_type_mode) ) {
  17341.                         /* ignored if outside scroll region */
  17342.                         if ( wherey[VTERM] < margintop ||
  17343.                              wherey[VTERM] > marginbot )
  17344.                             break;
  17345.                     }
  17346.                     if ( pn[1] == 0 )
  17347.                         pn[1] = 1 ;
  17348.                     else if ( pn[1] > marginbot )
  17349.                         pn[1] = marginbot ;
  17350.                     
  17351.                     if ( ISVT320(tt_type_mode) || IS97801(tt_type_mode) ) {
  17352.                         if ( sni_scroll_mode ) {
  17353.                             VscrnScroll(VTERM, UPWARD,
  17354.                                          margintop-1, wherex[VTERM]-1,
  17355.                                          pn[1],
  17356.                                          margintop == 1,
  17357.                                          SP);
  17358.                         } else { /* Roll Mode */
  17359.                             VscrnScroll(VTERM, UPWARD,
  17360.                                          margintop-1, marginbot-1,
  17361.                                          pn[1],
  17362.                                          margintop == 1,
  17363.                                          SP);
  17364.                         }
  17365.                     }
  17366.                     /* No paged memory, so do nothing */
  17367.                     else if (ISHFT(tt_type_mode) || ISANSI(tt_type_mode)) {
  17368.                             VscrnScroll(VTERM, UPWARD,
  17369.                                          0, VscrnGetHeight(VTERM)-((tt_status)?2:1),
  17370.                                          pn[1], TRUE, SP);
  17371.                     }
  17372.                 }
  17373.                 break;
  17374.             case 's':   /* Proprietary */
  17375.                 if ( private ) {
  17376.                     /* Save Modes */
  17377.                     if ( ISHFT(tt_type_mode) ) {
  17378.                         for (j = 1; j <= k; ++j) /* Go thru all Pn's */
  17379.                             switch ((pn[j])) {   /* This one... */
  17380.                             default:
  17381.                                 break;
  17382.                             }
  17383.                     }
  17384.                 } 
  17385.                 else if ( ISAAA(tt_type_mode) ) {
  17386.                     /* zPSH - Push Line */
  17387.                 }
  17388.                 else if ( ISSUN(tt_type_mode) ) {
  17389.                      /*
  17390.                      ESC[s       Reset terminal emulator (SUNRESET)
  17391.                      Takes no parameters.   Resets  all  modes  to  default,
  17392.                      restores  current  font  from  PROM.  Screen and cursor
  17393.                      position are
  17394.                      */
  17395.                     doreset(1);
  17396.                 }
  17397.                 else if ( IS97801(tt_type_mode) ) {
  17398.                         switch ( pn[1] ) {
  17399.                         case 0: /* Repeat off */
  17400.                             break;
  17401.                         case 1: /* Repeat on */
  17402.                             break;
  17403.                         case 2: /* Clicker off */
  17404.                             setkeyclick(FALSE);
  17405.                             break;
  17406.                         case 3: /* Clicker on */
  17407.                             setkeyclick(TRUE);
  17408.                             break;
  17409.                         }
  17410.                 }
  17411.                 else if ( ISANSI(tt_type_mode) ||
  17412.                             IS97801(tt_type_mode) ||
  17413.                             ISSCO(tt_type_mode) ) {
  17414.                     /* Save Cursor Position */
  17415.                     savecurpos(VTERM,0);
  17416.                 }
  17417.                 break;
  17418.             case '^': /* (SD) Scroll Down (ECMA 48) */
  17419.                 if ( pn[1] == 0 )
  17420.                     pn[1] = 1 ;
  17421.                 else if ( pn[1] > VscrnGetHeight(VTERM)
  17422.                           -((tt_status)?2:1) - margintop )
  17423.                     pn[1] = VscrnGetHeight(VTERM)
  17424.                         -((tt_status)?2:1) - margintop ;
  17425.                 if ( debses )
  17426.                     break;
  17427.                 VscrnScroll(VTERM,
  17428.                              DOWNWARD,
  17429.                              0,
  17430.                              VscrnGetHeight(VTERM)
  17431.                              -(tt_status[VTERM]?2:1),
  17432.                              pn[1],
  17433.                              TRUE,
  17434.                              SP);
  17435.                 break;
  17436.             case 'T':
  17437.                 /* (SD) Scroll down-scrolls the characters down */
  17438.                 /* n lines.  The top n lines are    */
  17439.                 /* cleared to blanks (default: n=1). */
  17440.                 /* Also (RD) Roll down with SNI 97801 */
  17441.                 if ( debses )
  17442.                     break;
  17443.  
  17444.                 if ( IS97801(tt_type_mode) ) {
  17445.                     /* ignored if outside scroll region */
  17446.                     if ( wherey[VTERM] < margintop ||
  17447.                          wherey[VTERM] > marginbot )
  17448.                         break;
  17449.                 }
  17450.  
  17451.                 if ( pn[1] == 0 )
  17452.                     pn[1] = 1 ;
  17453.                 else if ( pn[1] > VscrnGetHeight(VTERM)
  17454.                           -((tt_status)?2:1) - margintop )
  17455.                     pn[1] = VscrnGetHeight(VTERM)
  17456.                         -((tt_status)?2:1) - margintop ;
  17457.  
  17458.                 if ( private ) {
  17459.                     if ( ISAIXTERM(tt_type_mode) ) {
  17460.                         /* Go to column pn[1] of Status Line */
  17461.                         setdecssdt(SSDT_HOST_WRITABLE);
  17462.                         setdecsasd(SASD_STATUS);
  17463.                         lgotoxy(VSTATUS,pn[1],1);
  17464.                         break;
  17465.                     }
  17466.                 }
  17467.                 else if ( ISVT320(tt_type_mode) ||
  17468.                           IS97801(tt_type_mode) ) {
  17469.                     if ( sni_scroll_mode ) {
  17470.                         VscrnScroll(VTERM,
  17471.                                      DOWNWARD,
  17472.                                      wherex[VTERM]-1,
  17473.                                      marginbot-1,
  17474.                                      pn[1],
  17475.                                      FALSE,
  17476.                                      SP);
  17477.                     } else { /* Roll Mode */
  17478.                         VscrnScroll(VTERM,
  17479.                                      DOWNWARD,
  17480.                                      margintop-1,
  17481.                                      marginbot-1,
  17482.                                      pn[1],
  17483.                                      FALSE,
  17484.                                      SP);
  17485.                     }
  17486.                 }
  17487.                 /* We don't support paged memory so it does nothing */
  17488.                 else if (ISHFT(tt_type_mode) || ISANSI(tt_type_mode)) {
  17489.                 VscrnScroll(VTERM,
  17490.                              DOWNWARD,
  17491.                              0,
  17492.                              VscrnGetHeight(VTERM)
  17493.                              -(tt_status[VTERM]?2:1),
  17494.                              pn[1],
  17495.                              TRUE,
  17496.                              SP);
  17497.                 }
  17498.                 break;
  17499.             case 't':   /* Proprietary */
  17500.                 if ( ISAAA(tt_type_mode) ) {
  17501.                     /* zPOP - Pop Line */
  17502.                     break;
  17503.                 }
  17504.                 else if ( IS97801(tt_type_mode) ) {
  17505.                      switch ( pn[1] ) {
  17506.                      case 0: /* Disable ID card reader */
  17507.                          break;
  17508.                      case 1: /* Enable ID Card reader */
  17509.                          break;
  17510.                      case 2: {
  17511.                          /* Query ID Card reader status */
  17512.                          /* @ - ID Card Reader Present */
  17513.                          /* A = ID Card Reader broken or missing */
  17514.                          char buf[8];
  17515.                          if ( debses )
  17516.                              break;
  17517.                          if ( send_c1 )
  17518.                              sprintf(buf,"%cPt%c%c",_DCS,'A',_ST8);
  17519.                          else
  17520.                              sprintf(buf,"%cPPt%c%c\\",ESC,'A',ESC);
  17521.                          sendchars(buf,strlen(buf));
  17522.                          break;
  17523.                      }
  17524.                      }
  17525.                 }
  17526.                 else {
  17527.                     switch ( pn[1] ) {
  17528.                     case 24:    /* DECSLPP - Set screen height */
  17529.                     case 25:
  17530.                     case 36:
  17531.                     case 41:
  17532.                     case 42:
  17533.                     case 48:
  17534.                     case 52:
  17535.                     case 53:
  17536.                     case 72:
  17537.                         if ( tt_modechg == TVC_ENA ) {
  17538.                             tt_szchng[VTERM] = 1 ;
  17539.                             tt_rows[VTERM] = pn[1] ;
  17540.                             VscrnInit( VTERM ) ;  /* Height set here */
  17541. #ifdef TCPSOCKET    
  17542. #ifdef CK_NAWS      
  17543.                                 if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  17544.                                     tn_snaws();
  17545. #ifdef RLOGCODE     
  17546.                                     rlog_naws();
  17547. #endif /* RLOGCODE */
  17548. #ifdef SSHBUILTIN
  17549.                                     ssh_snaws();
  17550. #endif /* SSHBUILTIN */
  17551.                                 }
  17552. #endif /* CK_NAWS */
  17553. #endif /* TCPSOCKET */
  17554.                         }
  17555.                         break;
  17556.  
  17557.                         /* These are XTERM functions */
  17558.                     case 1: /* Deiconify (Restore window) */
  17559. #ifdef KUI
  17560.                         gui_win_run_mode(1);
  17561. #endif
  17562.                         break;
  17563.                     case 2: /* Iconify (Minimize window) */
  17564. #ifdef KUI
  17565.                         gui_win_run_mode(2);
  17566. #endif
  17567.                         break;
  17568.                     case 3: /* Position window (Y=Pn[2],X=Pn[3]) */
  17569. #ifdef KUI
  17570.                         if ( k < 2 ) {
  17571.                             pn[2] = 0;
  17572.                             pn[3] = 0;
  17573.                         } else if ( k < 3 )
  17574.                             pn[3] = 0;
  17575.  
  17576.                         gui_position(pn[3],pn[2]);
  17577. #endif /* KUI */
  17578.                         break;
  17579.                     case 4: /* Size window in pixels (Y=Pn[2],X=Pn[3]) */
  17580.                         /* 0 means leave that dimension alone */
  17581.                         if ( k < 2 ) {
  17582.                             pn[2] = 0;
  17583.                             pn[3] = 0;
  17584.                         } else if ( k < 3 )
  17585.                             pn[3] = 0;
  17586.  
  17587.                         if ( pn[2] == 0 && pn[3] == 0 )
  17588.                             break;
  17589. #ifdef KUI
  17590.                         gui_resize_pixels(pn[3], pn[2]);
  17591. #endif /* KUI */
  17592.                         break;
  17593.                     case 5: /* Raise Window */
  17594.                         break;
  17595.                     case 6: /* Lower Window */
  17596.                         break;
  17597.                     case 8: /* Size window in characters (Y=Pn[2],X=Pn[3]) */
  17598.                         /* 0 means leave that dimension alone */
  17599.                         if ( k < 2 || pn[2] == 0 && pn[3] == 0 )
  17600.                             break;
  17601.                         if ( k < 3 )
  17602.                             pn[3] = 0 ;
  17603.                         if ( pn[2] == 0 )
  17604.                             pn[2] = tt_rows[VTERM] ;
  17605.                         if ( pn[3] == 0 )
  17606.                             pn[3] = tt_cols[VTERM] ;
  17607.                         if ( tt_modechg == TVC_ENA ) {
  17608.                             tt_szchng[VTERM] = 1 ;
  17609.                             tt_rows[VTERM] = pn[2] ;
  17610.                             tt_cols[VTERM] = pn[3]%2 ? pn[3]+1 : pn[3] ;
  17611.                             VscrnInit( VTERM ) ; /* Size is set here */
  17612.                             msleep(50);
  17613. #ifdef TCPSOCKET    
  17614. #ifdef CK_NAWS      
  17615.                             if (TELOPT_ME(TELOPT_NAWS) && ttmdm < 0){
  17616.                                 tn_snaws();
  17617. #ifdef RLOGCODE     
  17618.                                 rlog_naws();
  17619. #endif /* RLOGCODE */
  17620. #ifdef SSHBUILTIN
  17621.                                 ssh_snaws();
  17622. #endif /* SSHBUILTIN */
  17623.                             }
  17624. #endif /* CK_NAWS */
  17625. #endif /* TCPSOCKET */
  17626.                         }
  17627.                         break;
  17628.                     case 20: /* Report Icon Label */
  17629.                         break;
  17630.                     case 21: /* Report Window Label */
  17631.                         break;
  17632.                     case 18: /* Report size of Window in chars */
  17633.                         break;
  17634.                     case 14: /* Report size of Window in pixels */
  17635.                         break;
  17636.                     case 13: /* Report position of Window in pixels */
  17637.                         break;
  17638.                     case 11: /* Report state of Window (normal/iconified) */
  17639.                         break;
  17640.                     }
  17641.                 }
  17642.                 break;
  17643.             case 'u':
  17644.                 if ( ISAAA(tt_type_mode) ) {
  17645.                     /* zSTP - Set Transfer Point */
  17646.                     break;
  17647.                 }
  17648.                 else if ( IS97801(tt_type_mode) ) {
  17649.                     switch ( pn[1] ) {
  17650.                     case 0: /* 25-line mode on */
  17651.                         if ( debses )
  17652.                             break;
  17653.                         setdecssdt(SSDT_BLANK);
  17654.                         margintop = 1;
  17655.                         marginbot = VscrnGetHeight(VTERM);
  17656.                         break;
  17657.                     case 1: /* 24-line mode on */
  17658.                         if ( debses )
  17659.                             break;
  17660.                         setdecssdt(SSDT_HOST_WRITABLE);
  17661.                         margintop = 1;
  17662.                         marginbot = VscrnGetHeight(VTERM)-1;
  17663.                         break;
  17664.                     case 2: /* Clear character NUL */
  17665.                         break;
  17666.                     case 3: /* Clear character SP */
  17667.                         break;
  17668.                     case 4: /* Video timeout off */
  17669.                         break;
  17670.                     case 5: /* Video timeout on */
  17671.                         break;
  17672.                     case 8: /* Page mode on */
  17673.                         if ( debses )
  17674.                             break;
  17675.                         sni_pagemode = TRUE;
  17676.                         break;
  17677.                     case 9: /* Auto Roll mode on */
  17678.                         if ( debses )
  17679.                             break;
  17680.                         sni_pagemode = FALSE;
  17681.                         break;
  17682.                     case 10: /* Roll mode */
  17683.                         /* Only affects RD/SD - CSI Pn T */
  17684.                         if ( debses )
  17685.                             break;
  17686.                         sni_scroll_mode = FALSE;
  17687.                         break;
  17688.                     case 11: /* Scroll mode */
  17689.                         /* Only affects RD/SD - CSI Pn T */
  17690.                         if ( debses )
  17691.                             break;
  17692.                         sni_scroll_mode = TRUE;
  17693.                         break;
  17694.                     case 18: /* Reduced-intensity character display */
  17695.                         break;
  17696.                     case 19: /* Reduced-intensity background display */
  17697.                         break;
  17698.                     case 20: /* Dark background (white on black) */
  17699.                         if (!decscnm) /* Already normal? */
  17700.                             break;
  17701.                         else {
  17702.                             flipscreen(VTERM);
  17703.                             VscrnIsDirty(VTERM);
  17704.                         }
  17705.                         break;
  17706.                     case 21: /* Light background (black on white) */
  17707.                         if (decscnm) /* Already reverse */
  17708.                             break;
  17709.                         else {
  17710.                             flipscreen(VTERM);
  17711.                             VscrnIsDirty(VTERM) ;
  17712.                         }
  17713.                         break;
  17714.                     }
  17715.                 }
  17716.                 else if ( ISANSI(tt_type_mode) ||
  17717.                           ISHFT(tt_type_mode) ||
  17718.                           ISSCO(tt_type_mode) ) {
  17719.                     /* Restore Cursor Position */
  17720.                     restorecurpos(VTERM,0);
  17721.                     break;
  17722.                 }
  17723.                 break;
  17724.             case 'W':
  17725.                 if ( ISHFT(tt_type_mode) ||
  17726.                      ISLINUX(tt_type_mode) ||
  17727.                      ISAAA(tt_type_mode)) {
  17728.                     /* CTC - Cursor Tab Stop Control */
  17729.                     do {
  17730.                         cursordown(0);
  17731.                         pn[1] = pn[1] - 1;
  17732.                     } while (pn[1] > 0);
  17733.                 }
  17734.                 break;
  17735.             case 'X':
  17736.                 if (( ISVT220(tt_type_mode) ||
  17737.                       ISHFT(tt_type_mode) ||
  17738.                       ISLINUX(tt_type_mode) ||
  17739.                       ISANSI(tt_type_mode) || 
  17740.                       ISAAA(tt_type_mode)) &&
  17741.                      private == FALSE &&
  17742.                      ansiext == FALSE ) {
  17743.                     /* Erase characters (ECH) VT200 */
  17744.                     blankvcell.c = ' ' ;
  17745.                     blankvcell.a = geterasecolor(VTERM);
  17746.                     if ( pn[1] == 0 ) pn[1] = 1 ;
  17747.                     if ( pn[1] >
  17748.                          VscrnGetWidth(VTERM) + 1
  17749.                          - wherex[VTERM] )
  17750.                         pn[1] =
  17751.                             VscrnGetWidth(VTERM) + 1
  17752.                                 - wherex[VTERM] ;
  17753.                     for ( i = 0 ; i < pn[1] ; i++ ) {
  17754.                         VscrnWrtCell(VTERM,
  17755.                                       blankvcell,
  17756.                                       blankattrib,
  17757.                                       wherey[VTERM]-1,
  17758.                                       wherex[VTERM]-1+i
  17759.                                       );
  17760.                     }
  17761.                 }
  17762.                 break;
  17763.             case 'Y':
  17764.                 /* Cursor Vertical Tab */
  17765.                 if ( ISHFT(tt_type_mode) ) {
  17766.                 }
  17767.                 break;
  17768.             case 'y':   /* Proprietary */
  17769.                 if ( ISVIP(tt_type_mode) ) {
  17770.                     char vipstr[32] ;
  17771.                     sprintf(vipstr,"%c[8p  OT%c%c[y7813  P GC  A %c%c",
  17772.                              ESC,ETX,ESC,ETX,NUL);
  17773.                     sendchars(vipstr,28);
  17774.                 }
  17775.                 else if ( ISHFT(tt_type_mode) ) {
  17776.                     /* Virtual Terminal locator report */
  17777.                     ;
  17778.                 }
  17779.                 else if ( IS97801(tt_type_mode) ) {
  17780.                     switch ( pn[1] ) {
  17781.                     case 1:
  17782.                         /* Execute hardware test for terminal */
  17783.                         break;
  17784.                     case 2:
  17785.                         /* Transmit results of hardware test */
  17786.                         break;
  17787.                     case 3:
  17788.                         /* Activate system test and request result */
  17789.                         break;
  17790.                     case 4:
  17791.                         /* Request firmware version of terminal control */
  17792.                         break;
  17793.                     case 5:
  17794.                         /* Transmit firmware version of keyboard */
  17795.                         break;
  17796.                     case 11:
  17797.                         /* Read current key assignment table */
  17798.                         break;
  17799.                     case 12:
  17800.                         /* Query load process for character generator */
  17801.                         break;
  17802.                     case 19:
  17803.                         /* Transmit board code */
  17804.                         break;
  17805.                     case 20:
  17806.                         /* Activate 8-bit mode   */
  17807.                         /* US_ASCII to G0   (GL) */
  17808.                         /* Brackets to G1        */
  17809.                         /* Blanks   to G2        */
  17810.                         /* ISO 8859-1 to G3 (GR) */
  17811.                         SNI_bitmode(8);
  17812.                         sni_chcode_8 = TRUE;
  17813.                         break;
  17814.                     case 21:
  17815.                         /* Activate 7-bit mode */
  17816.                         /* US_ASCII to G0  (GL)  */
  17817.                         /* US_ASCII to G0  (GR)  */
  17818.                         SNI_bitmode(7);
  17819.                         sni_chcode_7 = TRUE;
  17820.                         break;
  17821.                     case 22: {
  17822.                         /* Query active mode */
  17823.                         char buf[9];
  17824.                         sprintf(buf,"%c22y%c%c",
  17825.                                  _DCS,
  17826.                                  decnrcm?'7':'8',
  17827.                                  _ST8);
  17828.                         ttol(buf,6);
  17829.                         break;
  17830.                     }
  17831.                     case 30:
  17832.                         /* Query load process for string key table */
  17833.                         break;
  17834.                     }
  17835.                 }
  17836.                 else if ( k == 2 && pn[1] == 2 ) { /* Confidence Tests */
  17837.                     if ( pn[2] & 0x01 )
  17838.                         /* Power-up self test */
  17839.                         ;
  17840.                     if ( pn[2] & 0x02 )
  17841.                         /* Data Loop Back test */
  17842.                         ;
  17843.                     if ( pn[2] & 0x04 )
  17844.                         /* EIA modem control test */
  17845.                         ;
  17846.                     if ( pn[2] & 0x08 )
  17847.                         /* Repeat selected test(s) indefinitely */
  17848.                         ;
  17849.                     }
  17850.                 break;
  17851.             case 'Z':
  17852.                 if ( ISANSI(tt_type_mode) &&
  17853.                      ansiext ) {
  17854.                     resetcolors(1);
  17855.                 }
  17856.                 else {
  17857.                     /* Cursor Backward Tabulation (CBT) */
  17858.                     /* moves active position back n tabstops */
  17859.                     if (k < 1) pn[1] = 1;
  17860.                     i = wherex[VTERM];
  17861.                     while (pn[1]) {
  17862.                         if (i > 1) {
  17863.                             do {
  17864.                                 i--;
  17865.                                 cursorleft(0);
  17866.                             } while ((htab[i] != 'T') && (i >= 2));
  17867.                         }
  17868.                         pn[1]--;
  17869.                     }
  17870.                     VscrnIsDirty(VTERM);
  17871.                 }
  17872.                 break;
  17873.             case 'z':   /* Proprietary */
  17874.                 if ( ISH19(tt_type) ) {
  17875.                     doreset(1) ;
  17876.                 }
  17877.                 else if ( ISAAA(tt_type_mode) ) {
  17878.                     /* zSTE - Set Transfer End */
  17879.                 }
  17880.                 else if ( IS97801( tt_type_mode) ) {
  17881.                     /* Define left (pn[1]) and right (pn[2]) margins */
  17882.                     /* 1 <= pn[1] < pn[2] <= 80                      */
  17883.                     /* This sequence affects only the character that */
  17884.                     /* immediately follows this sequence.  That char */
  17885.                     /* is used to fill the scroll region using these */
  17886.                     /* borders, then the borders revert to 1,80.     */
  17887.                     int width = VscrnGetWidth(VTERM);
  17888.                     if ( debses )
  17889.                         break;
  17890.                     if ( pn[1] < 1 || pn[1] > width )
  17891.                         pn[1] = 1;
  17892.                     if ( pn[2] < 1 || pn[2] > width )
  17893.                         pn[2] = width;
  17894.                     if ( pn[1] > pn[2] )
  17895.                         break;
  17896. #ifdef COMMENT
  17897.                     /* Not implemented yet. (see above note.) */
  17898.                     marginleft = pn[1];
  17899.                     marginright = pn[2];
  17900. #endif /* COMMENT */
  17901.                     break;
  17902.                 } else if ( ISSCO(tt_type_mode) ) {
  17903.                     if ( ansiext ) {
  17904.                         /* Clear All Tabs (CAT) */
  17905.                         for (j = 1; j <=MAXTERMCOL; ++j)
  17906.                             htab[j] = '0';
  17907.                     } else {
  17908.                         /* Screen Switch - pn[1] specifies screen to switch to */
  17909.                     }
  17910.                 }
  17911.                 break;
  17912.             case ',': {
  17913.                 achar = (escnext<=esclast)?
  17914.                     escbuffer[escnext++]:0;
  17915.                 switch ( achar ) {
  17916.                 case 'p':   /* DECLTOD - Load Time of Day */
  17917.                     /* pn[1] = hr 00-23; default 8 */
  17918.                     /* pn[2] = mn 00-59; default 0 */
  17919.                     if ( k < 2 )
  17920.                         pn[2] = 0 ;
  17921.                     if ( k < 1 )
  17922.                         pn[1] = 8 ;
  17923.                     loadtod( pn[1], pn[2] ) ;
  17924.                     break;
  17925.                 }
  17926.                 break;
  17927.             }
  17928.             case '\'':
  17929.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  17930.                 switch (achar) {
  17931.                 case '~':
  17932.                     if ( ISVT420(tt_type_mode) ) {
  17933.                         /* DECDC - Delete Column */
  17934.                         viocell cell ;
  17935.                         cell.c = SP ;
  17936.                         cell.a = geterasecolor(VTERM) ;
  17937.                         if ( k < 1 || pn[0] == 0 )
  17938.                             pn[1] = 1;
  17939.                         else if ( pn[1] > VscrnGetWidth(VTERM)-1 )
  17940.                             pn[1] = VscrnGetWidth(VTERM)-1 ;
  17941.  
  17942.                         VscrnScrollLf( VTERM,
  17943.                                        relcursor ? margintop - 1 : 0, /* top row */
  17944.                                        wherex[VTERM], /* left col */
  17945.                                        relcursor ? marginbot - 1 :
  17946.                                        VscrnGetHeight(VTERM)
  17947.                                        -(tt_status[VTERM]?2:1), /* bot row */
  17948.                                        VscrnGetWidth(VTERM)-1,  /* right col */
  17949.                                        pn[1],
  17950.                                        cell);
  17951.                     }
  17952.                     break;
  17953.                 case '}':
  17954.                     if ( ISVT420(tt_type_mode) ) {
  17955.                         /* DECIC - Insert Column */
  17956.                         viocell cell ;
  17957.                         cell.c = SP ;
  17958.                         cell.a = geterasecolor(VTERM) ;
  17959.                         if ( k < 1 || pn[0] == 0 )
  17960.                             pn[1] = 1;
  17961.                         else if ( pn[1] > VscrnGetWidth(VTERM)-1 )
  17962.                             pn[1] = VscrnGetWidth(VTERM)-1 ;
  17963.  
  17964.                         VscrnScrollRt( VTERM,
  17965.                                        relcursor ? margintop - 1 : 0, /* top row */
  17966.                                        wherex[VTERM], /* left col */
  17967.                                        relcursor ? marginbot - 1 :
  17968.                                        VscrnGetHeight(VTERM)
  17969.                                        -(tt_status[VTERM]?2:1), /* bot row */
  17970.                                        VscrnGetWidth(VTERM)-1,  /* right col */
  17971.                                        pn[1],
  17972.                                        cell);
  17973.                     }
  17974.                     break;
  17975.                 }
  17976.                 break;
  17977.             case SP:
  17978.             if ( ISSCO(tt_type_mode) ) {
  17979.                 /* SCO ANSI violates the rules and uses SP as a final character */
  17980.                 do {
  17981.                     cursorleft(0);
  17982.                     pn[1] -= 1;
  17983.                 } while (pn[1] > 0);
  17984.                 break;
  17985.             } else {
  17986.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  17987.                 switch (achar) {
  17988.                 case '@': {
  17989.                     /* Scroll Left - Pan Right */
  17990.                     viocell cell ;
  17991.                     cell.c = SP ;
  17992.                     cell.a = geterasecolor(VTERM) ;
  17993.                     if ( pn[1] == 0 )
  17994.                         pn[1] = 1 ;
  17995.                     else if ( pn[1] > VscrnGetWidth(VTERM)-1 )
  17996.                         pn[1] = VscrnGetWidth(VTERM)-1 ;
  17997.                     VscrnScrollLf( VTERM,
  17998.                                    0,
  17999.                                    0,
  18000.                                    VscrnGetHeight(VTERM)
  18001.                                    -(tt_status[VTERM]?2:1),
  18002.                                    VscrnGetWidth(VTERM)-1,
  18003.                                    pn[1],
  18004.                                    cell);
  18005.                     break;
  18006.                 }
  18007.                 case 'A': {
  18008.                     /* Scroll Right - Pan Left */
  18009.                     viocell cell ;
  18010.                     cell.c = SP ;
  18011.                     cell.a = geterasecolor(VTERM) ;
  18012.                     if ( pn[1] == 0 )
  18013.                         pn[1] = 1 ;
  18014.                     else if ( pn[1] > VscrnGetWidth(VTERM)-1 )
  18015.                         pn[1] = VscrnGetWidth(VTERM)-1 ;
  18016.                         VscrnScrollRt( VTERM,
  18017.                                        0,
  18018.                                        0,
  18019.                                        VscrnGetHeight(VTERM)
  18020.                                        -(tt_status[VTERM]?2:1),
  18021.                                        VscrnGetWidth(VTERM)-1,
  18022.                                        pn[1],
  18023.                                        cell);
  18024.                         break;
  18025.                 }
  18026.                 case 'q':       /* Set Cursor Type - VT520 */
  18027.                     switch ( pn[1] ) {
  18028.                     case 0:
  18029.                     case 1:
  18030.                         /* Blinking Block */
  18031.                         tt_cursor = TTC_BLOCK ;
  18032.                         break;
  18033.                     case 2:
  18034.                         /*  Steady Block */
  18035.                         tt_cursor = TTC_BLOCK ;
  18036.                         break;
  18037.                     case 3:
  18038.                         /* Blinking Underline */
  18039.                         tt_cursor = TTC_ULINE ;
  18040.                         break;
  18041.                     case 4:
  18042.                         /* Steady Underline */
  18043.                         tt_cursor = TTC_ULINE ;
  18044.                         break;
  18045.                     }
  18046.                     setcursormode() ;
  18047.                     cursorena[VTERM] = TRUE;
  18048.                     break;
  18049.                 }
  18050.                 break;
  18051.             } /* SP */
  18052.             case '~': {
  18053.                 if ( kermext ) {
  18054.                     /* MS-DOS Kermit PRODUCT macro */
  18055. #ifdef CK_APC
  18056.                     sprintf(apcbuf,
  18057.                              "do product %d %d %d %d %d %d %d %d %d",
  18058.                              1<=k?pn[1]:0,
  18059.                              2<=k?pn[2]:0,
  18060.                              3<=k?pn[3]:0,
  18061.                              4<=k?pn[4]:0,
  18062.                              5<=k?pn[5]:0,
  18063.                              6<=k?pn[6]:0,
  18064.                              7<=k?pn[7]:0,
  18065.                              8<=k?pn[8]:0,
  18066.                              9<=k?pn[9]:0);
  18067.                     apc_command(APC_LOCAL,apcbuf);
  18068. #endif /* CK_APC */
  18069.                 }
  18070.                 else { /* DECTME */
  18071.                     switch ( pn[1] ) {
  18072.                     case 0:
  18073.                     case 1:
  18074.                         switch ( tt_type ) {
  18075.                         case TT_VT220:
  18076.                         case TT_VT220PC:
  18077.                         case TT_VT320:
  18078.                         case TT_VT320PC:
  18079.                         case TT_WY370:
  18080.                             tt_type_mode = tt_type;
  18081.                             break;
  18082.                         default:
  18083.                             tt_type_mode = TT_VT320 ;
  18084.                             break;
  18085.                         }
  18086.                         if ( k > 1 && pn[2] == 1 )
  18087.                             send_c1 = FALSE ; /* 7-bit cntrols */
  18088.                         else
  18089.                             send_c1 = TRUE ; /* 8-bit controls */
  18090.                         break;
  18091.                     case 2:
  18092.                         switch ( tt_type ) {
  18093.                         case TT_VT100:
  18094.                             tt_type_mode = TT_VT100 ;
  18095.                             break;
  18096.                         default:
  18097.                             tt_type_mode = TT_VT102 ;
  18098.                             break;
  18099.                         }
  18100.                         break;
  18101.                     case 3:
  18102.                         tt_type_mode = TT_VT52;
  18103.                         break;
  18104.                     case 4:   /* PC TERM */
  18105.                         break;
  18106.                     case 5:
  18107.                         tt_type_mode = TT_WY60 ;
  18108.                         break;
  18109.                     case 6:   /* WYSE PC TERM */
  18110.                         break;
  18111.                     case 7:
  18112.                         tt_type_mode = TT_WY50 ;
  18113.                         break;
  18114.                     case 8:   /* WYSE 150/120 */
  18115.                         break;
  18116.                     case 9:
  18117.                         tt_type_mode = TT_TVI950 ;
  18118.                         break;
  18119.                     case 10:
  18120.                         tt_type_mode = TT_TVI925 ;
  18121.                             break;
  18122.                     case 11:
  18123.                         tt_type_mode = TT_TVI910 ;
  18124.                         break;
  18125.                     case 12:  /* ADDS A2 */
  18126.                         break;
  18127.                     case 13:
  18128.                         tt_type_mode = TT_SCOANSI ;
  18129.                         break;
  18130.                     case 14:  /* WYSE 325 */
  18131.                     break;
  18132.                     }
  18133.                     /* status line needs to be updated */
  18134.                     VscrnIsDirty(VTERM);
  18135.                 }
  18136.                 break;
  18137.             }
  18138.             case '[': {
  18139.                 if ( ISHFT(tt_type_mode) ) {
  18140.                     /* Select Reversed String */
  18141.                     switch ( pn[1] ) {
  18142.                     case 0: /* End Push */
  18143.                         break;
  18144.                     case 1: /* Start Push */
  18145.                         break;
  18146.                     }
  18147.                 }
  18148.                 break;
  18149.             }
  18150.             case ']': {
  18151.                 if ( ISHFT(tt_type_mode) ) {
  18152.                     /* Select Alternate Presentation Variant */
  18153.                     for (j = 1; j <= k; ++j) { /* Go thru all Pn's */
  18154.                         switch ((pn[j])) {   /* This one... */
  18155.                         case 0:
  18156.                             /* Set Default Values for BIDI */
  18157.                             break;
  18158.                         case 1:
  18159.                             /* Set Arabic numeric shapes */
  18160.                             break;
  18161.                         case 2:
  18162.                             /* Set Hindi numeric shapes */
  18163.                             break;
  18164.                         case 3:
  18165.                             /* Set symmetric swapping mode */
  18166.                             /* for directional characters */
  18167.                             break;
  18168.                         case 5:
  18169.                             /* the following graphic character */
  18170.                             /* is presented in its isolated form */
  18171.                             /* (Arabic only) */
  18172.                             /* effects only the following char */
  18173.                             /* unless used with 21 and 22 */
  18174.                             break;
  18175.                         case 6:
  18176.                             /* the following graphic character */
  18177.                             /* is presented in it initial form */
  18178.                             /* (Arabic only) */
  18179.                             /* effects only the following char */
  18180.                             /* unless used with 21 and 22 */
  18181.                             break;
  18182.                         case 7:
  18183.                             /* the following graphic character */
  18184.                             /* is presented in it middle form */
  18185.                             /* (Arabic only) */
  18186.                             /* effects only the following char */
  18187.                             /* unless used with 21 and 22 */
  18188.                         case 8:
  18189.                             /* the following graphic character */
  18190.                             /* is presented in it final form */
  18191.                             /* (Arabic only) */
  18192.                             /* effects only the following char */
  18193.                             /* unless used with 21 and 22 */
  18194.                             break;
  18195.                         case 13:
  18196.                             /* set Special shaping mode */
  18197.                             break;
  18198.                         case 14:
  18199.                             /* set standard shaping mode */
  18200.                             break;
  18201.                         case 15:
  18202.                             /* set symmetric mode */
  18203.                             break;
  18204.                         case 18:
  18205.                             /* Passthru (everything) */
  18206.                             break;
  18207.                         case 19:
  18208.                             /* Passthru (everything but numbers) */
  18209.                             break;
  18210.                         case 20:
  18211.                             /* Contextual numbers (device dependent) */
  18212.                             break;
  18213.                         case 21:
  18214.                             /* lock 5,6,7,8 */
  18215.                             break;
  18216.                         case 22:
  18217.                             /* unlock */
  18218.                             break;
  18219.                         case 23:
  18220.                             /* set the nonull mode */
  18221.                             break;
  18222.                         case 24:
  18223.                             /* reset the nonull mode */
  18224.                             break;
  18225.                         default:
  18226.                             break;
  18227.                         }
  18228.                     }
  18229.                 } else if ( ISLINUX(tt_type_mode) ) {
  18230.                     /*
  18231.                     ESC [ 1 ; n ]       Set color n as the underline color
  18232.                     ESC [ 2 ; n ]       Set color n as the dim color
  18233.                     ESC [ 8 ]           Make the current color pair the default attributes.
  18234.                     ESC [ 9 ; n ]       Set screen blank timeout to n minutes.
  18235.                     ESC [ 10 ; n ]      Set bell frequency in Hz.
  18236.                     ESC [ 11 ; n ]      Set bell duration in msec.
  18237.                     ESC [ 12 ; n ]      Bring specified console to the front.
  18238.                     ESC [ 13 ]          Unblank the screen.
  18239.                     ESC [ 14 ; n ]      Set the VESA powerdown interval in minutes.
  18240.                     */
  18241.                 }
  18242.                 break;
  18243.             }
  18244.             case '&': {
  18245.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  18246.                 switch (achar) {
  18247.                 case 'x': /* Enable Session */
  18248.                     break;
  18249.                 }
  18250.                 break;
  18251.             }
  18252.             default:
  18253.                 debug(F111,"ANSI X3.64","unknown achar",achar);
  18254.                 break;
  18255.             }       /* third level of left bracket */
  18256.         }   /* Esc [ Pn...Pn x   functions */
  18257.             break;
  18258.         }   /* Second level */
  18259.  
  18260.     } /* Left square bracket */
  18261. }
  18262.  
  18263. void
  18264. vtescape( void )
  18265. {
  18266.     unsigned short  j;
  18267.     unsigned short  k;
  18268.     unsigned short  l;
  18269.     unsigned char   blankcell[2];
  18270.     viocell         blankvcell ;
  18271.     int             i;
  18272.     char            tempstr[20];
  18273.     int             fore, back;
  18274.     int             tcs ;
  18275.     unsigned char   des ;
  18276.  
  18277.     /* Initialize default values */
  18278.     for (i=0;i<11;i++)
  18279.         pn[i]=0;
  18280.     private = ansiext = zdsext = kermext = FALSE;
  18281.  
  18282.     escstate = ES_NORMAL;               /* Set escape state back to normal */
  18283.     escnext = 1;                        /* Point to beginning of esc seq buf */
  18284.     if (debses)                         /* If TERMINAL DEBUG ON, */
  18285.       return;                           /* we don't actually do anything. */
  18286.  
  18287.     achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  18288.     if ( !xprint /* && screenon */) {
  18289.         /* screen escape sequences  */
  18290.         switch (achar) {                /* First Level */
  18291.         case '[':      /* CSI */
  18292.             vtcsi();
  18293.             break;
  18294.         case SP:
  18295.               achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  18296.               if (ISVT220(tt_type_mode)) {
  18297.                   switch (achar) {
  18298.                   case 'F':  /* S7C1T */
  18299.                       send_c1 = FALSE;
  18300.                       break;
  18301.                   case 'G':  /* S8C1T */
  18302.                       send_c1 = TRUE ;
  18303.                       break;
  18304.                   case '0':     /* WYID */
  18305.                       if ( tt_type == TT_WY370 )
  18306.                           sendchars("370\r",4);
  18307.                       break;
  18308.                   case 'L': /* Select ANSI Level 1 */
  18309.                       /* ASCII set designated as G0 */
  18310.                       /* ISO Latin-1 supplemental set designated as G1 */
  18311.                       /* G0 mapped into GL */
  18312.                       /* G1 mapped into GR */
  18313.                   case 'M': /* Select ANSI Level 2 */
  18314.                       /* ASCII set designated as G0 */
  18315.                       /* ISO Latin-1 supplemental set designated as G1 */
  18316.                       /* G0 mapped into GL */
  18317.                       /* G1 mapped into GR */
  18318.                   case 'N': /* Select ANSI Level 3 */
  18319.                       /* ASCII set designated as G0 */
  18320.                       /* G0 mapped into GL */
  18321.                       {
  18322.                           int tcs;
  18323.                           decnrcm = FALSE ;
  18324.                           /* we treat all of the conformance levels the same    */
  18325.                           /* ISO-4873 does not specify that lower levels cannot */
  18326.                           /* support the capabilities of the higher levels      */
  18327.                           for ( i = 0 ; i < 4 ; i++ ) {
  18328.                               G[i].designation = G[i].def_designation ;
  18329.                               G[i].size = G[i].def_size ;
  18330.                               G[i].c1   = G[i].def_c1 ;
  18331.                               G[i].national = CSisNRC(G[i].designation);
  18332.                               if ( G[i].def_designation == FC_TRANSP ) {
  18333.                                   G[i].rtoi = NULL ;
  18334.                                   G[i].itol = NULL ;
  18335.                                   G[i].itor = NULL ;
  18336.                                   G[i].ltoi = NULL;
  18337.                               }
  18338.                               else {
  18339.                                   G[i].rtoi = xl_u[G[i].def_designation];
  18340.                                   if ( isunicode() ) {
  18341.                                       G[i].itol = NULL ;
  18342.                                       G[i].ltoi = NULL;
  18343.                                   }
  18344.                                   else {
  18345.                                       G[i].itol = xl_tx[tcsl] ;
  18346.                                       G[i].ltoi = xl_u[tcsl] ;
  18347.                                   }
  18348.                                   G[i].itor = xl_tx[G[i].def_designation];
  18349.                               }
  18350.                           }
  18351.                       }
  18352.                       break;
  18353.                   case '}':     /* DECKBD */
  18354.                       /* Pn[1] specifies the keyboard Layout */
  18355.                       /*       0,1, or None - VT             */
  18356.                       /*       2            - enhanced PC    */
  18357.                       /* Pn[2] indicates the national keyboard language */
  18358.                       /*       0,1, or None - North American */
  18359.                       /*       2            - British */
  18360.                       /*       3            - Belgian (Flemish) */
  18361.                       /*       4            - French Canadian */
  18362.                       /*       5            - Danish */
  18363.                       /*       6            - Finnish */
  18364.                       /*       7            - German */
  18365.                       /*       8            - Dutch */
  18366.                       /*       9            - Italian */
  18367.                       /*       10           - Swiss French */
  18368.                       /*       11           - Swiss German */
  18369.                       /*       12           - Swedish */
  18370.                       /*       13           - Norwegian */
  18371.                       /*       14           - French */
  18372.                       /*       15           - Spanish */
  18373.                       /*       16           - Portuguese */
  18374.                       /*       19           - Hebrew */
  18375.                       /*       22           - Greek */
  18376.                       /*       28           - Canadian (English) */
  18377.                       /*       29           - Turkish Q/Turkish */
  18378.                       /*       30           - Turkish F */
  18379.                       /*       31           - Hungarian */
  18380.                       /*       33           - Slovak */
  18381.                       /*       34           - Czech */
  18382.                       /*       35           - Polish */
  18383.                       /*       36           - Romanian */
  18384.                       /*       38           - SCS */
  18385.                       /*       39           - Russian */
  18386.                       /*       40           - Latin American */
  18387.                       break;
  18388.                       if ( k<1 )
  18389.                           pn[1] = 1;
  18390.                       if ( k<2 )
  18391.                           pn[2] = 0;
  18392.  
  18393.                       /* We do not support the PC mode yet */
  18394.                       if ( pn[1] != 0 && pn[1] != 1 )
  18395.                           break;
  18396.  
  18397.                       switch ( pn[2] ) {
  18398.                       case VTL_NORTH_AM:  /* North American */
  18399.                           /* Multinational: Latin-1   */
  18400.                           /* National:      US_ASCII  */
  18401.                           dec_lang = pn[2];
  18402.                           dec_nrc = TX_ASCII;
  18403.                           dec_kbd = TX_8859_1;
  18404.                           break;
  18405.                       case VTL_BRITISH :
  18406.                           /* Multinational: Latin-1   */
  18407.                           /* National:      UK_ASCII  */
  18408.                           dec_lang = pn[2];
  18409.                           dec_nrc = TX_BRITISH;
  18410.                           dec_kbd = TX_8859_1;
  18411.                           break;
  18412.                       case VTL_FRENCH  :
  18413.                       case VTL_BELGIAN :
  18414.                       case VTL_CANADIAN:
  18415.                           /* Multinational: Latin-1   */
  18416.                           /* National:      FR_ASCII  */
  18417.                           dec_lang = pn[2];
  18418.                           dec_nrc = TX_FRENCH;
  18419.                           dec_kbd = TX_8859_1;
  18420.                           break;
  18421.                       case VTL_FR_CAN  :
  18422.                           /* Multinational: Latin-1   */
  18423.                           /* National:      FC_ASCII  */
  18424.                           dec_lang = pn[2];
  18425.                           dec_nrc = TX_CN_FRENCH;
  18426.                           dec_kbd = TX_8859_1;
  18427.                           break;
  18428.                       case VTL_DANISH  :
  18429.                       case VTL_NORWEGIA:
  18430.                           /* Multinational: Latin-1   */
  18431.                           /* National:      NO_ASCII  */
  18432.                           dec_lang = pn[2];
  18433.                           dec_nrc = TX_NORWEGIAN;
  18434.                           dec_kbd = TX_8859_1;
  18435.                           break;
  18436.                       case VTL_FINNISH :
  18437.                           /* Multinational: Latin-1   */
  18438.                           /* National:      FI_ASCII  */
  18439.                           dec_lang = pn[2];
  18440.                           dec_nrc = TX_FINNISH;
  18441.                           dec_kbd = TX_8859_1;
  18442.                           break;
  18443.                       case VTL_GERMAN  :
  18444.                           /* Multinational: Latin-1   */
  18445.                           /* National:      GR_ASCII  */
  18446.                           dec_lang = pn[2];
  18447.                           dec_nrc = TX_GERMAN;
  18448.                           dec_kbd = TX_8859_1;
  18449.                           break;
  18450.                       case VTL_DUTCH   :
  18451.                           /* Multinational: Latin-1   */
  18452.                           /* National:      DU_ASCII  */
  18453.                           dec_lang = pn[2];
  18454.                           dec_nrc = TX_DUTCH;
  18455.                           dec_kbd = TX_8859_1;
  18456.                           break;
  18457.                       case VTL_ITALIAN :
  18458.                           /* Multinational: Latin-1   */
  18459.                           /* National:      IT_ASCII  */
  18460.                           dec_lang = pn[2];
  18461.                           dec_nrc = TX_ITALIAN;
  18462.                           dec_kbd = TX_8859_1;
  18463.                           break;
  18464.                       case VTL_SW_FR   :
  18465.                       case VTL_SW_GR   :
  18466.                           /* Multinational: Latin-1   */
  18467.                           /* National:      CH_ASCII  */
  18468.                           dec_lang = pn[2];
  18469.                           dec_nrc = TX_SWISS;
  18470.                           dec_kbd = TX_8859_1;
  18471.                           break;
  18472.                       case VTL_SWEDISH :
  18473.                           /* Multinational: Latin-1   */
  18474.                           /* National:      SW_ASCII  */
  18475.                           dec_lang = pn[2];
  18476.                           dec_nrc = TX_SWEDISH;
  18477.                           dec_kbd = TX_8859_1;
  18478.                           break;
  18479.                       case VTL_SPANISH :
  18480.                           /* Multinational: Latin-1   */
  18481.                           /* National:      SP_ASCII  */
  18482.                           dec_lang = pn[2];
  18483.                           dec_nrc = TX_SPANISH;
  18484.                           dec_kbd = TX_8859_1;
  18485.                           break;
  18486.                       case VTL_PORTUGES:
  18487.                           /* Multinational: Latin-1   */
  18488.                           /* National:      Portugese ASCII  */
  18489.                           dec_lang = pn[2];
  18490.                           dec_nrc = TX_PORTUGUESE;
  18491.                           dec_kbd = TX_8859_1;
  18492.                           break;
  18493.                       case VTL_HEBREW  :
  18494.                           /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  18495.                           /* National:      DEC 7-bit Hebrew  */
  18496.                           dec_lang = pn[2];
  18497.                           dec_nrc = TX_HE7;
  18498.                           dec_kbd = TX_8859_8;
  18499.                           break;
  18500.                       case VTL_GREEK   :
  18501.                           /* Multinational: Latin-Greek / DEC-Greek   */
  18502.                           /* National:      DEC Greek NRC             */
  18503.                           /* is ELOT927 equivalent to DEC Greek????   */
  18504.                           dec_lang = pn[2];
  18505.                           dec_nrc = TX_ELOT927;
  18506.                           dec_kbd = TX_8859_7;
  18507.                           break;
  18508. #ifdef COMMENT
  18509.                       case VTL_TURK_Q  :
  18510.                       case VTL_TURK_F  :
  18511.                           /* Multinational: Latin-Turkish / DEC-Turkish   */
  18512.                           /* National:      DEC 7-bit Turkish             */
  18513.                           break;
  18514. #endif /* COMMENT */
  18515.                       case VTL_HUNGARIA:
  18516.                           /* Multinational: Latin-2   */
  18517.                           /* National:      no national mode  */
  18518.                           dec_lang = pn[2];
  18519.                           dec_nrc = TX_HUNGARIAN;
  18520.                           dec_kbd = TX_8859_2;
  18521.                           break;
  18522.                       case VTL_SLOVAK  :
  18523.                       case VTL_CZECH   :
  18524.                       case VTL_POLISH  :
  18525.                       case VTL_ROMANIAN:
  18526.                           /* Multinational: Latin-2   */
  18527.                           /* National:      no national mode  */
  18528.                           dec_lang = pn[2];
  18529.                           dec_nrc = TX_ASCII;
  18530.                           dec_kbd = TX_8859_2;
  18531.                           break;
  18532.                       case VTL_RUSSIAN :
  18533.                           /* Multinational: Latin-Cyrillic / KOI-8   */
  18534.                           /* National:      DEC Russian NRC  */
  18535.                           dec_lang = pn[2];
  18536.                           dec_nrc = TX_KOI7;
  18537.                           dec_kbd = TX_8859_5;
  18538.                           break;
  18539.                       case VTL_LATIN_AM:
  18540.                           /* Multinational: not listed in table   */
  18541.                           /* National:      not listed in table  */
  18542.                           dec_lang = pn[2];
  18543.                           dec_nrc = TX_ASCII;
  18544.                           dec_kbd = TX_8859_1;
  18545.                           break;
  18546. #ifdef COMMENT
  18547.                       case VTL_SCS     :
  18548.                           /* Multinational: Latin-2   */
  18549.                           /* National:      SCS NRC   */
  18550.                           break;
  18551. #endif /* COMMENT */
  18552.                       }
  18553.                   }
  18554.               }
  18555.               break;
  18556.         case '\\':
  18557.               if ( ISH19(tt_type_mode) ) {
  18558.                   /* Exit Hold Screen Mode */
  18559.               }
  18560.               /* String Terminator */
  18561.               /*
  18562.                  Only here for debugging purposes; really handled in cwrite()
  18563.                  Assuming we are in a string; otherwise, we ignore it.
  18564.                  */
  18565.               break;
  18566.         case '@':
  18567.             if ( ISH19(tt_type_mode) ) {
  18568.                 /* Enter Insert Character Mode */
  18569.                 insertmode = TRUE ;
  18570.             }
  18571.             break;
  18572.         case '1':
  18573.                 if ( ISH19(tt_type_mode) ) {
  18574.                     /* Enter Keypad Shift Mode */
  18575.                     tt_shift_keypad = TRUE ;
  18576.                     break;
  18577.                 }
  18578.                 else if ( ISVT100(tt_type_mode) ) {
  18579.                     /* Graphic Processor On */
  18580.                 }
  18581.                 break;
  18582.         case '2':
  18583.               if ( ISVT100(tt_type_mode) ) {
  18584.                     /* Graphic Processor Off */
  18585.               }
  18586.               break;
  18587.         case 5:
  18588.             /* Wy75 - Transmit Character at Cursor */
  18589.             if ( ISAAA(tt_type_mode) ) {
  18590.                 /* AnnArbor: zTFC - Toggle Fast-Blink Cursor */
  18591.             }
  18592.             break;
  18593.         case '6':  
  18594.             if ( ISAAA(tt_type_mode) ) {
  18595.                 /* AnnArbor: zTI - Toggle IRM */
  18596.             } else if (ISVT100(tt_type_mode)) {
  18597.                 /* DECBI - Back Index */
  18598.                 if ( wherex[VTERM] > 1 )
  18599.                     cursorleft(0);
  18600.                 else {
  18601.                     blankvcell.c = SP;
  18602.                     blankvcell.a = geterasecolor(VTERM);
  18603.                     VscrnScrollRt(VTERM,
  18604.                                wherey[VTERM] - 1,
  18605.                                0,
  18606.                                wherey[VTERM] - 1,
  18607.                                VscrnGetWidth(VTERM) - 1,
  18608.                                1, blankvcell);
  18609.                 }
  18610.             }
  18611.             break;
  18612.         case '7':
  18613.             /* AnnArbor - zSC - Save Cursor */
  18614.             /* Save cursor position and attributes */
  18615.             if ( ISANSI(tt_type_mode) || ISAAA(tt_type_mode) )
  18616.                 savecurpos(VTERM,0);
  18617.             else
  18618.                 savecurpos(VTERM,1);
  18619.             break;
  18620.         case '8':
  18621.             /* AnnArbor: - zRC - Restore Cursor */
  18622.             /* Restore Cursor Position and attributes */
  18623.             if ( ISANSI(tt_type_mode) || ISAAA(tt_type_mode) )
  18624.                 restorecurpos(VTERM,0);
  18625.             else
  18626.                 restorecurpos(VTERM, 1);
  18627.             break;
  18628.         case '9':  
  18629.               if ( ISAAA(tt_type_mode) ) {
  18630.                   /* zCGR - Change Graphic Rendition to Qualified Area */
  18631.           /* Default area goes from Current Cursor position to End of Screen */
  18632.           /* Lawrence A Deck - Raytheon 1 Nov 2002 */
  18633.  
  18634.           int start_x, start_y, end_x, end_y, x, y;
  18635.           int h = VscrnGetHeight(VTERM)-(tt_status[vmode]?1:0);
  18636.           int w = VscrnGetWidth(VTERM);
  18637.               
  18638.           start_x = wherex[VTERM];
  18639.           start_y = wherey[VTERM];
  18640.           end_x = w;
  18641.           end_y = h;
  18642.  
  18643.           for ( x=start_x; 
  18644.             x < (start_y == end_y ? end_x : MAXTERMCOL); 
  18645.             x++ ) {
  18646.               viocell * pcell = VscrnGetCell(VTERM,x-1,start_y-1);
  18647.               pcell->a = attribute;
  18648.               VscrnWrtCell( VTERM, *pcell, attrib,
  18649.                     start_y - 1,
  18650.                     x - 1);
  18651.           }
  18652.           if ( start_y != end_y ) {
  18653.               for ( y=start_y+1; y<end_y; y++) {
  18654.               for ( x=0; x<MAXTERMCOL; x++ ) {
  18655.                   viocell * pcell = VscrnGetCell(VTERM,x-1,y-1);
  18656.                   pcell->a = attribute;
  18657.                   VscrnWrtCell( VTERM, *pcell, attrib,
  18658.                         y - 1,
  18659.                         x - 1);
  18660.               }
  18661.               }
  18662.               for ( x=0; 
  18663.                 x <= end_x; 
  18664.                 x++ ) {
  18665.               viocell * pcell = VscrnGetCell(VTERM,x-1,end_y-1);
  18666.               pcell->a = attribute;
  18667.               VscrnWrtCell( VTERM, *pcell, attrib,
  18668.                     end_y - 1,
  18669.                     x - 1);
  18670.               }
  18671.           }
  18672.               } else if (ISVT100(tt_type_mode)) { 
  18673.                   /* DECFI - Forward Index */
  18674.                   if ( wherex[VTERM] < VscrnGetWidth(VTERM) )
  18675.                       cursorright(0);
  18676.                   else {
  18677.                       blankvcell.c = SP;
  18678.                       blankvcell.a = geterasecolor(VTERM);
  18679.                       VscrnScrollLf(VTERM,
  18680.                                  wherey[VTERM] - 1,
  18681.                                  0,
  18682.                                  wherey[VTERM] - 1,
  18683.                                  VscrnGetWidth(VTERM) - 1,
  18684.                                  1, blankvcell);
  18685.                   }
  18686.               }
  18687.         VscrnIsDirty(VTERM);
  18688.             break;
  18689.         case ':':
  18690.             if ( ISAAA(tt_type_mode) ) {
  18691.                 /* zGUA - Guard Unprotected Areas */
  18692.             }
  18693.             break;
  18694.         case '`':
  18695.             if ( ISVIP(tt_type_mode) ) {
  18696.                 /* Honeywell Clear screen, cursor does not move */
  18697.                 clrscreen(VTERM,SP);
  18698.             }
  18699.             else if ( IS97801(tt_type_mode) ||
  18700.                       ISHFT(tt_type_mode) || 
  18701.                       ISAAA(tt_type_mode) ) {
  18702.                 /* DMI (Disable Manual Input */
  18703.                 keylock = TRUE ;
  18704.                 break;
  18705.             }
  18706.             break;
  18707.         case 'A':
  18708.             if ( ISVT52(tt_type_mode) ) /* VT52 control */
  18709.                 cursorup(0);
  18710.             break;
  18711.         case 'a':
  18712.             if ( ISAAA(tt_type_mode) ) {
  18713.                 /* INT - INTERRUPT */
  18714.             }
  18715.             break;
  18716.         case 'B':
  18717.             if ( ISVT52(tt_type_mode) ) /* VT52 control */
  18718.                 cursordown(0);
  18719.             break;
  18720.         case 'b':
  18721.             if ( ISH19(tt_type_mode) ) {
  18722.                 /* Erase Beginning of Display */
  18723.                 clrboscr_escape(VTERM,SP);
  18724.             }
  18725.             else if ( IS97801(tt_type_mode) ||
  18726.                       ISHFT(tt_type_mode) ||
  18727.                       ISAAA(tt_type_mode)) {
  18728.                 /* EMI (Enable Manual Input) */
  18729.                 keylock = FALSE ;
  18730.                 break;
  18731.             }
  18732.             break;
  18733.         case 'C':
  18734.             if ( ISVT52(tt_type_mode) ) /* VT52 control */
  18735.                 cursorright(0);
  18736.             break;
  18737.         case 'c':
  18738.             /* Reset - RIS */
  18739.             doreset(1);
  18740.             break;
  18741.         case 'D':
  18742.             if ( ISVT52(tt_type_mode) ) /* VT52 control */
  18743.                 cursorleft(0);
  18744.             else if ( ISVT100(tt_type_mode) ) {/* IND - Index */
  18745.                 if (wherey[VTERM] == marginbot) {
  18746.                     VscrnScroll(VTERM,
  18747.                                  UPWARD,
  18748.                                  margintop - 1,
  18749.                                  marginbot - 1,
  18750.                                  1,
  18751.                                  (margintop==1),
  18752.                                  SP);
  18753.                 } else
  18754.                     cursordown(0);
  18755.             }
  18756.             break;
  18757.         case 'E':
  18758.             if ( ISH19(tt_type_mode) ) {
  18759.                 /* Clear Display (Shift Erase) */
  18760.                 clrscreen(VTERM,SP);
  18761.                 lgotoxy(VTERM,1,1);       /* and home the cursor */
  18762.             }
  18763.             else {                      /* NEL - Next Line */
  18764.                 cursornextline();
  18765.             }
  18766.             break;
  18767.         case 'F':
  18768.             if ( ISVT52(tt_type_mode) ) /* VT52 control */
  18769.                 vt52graphics = TRUE;
  18770.             else if ( ISVT220(tt_type_mode) ) {
  18771.                 /* SSA - Start Selected Area */
  18772.                 ;
  18773.             }
  18774.             break;
  18775.         case 'G':
  18776.             if ( ISVT52(tt_type_mode) ) /* VT52 control */
  18777.                 vt52graphics = FALSE;
  18778.             else if ( ISVT220(tt_type_mode) ) {
  18779.                 /* ESA - End selected area */
  18780.                 ;
  18781.             }
  18782.             break;
  18783.         case 'H':
  18784.               if ( ISVT100(tt_type_mode) ) {
  18785.                   /* HTS - Set Tab Stop */
  18786.                   htab[wherex[VTERM]] = 'T';
  18787.               }
  18788.               else if ( ISVT52(tt_type_mode) )
  18789.                   /* Cursor Home */
  18790.                   lgotoxy(VTERM,1, 1);
  18791.               break;
  18792.         case 'I':                       
  18793.             if ( ISAAA(tt_type_mode) ) {
  18794.                 /* HTJ - Horizontal Tab with Justify */
  18795.                 ;
  18796.             } else if (ISVT52(tt_type_mode)) {
  18797.                 /* Reverse Linefeed */
  18798.                 if (margintop == wherey[VTERM])
  18799.                     VscrnScroll(VTERM,
  18800.                                  DOWNWARD,
  18801.                                  margintop - 1,
  18802.                                  marginbot - 1,
  18803.                                  1,
  18804.                                   FALSE,
  18805.                                   SP
  18806.                                   );
  18807.                 else
  18808.                     cursorup(0);
  18809.             }
  18810.             break;
  18811.         case 'J':
  18812.             if (ISVT52(tt_type_mode))
  18813.                 /* VT52 control */
  18814.                 clreoscr_escape(VTERM,SP);
  18815.             break;
  18816.         case 'j':
  18817.             if ( ISH19(tt_type_mode) ) {
  18818.                 /* H19 - Save Cursor Position */
  18819.                 savecurpos(VTERM,0);
  18820.             }
  18821.             break;
  18822.         case 'K':
  18823.             if (ISVT52(tt_type_mode))
  18824.                 /* VT52 control */
  18825.                 clrtoeoln(VTERM,SP);
  18826.             break;
  18827.         case 'k':
  18828.             if (ISH19(tt_type_mode)) {
  18829.                 /* H19 - Restore Cursor Position */
  18830.                 restorecurpos(VTERM,0);
  18831.             }
  18832.             break;
  18833.         case 'L':
  18834.             if ( ISH19(tt_type_mode) ) {
  18835.                 /* H19 - Insert Line */
  18836.                 VscrnScroll(VTERM,
  18837.                              DOWNWARD,
  18838.                              wherey[VTERM] - 1,
  18839.                              marginbot - 1,
  18840.                              1,
  18841.                              FALSE,
  18842.                              SP);
  18843.             }
  18844.             break;
  18845.         case 'l':
  18846.               if ( ISH19(tt_type_mode) ) {
  18847.                   /* Erase Entire Line */
  18848.                   clrline_escape(VTERM,SP);
  18849.               } else if ( ISSCO(tt_type_mode) ) {
  18850.                   /* Lock Memory Area */
  18851.                   setmargins(wherey[VTERM],VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));
  18852.                   lgotoxy(VTERM, relcursor ? marginleft : 1,
  18853.                            relcursor ? marginbot : 1);
  18854.               }
  18855.               break;
  18856.         case 'M':                       
  18857.             /* RI - Reverse Index, VT102 */
  18858.             if (ISVT100(tt_type_mode)) {
  18859.                 if (margintop == wherey[VTERM])
  18860.                     VscrnScroll(VTERM,
  18861.                                  DOWNWARD,
  18862.                                  margintop - 1,
  18863.                                  marginbot - 1,
  18864.                                  1,
  18865.                                   FALSE,
  18866.                                   SP
  18867.                                   );
  18868.                 else
  18869.                     cursorup(0);
  18870.             }
  18871.             else if ( ISH19(tt_type_mode) && achar == 'M' ) {
  18872.                 /* H19 - Delete Line */
  18873.                 VscrnScroll(VTERM,
  18874.                              UPWARD,
  18875.                              wherey[VTERM] - 1,
  18876.                              marginbot - 1,
  18877.                                  1,
  18878.                                  FALSE,
  18879.                                  SP);
  18880.             }
  18881.             break;
  18882.         case 'm':
  18883.               if ( ISSCO(tt_type_mode) ) {
  18884.                   /* Unlock Memory Area */
  18885.                   setmargins(1,VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));
  18886.                   lgotoxy(VTERM, 1, 1);
  18887.               }
  18888.               break;
  18889.         case 'p':
  18890.             if ( ISH19(tt_type_mode) ) {
  18891.                 /* Enter Reverse Video Mode */
  18892.                 attrib.reversed = TRUE ;
  18893.             }
  18894.             break;
  18895.         case 'Q':               
  18896.             /* SCOANSI/AT386 Fn key assignments */
  18897.             /* Normally PU1 String.  SCOANSI break ANSI X.64-1979 */
  18898.             if ( ISANSI(tt_type_mode) )
  18899.             {
  18900.                 int fn,quote, next, control=0 ;
  18901.  
  18902.                 fn = ttinc(0) - '0' ;   /* get the Fn number */
  18903.                 if ( fn < 0 ) {         /* illegal Fn */
  18904.                     le_putchar(fn);
  18905.                     break;
  18906.                 }
  18907.  
  18908.                 if ( !savefiletext[0] )
  18909.                     strcpy(savefiletext,filetext);
  18910.                 strcpy( filetext, "ANSI FN" ) ;
  18911.                 VscrnIsDirty(VTERM) ;
  18912.  
  18913.                 quote = ttinc(0) ;              /* get the Quote char */
  18914. #ifdef CK_APC
  18915.                 apclength = 0 ;
  18916.                 while ( (next = ttinc(0)) != quote &&
  18917.                         apclength < apcbuflen ) {
  18918.                     if ( control )
  18919.                     {
  18920.                         apcbuf[apclength++] = next-32 ;
  18921.                         control = 0 ;
  18922.                     }
  18923.                     else
  18924.                     {
  18925.                         if ( next == '^' )
  18926.                             control = 1 ;
  18927.                         else
  18928.                             apcbuf[apclength++] = next ;
  18929.                     }
  18930.                 }
  18931.                 apcbuf[apclength] = '\0' ;
  18932. #else /* CK_APC */
  18933.                 while ( ttinc(0) != quote );
  18934. #endif /* CK_APC */
  18935.                 if (savefiletext[0]) {          /* Fix status line */
  18936.                     strcpy(filetext,savefiletext);
  18937.                     savefiletext[0] = NUL;
  18938.                     VscrnIsDirty(VTERM);  /* status line needs to be updated */
  18939.                 }
  18940.  
  18941. #ifdef CK_APC
  18942. #ifndef NOSETKEY
  18943. #ifndef NOKVERBS
  18944.                 if ( next == quote )
  18945.                 {
  18946.                     /* assign the string to the function key */
  18947.                     if ( udkfkeys[fn] ) {
  18948.                         free(udkfkeys[fn]) ;
  18949.                         udkfkeys[fn]=NULL;
  18950.                     }
  18951.                     if ( strlen(apcbuf) )
  18952.                         udkfkeys[fn] = strdup(apcbuf) ;
  18953.                 }
  18954. #endif /* NOKVERBS */
  18955. #endif /* NOSETKEY */
  18956. #endif /* CK_APC */
  18957.             }
  18958.             break;
  18959.         case 'q':
  18960.             if ( ISH19(tt_type_mode) ) {
  18961.                 /* Exit Reverse Video Mode */
  18962.                 attrib.reversed = FALSE ;
  18963.             }
  18964.             break;
  18965.         case 'r':
  18966.             if ( ISH19(tt_type_mode) ) {
  18967.                 /* Modify Baud Rate */
  18968.                 /* we don't do this, just eat the next character */
  18969.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  18970.             }
  18971.             break;
  18972.         case 'S':
  18973.             if ( ISAAA(tt_type_mode) ) {
  18974.                 /* STS - Set Transmit State */
  18975.             }
  18976.             break;
  18977. /*
  18978.   VT52 printer controls.  For now, autoprint is treated like transparent
  18979.   print.  32-bit version only, to avoid stack overflows in 16-bit version.
  18980.   Edit 190, fdc.
  18981. */
  18982.         case 'u':
  18983.                 if ( ISH19(tt_type_mode) ) {
  18984.                     /* Exit Keypad Shift Mode */
  18985.                     tt_shift_keypad = FALSE ;
  18986.                     break;
  18987.                 }
  18988.         case 'V':                       
  18989.             if (ISVT52(tt_type_mode)) {/* VT52 control */
  18990.                 /* Print cursor line */
  18991.                 prtscreen(VTERM,wherey[VTERM],wherey[VTERM]);
  18992.             } else if ( ISAAA(tt_type_mode) ) {
  18993.                 /* SPA - Start Protected Area */
  18994.             }
  18995.             break;
  18996.         case 'v':
  18997.                 if ( ISH19(tt_type_mode) ) {
  18998.                     /* Wrap Around at End of Line */
  18999.                     tt_wrap = TRUE ;
  19000.                 }
  19001.                 break;
  19002.         case 'W':                       
  19003.             if (ISVT52(tt_type_mode)) { /* VT52 control */
  19004.                 /* Transparent print on */
  19005.                 turnonprinter = xprint = TRUE;
  19006.             } else if ( ISAAA(tt_type_mode) ) {
  19007.                 /* EPA - End Protected Area */
  19008.             }
  19009.             break;
  19010.         case 'w':
  19011.                 if ( ISH19(tt_type_mode) ) {
  19012.                     /* Discard at End of Line */
  19013.                     tt_wrap = FALSE ;
  19014.                 }
  19015.                 break;
  19016.         case 'X':                       /* Transparent print off */
  19017.             if (ISVT52(tt_type_mode)) { /* VT52 control */
  19018.                 turnoffprinter = TRUE;
  19019.                 xprint = FALSE ;
  19020.             }
  19021.             break;
  19022.         case 'x':
  19023.             if ( ISH19(tt_type_mode) ) {
  19024.                 /* Set Modes */
  19025.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19026.                 switch ( achar ) {
  19027.                 case '1':       /* Enable 25th line */
  19028.                     if ( !tt_status[VTERM] )
  19029.                         break;
  19030.                     settermstatus(FALSE);
  19031.                     break;
  19032.                 case '2':       /* No Key Click */
  19033.                     setkeyclick(FALSE);
  19034.                     break;
  19035.                 case '3':       /* Hold Screen Mode */
  19036.                     break;
  19037.                 case '4':       /* Block Cursor */
  19038.                     tt_cursor = TTC_BLOCK ;
  19039.                     setcursormode() ;
  19040.                     break;
  19041.                 case '5':       /* Cursor Off */
  19042.                     cursorena[VTERM] = FALSE ;
  19043.                     break;
  19044.                 case '6':       /* Keypad Shifted */
  19045.                     tt_shift_keypad = TRUE ;
  19046.                     break;
  19047.                 case '7':       /* Alternate keypad mode */
  19048.                     tt_keypad = TTK_APPL ;
  19049.                     break;
  19050.                 case '8':       /* Auto Line Feed on receipt of CR */
  19051.                     tt_crd = TRUE ;
  19052.                     break;
  19053.                 case '9':       /* Auto CR on receipt of LF */
  19054.                     tnlm = TRUE ;
  19055.                     break;
  19056.                 }
  19057.             }
  19058.             break;
  19059.         case 'Y':                       /* Direct cursor address */
  19060.             if (ISVT52(tt_type_mode)) { /* VT52 control */
  19061.                 int row,column ;
  19062.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19063.                 row = achar - 31;
  19064.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19065.                 column = achar - 31;
  19066.                 lgotoxy(VTERM,column, row);
  19067.             }
  19068.             break;
  19069.         case 'y':
  19070.             if ( ISH19(tt_type_mode) ) {
  19071.                 /* Reset Modes */
  19072.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19073.                 switch ( achar ) {
  19074.                 case '1':       /* Disable 25th line */
  19075.                     if ( tt_status[VTERM] )
  19076.                         break;
  19077.                     settermstatus(TRUE);
  19078.                     break;
  19079.                 case '2':       /* Key Click */
  19080.                     setkeyclick(TRUE);
  19081.                     break;
  19082.                 case '3':       /* Exit Hold Screen Mode */
  19083.                     break;
  19084.                 case '4':       /* Underline Cursor */
  19085.                     tt_cursor = TTC_ULINE ;
  19086.                     setcursormode() ;
  19087.                     break;
  19088.                 case '5':       /* Cursor On */
  19089.                     cursorena[VTERM] = TRUE ;
  19090.                     break;
  19091.                 case '6':       /* Keypad Unshifted */
  19092.                     tt_shift_keypad = FALSE ;
  19093.                     break;
  19094.                 case '7':       /* Exit Alternate keypad mode */
  19095.                     tt_keypad = TTK_NORM ;
  19096.                     break;
  19097.                 case '8':       /* No Auto Line Feed on receipt of CR */
  19098.                     tt_crd = FALSE ;
  19099.                     break;
  19100.                 case '9':       /* No Auto CR on receipt of LF */
  19101.                     tnlm = FALSE ;
  19102.                     break;
  19103.                 }
  19104.             }
  19105.             break;
  19106.         case 'Z':                       /* DECID - Identify Terminal */
  19107.             if ( ISVT52(tt_type_mode) ) {
  19108.                 sendescseq(tt_info[TT_VT52].x_id);
  19109.             }
  19110.             else if ( ISVT220(tt_type) ) {
  19111.                 sendescseq(tt_info[tt_type].x_id);
  19112.             }
  19113.             else if (tt_type_mode >= 0 && tt_type_mode <= max_tt) {
  19114.                 sendescseq(tt_info[tt_type_mode].x_id);
  19115.             }
  19116.             break;
  19117.         case 'z':
  19118.             if ( ISH19(tt_type_mode) ) {
  19119.                 doreset(1) ;
  19120.             }
  19121.             break;
  19122.         case ']':
  19123.             if ( ISH19(tt_type_mode) ) {
  19124.                 /* Transmit 25th line to host */
  19125.                 ;
  19126.             }
  19127.             else if (ISVT52(tt_type_mode)) /* VT52 control */
  19128.                 /* Print screen */
  19129.                 prtscreen(VTERM,1,VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));
  19130.             break;
  19131.         case '^':                       /* Autoprint on */
  19132.               if (ISVT52(tt_type_mode)) {/* VT52 control */
  19133.                   turnonprinter = TRUE;
  19134.                   setaprint(TRUE);
  19135.               }
  19136.             break;
  19137.         case '_':                       /* Autoprint off */
  19138.             if (ISVT52(tt_type_mode)) { /* VT52 control */
  19139.                 turnoffprinter = TRUE;
  19140.                 setaprint(FALSE);
  19141.             }
  19142.             break;
  19143.         case '#':
  19144.             if ( ISH19(tt_type_mode) ) {
  19145.                 /* Transmit Page (lines 1-24) to Host */
  19146.                 break;
  19147.             }
  19148.             /* Esc # sequence */
  19149.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19150.             switch (achar) {
  19151.             case '3': /* DECDHL */
  19152.                 decdwl_escape(VT_LINE_ATTR_DOUBLE_WIDE |
  19153.                                VT_LINE_ATTR_DOUBLE_HIGH |
  19154.                                   VT_LINE_ATTR_UPPER_HALF );
  19155.                 break;
  19156.             case '4': /* DECDHL */
  19157.                 decdwl_escape(VT_LINE_ATTR_DOUBLE_WIDE |
  19158.                                   VT_LINE_ATTR_DOUBLE_HIGH |
  19159.                                   VT_LINE_ATTR_LOWER_HALF);
  19160.                 break;
  19161.             case '5': /* DECSWL */
  19162.                 decdwl_escape(VT_LINE_ATTR_NORMAL);
  19163.                 break;
  19164.             case '6': /* DECDWL */
  19165.                 decdwl_escape(VT_LINE_ATTR_DOUBLE_WIDE);
  19166.                 break;
  19167.             case '7': /* Hardcopy (vt100) */
  19168.                 break;
  19169.             case '8': /* Screen Alignment Display */
  19170.                 {
  19171.                     videoline * line ;
  19172.                     viocell cell;
  19173.                     short x,y ;
  19174.  
  19175.                     cell.c = 'E';
  19176.                     cell.a = defaultattribute; /* was 0x07 */
  19177.                     /* Self Test */
  19178.                     /* 24 lines of MAXTERMCOL cols of cells */
  19179.                     for ( y=0 ; y < 24 ; y++ ) {
  19180.                         line = VscrnGetLineFromTop(VTERM, y) ;
  19181.                         for ( x=0 ; x < MAXTERMCOL ; x++ ) {
  19182.                             line->cells[x] = cell ;
  19183.                             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL;
  19184.                         }
  19185.                         line->vt_line_attr = VT_LINE_ATTR_NORMAL;
  19186.                     }
  19187.                     setmargins(1, VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));
  19188.                     if ( decsasd == SASD_STATUS )
  19189.                         lgotoxy( VSTATUS, 1, 1 );
  19190.                     else
  19191.                         lgotoxy(VTERM,1, 1);
  19192.                     VscrnIsDirty(VTERM);
  19193.                 }
  19194.                 break;
  19195.             case ':':   /* WYDHL */
  19196.                 decdwl_escape(VT_LINE_ATTR_DOUBLE_HIGH |
  19197.                                VT_LINE_ATTR_UPPER_HALF);
  19198.                 break;
  19199.             case ';':   /* WYDHL */
  19200.                 decdwl_escape(VT_LINE_ATTR_DOUBLE_HIGH |
  19201.                                VT_LINE_ATTR_LOWER_HALF);
  19202.                 break;
  19203.             default:
  19204.                 break;
  19205.             } /* Esc # sequence */
  19206.             break;
  19207.  
  19208.         case '=':                       /* Application mode */
  19209.             tt_keypad = TTK_APPL;
  19210.             break;
  19211.         case '>':                       /* Numeric mode */
  19212.             tt_keypad = TTK_NORM;
  19213.             break;
  19214.         case '<':                       /* Enter ANSI mode */
  19215.             /* VT52 control */
  19216.             if (ISVT52(tt_type_mode) && tt_type != TT_VT52 ) {
  19217.                 if ( ISH19(tt_type) )
  19218.                     tt_type_mode = TT_VT100 ;
  19219.                 else {
  19220. #ifdef COMMENT
  19221.                     tt_type_mode = tt_type_vt52;
  19222. #else /* COMMENT */
  19223.                     /* As per dickey@clark.net */
  19224.                     tt_type_mode = TT_VT102 ;
  19225. #endif /* COMMENT */
  19226.                 }
  19227.                 ipadl25();
  19228.             }
  19229.             break;
  19230.  
  19231.         case '(':                       /* Select 94 Character Set into G0 */
  19232.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19233.               if ( ISLINUX(tt_type_mode) ) {
  19234. #ifndef COMMENT
  19235.                   /* From man "console_codes" as of Red Hat 8.0
  19236.                    *  ESC (    Start sequence defining G0 character set
  19237.                    *  ESC ( B     Select default (ISO 8859-1 mapping)
  19238.                    *  ESC ( 0     Select vt100 graphics mapping
  19239.                    *  ESC ( U     Select null mapping - straight to character ROM
  19240.                    *  ESC ( K     Select user mapping - the map that is loaded by
  19241.                    *              the utility mapscrn(8).
  19242.                    *  ESC )    Start sequence defining G1
  19243.                    *           (followed by one of B, 0, U, K, as above).
  19244.                    */
  19245.                   charset( cs94, achar, &G[0]) ;
  19246. #else
  19247.                   /* Linux only has two 256 char character sets */
  19248.                   /* We simulate them by using G0 for ASCII and */
  19249.                   /* G2 as Linux-G0 and G3 as Linux-G1          */
  19250.                   charset( cs94, achar, &G[3]) ;
  19251. #endif /* COMMENT */
  19252.               } else {
  19253.                   if ( decnrcm && isNRC(achar))
  19254.                   {
  19255.                       for ( i=0; i<=3 ; i++ )
  19256.                           charset( cs94, achar, &G[i] ) ;
  19257.                   }
  19258.                   else
  19259.                   {
  19260.                       charset( cs94, achar, &G[0] ) ;
  19261.                   }
  19262.             }
  19263.             break;
  19264.         case ')':                       /* Select 94 Character Set into G1 */
  19265.             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19266.               if ( ISLINUX(tt_type_mode) ) {
  19267. #ifndef COMMENT
  19268.                   /* From man "console_codes" as of Red Hat 8.0
  19269.                    *  ESC (    Start sequence defining G0 character set
  19270.                    *  ESC ( B     Select default (ISO 8859-1 mapping)
  19271.                    *  ESC ( 0     Select vt100 graphics mapping
  19272.                    *  ESC ( U     Select null mapping - straight to character ROM
  19273.                    *  ESC ( K     Select user mapping - the map that is loaded by
  19274.                    *              the utility mapscrn(8).
  19275.                    *  ESC )    Start sequence defining G1
  19276.                    *           (followed by one of B, 0, U, K, as above).
  19277.                    */
  19278.                   charset( cs94, achar, &G[0]) ;
  19279. #else /* COMMENT */
  19280.                   /* Linux only has two 256 char character sets */
  19281.                   /* We simulate them by using G0 for ASCII and */
  19282.                   /* G2 as Linux-G0 and G3 as Linux-G1          */
  19283.                   charset( cs94, achar, &G[3]) ;
  19284. #endif /* COMMENT */
  19285.               } else {
  19286.                   if ( decnrcm && isNRC(achar) )
  19287.                   {
  19288.                       for ( i=0; i<=3 ; i++ )
  19289.                           charset( cs94, achar, &G[i] ) ;
  19290.                   }
  19291.                   else
  19292.                   {
  19293.                       charset( cs94, achar, &G[1] ) ;
  19294.                   }
  19295.             }
  19296.             break;
  19297.         case '*':  /* Select 94 Character Set into G2 */
  19298.               if ( !ISLINUX(tt_type_mode) &&
  19299.                    (ISVT220(tt_type_mode) || ISANSI(tt_type_mode))) {
  19300.                   achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19301.                   if ( decnrcm && isNRC(achar) )
  19302.                   {
  19303.                       for ( i=0; i<=3 ; i++ )
  19304.                           charset( cs94, achar, &G[i] ) ;
  19305.                   }
  19306.                   else
  19307.                   {
  19308.                       charset( cs94, achar, &G[2] ) ;
  19309.                   }
  19310.               }
  19311.               break;
  19312.         case '%':       /* Non-ISO 2022 character sets */
  19313.               achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19314.               switch ( achar ) {
  19315.               case '@':         /* Return to ISO 2022 mode */
  19316.                   tt_utf8 = 0;
  19317.                   break;
  19318.               case 'G':         /* UTF-8 with standard return */
  19319.                   tt_utf8 = 1;
  19320.                   break;
  19321.               }
  19322.               break;
  19323.         case '+':                       /* Select 94 Character Set into G3 */
  19324.               if ( !ISLINUX(tt_type_mode) &&
  19325.                    (ISVT220(tt_type_mode) || ISANSI(tt_type_mode))) {
  19326.                   achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19327.                   if ( decnrcm && isNRC(achar) )
  19328.                   {
  19329.                       for ( i=0; i<=3 ; i++ )
  19330.                           charset( cs94, achar, &G[i] ) ;
  19331.                   }
  19332.                   else
  19333.                   {
  19334.                       charset( cs94, achar, &G[3] ) ;
  19335.                   }
  19336.               }
  19337.               break;
  19338.  
  19339.         case '-':                       /* Select 96 Character Set into G1 */
  19340.               achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19341.               charset( cs96, achar, &G[1] ) ;
  19342.               break;
  19343.         case '.':                       /* Select 96 Character Set into G2 */
  19344.               if ( ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19345.                   achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19346.                   charset( cs96, achar, &G[2] ) ;
  19347.               }
  19348.               break;
  19349.         case '/':                       /* Select 96 Character Set into G3 */
  19350.               if ( ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19351.                   achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19352.                   charset( cs96, achar, &G[3] ) ;
  19353.               }
  19354.               break;
  19355.  
  19356.         case '~':                       /* Lock shift G1, right */
  19357.               if ( ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19358.                   GR = &G[1] ;
  19359.               }
  19360.               break;
  19361.         case '}':                       /* Lock shift G2, right */
  19362.               if (ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19363.                   GR = &G[2] ;
  19364.               }
  19365.               else if ( ISH19(tt_type_mode) ) {
  19366.                   /* Keyboard Disabled */
  19367.                   keylock = TRUE ;
  19368.               }
  19369.               break;
  19370.         case 'n':
  19371.               if ( ISH19(tt_type_mode) ) {
  19372.                   /* Cursor Position Report */
  19373.                   char buf[12] ;
  19374.                   sprintf(buf,"%cY%c%c",ESC,wherey[VTERM]+31,wherex[VTERM]+31);
  19375.                   sendchars(buf,strlen(buf));
  19376.               }
  19377.               else if ( ISVT220(tt_type_mode)  || ISANSI(tt_type_mode)) {
  19378.                   /* Lock shift G2, left */
  19379.                   GL = &G[2] ;
  19380.               }
  19381.               break;
  19382.         case 'o':                       /* Lock shift G3, left */
  19383.               if (ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19384.                   GL = &G[3] ;
  19385.               }
  19386.               else if ( ISH19(tt_type_mode) ) {
  19387.                   /* Erase Beginning of Line */
  19388.                   clrbol_escape(VTERM,SP);
  19389.               }
  19390.               break;
  19391.         case '|':                       /* Lock shift G3, right */
  19392.               if (ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19393.                   GR = &G[3] ;
  19394.               }
  19395.               break;
  19396.         case 'N':                       /* Single shift G2, left */
  19397.               if (ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19398.                   SSGL = &G[2] ;
  19399.               }
  19400.               else if ( ISH19(tt_type_mode) ) {
  19401.                   /* H19 - Delete Character */
  19402.                   blankvcell.c = SP;
  19403.                   blankvcell.a = geterasecolor(VTERM);
  19404.                   if (pn[1] > VscrnGetWidth(VTERM) + 1 -
  19405.                        wherex[VTERM])
  19406.                       pn[1] = VscrnGetWidth(VTERM) + 1 -
  19407.                           wherex[VTERM];
  19408.                   VscrnScrollLf(VTERM, wherey[VTERM] - 1,
  19409.                                  wherex[VTERM] - 1,
  19410.                                  wherey[VTERM] - 1,
  19411.                                  VscrnGetWidth(VTERM) - 1,
  19412.                                  pn[1],
  19413.                                  blankvcell
  19414.                                  ) ;
  19415.  
  19416.               }
  19417.               break;
  19418.         case 'O':                       /* Single shift G3, left */
  19419.               if (ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) {
  19420.                   SSGL = &G[3] ;
  19421.               }
  19422.               else if ( ISH19(tt_type_mode) ) {
  19423.                   /* Exit Insert Character Mode */
  19424.                   insertmode = FALSE ;
  19425.               }
  19426.               break;
  19427.  
  19428.         case '{':
  19429.                 if ( ISH19(tt_type_mode) ) {
  19430.                     /* Keyboard Enabled */
  19431.                     keylock = FALSE ;
  19432.                     break;
  19433.                 }
  19434.                 break;
  19435.         default:
  19436.             if (achar == 12) {  /* ESC Ctrl-L */
  19437.                 if ( decsasd == SASD_STATUS ) {
  19438.                     lgotoxy( VSTATUS, 1, 1 );
  19439.                     clrscreen(VSTATUS,SP);
  19440.                 }
  19441.                 else {
  19442.                     lgotoxy(VTERM,1, 1);
  19443.                     clrscreen(VTERM,SP);
  19444.                 }
  19445.             }
  19446.             break;
  19447.         } /* First Level Case  */
  19448.     }
  19449.     else {                              /* transparent print */
  19450.         switch (achar) {                /* First Level */
  19451.           case '[':                     /* CSI */
  19452.             {
  19453.                 achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19454.               LB3000:
  19455.                 switch (achar) {        /* Second level */
  19456.                   case '?':             /* DEC private */
  19457.                     private = TRUE;
  19458.                     achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19459.                     goto LB3000;
  19460.                     break;
  19461.                   default:              /* Pn - got a number */
  19462.                   LB3001:
  19463.                     {                   /* Esc [ Pn...Pn x   functions */
  19464.                         pn[1] = pnumber(&achar);
  19465.                         k = 1;
  19466.                       LB3002:
  19467.                         while (achar == ';') { /* get Pn[k] */
  19468.                             achar = (escnext<=esclast)?escbuffer[escnext++]:0;
  19469.                             k++;
  19470.                             if (achar == '?')
  19471.                               achar =
  19472.                                 (escnext<=esclast)?escbuffer[escnext++]:0;
  19473.                             pn[k] = pnumber(&achar);
  19474.                         }
  19475.                         pn[k + 1] = 1;
  19476.                       LB3003:
  19477.                         switch (achar) { /* Third level */
  19478.                           case 'i':     /* Media Copy */
  19479.                             switch (pn[1]) {
  19480.                             case  4:
  19481.                                 if ( private == FALSE ) {
  19482.                                     xprint = FALSE;
  19483.                                 }
  19484.                                 if ( is_noprint() )
  19485.                                   turnoffprinter = TRUE;
  19486.                                 break;
  19487.                             case 5:
  19488.                                 if ( private == FALSE )
  19489.                                     return ; /* Don't print this */
  19490.                                 break;
  19491.                             case 7:
  19492.                                 if ( !xprint && private == FALSE) {
  19493.                                     /* Turn on screen display */
  19494.                                     screenon = TRUE;
  19495.                                     if ( savefiletext[0] ) {
  19496.                                         strcpy(filetext,savefiletext);
  19497.                                         savefiletext[0] = NUL ;
  19498.                                         /* Update status line */
  19499.                                         VscrnIsDirty(VTERM);
  19500.                                     }
  19501.                                 }
  19502.                                 break;
  19503.                             }
  19504.                         }
  19505.                     }
  19506.                     break;
  19507.                 }
  19508.             }                   /* Left square bracket */
  19509.             break;
  19510.         } /* First Level Case  */
  19511.     } /* transparent print || screen off */
  19512.  
  19513.     /* Host said to turn off the printer. */
  19514.  
  19515.     if (turnoffprinter) {
  19516.         printeroff();
  19517.         turnoffprinter = FALSE;
  19518.     }
  19519.  
  19520. /* If printer is in User or Controller modes, print this escape sequence. */
  19521. /* but not if Auto print mode */
  19522.  
  19523.     if ( printon && (is_xprint() || is_uprint())) {
  19524.         switch(escbuffer[0]) {
  19525.         case _CSI:
  19526.             prtchar(_CSI);
  19527.             i = 2;
  19528.             break;
  19529.         case ESC:
  19530.         default:
  19531.             i=0;;
  19532.             break;
  19533.         }
  19534.         if (esclast > 0) {
  19535.             /* print esc sequence */
  19536.             for (; i <= esclast; ++i)
  19537.                 prtchar(escbuffer[i]);
  19538.         }
  19539.     }
  19540. /*
  19541.   If we just got a "printer on" directive, turn on the printer now.
  19542.   This way, the "printer on" directive itself is not printed.
  19543. */
  19544.     if (turnonprinter) {                /* Last command was "printer on" */
  19545.         printeron();
  19546.         turnonprinter = FALSE;
  19547.     }
  19548.     if ( xprint == FALSE )
  19549.       VscrnIsDirty(VTERM);
  19550. }
  19551.  
  19552. /* ================================================================== */
  19553. /* VT100  -  emulate a DEC VT terminal writing a character            */
  19554. /* ================================================================== */
  19555. void
  19556. vt100(unsigned short vtch) {
  19557.     int             i, j;
  19558.     viocell       cell ;
  19559.     int vmode = decsasd == SASD_TERMINAL ? VTERM : VSTATUS ;
  19560.  
  19561. #ifdef COMMENT
  19562.     debug(F101,"vt100","",vtch);
  19563. #endif /* COMMENT */
  19564.  
  19565.    if (tt_type_mode == TT_NONE) {
  19566.       wrtch(vtch);
  19567.       return;
  19568.    } else if (!xprint) {
  19569.       if (vtch < 32 &&                  /* Control Character */
  19570.           (!crm && !literal_ch)) {      /* no display of c0 control chars */
  19571.          achar = vtch;  /* Let the rest of this module see the value */
  19572.          switch (achar) {
  19573.          case FF:                       /* Formfeed */
  19574.              if ( ISSUN(tt_type_mode) ) {
  19575.                  clrscreen(vmode,SP);
  19576.                  lgotoxy(vmode,1,1);       /* and home the cursor */
  19577.                  VscrnIsDirty(vmode);
  19578.              }
  19579.              else if ( (IS97801(tt_type_mode) || ISHP(tt_type_mode)) ) {
  19580.                  if (wherex[vmode] < marginright)
  19581.                      wherex[vmode]++;
  19582.              }
  19583.              else if ( ISANSI(tt_type_mode) ) {
  19584.                  if ( ISAVATAR(tt_type_mode) )  /* Avatar */
  19585.                      attribute = defaultattribute ;
  19586.                  clrscreen(vmode,SP);
  19587.                  lgotoxy(vmode,1,1);       /* and home the cursor */
  19588.                  VscrnIsDirty(vmode);
  19589.              }
  19590.              else {
  19591.                  wrtch((char) LF);
  19592.              }
  19593.              break;
  19594.          case LF:                       /* Linefeed */
  19595.          case VT:                       /* Vertical tab */
  19596.              wrtch((char) LF);
  19597.              break;
  19598.          case CR:                       /* Carriage return */
  19599.              wrtch((char) achar);
  19600.              break;
  19601.          case SO:                       /* SO */
  19602.              /* If I read the Linux Console Codes doc right, this is the proper behavior */
  19603.              if ( ISLINUX(tt_type_mode) ) {
  19604.                  GR = &G[3];
  19605.              } else if ( !ISANSI(tt_type_mode) )       { /* "ANSI music" protection... */
  19606.                  GL = &G[1] ;
  19607.              }
  19608.              break;
  19609.  
  19610.          case SI:                       /* SI */
  19611.              /* ditto */
  19612.              if ( ISLINUX(tt_type_mode) ) {
  19613.                  GR = &G[2];
  19614.              } else if ( !ISANSI(tt_type_mode) )       { /* Ditto, gag... */
  19615.                  GL = &G[0] ;
  19616.              }
  19617.              break;
  19618.  
  19619.          case BS:                       /* BS */
  19620.              wrtch((CHAR) achar);
  19621.              break;
  19622.  
  19623.          case BEL:                      /* BEL */
  19624.              bleep(BP_BEL);
  19625.              break;
  19626.  
  19627.          case ENQ:                      /* ENQ */
  19628.              if ( ISVIP(tt_type_mode) ) {
  19629.                  sendescseq("7813  P GC  A\003");
  19630.              }
  19631.              else if (tt_answer)
  19632.                  sendchars(answerback,strlen(answerback)) ;
  19633.              break;
  19634.          case HT:               /* Horizontal tab */
  19635.              i = wherex[vmode];
  19636.              if (i < VscrnGetWidth(vmode))
  19637.              {
  19638.                  do {
  19639.                      i++;
  19640.                      cursorright(0);
  19641.                   } while ((htab[i] != 'T') &&
  19642.                             (i <= VscrnGetWidth(vmode)-1));
  19643.                   VscrnIsDirty(vmode);
  19644.              }
  19645.              break;
  19646.          case SYN:      /* Ctrl-V - AVATAR AVTCODE */
  19647.              if ( ISAVATAR(tt_type_mode) )
  19648.                  avatar() ;
  19649.              break;
  19650.          case XEM:       /* AVATAR - Repeat character */
  19651.              if ( ISAVATAR(tt_type_mode) ) {
  19652.                  int ch, count;
  19653.                  ch = avainc(0) ;
  19654.                  count = avainc(0) ;
  19655.                  if ( debses )
  19656.                      break;
  19657.                  while ( count-- )
  19658.                      wrtch(ch);
  19659.              }
  19660.              break;
  19661.          case NUL:
  19662.              if ( IS97801(tt_type_mode) )
  19663.                  wrtch(SP);
  19664.              break;
  19665.          default:               /* ignore it */
  19666.              break;
  19667.          }
  19668.             /* End of Control Character */
  19669.       } else {
  19670.          if (vtch != DEL) {             /* Normal character. */
  19671.             if (ISVT100(tt_type_mode)) {
  19672.                 if ( vtch == 35 &&
  19673.                      GNOW->designation == TX_BRITISH &&
  19674.                      tcsr == TX_ASCII )
  19675.                 {
  19676.                     /* UK ISO 646 character-set, # = Pound Sterling Sign */
  19677.                     vtch = 156;
  19678.                 }
  19679.             } else {
  19680.                 if (vt52graphics) {
  19681.                     if ( ISH19(tt_type) && (94 <= vtch) && (vtch <= 126)) {
  19682.                        literal_ch = TRUE ;
  19683.                         vtch = xlh19grph(vtch) ;
  19684.                     }
  19685.                     else if ((95 <= vtch) && (vtch <= 126)) {
  19686.                         literal_ch = TRUE;
  19687.                         vtch = xldecgrph(vtch);
  19688.                     }
  19689.                 }
  19690.             }
  19691.  
  19692.             /* On the right margin? */
  19693.             if (wherex[vmode] != (isdoublewidth(wherey[vmode]) ?
  19694.                                    VscrnGetWidth(vmode)/2 :
  19695.                                    VscrnGetWidth(vmode)))
  19696.             {
  19697.                 wrtch(vtch);    /* Not on right margin */
  19698.                 wrapit = FALSE;
  19699.             } else {            /* On right margin. */
  19700.                 if (wrapit) {   /* Time to wrap?  */
  19701.                     if (literal_ch) {
  19702.                         literal_ch = 0;
  19703.                         wrtch(CR);
  19704.                         wrtch(LF);
  19705.                         literal_ch = 1;
  19706.                     } else {
  19707.                         wrtch(CR);
  19708.                         wrtch(LF);
  19709.                     }
  19710.                     wrtch(vtch);        /* Now write the character */
  19711.                     wrapit = FALSE;     /* Remember wrapping is done */
  19712.                 } else {                /* Not time to wrap */
  19713.                     cell.c = vtch;
  19714.                     cell.a = attribute ;
  19715.                     if (isdoublewidth(wherey[vmode]))
  19716.                         VscrnWrtCell(vmode, cell,attrib,wherey[vmode]-1,
  19717.                                       VscrnGetWidth(vmode)/2-1);
  19718.                     else
  19719.                         VscrnWrtCell(vmode, cell,attrib,wherey[vmode]-1,
  19720.                                       VscrnGetWidth(vmode)-1) ;
  19721.                     VscrnIsDirty(vmode);
  19722.                     literal_ch = FALSE;
  19723.                     if (tt_wrap) { /* If TERM WRAP ON */
  19724.                         if ( IS97801(tt_type_mode) ) {
  19725.                             if ( wherey[vmode] == marginbot ) {
  19726.                                 if ( !sni_pagemode ) {
  19727.                                     wrtch(CR);
  19728.                                     wrtch(LF);
  19729.                                 }
  19730.                                 else {  /* Page Mode */
  19731.                                     lgotoxy(vmode,1,1);
  19732.                                 }
  19733.                             }
  19734.                             else {
  19735.                                 wrtch(CR);
  19736.                                 wrtch(LF);
  19737.                             }
  19738.                         } else /* if ( !deccolm ) */ {
  19739.                             /* 20050407 - I do not remember why there is a test
  19740.                              * to disable wrapping if 132 column mode is on.
  19741.                              * If there was such a exclusion it must be restricted
  19742.                              * to a particular model of terminal.  Which one?
  19743.                              */
  19744.                             if ( (ISLINUX(tt_type_mode) ||
  19745.                                   ISVT100(tt_type_mode) ||
  19746.                                   ISVT52(tt_type_mode)) &&
  19747.                                   !ISHFT(tt_type_mode))
  19748.                                 wrapit = TRUE ; /* need to wrap next time */
  19749.                             else {
  19750.                                 wrtch(CR);
  19751.                                 wrtch(LF);
  19752.                             }
  19753.                         }
  19754.                     }
  19755.                 }
  19756.             }
  19757.          }                      /* End Normal char */
  19758.       }
  19759.    }
  19760.    if (is_xprint() || (is_uprint() && (vtch != 27)))
  19761.        prtchar(vtch) ;
  19762. }
  19763.  
  19764. #ifdef CK_APC
  19765. void
  19766. apc_command(int type, char * cmd)
  19767. {
  19768.     extern struct mtab *mactab;             /* Macro table */
  19769.     extern int nmac;
  19770. #ifdef DCMDBUF
  19771.     extern struct cmdptr *cmdstk;
  19772. #else
  19773.     extern struct cmdptr cmdstk[];
  19774. #endif /* DCMDBUF */
  19775.  
  19776.     debug(F111,"apc_command",cmd,type);
  19777.     if ( cmd == NULL )
  19778.         return;
  19779.     if ( cmd != apcbuf )
  19780.         ckstrncpy(apcbuf,cmd,APCBUFLEN);
  19781.     apcactive = type;
  19782.     apclength = strlen(apcbuf) ;
  19783.  
  19784.     if (apcstatus & APC_NOINP) {
  19785.         debug(F110,"apc_command (no input) about to execute APC",apcbuf,0);
  19786.         domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  19787.         debug(F110,"apc_command finished executing APC",apcbuf,0);
  19788.         delmac("_apc_commands",1);
  19789.         cmini(ckxech);
  19790.         if ( apcactive == APC_INACTIVE
  19791. #ifndef NOXFER
  19792.              || (apcactive == APC_LOCAL && !xferstat && adl_err != 0)
  19793. #endif /* NOXFER */
  19794.              )
  19795.             SetConnectMode(FALSE,CSX_APC); /* exit from terminal emulator */
  19796.         return;
  19797.     }
  19798.  
  19799.     debug(F111,"apc_command","tt_async",tt_async);
  19800.     if ( tt_async ) {
  19801.         if (mlook(mactab,"_apc_commands",nmac) == -1) {
  19802.             int vmsave = vmode;
  19803.             SaveTermMode(wherex[VTERM],wherey[VTERM]);
  19804.             RestoreCmdMode();
  19805.             concooked();
  19806.             debug(F110,"apc_command about to execute APC",apcbuf,0);
  19807.             domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  19808.             debug(F110,"apc_command finished executing APC",apcbuf,0);
  19809.             delmac("_apc_commands",1);
  19810.             cmini(ckxech);
  19811.             conraw();
  19812.             RestoreTermMode();
  19813.             vmode = vmsave;
  19814.             VscrnIsDirty(VCMD);
  19815.             VscrnIsDirty(vmode);
  19816.             if ( apcactive == APC_INACTIVE
  19817. #ifndef NOXFER
  19818.                  || (apcactive == APC_LOCAL && !xferstat && adl_err != 0)
  19819. #endif /* NOXFER */
  19820.                  )
  19821.                 SetConnectMode(FALSE,CSX_APC); /* exit from terminal emulator */
  19822.         }
  19823.         apcactive = APC_INACTIVE;
  19824.     } else {
  19825.         term_io = FALSE;                /* Disable Emulator I/O */
  19826.         SetConnectMode(FALSE,CSX_APC);  /* exit from terminal emulator */
  19827.     }
  19828. }
  19829. #endif /* CK_APC */
  19830. #endif /* NOTERM */
  19831. #endif /* NOLOCAL */
  19832.