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

  1. /*  C K O H P . C  --  Hewlett-Packard Emulation  */
  2.  
  3. /*
  4.   Author: Jeffrey Altman <jaltman@secure-endpoints.com>,
  5.             Secure Endpoints Inc., New York City.
  6.  
  7.   Copyright (C) 1985, 2004, Trustees of Columbia University in the City of New
  8.   York.
  9. */
  10.  
  11. #include "ckcdeb.h"
  12. #ifndef NOTERM
  13. #ifdef NT
  14. #include <windows.h>
  15. #else /* NT */
  16. #include <os2.h>
  17. #undef COMMENT
  18. #endif /* NT */
  19.  
  20. #include "ckcker.h"
  21. #include "ckcasc.h"
  22. #include "ckuusr.h"
  23. #include "ckcuni.h"
  24. #include "ckocon.h"
  25. #include "ckotvi.h"
  26. #include "ckokey.h"
  27.  
  28. extern bool keyclick ;
  29. extern int  cursorena[], keylock, duplex, duplex_sav, screenon ;
  30. extern int  printon, aprint, cprint, uprint, xprint, seslog ;
  31. extern int  insertmode, tnlm, decssdt ;
  32. extern int  escstate, debses, decscnm, tt_cursor ;
  33. extern int  tt_type, tt_type_mode, tt_max, tt_answer, tt_status[VNUM], tt_szchng[] ;
  34. extern int  tt_cols[], tt_rows[], tt_wrap, tt_modechg ;
  35. extern int  wherex[], wherey[], margintop, marginbot, marginleft, marginright ;
  36. extern int  marginbell, marginbellcol ;
  37. extern char answerback[], htab[] ;
  38. extern struct tt_info_rec tt_info[] ;
  39. extern vtattrib attrib ;
  40. extern unsigned char attribute, colorstatus;
  41. extern char * udkfkeys[];
  42. extern int tt_senddata;
  43. extern struct _vtG G[4];
  44. extern struct _vtG *GL,*GR;
  45. extern int tt_hidattr;
  46.  
  47. extern int protect ;
  48. extern int autoscroll ;
  49. extern int writeprotect ;
  50. extern int linelock ;
  51. extern int attrmode ;
  52. extern int wy_keymode ;
  53. extern int wy_enhanced ;
  54. extern int wy_widthclr ;
  55. extern int wy_autopage ;
  56. extern int wy_nullsuppress ;
  57. extern int wy_monitor ;
  58.  
  59. extern char fkeylabel[16][32];
  60.  
  61. static int attr_x=0,attr_y=0;
  62. static int hpprt_term=-1;
  63. static int hpprt_count=0;
  64. static int hpprt_lf=0;
  65. static int hpprt_len=0;
  66.  
  67. int
  68. hpinc(void)
  69. {
  70.     extern int pmask, cmask;
  71.     extern int tt_utf8;
  72.     int ch;
  73.  
  74.   loop:
  75.     ch = ttinc(0);
  76.     if ( ch < 0 )
  77.         return ch;
  78.  
  79.     if ( seslog )
  80.         logchar(ch);
  81.  
  82.     /* Handle the UTF8 conversion if we are in that mode */
  83.     if ( tt_utf8 ) {
  84.         USHORT * ucs2 = NULL;
  85.         int rc = utf8_to_ucs2( (CHAR)(ch & 0xFF), &ucs2 );
  86.         if ( rc > 0 )
  87.             goto loop;
  88.         else if ( rc < 0 )
  89.             ch = 0xfffd;
  90.         else
  91.             ch = *ucs2;
  92.     }
  93.  
  94.     if ( !xprint ) {
  95. #ifndef NOXFER
  96.         autodown(ch);
  97. #endif /* NOXFER */
  98.         autoexitchk(ch);
  99.     }
  100.  
  101.     ch = ch & pmask & cmask;
  102.     debugses(ch);
  103.     if (printon && (is_xprint() || is_uprint()))
  104.         prtchar(ch);
  105.     if ( ch < SP && escstate == ES_ESCSEQ ) {
  106.         /* HP ignores many control characters during escape sequences */
  107.         switch ( ch ) {
  108.         case NUL:
  109.         case SOH:
  110.         case STX:
  111.         case ETX:
  112.         case EOT:
  113.         case ENQ:
  114.         case ACK:
  115.         case DLE:
  116.         case DC1:
  117.         case DC2:
  118.         case DC3:
  119.         case DC4:
  120.         case NAK:
  121.         case SYN:
  122.         case ETB:
  123.         case DEL:
  124.             ch = hpinc();
  125.             break;
  126.         default:
  127.             break;
  128.         }
  129.     }
  130.     return ch;
  131. }
  132.  
  133. void
  134. hpattroff( void )
  135. {
  136.     attrib.blinking = FALSE;            /* No blink */
  137.     attrib.bold = FALSE;                /* No bold */
  138.     attrib.invisible = FALSE;           /* Visible */
  139.     attrib.underlined = FALSE;          /* No underline */
  140.     attrib.reversed = FALSE;            /* No reverse video */
  141.     attrib.unerasable = FALSE;          /* Erasable */
  142.     attrib.graphic = FALSE ;            /* Not graphic character */
  143.     attrib.dim = FALSE ;                /* No dim */
  144. }
  145.  
  146. void
  147. hpctrl( int ch )
  148. {
  149.     int i,j,x,y;
  150.  
  151.     switch ( ch ) {
  152.     case ETX:
  153.         debug(F100,"HPTERM Control: ETX","",0);
  154.         if ( debses )
  155.             break;
  156.         break;
  157.     case EOT:
  158.         debug(F100,"HPTERM Control: EOT","",0);
  159.         if ( debses )
  160.             break;
  161.         break;
  162.     case ENQ:
  163.         debug(F100,"HPTERM Control: ENQ","",0);
  164.         if ( debses )
  165.             break;
  166.         sendchar(ACK);
  167.         break;
  168.     case ACK:
  169.         debug(F100,"HPTERM Control: ACK","",0);
  170.         if ( debses )
  171.             break;
  172.         break;
  173.     case BEL:
  174.         debug(F100,"HPTERM Control: BEL","",0);
  175.         if ( debses )
  176.             break;
  177.         bleep(BP_BEL);
  178.         break;
  179.     case BS:
  180.         debug(F100,"HPTERM Control: BS","",0);
  181.         if ( debses )
  182.             break;
  183.         wrtch(BS);
  184.         break;
  185.     case HT:
  186.         debug(F100,"HPTERM Control: HT","",0);
  187.         if ( debses )
  188.             break;
  189.  
  190.         i = wherex[VTERM];
  191.         if (i < marginright)
  192.         {
  193.             do {
  194.                 i++;
  195.                 cursorright(0);
  196.             } while ((htab[i] != 'T') &&
  197.                       (i <= marginright-1));
  198.         }
  199.         if ( i == marginright ) {
  200.             wrtch(CR);
  201.             wrtch(LF);
  202.         }
  203.         VscrnIsDirty(VTERM);
  204.         break;
  205.     case LF:
  206.         debug(F100,"HPTERM Control: LF","",0);
  207.         if ( debses )
  208.             break;
  209.         wrtch(LF);
  210.         break;
  211.     case VT:
  212.         debug(F100,"HPTERM Control: VT","",0);
  213.         if ( debses )
  214.             break;
  215.         break;
  216.     case FF:
  217.         debug(F100,"HPTERM Control: FF","",0);
  218.         if ( debses )
  219.             break;
  220.         break;
  221.     case CR:
  222.         debug(F100,"HPTERM Control: CR","",0);
  223.         if ( debses )
  224.             break;
  225.         wrtch(CR);
  226.         break;
  227.     case SO:    /* Use alternate character set */
  228.         debug(F110,"HPTERM Control: SO","Use Alternate Character Set",0);
  229.         if ( debses )
  230.             break;
  231.         GL = &G[2];
  232.         GR = &G[3];
  233.         break;
  234.     case SI:    /* Use normal character set */
  235.         debug(F110,"HPTERM Control: SI","Use Normal Character Set",0);
  236.         if ( debses )
  237.             break;
  238.         GL = &G[0];
  239.         GR = &G[1];
  240.         break;
  241.     case DLE:
  242.         debug(F100,"HPTERM Control: DLE","",0);
  243.         break;
  244.     case DC1:
  245.         debug(F100,"HPTERM Control: DC1","",0);
  246.         break;
  247.     case DC2:
  248.         debug(F100,"HPTERM Control: DC2","",0);
  249.         break;
  250.     case DC3:
  251.         debug(F100,"HPTERM Control: DC3","",0);
  252.         break;
  253.     case DC4:
  254.         debug(F100,"HPTERM Control: DC4","",0);
  255.         break;
  256.     case NAK:
  257.         debug(F100,"HPTERM Control: NAK","",0);
  258.         break;
  259.     case SYN:
  260.         debug(F100,"HPTERM Control: SYN","",0);
  261.         break;
  262.     case ETB:
  263.         debug(F100,"HPTERM Control: ETB","",0);
  264.         break;
  265.     case CAN:
  266.         debug(F100,"HPTERM Control: CAN","",0);
  267.         break;
  268.     case XEM:
  269.         debug(F100,"HPTERM Control: EM","",0);
  270.         break;
  271.     case SUB:
  272.         debug(F100,"HPTERM Control: SUB","",0);
  273.         break;
  274.     case ESC:
  275.         /* initiate escape sequence */
  276.         debug(F100,"HPTERM Control: ESC","",0);
  277.         escstate = ES_GOTESC ;
  278.         break;
  279.     case XRS:
  280.         debug(F100,"HPTERM Control: RS","",0);
  281.         break;
  282.     case US:
  283.         debug(F100,"HPTERM Control: US","",0);
  284.         break;
  285.     default:
  286.         debug(F101,"HPTERM Control: <unknown>","",ch);
  287.     }
  288. }
  289.  
  290. /* Reads a parameter combination */
  291. /* Returns -1 if error, 0 if this is this last parameter, */
  292. /* and 1 if there are more parameters in the sequence.    */
  293. /* num is set to the numeric value and alpha to the command code */
  294.  
  295. int
  296. hpparam( int * num, int * alpha, int * relative )
  297. {
  298.     int ch=0;
  299.     int neg=0;
  300.  
  301.     *num = 0;
  302.     *alpha = NUL;
  303.     *relative = 0;
  304.  
  305.     while((ch = hpinc()) >= 0) {
  306.         if ( isdigit(ch) ) {
  307.             *num *= 10;
  308.             *num += (ch - '0');
  309.         }
  310.         else if ( islower(ch) ) {
  311.             *alpha = ch;
  312.             if ( neg ) *num *= -1;
  313.             return(1);
  314.         }
  315.         else if ( isupper(ch) ) {
  316.             *alpha = tolower(ch);
  317.             if ( neg ) *num *= -1;
  318.             return(0);
  319.         }
  320.         else if ( ch == '-' ) {
  321.             neg = 1;
  322.             *relative = 1;
  323.         }
  324.         else if ( ch == '+' ) {
  325.             neg = 0;
  326.             *relative = 1;
  327.         }
  328.         else if ( ch < SP ) {
  329.             debug(F101,"HPTERM hpparam() got control","",ch);
  330.         }
  331.         else if ( ispunct(ch) ) {
  332.             *alpha = ch;
  333.             if ( neg ) *num *= -1;
  334.             return(0);
  335.         }
  336.         else {
  337.             debug(F101,"HPTERM hpparam() got <unknown>","",ch);
  338.         }
  339.     }
  340.     return(ch);
  341. }
  342.  
  343. void
  344. hpascii( int ch )
  345. {
  346.     int i=0,j=0,k=0,m=0,n=0,x=0,y=0,z=0;
  347.     vtattrib attr={0,0,0,0,0,0,0,0,0,0,0} ;
  348.     viocell blankvcell;
  349.     char debbuf[256]="";
  350.  
  351.     if ( xprint ) {
  352.         /* RECORD MODE */
  353.         if ( (hpprt_term == ch &&
  354.              (hpprt_lf || !(hpprt_count%256))) ||
  355.              (hpprt_term == LF && ch == LF)) {
  356.             /* we are done */
  357.             xprint = FALSE;
  358.             if ( !uprint && !xprint && !cprint && !aprint && printon )
  359.                 printeroff();
  360.         }
  361.         else {
  362.             hpprt_count++;
  363.             hpprt_lf = (ch == LF);
  364.             if (printon && (is_xprint() || is_uprint()))
  365.                 prtchar(ch);
  366.  
  367.             if ( hpprt_len && hpprt_count >= hpprt_len ) {
  368.                 /* we are done */
  369.                 xprint = FALSE;
  370.                 if ( !uprint && !xprint && !cprint && !aprint && printon )
  371.                     printeroff();
  372.             }
  373.         }
  374.         return;
  375.     }
  376.  
  377.     if (printon && (is_xprint() || is_uprint()))
  378.         prtchar(ch);
  379.  
  380.     if ( escstate == ES_GOTESC )/* Process character as part of an escstate sequence */
  381.     {
  382.         if ( ch <= SP ) {
  383.             /* Illegal sequence; ignore both characters */
  384.             escstate = ES_NORMAL ;
  385.             debug(F101,"HPTERM illegal escape sequence","",ch);
  386.         }
  387.         else
  388.         {
  389.             escstate = ES_ESCSEQ ;
  390.             switch ( ch ) {
  391. #ifdef COMMENT
  392.             case '!':
  393.                 break;
  394.             case '"':
  395.                 break;
  396.             case '#':
  397.                 break;
  398. #endif /* COMMENT */
  399.             case '$': { /* HPTERM Kanji */
  400.                 int ch2;
  401.                 do {
  402.                     if ((x = hpparam(&n,&ch2,&y)) < 0)
  403.                         break;
  404.                     switch ( ch2 ) {
  405.                     case '@':   /* JIS Kanji Character Set */
  406.                     case 'a':
  407.                     case 'b':
  408.                     case 'c':
  409.                     case 'd':
  410.                     case 'e':
  411.                     case 'f':
  412.                     case 'g':
  413.                         if ( deblog ) {
  414.                             sprintf(debbuf,
  415.                                      "ESC %c %d %c%s",
  416.                                      ch, n, ch2, y ? " (relative)" : "");
  417.                             debug(F110,"HPTERM Kanji Character Set selection (unsupported)",
  418.                                    debbuf,0);
  419.                         }
  420.                         break;
  421.                     default:
  422.                         if ( deblog ) {
  423.                             sprintf(debbuf,
  424.                                      "ESC %c %d %c%s",
  425.                                      ch, n, ch2, y ? " (relative)" : "");
  426.                             debug(F110,"HPTERM Unknown",
  427.                                    debbuf,0);
  428.                         }
  429.                     }
  430.                 } while (x>0);
  431.                 break;
  432.             }
  433.             case '%': { /* HPTERM Text Direction */
  434.                 int ch2;
  435.                 do {
  436.                     if ((x = hpparam(&n,&ch2,&y)) < 0)
  437.                         break;
  438.                     switch ( ch2 ) {
  439.                     case 'r':   /* Latin Text Direction */
  440.                         if ( deblog ) {
  441.                             sprintf(debbuf,
  442.                                      "ESC %c %d %c%s",
  443.                                      ch, n, ch2, y ? " (relative)" : "");
  444.                             debug(F110,"HPTERM Text Direction: Latin (unsupported)",
  445.                                    debbuf,0);
  446.                             }
  447.                         break;
  448.                     case 's':   /* Arabic Text Direction */
  449.                         if ( deblog ) {
  450.                             sprintf(debbuf,
  451.                                      "ESC %c %d %c%s",
  452.                                      ch, n, ch2, y ? " (relative)" : "");
  453.                             debug(F110,"HPTERM Text Direction: Arabic (unsupported)",
  454.                                    debbuf,0);
  455.                             }
  456.                         break;
  457.                     default:
  458.                         if ( deblog ) {
  459.                             sprintf(debbuf,
  460.                                      "ESC %c %d %c%s",
  461.                                      ch, n, ch2, y ? " (relative)" : "");
  462.                             debug(F110,"HPTERM Unknown",
  463.                                    debbuf,0);
  464.                         }
  465.                     }
  466.                 } while (x>0);
  467.                 break;
  468.             }
  469.             case '&': {
  470.                 /* Parameter Sequence */
  471.                 int ch2 = hpinc() ;
  472.                 switch ( ch2 ) {
  473.                 case 'a': {
  474.                     /* Memory and Screen Addressing */
  475.                     /* memory row number r column number C - Absolute Memory Addressing */
  476.                     /* screen row number y column number C - Absolute Screen Addressing */
  477.                     /* +/- memory row number r column number C - Relative Memory Addressing */
  478.                     /* +/- screen row number y column number C - Relative Screen Addressing */
  479.                     int row=-1,column=-1,relcol=FALSE,relrow=FALSE;
  480.                     int ch3;
  481.  
  482.                     do {
  483.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  484.                             break;
  485.                         switch ( ch3 ) {
  486.                         case 'c':       /* column */
  487.                             column = n;
  488.                             relcol = y;
  489.                             if ( deblog ) {
  490.                             sprintf(debbuf,
  491.                                      "ESC %c %c %d %c%s",
  492.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  493.                             debug(F110,"HPTERM Memory and Screen Addressing: column",
  494.                                    debbuf,0);
  495.                             }
  496.                             break;
  497.                         case 'r':       /* memory row */
  498.                             row = n;
  499.                             relrow = y;
  500.                             if ( deblog ) {
  501.                             sprintf(debbuf,
  502.                                      "ESC %c %c %d %c%s",
  503.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  504.                             debug(F110,"HPTERM Memory Addressing: row",
  505.                                    debbuf,0);
  506.                             }
  507.                             break;
  508.                         case 'y':       /* screen row */
  509.                             row = n;
  510.                             relrow = y;
  511.                             if ( deblog ) {
  512.                             sprintf(debbuf,
  513.                                      "ESC %c %c %d %c%s",
  514.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  515.                             debug(F110,"HPTERM Screen Addressing: row",
  516.                                    debbuf,0);
  517.                             }
  518.                             break;
  519.                         default:
  520.                             if ( deblog ) {
  521.                             sprintf(debbuf,
  522.                                      "ESC %c %c %d %c%s",
  523.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  524.                             debug(F110,"HPTERM unknown command",debbuf,0);
  525.                             }
  526.                         }
  527.                     } while (x>0);
  528.  
  529.                     if ( x < 0 )
  530.                         break;
  531.  
  532.                     if ( debses )
  533.                         break;
  534.  
  535.                     if ( column < 0 && !relcol ) {
  536.                         /* not assigned */
  537.                         column = wherex[VTERM];
  538.                     }
  539.                     else if ( relcol ) {
  540.                         column += wherex[VTERM];
  541.                     }
  542.                     else {
  543.                         column += 1;
  544.                     }
  545.                     if ( row < 0 && !relrow ) {
  546.                         /* not assigned */
  547.                         row = wherey[VTERM];
  548.                     } else if ( relrow ) {
  549.                         row += wherey[VTERM];
  550.                     } else {
  551.                         row += 1;
  552.                     }
  553.  
  554.                     if ( column > VscrnGetWidth(VTERM) )
  555.                         column = VscrnGetWidth(VTERM);
  556.                     else if ( column < 1 )
  557.                         column = 1;
  558.  
  559.                     if ( row > VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  560.                         row = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  561.                     else if ( row < 1 )
  562.                         row = 1;
  563.  
  564.                     lgotoxy(VTERM,column, row);
  565.                     break;
  566.                 }
  567.                 case 'd': {
  568.                     /* Display Enhancement */
  569.                     /* A -> O - Enable Underline; @ - Disable Underline */
  570.                     int ch3;
  571.  
  572.                     do {
  573.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  574.                             break;
  575.                     switch ( ch3 ) {
  576.                     case '@':
  577.                         attr.blinking = FALSE;
  578.                         attr.reversed = FALSE;
  579.                         attr.underlined = FALSE;
  580.                         attr.dim = FALSE;
  581.                         if ( deblog ) {
  582.                             sprintf(debbuf,
  583.                                      "ESC %c %c %d %c%s",
  584.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  585.                             debug(F110,"HPTERM Display Enhancement: Normal",
  586.                                    debbuf,0);
  587.                             }
  588.                         break;
  589.                     case 'a':
  590.                         attr.blinking = TRUE ;
  591.                         if ( deblog ) {
  592.                             sprintf(debbuf,
  593.                                      "ESC %c %c %d %c%s",
  594.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  595.                             debug(F110,"HPTERM Display Enhancement: Blink",
  596.                                    debbuf,0);
  597.                         }
  598.                         break;
  599.                     case 'b':
  600.                         attr.reversed = TRUE ;
  601.                         if ( deblog ) {
  602.                             sprintf(debbuf,
  603.                                      "ESC %c %c %d %c%s",
  604.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  605.                             debug(F110,"HPTERM Display Enhancement: Reverse",
  606.                                    debbuf,0);
  607.                         }
  608.                         break;
  609.                     case 'c':
  610.                         attr.blinking = TRUE;
  611.                         attr.reversed = TRUE;
  612.                         if ( deblog ) {
  613.                             sprintf(debbuf,
  614.                                      "ESC %c %c %d %c%s",
  615.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  616.                             debug(F110,"HPTERM Display Enhancement: Blink Reverse",
  617.                                    debbuf,0);
  618.                         }
  619.                         break;
  620.                     case 'd':
  621.                         attr.underlined = TRUE;
  622.                         if ( deblog ) {
  623.                             sprintf(debbuf,
  624.                                      "ESC %c %c %d %c%s",
  625.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  626.                             debug(F110,"HPTERM Display Enhancement: Underline",
  627.                                    debbuf,0);
  628.                         }
  629.                         break;
  630.                     case 'e':
  631.                         attr.blinking = TRUE;
  632.                         attr.underlined = TRUE;
  633.                         if ( deblog ) {
  634.                             sprintf(debbuf,
  635.                                      "ESC %c %c %d %c%s",
  636.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  637.                             debug(F110,"HPTERM Display Enhancement: Blink Underline",
  638.                                    debbuf,0);
  639.                         }
  640.                         break;
  641.                     case 'f':
  642.                         attr.reversed = TRUE;
  643.                         attr.underlined = TRUE;
  644.                         if ( deblog ) {
  645.                             sprintf(debbuf,
  646.                                      "ESC %c %c %d %c%s",
  647.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  648.                             debug(F110,"HPTERM Display Enhancement: Reverse Underline",
  649.                                    debbuf,0);
  650.                         }
  651.                         break;
  652.                     case 'g':
  653.                         attr.blinking = TRUE;
  654.                         attr.reversed = TRUE;
  655.                         attr.underlined = TRUE;
  656.                         if ( deblog ) {
  657.                             sprintf(debbuf,
  658.                                      "ESC %c %c %d %c%s",
  659.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  660.                             debug(F110,"HPTERM Display Enhancement: Blink Reverse Underline",
  661.                                    debbuf,0);
  662.                         }
  663.                         break;
  664.                     case 'h':
  665.                         attr.dim = TRUE ;
  666.                         if ( deblog ) {
  667.                             sprintf(debbuf,
  668.                                      "ESC %c %c %d %c%s",
  669.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  670.                             debug(F110,"HPTERM Display Enhancement: Dim",
  671.                                    debbuf,0);
  672.                         }
  673.                         break;
  674.                     case 'i':
  675.                         attr.blinking = TRUE;
  676.                         attr.dim = TRUE;
  677.                         if ( deblog ) {
  678.                             sprintf(debbuf,
  679.                                      "ESC %c %c %d %c%s",
  680.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  681.                             debug(F110,"HPTERM Display Enhancement: Blink Dim",
  682.                                    debbuf,0);
  683.                         }
  684.                         break;
  685.                     case 'j':
  686.                         attr.reversed = TRUE;
  687.                         attr.dim = TRUE;
  688.                         if ( deblog ) {
  689.                             sprintf(debbuf,
  690.                                      "ESC %c %c %d %c%s",
  691.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  692.                             debug(F110,"HPTERM Display Enhancement: Reverse Dim",
  693.                                    debbuf,0);
  694.                         }
  695.                         break;
  696.                     case 'k':
  697.                         attr.blinking = TRUE;
  698.                         attr.reversed = TRUE;
  699.                         attr.dim = TRUE;
  700.                         if ( deblog ) {
  701.                             sprintf(debbuf,
  702.                                      "ESC %c %c %d %c%s",
  703.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  704.                             debug(F110,"HPTERM Display Enhancement: Blink Reverse Dim",
  705.                                    debbuf,0);
  706.                         }
  707.                         break;
  708.                     case 'l':
  709.                         attr.underlined = TRUE;
  710.                         attr.dim = TRUE;
  711.                         if ( deblog ) {
  712.                             sprintf(debbuf,
  713.                                      "ESC %c %c %d %c%s",
  714.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  715.                             debug(F110,"HPTERM Display Enhancement: Underline Dim",
  716.                                    debbuf,0);
  717.                         }
  718.                         break;
  719.                     case 'm':
  720.                         attr.blinking = TRUE;
  721.                         attr.underlined = TRUE;
  722.                         attr.dim = TRUE;
  723.                         if ( deblog ) {
  724.                             sprintf(debbuf,
  725.                                      "ESC %c %c %d %c%s",
  726.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  727.                             debug(F110,"HPTERM Display Enhancement: Blink Underline Dim",
  728.                                    debbuf,0);
  729.                         }
  730.                         break;
  731.                     case 'n':
  732.                         attr.reversed = TRUE;
  733.                         attr.underlined = TRUE;
  734.                         attr.dim = TRUE;
  735.                         if ( deblog ) {
  736.                             sprintf(debbuf,
  737.                                      "ESC %c %c %d %c%s",
  738.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  739.                             debug(F110,"HPTERM Display Enhancement: Reverse Underline Dim",
  740.                                    debbuf,0);
  741.                         }
  742.                         break;
  743.                     case 'o':
  744.                         attr.blinking = TRUE;
  745.                         attr.reversed = TRUE;
  746.                         attr.underlined = TRUE;
  747.                         attr.dim = TRUE;
  748.                         if ( deblog ) {
  749.                             sprintf(debbuf,
  750.                                      "ESC %c %c %d %c%s",
  751.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  752.                             debug(F110,"HPTERM Display Enhancement: Blink Reverse Underline Dim",
  753.                                    debbuf,0);
  754.                         }
  755.                         break;
  756.                     default:
  757.                         if ( deblog ) {
  758.                         sprintf(debbuf,
  759.                                  "ESC %c %c %d %c%s",
  760.                                  ch, ch2, n, ch3, y ? " (relative)" : "");
  761.                         debug(F110,"HPTERM unknown command",debbuf,0);
  762.                         }
  763.                     }
  764.                     } while(x>0);
  765.                     if ( x < 0 ) break;
  766.                     if ( debses )
  767.                         break;
  768.  
  769.                     attr_x = x = wherex[VTERM];
  770.                     attr_y = y = wherey[VTERM];
  771.                     if ( !tt_hidattr )
  772.                         wrtch(SP) ;
  773.                     ApplyLineAttribute( VTERM, x, y, attr );
  774.                     attrib = attr;
  775.                     break;
  776.                 }
  777.                 case 'f': {
  778.                     /* Program Screen Labels */
  779.                     /* (Use) a (key) k (label length) d (string length) | (label) (string) soft key */
  780.                     /* label where: */
  781.                     /* Use: 0 = normal; 1 = local ; 2 = remote (default) */
  782.                     /* Key: 1 = F1 Function Key to 8 = F8 Function Key */
  783.                     /* label = length 0 to 8 - number of characters in label (0 default) */
  784.                     /* string length = 0 to 72 - number of characters in string (1 default) */
  785.                     /* string length = 0 to 72 - number of diacritical characters in string */
  786.                     /* <n> E - invoke softkey */
  787.                     /* 0 k <length> D <icon-name> */
  788.                     /* -1 k <length> D <window-name> */
  789.                     int use=0, key=1, invoke=-2, llen=0, slen=0;
  790.                     char label[80]="";
  791.                     char string[160]="";
  792.                     int ch3=0, keyi=0, i=0;     /* work variables */
  793.  
  794.                     do {
  795.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  796.                             break;
  797.                         switch ( ch3 ) {
  798.                         case 'a':       /* attribute */
  799.                         case 'A':
  800.                             use = n ;
  801.                             if ( deblog ) {
  802.                                 sprintf(debbuf,
  803.                                          "ESC %c %c %d %c%s",
  804.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  805.                                 debug(F110,"HPTERM Program Screen Labels: attribute",
  806.                                        debbuf,0);
  807.                             }
  808.                             break;
  809.                         case 'e':       /* Invoke key */
  810.                         case 'E':
  811.                             invoke = n;
  812.                             if ( deblog ) {
  813.                                 sprintf(debbuf,
  814.                                          "ESC %c %c %d %c%s",
  815.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  816.                                 debug(F110,"HPTERM Program Screen Labels: invoke key",
  817.                                        debbuf,0);
  818.                             }
  819.                             break;
  820.                         case 'k':       /* key */
  821.                         case 'K':
  822.                             key = n ;
  823.                             if ( deblog ) {
  824.                                 sprintf(debbuf,
  825.                                          "ESC %c %c %d %c%s",
  826.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  827.                                 debug(F110,"HPTERM Program Screen Labels: key",
  828.                                        debbuf,0);
  829.                             }
  830.                             break;
  831.                         case 'd':       /* label-length */
  832.                         case 'D':
  833.                             llen = n ;
  834.                             if ( deblog ) {
  835.                                 sprintf(debbuf,
  836.                                          "ESC %c %c %d %c%s",
  837.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  838.                                 debug(F110,"HPTERM Program Screen Labels: label length",
  839.                                        debbuf,0);
  840.                             }
  841.                             break;
  842.                         case 'l':       /* string-length */
  843.                         case 'L':
  844.                             slen = n ;
  845.                             if ( deblog ) {
  846.                                 sprintf(debbuf,
  847.                                          "ESC %c %c %d %c%s",
  848.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  849.                                 debug(F110,"HPTERM Program Screen Labels: string length",
  850.                                        debbuf,0);
  851.                             }
  852.                             break;
  853.                         default:
  854.                             sprintf(debbuf,
  855.                                      "ESC %c %c %d %c%s",
  856.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  857.                             debug(F110,"HPTERM unknown command",debbuf,0);
  858.                         }
  859.                     } while(x>0);
  860.                     if ( x < 0 ) break;
  861.  
  862.                     /* Now read the strings if any */
  863.                     if ( llen > 0 ) {
  864.                         for ( i=0; i < llen && i < 79 ; i++ ) {
  865.                             label[i] = hpinc();
  866.                         }
  867.                     }
  868.                     label[i] = '\0';
  869.                     debug(F110,"HPTERM Label",label,0);
  870.                     if ( slen > 0 ) {
  871.                         for ( i=0; i < slen && i < 159 ; i++ ) {
  872.                             string[i] = hpinc();
  873.                         }
  874.                     }
  875.                     string[i] = '\0';
  876.                     debug(F110,"HPTERM String",string,0);
  877.  
  878.                     if ( debses )
  879.                         break;
  880.                     if ( use < 0 || use > 2 ||
  881.                          use == 1 /* we don't support local mode */)
  882.                         break;
  883.                     if ( key < -1 || key > 16 )
  884.                         break;
  885.  
  886.                     /* For when we support labels */
  887.                     if ( llen == -1 && key > 0) {
  888.                         /* undefine the label for this key */
  889.                         strcpy( fkeylabel[key-1], "");
  890.                     }
  891.                     else if ( llen == 0 && key > 0) {
  892.                         /* leave the label alone */;
  893.                     }
  894.                     else {
  895.                         if ( key > 0 ) {
  896.                         /* assign the first 16 chars as the new label  */
  897.                         /* ignore labels for the Enter and Return keys */
  898.                             ckstrncpy( fkeylabel[key-1], label, 32);
  899.                         }
  900.                         else if ( key == 0 ) {
  901.                             /* Set Icon Label */;
  902.                         }
  903.                         else if ( key == -1 ) {
  904.                             /* Set Window Title */
  905.                             os2settitle(label,1);
  906.                         }
  907.                     }
  908.                     switch ( key ) {
  909. #ifndef NOKVERBS
  910.                     case -1:
  911.                         keyi = K_HPENTER - K_HPF01;
  912.                         break;
  913.                     case 0:
  914.                         keyi = K_HPRETURN - K_HPF01;
  915.                         break;
  916. #endif /* NOKVERBS */
  917.                     default:
  918.                         keyi = key - 1;
  919.                         break;
  920.                     }
  921. #ifndef NOSETKEY
  922.                     if ( slen == -1 ) {
  923.                         /* undefine the string for this key */;
  924.                         if ( udkfkeys[keyi] ){
  925.                             free( udkfkeys[keyi] ) ;
  926.                             udkfkeys[keyi]=NULL;
  927.                         }
  928.                     }
  929.                     else if ( slen == 0 )
  930.                         /* leave the string alone */;
  931.                     else {
  932.                         /* assign the first 80 chars as the new string */
  933.                         /* except for Enter and Return which use 8 chars */
  934.                         if ( udkfkeys[keyi] ){
  935.                             free( udkfkeys[keyi] ) ;
  936.                             udkfkeys[keyi]=NULL;
  937.                         }
  938.                         if ( strlen(string) )
  939.                             udkfkeys[keyi] = strdup(string) ;
  940.                     }
  941. #endif /* NOSETKEY */
  942.                     /* Now handle invocation */
  943.                     if ( invoke > -2 ) {
  944.                         switch ( invoke ) {
  945. #ifndef NOKVERBS
  946.                         case -1:
  947.                             keyi = K_HPENTER - K_HPF01;
  948.                             break;
  949.                         case 0:
  950.                             keyi = K_HPRETURN - K_HPF01;
  951.                             break;
  952. #endif /* NOKVERBS */
  953.                         default:
  954.                             keyi = key - 1;
  955.                             break;
  956.                         }
  957. #ifndef NOSETKEY
  958.                         if ( udkfkeys[keyi] )
  959.                             sendcharsduplex(udkfkeys[keyi],
  960.                                              strlen(udkfkeys[keyi]),TRUE);
  961. #endif /* NOSETKEY */
  962.                     }
  963.                     break;
  964.                 }
  965.                 case 'j': {
  966.                     /* Screen Labels Control */
  967.                     int ch3;
  968.                     do {
  969.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  970.                             break;
  971.                         switch ( ch3 ) {
  972.                         case '@':       /* Clear Screen Labels */
  973.                             if ( deblog ) {
  974.                                 sprintf(debbuf,
  975.                                          "ESC %c %c %d %c%s",
  976.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  977.                                 debug(F110,"HPTERM Screen Labels Control: Clear Labels",
  978.                                        debbuf,0);
  979.                             }
  980.                             break;
  981.                         case 'a':       /* Display Screen Labels */
  982.                             if ( deblog ) {
  983.                                 sprintf(debbuf,
  984.                                          "ESC %c %c %d %c%s",
  985.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  986.                                 debug(F110,"HPTERM Screen Labels Control: Display Labels (unsupported)",
  987.                                        debbuf,0);
  988.                             }
  989.                             break;
  990.                         case 'b':       /* Display F1-F8 Screen Labels */
  991.                             if ( deblog ) {
  992.                                 sprintf(debbuf,
  993.                                          "ESC %c %c %d %c%s",
  994.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  995.                                 debug(F110,"HPTERM Screen Labels Control: Display F1-F8 Labels (unsupported)",
  996.                                        debbuf,0);
  997.                             }
  998.                             break;
  999.                         case 'r':       /* Unlock labels */
  1000.                             if ( deblog ) {
  1001.                                 sprintf(debbuf,
  1002.                                          "ESC %c %c %d %c%s",
  1003.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1004.                                 debug(F110,"HPTERM Screen Labels Control: Unlock Labels (unsupported)",
  1005.                                        debbuf,0);
  1006.                             }
  1007.                             break;
  1008.                         case 's':       /* Lock current labels */
  1009.                             if ( deblog ) {
  1010.                                 sprintf(debbuf,
  1011.                                          "ESC %c %c %d %c%s",
  1012.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1013.                                 debug(F110,"HPTERM Screen Labels Control: Lock Labels (unsupported)",
  1014.                                        debbuf,0);
  1015.                             }
  1016.                             break;
  1017.                         case 'c':       /* Clear Status Line ??? */
  1018.                             if ( deblog ) {
  1019.                                 sprintf(debbuf,
  1020.                                          "ESC %c %c %d %c%s",
  1021.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1022.                                 debug(F110,"HPTERM Screen Labels Control: Clear Status Line ??? (unsupported)",
  1023.                                        debbuf,0);
  1024.                             }
  1025.                             break;
  1026.                         case 'd':       /* ??? */
  1027.                             /* <ESC>&j<p>D have seen <p> = 1 and 2 */
  1028.                             if ( deblog ) {
  1029.                                 sprintf(debbuf,
  1030.                                          "ESC %c %c %d %c%s",
  1031.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1032.                                 debug(F110,"HPTERM Screen Labels Control: ??? (unsupported)",
  1033.                                        debbuf,0);
  1034.                             }
  1035.                             break;
  1036.                         case 'l': {  /* Program Status Line */
  1037.                             /* <ESC>&j<p>L */
  1038.                             char buf[132];
  1039.                             int width = VscrnGetWidth(VTERM);
  1040.                             int i = 0;
  1041.  
  1042.                             if ( debses ) {
  1043.                                 while ( i < n ) {
  1044.                                     hpinc();
  1045.                                     i++;
  1046.                                 }
  1047.                             }
  1048.                             else {
  1049.                                 while ( i < n ) {
  1050.                                     buf[i]=hpinc();
  1051.                                     i++;
  1052.                                 }
  1053.                                 buf[i] = NUL ;
  1054.                             }
  1055.                             while ( i < width )
  1056.                                 buf[i++] = SP ;
  1057.                             buf[i]=NUL ;
  1058.  
  1059.                             if ( deblog ) {
  1060.                                 sprintf(debbuf,
  1061.                                          "ESC %c %c %d %c%s: %s",
  1062.                                          ch, ch2, n, ch3, y ? " (relative)" : "",
  1063.                                          buf);
  1064.                                 debug(F110,"HPTERM Screen Labels Control: Program Status Line",
  1065.                                        debbuf,0);
  1066.                             }
  1067.                             if ( debses )
  1068.                                 break;
  1069.  
  1070.                             setdecssdt(SSDT_HOST_WRITABLE);
  1071.                             if ( decssdt == SSDT_HOST_WRITABLE ) {
  1072.                                 VscrnSetWidth(VSTATUS,VscrnGetWidth(VTERM));
  1073.                                 VscrnWrtCharStrAtt( VSTATUS, buf,
  1074.                                                     strlen(buf),
  1075.                                                     1, 1, &colorstatus ) ;
  1076.                             }
  1077.                             break;
  1078.                         }
  1079.                         default:
  1080.                             sprintf(debbuf,
  1081.                                      "ESC %c %c %d %c%s",
  1082.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1083.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1084.                         }
  1085.                     } while (x>0);
  1086.                     if ( x < 0 || debses )
  1087.                         break;
  1088.                     break;
  1089.                 }
  1090.                 case 'k': {
  1091.                     /* <ESC>&k0a0b0C */
  1092.                     int ch3=0;
  1093.                     do {
  1094.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  1095.                             break;
  1096.                         if ( debses )
  1097.                             continue;
  1098.                         switch ( ch3 ) {
  1099.                         case 'o':
  1100.                         case 'O':
  1101.                             /* Keycode mode */
  1102.                             if ( deblog ) {
  1103.                                 sprintf(debbuf,
  1104.                                          "ESC %c %c %d %c%s",
  1105.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1106.                                 debug(F110,"HPTERM Keycode Mode (unsupported)",
  1107.                                        debbuf,0);
  1108.                             }
  1109.                             break;
  1110.                         case 'p':
  1111.                         case 'P':
  1112.                             /* Enables/disables CAPS mode */
  1113.                             if ( deblog ) {
  1114.                                 sprintf(debbuf,
  1115.                                          "ESC %c %c %d %c%s",
  1116.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1117.                                 debug(F110,"HPTERM CAPS mode (unsupported)",
  1118.                                        debbuf,0);
  1119.                             }
  1120.                             break;
  1121.                         case '\\':
  1122.                             /* Change ANSI/HP mode */
  1123.                             if ( deblog ) {
  1124.                                 sprintf(debbuf,
  1125.                                          "ESC %c %c %d %c%s",
  1126.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1127.                                 debug(F110,"HPTERM ANSI/HP mode (unsupported)",
  1128.                                        debbuf,0);
  1129.                             }
  1130.  
  1131.                             break;
  1132.                         default:
  1133.                             sprintf(debbuf,
  1134.                                      "ESC %c %c %d %c%s",
  1135.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1136.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1137.                         }
  1138.                     } while (x>0);
  1139.                     break;
  1140.                 }
  1141.                 case 'p': {
  1142.                     /* Printer Control - HP2621P only */
  1143.                     /*
  1144.                        Esc & p 11 C
  1145.                        Enable data logging from the bottom of memory
  1146.                        (print current entry line)
  1147.  
  1148.                        Esc & p 12 C
  1149.                        Enable data logging from the top of memory
  1150.                        (print line as it rolls off top of memory)
  1151.  
  1152.                        Esc & p 13 C
  1153.                        Disable data logging (top or bottom, whichever is enabled)
  1154.  
  1155.                        Esc & p M
  1156.                        Print all data in memory from cursor line to bottom
  1157.  
  1158.                        Esc & p F
  1159.                        Print all data on screen from cursor line to end of screen
  1160.  
  1161.                        Esc & p B
  1162.                        Print cursor line
  1163.                     */
  1164.                     int action=0,device=0;
  1165.                     int ch3=0;
  1166.                     hpprt_term = -1;
  1167.                     hpprt_count = 0;
  1168.                     hpprt_lf = 0;
  1169.                     hpprt_len = 0;
  1170.  
  1171.                     do {
  1172.                         if ((x = hpparam(&n,&ch3,&z)) < 0)
  1173.                             break;
  1174.                         switch ( ch3 ) {
  1175.                         case '^':       /* Status of device */
  1176.                             device = n;
  1177.                             action = '^';
  1178.                             if ( deblog ) {
  1179.                                 sprintf(debbuf,
  1180.                                          "ESC %c %c %d %c%s",
  1181.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1182.                                 debug(F110,"HPTERM Printing: Status of Device",
  1183.                                        debbuf,0);
  1184.                             }
  1185.                             debug(F111,"HP Print","device",device);
  1186.                             debug(F111,"HP Print","action",action);
  1187.                             break;
  1188.                         case 'd':       /* Device number */
  1189.                         case 'D':
  1190.                         case 'u':       /* same, from Reflection manual */
  1191.                         case 'U':
  1192.                             device = n;     /* we ignore this anyway */
  1193.                             if ( deblog ) {
  1194.                                 sprintf(debbuf,
  1195.                                          "ESC %c %c %d %c%s",
  1196.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1197.                                 debug(F110,"HPTERM Printing: Device Number (unsupported)",
  1198.                                        debbuf,0);
  1199.                             }
  1200.                             debug(F111,"HP Print","device",device);
  1201.                             break;
  1202.                         case 'p':       /* Termination character */
  1203.                         case 'P':
  1204.                             hpprt_term = n;
  1205.                             if ( deblog ) {
  1206.                                 sprintf(debbuf,
  1207.                                          "ESC %c %c %d %c%s",
  1208.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1209.                                 debug(F110,"HPTERM Printing: Termination character",
  1210.                                        debbuf,0);
  1211.                             }
  1212.                             debug(F111,"HP Print","terminator",hpprt_term);
  1213.                             break;
  1214.                         case 'b':       /* Action */
  1215.                         case 'B':
  1216.                             action = 'B';
  1217.                             if ( deblog ) {
  1218.                                 sprintf(debbuf,
  1219.                                          "ESC %c %c %d %c%s",
  1220.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1221.                                 debug(F110,"HPTERM Printing: Action",
  1222.                                        debbuf,0);
  1223.                             }
  1224.                             debug(F111,"HP Print","action",action);
  1225.                             break;
  1226.                         case 'f':       /* Action */
  1227.                         case 'F':
  1228.                             action = 'F';
  1229.                             if ( deblog ) {
  1230.                                 sprintf(debbuf,
  1231.                                          "ESC %c %c %d %c%s",
  1232.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1233.                                 debug(F110,"HPTERM Printing: Action",
  1234.                                        debbuf,0);
  1235.                             }
  1236.                             debug(F111,"HP Print","action",action);
  1237.                             break;
  1238.                         case 'm':       /* Action */
  1239.                         case 'M':
  1240.                             action = 'M';
  1241.                             if ( deblog ) {
  1242.                                 sprintf(debbuf,
  1243.                                          "ESC %c %c %d %c%s",
  1244.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1245.                                 debug(F110,"HPTERM Printing: Action",
  1246.                                        debbuf,0);
  1247.                             }
  1248.                             debug(F111,"HP Print","action",action);
  1249.                             break;
  1250.                         case 'c':       /* Action */
  1251.                         case 'C':
  1252.                             action = n;
  1253.                             if ( deblog ) {
  1254.                                 sprintf(debbuf,
  1255.                                          "ESC %c %c %d %c%s",
  1256.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1257.                                 debug(F110,"HPTERM Printing: Action",
  1258.                                        debbuf,0);
  1259.                             }
  1260.                             debug(F111,"HP Print","action",action);
  1261.                             break;
  1262.                         case 'w':       /* Print ASCII string */
  1263.                         case 'W':
  1264.                             if ( n == 0 ) {
  1265.                                 hpprt_term = LF;
  1266.                                 hpprt_len = 256;
  1267.                                 debug(F111,"HP Print","terminator",LF);
  1268.                                 debug(F111,"HP Print","length",256);
  1269.                             }
  1270.                             else {
  1271.                                 hpprt_len = n;
  1272.                                 debug(F111,"HP Print","length",n);
  1273.                             }
  1274.                             action = 20;
  1275.                             if ( deblog ) {
  1276.                                 sprintf(debbuf,
  1277.                                          "ESC %c %c %d %c%s",
  1278.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1279.                                 debug(F110,"HPTERM Printing: Print String",
  1280.                                        debbuf,0);
  1281.                             }
  1282.                             debug(F111,"HP Print","action",action);
  1283.                             break;
  1284.                         default:
  1285.                             sprintf(debbuf,
  1286.                                      "ESC %c %c %d %c%s",
  1287.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1288.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1289.                         }
  1290.                     } while (x>0);
  1291.                     debug(F111,"HP Print","Final",ch3);
  1292.  
  1293.                     if ( debses )
  1294.                         break;
  1295.  
  1296.                     switch ( action ) {
  1297.                     case 1: {     /* Skip <x> lines */
  1298.                         int i;
  1299.                         for ( i=0;i<hpprt_term;i++ )
  1300.                             prtchar(LF);
  1301.                         break;
  1302.                     }
  1303.                     case 0:     /* Generate 1 form feed */
  1304.                     case 2:     /* Generate 1 form feed */
  1305.                     case 3:     /* Generate 1 form feed */
  1306.                     case 4:     /* Generate 1 form feed */
  1307.                     case 5:     /* Generate 1 form feed */
  1308.                     case 6:     /* Generate 1 form feed */
  1309.                     case 7:     /* Generate 1 form feed */
  1310.                     case 8:     /* Generate 1 form feed */
  1311.                     case 9:     /* Generate 1 form feed */
  1312.                     case 10:    /* Generate 1 form feed */
  1313.                         prtchar(FF);
  1314.                         break;
  1315.                     case 11:    /* Turns on log bottom mode */
  1316.                         setaprint(TRUE);
  1317.                         if ( !printon )
  1318.                             printeron();
  1319.                         break;
  1320.                     case 12:    /* Turns on log top mode */
  1321.                     case 13:    /* Turns off either log mode */
  1322.                         setaprint(FALSE);
  1323.                         if ( !uprint && !xprint && !cprint && !aprint && printon )
  1324.                             printeroff();
  1325.                         break;
  1326.                     case 14:    /* Print normal characters */
  1327.                     case 15:    /* Print expanded characters */
  1328.                     case 16:    /* Print compressed characters */
  1329.                     case 17:    /* Turns on report mode */
  1330.                     case 18:    /* Turns on metric report mode */
  1331.                     case 19:    /* Turns off any report mode */
  1332.                         break;
  1333.                     case 20:    /* Enables Record Mode */
  1334.                         xprint = TRUE ;
  1335.                         if ( !printon )
  1336.                             printeron() ;
  1337.                         break;
  1338.                     case 'B':    /* Print cursor line */
  1339.                         prtline(wherey[VTERM],LF);
  1340.                         break;
  1341.                     case 'F':    /* Copy from cursor to End of Screen */
  1342.                     case 'M':    /* Copy from cursor to End of Memory */
  1343.                         prtscreen(VTERM,wherey[VTERM],VscrnGetHeight(VTERM));
  1344.                         break;
  1345.                     case '^': {  /* Send device status */
  1346.                         char response[8];
  1347.                         response[0] = ESC;
  1348.                         response[1] = '\\';
  1349.                         response[2] = 'p';
  1350.                         response[3] = '0' + device;
  1351.                         response[4] = 48;       /* Printer Error */
  1352.                         response[5] = 56;       /* Printer Status */
  1353.                         response[6] = 49;       /* Printer Present */
  1354.                         response[7] = NUL;
  1355.                         debug(F110,"HP Print Status",response,0);
  1356.                         sendchars(response,7);
  1357.                         break;
  1358.                     }
  1359.                     default:
  1360.                         break;
  1361.                     }
  1362.                     break;
  1363.                 }
  1364.                 case 'q': {
  1365.                     /* Configuration Lock */
  1366.                     /*
  1367.                        0 L - Unlock Configuration
  1368.                        1 L - Lock Configuration
  1369.                     */
  1370.                     int ch3;
  1371.                     do {
  1372.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  1373.                             break;
  1374.                         if ( debses )
  1375.                             continue;
  1376.                         switch ( ch3 ) {
  1377.                         case 'l':       /* configuration lock */
  1378.                             switch ( n ) {
  1379.                             case 0:
  1380.                                 /* unlock */
  1381.                                 if ( deblog ) {
  1382.                                     sprintf(debbuf,
  1383.                                              "ESC %c %c %d %c%s",
  1384.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1385.                                     debug(F110,"HPTERM Configuration: Unlock (unsupported)",
  1386.                                            debbuf,0);
  1387.                                 }
  1388.                                 break;
  1389.                             case 1:
  1390.                                 /* lock */
  1391.                                 if ( deblog ) {
  1392.                                     sprintf(debbuf,
  1393.                                              "ESC %c %c %d %c%s",
  1394.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1395.                                     debug(F110,"HPTERM Configuration: Lock (unsupported)",
  1396.                                            debbuf,0);
  1397.                                 }
  1398.                                 break;
  1399.                             }
  1400.                             break;
  1401.                         default:
  1402.                             sprintf(debbuf,
  1403.                                      "ESC %c %c %d %c%s",
  1404.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1405.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1406.                         }
  1407.                     } while (x>0);
  1408.                     if ( x < 0 )
  1409.                         break;
  1410.                     break;
  1411.                 }
  1412.                 case 'r': {     /* Roll */
  1413.                     /* <n> d <n> l <n> r <n> u */
  1414.                     int ch3;
  1415.                     do {
  1416.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  1417.                             break;
  1418.                         if ( debses )
  1419.                             continue;
  1420.                         switch ( ch3 ) {
  1421.                         case 'd':       /* roll down n */
  1422.                             if ( deblog ) {
  1423.                                 sprintf(debbuf,
  1424.                                          "ESC %c %c %d %c%s",
  1425.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1426.                                 debug(F110,"HPTERM Roll: Down (unsupported)",
  1427.                                        debbuf,0);
  1428.                             }
  1429.                             break;
  1430.                         case 'l':       /* roll left n */
  1431.                             if ( deblog ) {
  1432.                                 sprintf(debbuf,
  1433.                                          "ESC %c %c %d %c%s",
  1434.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1435.                                 debug(F110,"HPTERM Roll: Left (unsupported)",
  1436.                                        debbuf,0);
  1437.                             }
  1438.                             break;
  1439.                         case 'r':       /* roll right n */
  1440.                             if ( deblog ) {
  1441.                                 sprintf(debbuf,
  1442.                                          "ESC %c %c %d %c%s",
  1443.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1444.                                 debug(F110,"HPTERM Roll: Right (unsupported)",
  1445.                                        debbuf,0);
  1446.                             }
  1447.                             break;
  1448.                         case 'u':       /* roll up n */
  1449.                             if ( deblog ) {
  1450.                                 sprintf(debbuf,
  1451.                                          "ESC %c %c %d %c%s",
  1452.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  1453.                                 debug(F110,"HPTERM Roll: Up (unsupported)",
  1454.                                        debbuf,0);
  1455.                             }
  1456.                             break;
  1457.                         default:
  1458.                             sprintf(debbuf,
  1459.                                      "ESC %c %c %d %c%s",
  1460.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1461.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1462.                         }
  1463.                     } while (x>0);
  1464.                     if ( x < 0 )
  1465.                         break;
  1466.                     break;
  1467.                 }
  1468.                 case 's': {
  1469.                     /* looks like it can handle multiple inputs of the form */
  1470.                     /* <ESC>&s0a0b1c0d0g0H */
  1471.                     /* <ESC>&s0b0c0D <ESC>&s0A */
  1472.  
  1473.                     int ch3=0;
  1474.                     do {
  1475.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  1476.                             break;
  1477.                         if ( debses )
  1478.                             continue;
  1479.                         switch ( ch3 ) {
  1480.                         case 'a':       /* HPTerm keypad controls */
  1481.                         case 'A':       /* Strap A: transmit function keys */
  1482.                             switch ( n ) {
  1483.                             case 0:
  1484.                                 /* turn off keypad */
  1485.                                 if ( deblog ) {
  1486.                                     sprintf(debbuf,
  1487.                                              "ESC %c %c %d %c%s",
  1488.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1489.                                     debug(F110,"HPTERM Strap A: Keypad off (unsupported)",
  1490.                                            debbuf,0);
  1491.                                 }
  1492.                                 break;
  1493.                             case 1:
  1494.                                 /* turn on keypad */
  1495.                                 if ( deblog ) {
  1496.                                     sprintf(debbuf,
  1497.                                              "ESC %c %c %d %c%s",
  1498.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1499.                                     debug(F110,"HPTERM Strap A: Keypad On (unsupported)",
  1500.                                            debbuf,0);
  1501.                                 }
  1502.                                 break;
  1503.                             }
  1504.                             break;
  1505.                         case 'b':
  1506.                         case 'B':       /* Strap B: Space Overwrite */
  1507.                             switch ( n ) {
  1508.                             case 0:
  1509.                                 /* turn off */
  1510.                                 if ( deblog ) {
  1511.                                     sprintf(debbuf,
  1512.                                              "ESC %c %c %d %c%s",
  1513.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1514.                                     debug(F110,"HPTERM Strap B: Space Overwrite Off (unsupported)",
  1515.                                            debbuf,0);
  1516.                                 }
  1517.                                 break;
  1518.                             case 1:
  1519.                                 /* turn on  */
  1520.                                 if ( deblog ) {
  1521.                                     sprintf(debbuf,
  1522.                                              "ESC %c %c %d %c%s",
  1523.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1524.                                     debug(F110,"HPTERM Strap B: Space Overwrite On (unsupported)",
  1525.                                            debbuf,0);
  1526.                                 }
  1527.                                 break;
  1528.                             }
  1529.                             break;
  1530.                         case 'c':
  1531.                         case 'C':
  1532.                             /* Strap C: Inhibit word wrap */
  1533.                             switch ( n ) {
  1534.                             case 0:
  1535.                                 /* turn off wrap */
  1536.                                 if ( deblog ) {
  1537.                                     sprintf(debbuf,
  1538.                                              "ESC %c %c %d %c%s",
  1539.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1540.                                     debug(F110,"HPTERM Strap C: Word Wrap Off",
  1541.                                            debbuf,0);
  1542.                                 }
  1543.                                 if ( debses )
  1544.                                     break;
  1545.                                 tt_wrap = TRUE;
  1546.                                 break;
  1547.                             case 1:
  1548.                                 /* turn on wrap */
  1549.                                 if ( deblog ) {
  1550.                                     sprintf(debbuf,
  1551.                                              "ESC %c %c %d %c%s",
  1552.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1553.                                     debug(F110,"HPTERM Strap C: Word Wrap On",
  1554.                                            debbuf,0);
  1555.                                 }
  1556.                                 if ( debses )
  1557.                                     break;
  1558.                                 tt_wrap = FALSE;
  1559.                                 break;
  1560.                             }
  1561.                             break;
  1562.                         case 'd':
  1563.                         case 'D':
  1564.                             /* Strap D: Page/Line */
  1565.                             switch ( n ) {
  1566.                             case 0:
  1567.                                 /* Line at a time */
  1568.                                 if ( deblog ) {
  1569.                                     sprintf(debbuf,
  1570.                                              "ESC %c %c %d %c%s",
  1571.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1572.                                     debug(F110,"HPTERM Strap D: Block-Mode is Line at a time (unsupported)",
  1573.                                            debbuf,0);
  1574.                                 }
  1575.                                 break;
  1576.                             case 1:
  1577.                                 /* Page at a time */
  1578.                                 if ( deblog ) {
  1579.                                     sprintf(debbuf,
  1580.                                              "ESC %c %c %d %c%s",
  1581.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1582.                                     debug(F110,"HPTERM Strap D: Block-Mode is Page at a time (unsupported)",
  1583.                                            debbuf,0);
  1584.                                 }
  1585.                                 break;
  1586.                             }
  1587.                             break;
  1588.  
  1589.                             /* Straps G and H work in tandem.  */
  1590.                             /* G0 H0 - Data Transfers use DC1/DC2 Handshake.  */
  1591.                             /*   Other transfers triggered by receipt of DC1  */
  1592.                             /* G0 H1 - Data is sent when the host receives a  */
  1593.                             /*   DC2.  All other transfers are triggered by   */
  1594.                             /*   receipt of DC1.                              */
  1595.                             /* G1 H0 - All block transfers require a DC1/DC2  */
  1596.                             /*   handshake.                                   */
  1597.                             /* G1 H1 - No DC1/DC2 handshake is required for   */
  1598.                             /*    any block transfer.                         */
  1599.  
  1600.                         case 'g':
  1601.                         case 'G':
  1602.                             /* Strap G: DC2 Handshaking */
  1603.                             switch ( n ) {
  1604.                             case 0: /* Off */
  1605.                                 if ( deblog ) {
  1606.                                     sprintf(debbuf,
  1607.                                              "ESC %c %c %d %c%s",
  1608.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1609.                                     debug(F110,"HPTERM Strap G: Off (unsupported)",
  1610.                                            debbuf,0);
  1611.                                 }
  1612.                                 break;
  1613.                             case 1: /* On */
  1614.                                 if ( deblog ) {
  1615.                                     sprintf(debbuf,
  1616.                                              "ESC %c %c %d %c%s",
  1617.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1618.                                     debug(F110,"HPTERM Strap G: On (unsupported)",
  1619.                                            debbuf,0);
  1620.                                 }
  1621.                                 break;
  1622.                             }
  1623.                             break;
  1624.                         case 'h':
  1625.                         case 'H':
  1626.                             /* Strap H: Inhibit DC2 */
  1627.                             switch ( n ) {
  1628.                             case 0: /* Off */
  1629.                                 if ( deblog ) {
  1630.                                     sprintf(debbuf,
  1631.                                              "ESC %c %c %d %c%s",
  1632.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1633.                                     debug(F110,"HPTERM Strap H: Off (unsupported)",
  1634.                                            debbuf,0);
  1635.                                 }
  1636.                                 break;
  1637.                             case 1: /* On */
  1638.                                 if ( deblog ) {
  1639.                                     sprintf(debbuf,
  1640.                                              "ESC %c %c %d %c%s",
  1641.                                              ch, ch2, n, ch3, y ? " (relative)" : "");
  1642.                                     debug(F110,"HPTERM Strap H: On (unsupported)",
  1643.                                            debbuf,0);
  1644.                                 }
  1645.                                 break;
  1646.                             }
  1647.                             break;
  1648.                         default:
  1649.                             if ( deblog ) {
  1650.                             sprintf(debbuf,
  1651.                                      "ESC %c %c %d %c%s",
  1652.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1653.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1654.                             }
  1655.                         }
  1656.                     } while (x>0);
  1657.                     break;
  1658.                 }
  1659.                 case 'v': {     /* Color sequences */
  1660.                     int ch3;
  1661.                     do {
  1662.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  1663.                             break;
  1664.                         if ( debses )
  1665.                             continue;
  1666.                         switch ( ch3 ) {
  1667.                         default:
  1668.                             sprintf(debbuf,
  1669.                                      "ESC %c %c %d %c%s",
  1670.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  1671.                             debug(F110,"HPTERM unknown command",debbuf,0);
  1672.                         }
  1673.                     } while (x>0);
  1674.                 }
  1675.                 default:
  1676.                     sprintf(debbuf,"ESC %c %c", ch, ch2);
  1677.                     debug(F110,"HPTERM unknown command",debbuf,0);
  1678.                 }
  1679.                 break;
  1680.             }
  1681. #ifdef COMMENT
  1682.             case '\'':
  1683.                 break;
  1684. #endif /* COMMENT */
  1685.             case '(': { /* Select Specific Primary Character Set */
  1686.                 int ch2;
  1687.                 int len=0;
  1688.                 do {
  1689.                     if ((x = hpparam(&n,&ch2,&y)) < 0)
  1690.                         break;
  1691.                     switch ( ch2 ) {
  1692.                     case '@':   /* Select Primary Character Set */
  1693.                     case 'a':
  1694.                     case 'b':
  1695.                     case 'c':
  1696.                     case 'd':
  1697.                     case 'y':
  1698.                         if ( deblog ) {
  1699.                             sprintf(debbuf,
  1700.                                      "ESC %c %d %c%s",
  1701.                                      ch, n, ch2, y ? " (relative)" : "");
  1702.                             debug(F110,"HPTERM Select Primary Character Set (unsupported)",
  1703.                                    debbuf,0);
  1704.                             }
  1705.                         break;
  1706.                     case 's': { /* Define Primary Char Set Attributes */
  1707.                         int ch3;
  1708.                         do {
  1709.                             if ((x = hpparam(&m,&ch3,&z)) < 0)
  1710.                                 break;
  1711.                             switch ( ch3 ) {
  1712.                             case 'b':   /* Stroke Weight */
  1713.                                 if ( deblog ) {
  1714.                                     sprintf(debbuf,
  1715.                                              "ESC %c %d %c %d %c%s",
  1716.                                              ch, n, ch2, m, ch3,
  1717.                                              z ? " (relative)" : "");
  1718.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Stroke Weight (unsupported)",
  1719.                                            debbuf,0);
  1720.                                 }
  1721.                                 break;
  1722.                             case 'h':   /* Pitch */
  1723.                                 if ( deblog ) {
  1724.                                     sprintf(debbuf,
  1725.                                              "ESC %c %d %c %d %c%s",
  1726.                                              ch, n, ch2, m, ch3,
  1727.                                              z ? " (relative)" : "");
  1728.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Pitch (unsupported)",
  1729.                                            debbuf,0);
  1730.                                 }
  1731.                                 break;
  1732.                             case 'n':   /* Font name */
  1733.                                 if ( deblog ) {
  1734.                                     sprintf(debbuf,
  1735.                                              "ESC %c %d %c %d %c%s",
  1736.                                              ch, n, ch2, m, ch3,
  1737.                                              z ? " (relative)" : "");
  1738.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Font name (unsupported)",
  1739.                                            debbuf,0);
  1740.                                 }
  1741.                                 break;
  1742.                             case 'p':   /* Fixed or Proportional Spacing */
  1743.                                 if ( deblog ) {
  1744.                                     sprintf(debbuf,
  1745.                                              "ESC %c %d %c %d %c%s",
  1746.                                              ch, n, ch2, m, ch3,
  1747.                                              z ? " (relative)" : "");
  1748.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Fixed or Proportional Spacing (unsupported)",
  1749.                                            debbuf,0);
  1750.                                 }
  1751.                                 break;
  1752.                             case 'q':   /* Density */
  1753.                                 if ( deblog ) {
  1754.                                     sprintf(debbuf,
  1755.                                              "ESC %c %d %c %d %c%s",
  1756.                                              ch, n, ch2, m, ch3,
  1757.                                              z ? " (relative)" : "");
  1758.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Density (unsupported)",
  1759.                                            debbuf,0);
  1760.                                 }
  1761.                                 break;
  1762.                             case 's':   /* Style */
  1763.                                 if ( deblog ) {
  1764.                                     sprintf(debbuf,
  1765.                                              "ESC %c %d %c %d %c%s",
  1766.                                              ch, n, ch2, m, ch3,
  1767.                                              z ? " (relative)" : "");
  1768.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Style (unsupported)",
  1769.                                            debbuf,0);
  1770.                                 }
  1771.                                 break;
  1772.                             case 't':   /* Typeface */
  1773.                                 if ( deblog ) {
  1774.                                     sprintf(debbuf,
  1775.                                              "ESC %c %d %c %d %c%s",
  1776.                                              ch, n, ch2, m, ch3,
  1777.                                              z ? " (relative)" : "");
  1778.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Typeface (unsupported)",
  1779.                                            debbuf,0);
  1780.                                 }
  1781.                                 break;
  1782.                             case 'u':   /* Superior or inferior style */
  1783.                                 if ( deblog ) {
  1784.                                     sprintf(debbuf,
  1785.                                              "ESC %c %d %c %d %c%s",
  1786.                                              ch, n, ch2, m, ch3,
  1787.                                              z ? " (relative)" : "");
  1788.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Superior or Inferior (unsupported)",
  1789.                                            debbuf,0);
  1790.                                 }
  1791.                                 break;
  1792.                             case 'v':   /* Height in points */
  1793.                                 if ( deblog ) {
  1794.                                     sprintf(debbuf,
  1795.                                              "ESC %c %d %c %d %c%s",
  1796.                                              ch, n, ch2, m, ch3,
  1797.                                              z ? " (relative)" : "");
  1798.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Height (unsupported)",
  1799.                                            debbuf,0);
  1800.                                 }
  1801.                                 break;
  1802.                             case 'w':   /* Length of download characters */
  1803.                                 len = m;
  1804.                                 if ( deblog ) {
  1805.                                     sprintf(debbuf,
  1806.                                              "ESC %c %d %c %d %c%s",
  1807.                                              ch, n, ch2, m, ch3,
  1808.                                              z ? " (relative)" : "");
  1809.                                     debug(F110,"HPTERM Set Primary Char Set Attributes: Length of download (unsupported)",
  1810.                                            debbuf,0);
  1811.                                 }
  1812.                                 break;
  1813.                             default:
  1814.                                 if ( deblog ) {
  1815.                                     sprintf(debbuf,
  1816.                                              "ESC %c %d %c %d %c%s",
  1817.                                              ch, n, ch2, m, ch3,
  1818.                                              z ? " (relative)" : "");
  1819.                                     debug(F110,"HPTERM Unknown",
  1820.                                            debbuf,0);
  1821.                                 }
  1822.                             }
  1823.                         } while (x>0);
  1824.                         break;
  1825.                     }
  1826.                     default:
  1827.                         if ( deblog ) {
  1828.                             sprintf(debbuf,
  1829.                                      "ESC %c %d %c%s",
  1830.                                      ch, n, ch2, y ? " (relative)" : "");
  1831.                             debug(F110,"HPTERM Unknown",
  1832.                                    debbuf,0);
  1833.                         }
  1834.                     }
  1835.                 } while (x>0);
  1836.                 /* If there is download data, swallow it */
  1837.                 if ( len ) {
  1838.                     while ( len-- )
  1839.                         hpinc();
  1840.                 }
  1841.                 break;
  1842.             }
  1843.             case ')': { /* Select Specific Secondary Character Set */
  1844.                 int ch2;
  1845.                 int len=0;
  1846.                 do {
  1847.                     if ((x = hpparam(&n,&ch2,&y)) < 0)
  1848.                         break;
  1849.                     switch ( ch2 ) {
  1850.                     case '@':   /* Select Secondary Character Set */
  1851.                     case 'a':
  1852.                     case 'b':
  1853.                     case 'c':
  1854.                     case 'd':
  1855.                     case 'y':
  1856.                         if ( deblog ) {
  1857.                             sprintf(debbuf,
  1858.                                      "ESC %c %d %c%s",
  1859.                                      ch, n, ch2, y ? " (relative)" : "");
  1860.                             debug(F110,"HPTERM Select Secondary Character Set (unsupported)",
  1861.                                    debbuf,0);
  1862.                             }
  1863.                         break;
  1864.                     case 'f': { /* Reserved */
  1865.                         int ch3;
  1866.                         do {
  1867.                             if ((x = hpparam(&m,&ch3,&z)) < 0)
  1868.                                 break;
  1869.                             switch ( ch3 ) {
  1870.                             case 'h':   /* reserved */
  1871.                                 if ( deblog ) {
  1872.                                     sprintf(debbuf,
  1873.                                              "ESC %c %d %c %d %c%s",
  1874.                                              ch, n, ch2, m, ch3,
  1875.                                              z ? " (relative)" : "");
  1876.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Reserved (unsupported)",
  1877.                                            debbuf,0);
  1878.                                 }
  1879.                                 break;
  1880.                             default:
  1881.                                 if ( deblog ) {
  1882.                                     sprintf(debbuf,
  1883.                                              "ESC %c %d %c %d %c%s",
  1884.                                              ch, n, ch2, m, ch3,
  1885.                                              z ? " (relative)" : "");
  1886.                                     debug(F110,"HPTERM Unknown",
  1887.                                            debbuf,0);
  1888.                                 }
  1889.                             }
  1890.                         } while (x>0);
  1891.                         break;
  1892.                     }
  1893.                     case 's': { /* Define Secondary Char Set Attributes */
  1894.                         int ch3;
  1895.                         do {
  1896.                             if ((x = hpparam(&m,&ch3,&z)) < 0)
  1897.                                 break;
  1898.                             switch ( ch3 ) {
  1899.                             case 'b':   /* Stroke Weight */
  1900.                                 if ( deblog ) {
  1901.                                     sprintf(debbuf,
  1902.                                              "ESC %c %d %c %d %c%s",
  1903.                                              ch, n, ch2, m, ch3,
  1904.                                              z ? " (relative)" : "");
  1905.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Stroke Weight (unsupported)",
  1906.                                            debbuf,0);
  1907.                                 }
  1908.                                 break;
  1909.                             case 'h':   /* Pitch */
  1910.                                 if ( deblog ) {
  1911.                                     sprintf(debbuf,
  1912.                                              "ESC %c %d %c %d %c%s",
  1913.                                              ch, n, ch2, m, ch3,
  1914.                                              z ? " (relative)" : "");
  1915.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Pitch (unsupported)",
  1916.                                            debbuf,0);
  1917.                                 }
  1918.                                 break;
  1919.                             case 'n':   /* Font name */
  1920.                                 if ( deblog ) {
  1921.                                     sprintf(debbuf,
  1922.                                              "ESC %c %d %c %d %c%s",
  1923.                                              ch, n, ch2, m, ch3,
  1924.                                              z ? " (relative)" : "");
  1925.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Font name (unsupported)",
  1926.                                            debbuf,0);
  1927.                                 }
  1928.                                 break;
  1929.                             case 'p':   /* Fixed or Proportional Spacing */
  1930.                                 if ( deblog ) {
  1931.                                     sprintf(debbuf,
  1932.                                              "ESC %c %d %c %d %c%s",
  1933.                                              ch, n, ch2, m, ch3,
  1934.                                              z ? " (relative)" : "");
  1935.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Fixed or Proportional Spacing (unsupported)",
  1936.                                            debbuf,0);
  1937.                                 }
  1938.                                 break;
  1939.                             case 'q':   /* Density */
  1940.                                 if ( deblog ) {
  1941.                                     sprintf(debbuf,
  1942.                                              "ESC %c %d %c %d %c%s",
  1943.                                              ch, n, ch2, m, ch3,
  1944.                                              z ? " (relative)" : "");
  1945.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Density (unsupported)",
  1946.                                            debbuf,0);
  1947.                                 }
  1948.                                 break;
  1949.                             case 's':   /* Style */
  1950.                                 if ( deblog ) {
  1951.                                     sprintf(debbuf,
  1952.                                              "ESC %c %d %c %d %c%s",
  1953.                                              ch, n, ch2, m, ch3,
  1954.                                              z ? " (relative)" : "");
  1955.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Style (unsupported)",
  1956.                                            debbuf,0);
  1957.                                 }
  1958.                                 break;
  1959.                             case 't':   /* Typeface */
  1960.                                 if ( deblog ) {
  1961.                                     sprintf(debbuf,
  1962.                                              "ESC %c %d %c %d %c%s",
  1963.                                              ch, n, ch2, m, ch3,
  1964.                                              z ? " (relative)" : "");
  1965.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Typeface (unsupported)",
  1966.                                            debbuf,0);
  1967.                                 }
  1968.                                 break;
  1969.                             case 'u':   /* Superior or inferior style */
  1970.                                 if ( deblog ) {
  1971.                                     sprintf(debbuf,
  1972.                                              "ESC %c %d %c %d %c%s",
  1973.                                              ch, n, ch2, m, ch3,
  1974.                                              z ? " (relative)" : "");
  1975.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Superior or Inferior (unsupported)",
  1976.                                            debbuf,0);
  1977.                                 }
  1978.                                 break;
  1979.                             case 'v':   /* Height in points */
  1980.                                 if ( deblog ) {
  1981.                                     sprintf(debbuf,
  1982.                                              "ESC %c %d %c %d %c%s",
  1983.                                              ch, n, ch2, m, ch3,
  1984.                                              z ? " (relative)" : "");
  1985.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Height (unsupported)",
  1986.                                            debbuf,0);
  1987.                                 }
  1988.                                 break;
  1989.                             case 'w':   /* Length of download characters */
  1990.                                 len = m;
  1991.                                 if ( deblog ) {
  1992.                                     sprintf(debbuf,
  1993.                                              "ESC %c %d %c %d %c%s",
  1994.                                              ch, n, ch2, m, ch3,
  1995.                                              z ? " (relative)" : "");
  1996.                                     debug(F110,"HPTERM Set Secondary Char Set Attributes: Length of download (unsupported)",
  1997.                                            debbuf,0);
  1998.                                 }
  1999.                                 break;
  2000.                             default:
  2001.                                 if ( deblog ) {
  2002.                                     sprintf(debbuf,
  2003.                                              "ESC %c %d %c %d %c%s",
  2004.                                              ch, n, ch2, m, ch3,
  2005.                                              z ? " (relative)" : "");
  2006.                                     debug(F110,"HPTERM Unknown",
  2007.                                            debbuf,0);
  2008.                                 }
  2009.                             }
  2010.                         } while (x>0);
  2011.                         break;
  2012.                     }
  2013.                     default:
  2014.                         if ( deblog ) {
  2015.                             sprintf(debbuf,
  2016.                                      "ESC %c %d %c%s",
  2017.                                      ch, n, ch2, y ? " (relative)" : "");
  2018.                             debug(F110,"HPTERM Unknown",
  2019.                                    debbuf,0);
  2020.                         }
  2021.                     }
  2022.                 } while (x>0);
  2023.                 /* If there is download data, swallow it */
  2024.                 if ( len ) {
  2025.                     while ( len-- )
  2026.                         hpinc();
  2027.                 }
  2028.                 break;
  2029.             }
  2030.             case '*': {
  2031.                 /* ESC * d Q   Cursor On */
  2032.                 /* ESC * d R   Cursor Off */
  2033.                 /* ESC * s ^   Identify */
  2034.                 /* ESC * s 1 ^ Identify */
  2035.                 int ch2, ch3;
  2036.                 ch2 = hpinc() ;
  2037.                 if ( debses )
  2038.                     break;
  2039.                 switch ( ch2 ) {
  2040.                 case 'd':
  2041.                     do {
  2042.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  2043.                             break;
  2044.                         if ( debses )
  2045.                             continue;
  2046.                         switch ( ch3 ) {
  2047.                         case 'q':       /* Cursor On */
  2048.                             if ( deblog ) {
  2049.                                 sprintf(debbuf,
  2050.                                          "ESC %c %c %d %c%s",
  2051.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  2052.                                 debug(F110,"HPTERM Cursor On",
  2053.                                        debbuf,0);
  2054.                             }
  2055.                             if ( debses )
  2056.                                 break;
  2057.                             cursorena[VTERM] = TRUE;
  2058.                             break;
  2059.                         case 'r':       /* Cursor Off */
  2060.                             if ( deblog ) {
  2061.                                 sprintf(debbuf,
  2062.                                          "ESC %c %c %d %c%s",
  2063.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  2064.                                 debug(F110,"HPTERM Cursor Off",
  2065.                                        debbuf,0);
  2066.                             }
  2067.                             if ( debses )
  2068.                                 break;
  2069.                             cursorena[VTERM] = FALSE ;
  2070.                             break;
  2071.                         default:
  2072.                             if ( deblog ) {
  2073.                             sprintf(debbuf,
  2074.                                      "ESC %c %c %d %c%s",
  2075.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  2076.                             debug(F110,"HPTERM unknown command",debbuf,0);
  2077.                             }
  2078.                             break;
  2079.                         }
  2080.                     } while (x>0);
  2081.                     break;
  2082.                 case 's':
  2083.                     do {
  2084.                         if ((x = hpparam(&n,&ch3,&y)) < 0)
  2085.                             break;
  2086.                         if ( debses )
  2087.                             continue;
  2088.                         switch ( ch3 ) {
  2089.                         case '^':
  2090.                             if ( deblog ) {
  2091.                                 sprintf(debbuf,
  2092.                                          "ESC %c %c %d %c%s",
  2093.                                          ch, ch2, n, ch3, y ? " (relative)" : "");
  2094.                                 debug(F110,"HPTERM Identify Terminal",
  2095.                                        debbuf,0);
  2096.                             }
  2097.                             if ( debses )
  2098.                                 break;
  2099.                             sendchars( tt_info[tt_type].x_id,
  2100.                                        strlen(tt_info[tt_type].x_id) ) ;
  2101.                             break;
  2102.                         default:
  2103.                             if ( deblog ) {
  2104.                             sprintf(debbuf,
  2105.                                      "ESC %c %c %d %c%s",
  2106.                                      ch, ch2, n, ch3, y ? " (relative)" : "");
  2107.                             debug(F110,"HPTERM unknown command",debbuf,0);
  2108.                             }
  2109.                             break;
  2110.                         }
  2111.                     } while (x>0);
  2112.                     break;
  2113.                 default:
  2114.                     /* ignore everything we don't understand */
  2115.                     if ( deblog ) {
  2116.                         sprintf(debbuf,"ESC %c %c", ch, ch2);
  2117.                         debug(F110,"HPTERM unknown command",debbuf,0);
  2118.                     }
  2119.                 }
  2120.                 break;
  2121.             }
  2122. #ifdef COMMENT
  2123.             case '+':
  2124.                 break;
  2125.             case ',':   /* Status responses from Kanji Terminals */
  2126.                 break;
  2127. #endif /* COMMENT */
  2128.             case '-':
  2129.             case '.':
  2130.             case '/': {
  2131.                 int ch2;
  2132.                 int len=0;
  2133.                 do {
  2134.                     if ((x = hpparam(&n,&ch2,&y)) < 0)
  2135.                         break;
  2136.                     if ( x == 0 ) {
  2137.                         if ( deblog ) {
  2138.                             sprintf(debbuf,
  2139.                                      "ESC %c %d %c%s",
  2140.                                      ch, n, ch2, y ? " (relative)" : "");
  2141.                             debug(F110,"HPTERM Select Primary Character Set (unsupported)",
  2142.                                    debbuf,0);
  2143.                         }
  2144.                     }
  2145.                     else {
  2146.                         int ch3;
  2147.                         do {
  2148.                             if ((x = hpparam(&m,&ch3,&z)) < 0)
  2149.                                 break;
  2150.                             if ( deblog ) {
  2151.                                 sprintf(debbuf,
  2152.                                          "ESC %c %d %c %d %c%s",
  2153.                                          ch, n, ch2, m, ch3,
  2154.                                          z ? " (relative)" : "");
  2155.                                 debug(F110,"HPTERM Unknown",
  2156.                                        debbuf,0);
  2157.                             }
  2158.                         } while (x>0);
  2159.                     }
  2160.                 } while (x>0);
  2161.                 break;
  2162.             }
  2163.             case '0':
  2164.                 /* Print All */
  2165.                 if ( deblog ) {
  2166.                     sprintf(debbuf, "ESC %c", ch);
  2167.                     debug(F110,"HPTERM Print All",
  2168.                            debbuf,0);
  2169.                 }
  2170.                 if ( debses )
  2171.                     break;
  2172.                 prtscreen(VTERM,1,VscrnGetHeight(VTERM));
  2173.                 break;
  2174.             case '1':
  2175.                 /* Sets a tab stop */
  2176.                 if ( deblog ) {
  2177.                     sprintf(debbuf, "ESC %c", ch);
  2178.                     debug(F110,"HPTERM Set Tab Stop",
  2179.                            debbuf,0);
  2180.                 }
  2181.                 if ( debses )
  2182.                     break;
  2183.                 htab[wherex[VTERM]] = 'T';
  2184.                 break;
  2185.             case '2':
  2186.                 /* Clears a tab stop */
  2187.                 if ( deblog ) {
  2188.                     sprintf(debbuf, "ESC %c", ch);
  2189.                     debug(F110,"HPTERM Clear Tab Stop",
  2190.                            debbuf,0);
  2191.                 }
  2192.                 if ( debses )
  2193.                     break;
  2194.                 htab[wherex[VTERM]] = '0';
  2195.                 break;
  2196.             case '3':
  2197.                 /* Clears all tab stops */
  2198.                 if ( deblog ) {
  2199.                     sprintf(debbuf, "ESC %c", ch);
  2200.                     debug(F110,"HPTERM Clear All Tab Stops",
  2201.                            debbuf,0);
  2202.                 }
  2203.                 if ( debses )
  2204.                     break;
  2205.                 for (j = 1; j <=MAXTERMCOL; ++j)
  2206.                     htab[j] = '0';
  2207.                 break;
  2208.             case '4':
  2209.                 /* Set Left Margin */
  2210.                 if ( deblog ) {
  2211.                     sprintf(debbuf, "ESC %c", ch);
  2212.                     debug(F110,"HPTERM Set Left Margin",
  2213.                            debbuf,0);
  2214.                 }
  2215.                 if ( debses )
  2216.                     break;
  2217.                 marginleft = wherex[VTERM];
  2218.                 break;
  2219.             case '5':
  2220.                 /* Set Right Margin */
  2221.                 if ( deblog ) {
  2222.                     sprintf(debbuf, "ESC %c", ch);
  2223.                     debug(F110,"HPTERM Set Right Margin",
  2224.                            debbuf,0);
  2225.                 }
  2226.                 if ( debses )
  2227.                     break;
  2228.                 marginright = wherex[VTERM];
  2229.                 break;
  2230. #ifdef COMMENT
  2231.             case '6':
  2232.                 break;
  2233.             case '7':
  2234.                 break;
  2235.             case '8':
  2236.                 break;
  2237. #endif /* COMMENT */
  2238.             case '9':
  2239.                 /* Clear margins */
  2240.                 if ( deblog ) {
  2241.                     sprintf(debbuf, "ESC %c", ch);
  2242.                     debug(F110,"HPTERM Clear Margins",
  2243.                            debbuf,0);
  2244.                 }
  2245.                 if ( debses )
  2246.                     break;
  2247.                 margintop = 1;
  2248.                 marginbot = VscrnGetHeight(VTERM);
  2249.                 marginleft =1;
  2250.                 marginright=VscrnGetWidth(VTERM);
  2251.                 break;
  2252. #ifdef COMMENT
  2253.             case ':':
  2254.                 break;
  2255.             case ';':
  2256.                 break;
  2257. #endif /* COMMENT */
  2258.             case '<': {
  2259.                 /* <n> <alpha>    Change Base Font (G1) */
  2260.                 /* 8U - Roman 8 */
  2261.                 /* 8K - Kana 8  */
  2262.                 /* 8M - Math/Special Symbols 8 */
  2263.                 /* 0L - Line Draw 8 */
  2264.                 char n, alpha;
  2265.  
  2266.                 n = hpinc();
  2267.                 alpha = hpinc();
  2268.  
  2269.                 if ( deblog ) {
  2270.                     sprintf(debbuf, "ESC %c %c %c", ch, n, alpha);
  2271.                     debug(F110,"HPTERM Change Base Font (G1)",
  2272.                            debbuf,0);
  2273.                 }
  2274.  
  2275.                 if ( debses )
  2276.                     break;
  2277.                 if ( n == 8 )
  2278.                     n = '8';
  2279.                 if ( n == 0 )
  2280.                     n = '0';
  2281.  
  2282.                 if ( n == '8' ) {
  2283.                     switch ( alpha ) {
  2284.                     case 'U':
  2285.                         charset( cs94, 'B', &G[0] );
  2286.                         charset( cs96, 'h', &G[1] );
  2287.                         break;
  2288.                     case 'K':
  2289.                         charset( cs96, 'h', &G[0] );
  2290.                         charset( cs96, 'h', &G[1] );
  2291.                         break;
  2292.                     case 'M':
  2293.                         charset( cs96, 'i', &G[0] );
  2294.                         charset( cs96, 'i', &G[1] );
  2295.                         break;
  2296.                     }
  2297.                 }
  2298.                 else if ( n == '0' && alpha == 'L' ) {
  2299.                     charset( cs96, 'j', &G[0] );
  2300.                     charset( cs96, 'j', &G[1] );
  2301.                 }
  2302.                 break;
  2303.             }
  2304. #ifdef COMMENT
  2305.             case '=':
  2306.                 break;
  2307. #endif /* COMMENT */
  2308.             case '>': {
  2309.                 /* <n> <alpha>    Change Alternate Font (G2) */
  2310.                 /* 8U - Roman 8 */
  2311.                 /* 8K - Kana 8  */
  2312.                 /* 8M - Math/Special Symbols 8 */
  2313.                 /* 0L - Line Draw 8 */
  2314.                 char n, alpha;
  2315.                 n = hpinc();
  2316.                 alpha = hpinc();
  2317.  
  2318.                 if ( deblog ) {
  2319.                     sprintf(debbuf, "ESC %c %c %c", ch, n, alpha);
  2320.                     debug(F110,"HPTERM Change Alternate Font (G2)",
  2321.                            debbuf,0);
  2322.                 }
  2323.  
  2324.                 if ( debses )
  2325.                     break;
  2326.                 if ( n == 8 )
  2327.                     n = '8';
  2328.                 if ( n == 0 )
  2329.                     n = '0';
  2330.  
  2331.                 if ( n == '8' ) {
  2332.                     switch ( alpha ) {
  2333.                     case 'U':
  2334.                         charset( cs94, 'B', &G[2] );
  2335.                         charset( cs96, 'h', &G[3] );
  2336.                         break;
  2337.                     case 'K':
  2338.                         charset( cs96, 'h', &G[2] );
  2339.                         charset( cs96, 'h', &G[3] );
  2340.                         break;
  2341.                     case 'M':
  2342.                         charset( cs96, 'i', &G[2] );
  2343.                         charset( cs96, 'i', &G[3] );
  2344.                         break;
  2345.                     }
  2346.                 }
  2347.                 else if ( n == '0' && alpha == 'L' ) {
  2348.                     charset( cs96, 'j', &G[2] );
  2349.                     charset( cs96, 'j', &G[3] );
  2350.                 }
  2351.                 break;
  2352.             }
  2353. #ifdef COMMENT
  2354.             case '?':
  2355.                 break;
  2356. #endif /* COMMENT */
  2357.             case '@':
  2358.                 /* Delay 1 second */
  2359.                 if ( deblog ) {
  2360.                     sprintf(debbuf, "ESC %c", ch);
  2361.                     debug(F110,"HPTERM Delay 1 Second",
  2362.                            debbuf,0);
  2363.                 }
  2364.                 if ( debses )
  2365.                     break;
  2366.                 sleep(1);
  2367.                 break;
  2368.             case 'A':
  2369.                 /* Cursor Up */
  2370.                 if ( deblog ) {
  2371.                     sprintf(debbuf, "ESC %c", ch);
  2372.                     debug(F110,"HPTERM Cursor Up",
  2373.                            debbuf,0);
  2374.                 }
  2375.                 if ( debses )
  2376.                     break;
  2377.  
  2378.                 cursorup(0);
  2379.                 break;
  2380.             case 'B':
  2381.                 /* Cursor Down */
  2382.                 if ( deblog ) {
  2383.                     sprintf(debbuf, "ESC %c", ch);
  2384.                     debug(F110,"HPTERM Cursor Down",
  2385.                            debbuf,0);
  2386.                 }
  2387.                 if ( debses )
  2388.                     break;
  2389.  
  2390.                 cursordown(0);
  2391.                 break;
  2392.             case 'C':
  2393.                 /* Cursor Right */
  2394.                 if ( deblog ) {
  2395.                     sprintf(debbuf, "ESC %c", ch);
  2396.                     debug(F110,"HPTERM Cursor Right",
  2397.                            debbuf,0);
  2398.                 }
  2399.                 if ( debses )
  2400.                     break;
  2401.  
  2402.                 cursorright(0);
  2403.                 break;
  2404.             case 'D':
  2405.                 /* Cursor Left */
  2406.                 if ( deblog ) {
  2407.                     sprintf(debbuf, "ESC %c", ch);
  2408.                     debug(F110,"HPTERM Cursor Left",
  2409.                            debbuf,0);
  2410.                 }
  2411.                 if ( debses )
  2412.                     break;
  2413.  
  2414.                 cursorleft(0);
  2415.                 break;
  2416.             case 'E':
  2417.                 /* Reset Terminal */
  2418.                 if ( deblog ) {
  2419.                     sprintf(debbuf, "ESC %c", ch);
  2420.                     debug(F110,"HPTERM Reset Terminal",
  2421.                            debbuf,0);
  2422.                 }
  2423.                 if ( debses )
  2424.                     break;
  2425.                 doreset(1);
  2426.                 break;
  2427.             case 'F':
  2428.                 /* Cursor Home Down */
  2429.                 if ( deblog ) {
  2430.                     sprintf(debbuf, "ESC %c", ch);
  2431.                     debug(F110,"HPTERM Home Down",
  2432.                            debbuf,0);
  2433.                 }
  2434.                 if ( debses )
  2435.                     break;
  2436.  
  2437.                 lgotoxy(VTERM, 1, VscrnGetHeight(VTERM));
  2438.                 break;
  2439.             case 'G':
  2440.                 /* Cursor Return */
  2441.                 if ( deblog ) {
  2442.                     sprintf(debbuf, "ESC %c", ch);
  2443.                     debug(F110,"HPTERM Cursor Return",
  2444.                            debbuf,0);
  2445.                 }
  2446.                 if ( debses )
  2447.                     break;
  2448.  
  2449.                 wrtch(CR);
  2450.                 break;
  2451.             case 'H':
  2452.                 /* Cursor Home Up */
  2453.                 if ( deblog ) {
  2454.                     sprintf(debbuf, "ESC %c", ch);
  2455.                     debug(F110,"HPTERM Cursor Home Up",
  2456.                            debbuf,0);
  2457.                 }
  2458.                 if ( debses )
  2459.                     break;
  2460.  
  2461.                 lgotoxy(VTERM,1,1);
  2462.                 break;
  2463.             case 'I':
  2464.                 /* Horizontal Tab */
  2465.                 if ( deblog ) {
  2466.                     sprintf(debbuf, "ESC %c", ch);
  2467.                     debug(F110,"HPTERM Horizontal Tab",
  2468.                            debbuf,0);
  2469.                 }
  2470.                 if ( debses )
  2471.                     break;
  2472.  
  2473.                 i = wherex[VTERM];
  2474.                 if (i < marginright)
  2475.                 {
  2476.                     do {
  2477.                         i++;
  2478.                         cursorright(0);
  2479.                     } while ((htab[i] != 'T') &&
  2480.                               (i <= marginright-1));
  2481.                 }
  2482.                 if ( i == marginright ) {
  2483.                     wrtch(CR);
  2484.                     wrtch(LF);
  2485.                 }
  2486.                 VscrnIsDirty(VTERM);
  2487.                 break;
  2488.             case 'J':
  2489.                 /* Clear Display */
  2490.                 if ( deblog ) {
  2491.                     sprintf(debbuf, "ESC %c", ch);
  2492.                     debug(F110,"HPTERM Clear Display",
  2493.                            debbuf,0);
  2494.                 }
  2495.  
  2496.                 if ( debses )
  2497.                     break;
  2498.                 clreoscr_escape(VTERM,SP);
  2499.                 break;
  2500.             case 'K':
  2501.                 /* Erase to End of Line */
  2502.                 if ( deblog ) {
  2503.                     sprintf(debbuf, "ESC %c", ch);
  2504.                     debug(F110,"HPTERM Erase to End of Line",
  2505.                            debbuf,0);
  2506.                 }
  2507.                 if ( debses )
  2508.                     break;
  2509.                 clrtoeoln(VTERM,SP);
  2510.                 break;
  2511.             case 'L':
  2512.                 /* Insert Line */
  2513.                 if ( deblog ) {
  2514.                     sprintf(debbuf, "ESC %c", ch);
  2515.                     debug(F110,"HPTERM Insert Line",
  2516.                            debbuf,0);
  2517.                 }
  2518.                 if ( debses )
  2519.                     break;
  2520.  
  2521.                 VscrnScroll(VTERM,
  2522.                              DOWNWARD,
  2523.                              wherey[VTERM] - 1,
  2524.                              marginbot - 1,
  2525.                              1,
  2526.                              FALSE,
  2527.                              SP);
  2528.                 break;
  2529.             case 'M':
  2530.                 /* Delete Line */
  2531.                 if ( deblog ) {
  2532.                     sprintf(debbuf, "ESC %c", ch);
  2533.                     debug(F110,"HPTERM Delete Line",
  2534.                            debbuf,0);
  2535.                 }
  2536.                 if ( debses )
  2537.                     break;
  2538.  
  2539.                 VscrnScroll(VTERM,
  2540.                              UPWARD,
  2541.                              wherey[VTERM] - 1,
  2542.                              marginbot - 1,
  2543.                              1,
  2544.                              FALSE,
  2545.                              SP);
  2546.                 break;
  2547. #ifdef COMMENT
  2548.             case 'N':
  2549.                 break;
  2550.             case 'O':
  2551.                 break;
  2552. #endif /* COMMENT */
  2553.             case 'P':
  2554.                 /* Delete Char */
  2555.                 if ( deblog ) {
  2556.                     sprintf(debbuf, "ESC %c", ch);
  2557.                     debug(F110,"HPTERM Delete Char",
  2558.                            debbuf,0);
  2559.                 }
  2560.                 if ( debses )
  2561.                     break;
  2562.                 blankvcell.c = SP;
  2563.                 blankvcell.a = geterasecolor(VTERM);
  2564.                 VscrnScrollLf(VTERM, wherey[VTERM] - 1,
  2565.                                wherex[VTERM] - 1,
  2566.                                wherey[VTERM] - 1,
  2567.                                VscrnGetWidth(VTERM) - 1,
  2568.                                1, blankvcell) ;
  2569.  
  2570.                 break;
  2571.             case 'Q':
  2572.                 /* Inserts Character On */
  2573.                 if ( deblog ) {
  2574.                     sprintf(debbuf, "ESC %c", ch);
  2575.                     debug(F110,"HPTERM Inserts Character On",
  2576.                            debbuf,0);
  2577.                 }
  2578.                 if ( debses )
  2579.                     break;
  2580.                 insertmode = TRUE ;
  2581.                 break;
  2582.             case 'R':
  2583.                 /* Insert Character Off */
  2584.                 if ( deblog ) {
  2585.                     sprintf(debbuf, "ESC %c", ch);
  2586.                     debug(F110,"HPTERM Inserts Character Off",
  2587.                            debbuf,0);
  2588.                 }
  2589.                 if ( debses )
  2590.                     break;
  2591.                 insertmode = FALSE ;
  2592.                 break;
  2593.             case 'S':
  2594.                 /* Roll Up */
  2595.                 if ( deblog ) {
  2596.                     sprintf(debbuf, "ESC %c", ch);
  2597.                     debug(F110,"HPTERM Roll Up",
  2598.                            debbuf,0);
  2599.                 }
  2600.                 if ( debses )
  2601.                     break;
  2602.                 VscrnScroll(VTERM,
  2603.                              UPWARD,
  2604.                              0,
  2605.                              VscrnGetHeight(VTERM)
  2606.                              -(tt_status[VTERM]?2:1),
  2607.                              1,
  2608.                              TRUE,
  2609.                              SP);
  2610.                 break;
  2611.             case 'T':
  2612.                 /* Roll Down */
  2613.                 if ( deblog ) {
  2614.                     sprintf(debbuf, "ESC %c", ch);
  2615.                     debug(F110,"HPTERM Roll Down",
  2616.                            debbuf,0);
  2617.                 }
  2618.                 if ( debses )
  2619.                     break;
  2620.                 VscrnScroll(VTERM,
  2621.                              DOWNWARD,
  2622.                              0,
  2623.                              VscrnGetHeight(VTERM)
  2624.                              -(tt_status[VTERM]?2:1),
  2625.                              1,
  2626.                              TRUE,
  2627.                              SP);
  2628.                 break;
  2629.             case 'U':
  2630.                 /* Next Page */
  2631.                 if ( deblog ) {
  2632.                     sprintf(debbuf, "ESC %c", ch);
  2633.                     debug(F110,"HPTERM Next Page (unsupported)",
  2634.                            debbuf,0);
  2635.                 }
  2636.                 break;
  2637.             case 'V':
  2638.                 /* Previous Page */
  2639.                 if ( deblog ) {
  2640.                     sprintf(debbuf, "ESC %c", ch);
  2641.                     debug(F110,"HPTERM Previous Page (unsupported)",
  2642.                            debbuf,0);
  2643.                 }
  2644.                 break;
  2645. #ifdef COMMENT
  2646.             case 'W':
  2647.                 break;
  2648.             case 'X':
  2649.                 break;
  2650. #endif /* COMMENT */
  2651.             case 'Y':
  2652.                 /* Display Functions On */
  2653.                 if ( deblog ) {
  2654.                     sprintf(debbuf, "ESC %c", ch);
  2655.                     debug(F110,"HPTERM Display Functions On",
  2656.                            debbuf,0);
  2657.                 }
  2658.                 if ( debses || wy_monitor )
  2659.                     break;
  2660.                 setdebses(TRUE);
  2661.                 wy_monitor = TRUE ;
  2662.                 break;
  2663.             case 'Z':
  2664.                 /* Display Functions Off */
  2665.                 if ( deblog ) {
  2666.                     sprintf(debbuf, "ESC %c", ch);
  2667.                     debug(F110,"HPTERM Display Functions Off",
  2668.                            debbuf,0);
  2669.                 }
  2670.                 if ( !wy_monitor )
  2671.                     break;
  2672.                 setdebses(FALSE);
  2673.                 wy_monitor = FALSE ;
  2674.                 break;
  2675. #ifdef COMMENT
  2676.             case '[':
  2677.                 break;
  2678.             case '\\':
  2679.                 break;
  2680.             case ']':
  2681.                 break;
  2682. #endif /* COMMENT */
  2683.             case '^': {
  2684.                 /* Term Primary Status */
  2685.                 /* Respond with ESC \ terminal primary status bytes (Apdx C) */
  2686.                 char buf[11];
  2687.                 if ( deblog ) {
  2688.                     sprintf(debbuf, "ESC %c", ch);
  2689.                     debug(F110,"HPTERM Primary Status Request",
  2690.                            debbuf,0);
  2691.                 }
  2692.                 if ( debses )
  2693.                     break;
  2694.                 buf[0] = ESC ;
  2695.                 buf[1] = '\\';
  2696.                 buf[2] = '4';
  2697.                 buf[3] = '4';
  2698.                 buf[4] = '0';
  2699.                 buf[5] = '8';
  2700.                 buf[6] = '0';
  2701.                 buf[7] = '2';
  2702.                 buf[8] = '0';
  2703.                 buf[9] =  CR;
  2704.                 buf[10] = NUL;
  2705.                 sendchars(buf,10);
  2706.                 break;
  2707.             }
  2708. #ifdef COMMENT
  2709.             case '_':
  2710.                 break;
  2711. #endif /* COMMENT */
  2712.             case '`':
  2713.                 /* Relative Cursor Sense */
  2714.                 /* Respond with ESC & a column number x screen row Y */
  2715.                 if ( deblog ) {
  2716.                     sprintf(debbuf, "ESC %c", ch);
  2717.                     debug(F110,"HPTERM Relative Cursor Request",
  2718.                            debbuf,0);
  2719.                 }
  2720.                 if ( !debses )
  2721.                 {
  2722.                     char buf[20] ;
  2723.                     sprintf(buf,"%c&a%03dx%03dY\r",ESC,wherex[VTERM]-1,wherey[VTERM]-1);
  2724.                     sendchars(buf,strlen(buf));
  2725.                 }
  2726.                 break;
  2727.             case 'a':
  2728.                 /* Absolute Cursor Sense */
  2729.                 /* Respond with ESC & a column number c memory row R */
  2730.                 if ( deblog ) {
  2731.                     sprintf(debbuf, "ESC %c", ch);
  2732.                     debug(F110,"HPTERM Absolute Cursor Request",
  2733.                            debbuf,0);
  2734.                 }
  2735.                 if ( !debses )
  2736.                 {
  2737.                     char buf[20] ;
  2738.                     sprintf(buf,"%c&a%03dc%03dR\r",ESC,wherex[VTERM]-1,wherey[VTERM]-1);
  2739.                     sendchars(buf,strlen(buf));
  2740.                 }
  2741.                 break;
  2742.             case 'b':
  2743.                 /* Enable keyboard */
  2744.                 if ( deblog ) {
  2745.                     sprintf(debbuf, "ESC %c", ch);
  2746.                     debug(F110,"HPTERM Enable Keyboard",
  2747.                            debbuf,0);
  2748.                 }
  2749.                 if ( debses )
  2750.                     break;
  2751.                 keylock = FALSE ;
  2752.                 break;
  2753.             case 'c':
  2754.                 /* Disable keyboard */
  2755.                 if ( deblog ) {
  2756.                     sprintf(debbuf, "ESC %c", ch);
  2757.                     debug(F110,"HPTERM Disable Keyboard",
  2758.                            debbuf,0);
  2759.                 }
  2760.                 if ( debses )
  2761.                     break;
  2762.                 keylock = TRUE ;
  2763.                 break;
  2764.             case 'd':
  2765.                 /* Enter (Send current line) */
  2766.                 if ( deblog ) {
  2767.                     sprintf(debbuf, "ESC %c", ch);
  2768.                     debug(F110,"HPTERM Send Current Line",
  2769.                            debbuf,0);
  2770.                 }
  2771.                 if ( !debses )
  2772.                 {
  2773.                     int x;
  2774.                     for ( x=wherex[VTERM]-1;x<VscrnGetWidth(VTERM);x++ ) {
  2775.                         if ( !VscrnGetVtCharAttr(VTERM, x, wherey[VTERM]-1).unerasable ) {
  2776.                             unsigned short ch = VscrnGetCell( VTERM, x, wherey[VTERM]-1 )->c ;
  2777.                             if ( tt_senddata ) {
  2778.                                 unsigned char * bytes;
  2779.                                 int nbytes;
  2780.                                 if ( isunicode() )
  2781.                                     nbytes = utorxlat(ch,&bytes);
  2782.                                 else
  2783.                                     nbytes = utorxlat(ch,&bytes);
  2784.                                 while ( nbytes-- > 0 )
  2785.                                     sendchar(*bytes++) ;
  2786.                             } else
  2787.                                 sendchar(SP);
  2788.                         }
  2789.                     }
  2790.                     sendchar(CR);
  2791.                 }
  2792.                 break;
  2793. #ifdef COMMENT
  2794.             case 'e':
  2795.                 break;
  2796. #endif /* COMMENT */
  2797.             case 'f':
  2798.                 /* Modem Disconnect */
  2799.                 if ( deblog ) {
  2800.                     sprintf(debbuf, "ESC %c", ch);
  2801.                     debug(F110,"HPTERM Modem Disconnect (unsupported)",
  2802.                            debbuf,0);
  2803.                 }
  2804.  
  2805.                 break;
  2806. #ifdef COMMENT
  2807.             case 'g':
  2808.                 break;
  2809. #endif /* COMMENT */
  2810.             case 'h':
  2811.                 /* Home Cursor Up */
  2812.                 if ( deblog ) {
  2813.                     sprintf(debbuf, "ESC %c", ch);
  2814.                     debug(F110,"HPTERM Home Cursor Up",
  2815.                            debbuf,0);
  2816.                 }
  2817.                 if ( debses )
  2818.                     break;
  2819.  
  2820.                 lgotoxy(VTERM,1,1);
  2821.                 break;
  2822.             case 'i':
  2823.                 /* Back Tab */
  2824.                 if ( deblog ) {
  2825.                     sprintf(debbuf, "ESC %c", ch);
  2826.                     debug(F110,"HPTERM Back Tab",
  2827.                            debbuf,0);
  2828.                 }
  2829.                 if ( debses )
  2830.                     break;
  2831.                 i = wherex[VTERM];
  2832.                 if ( i == 1 && wherey[VTERM] != 1 ) {
  2833.                     wherex[VTERM] = VscrnGetWidth(VTERM);
  2834.                     cursorup(0);
  2835.                 }
  2836.                 if (i > 1) {
  2837.                     do {
  2838.                         i--;
  2839.                         cursorleft(0);
  2840.                     } while ((htab[i] != 'T') &&
  2841.                               (i >= 2));
  2842.  
  2843.                     /*
  2844.                     if the current cell is a protected cell, we must move
  2845.                     the current cursor to the first unprotected position.
  2846.                     */
  2847.                 }
  2848.                 VscrnIsDirty(VTERM);
  2849.                 break;
  2850. #ifdef COMMENT
  2851.             case 'j':
  2852.                 break;
  2853.             case 'k':
  2854.                 break;
  2855.             case 'l':   /* Lock Memory - HP Term ??? */
  2856.                 break;
  2857.             case 'm':   /* Unlock Memory - HP Term ??? */
  2858.                 break;
  2859.             case 'n':
  2860.                 break;
  2861.             case 'o':
  2862.                 break;
  2863. #endif /* COMMENT */
  2864.             case 'p':
  2865.             case 'q':
  2866.             case 'r':
  2867.             case 's':
  2868.             case 't':
  2869.             case 'u':
  2870.             case 'v':
  2871.             case 'w': {
  2872.                 /* set Softkey default values */
  2873.                 char string[3];
  2874.                 int keyi;
  2875.  
  2876.                 if ( deblog ) {
  2877.                     sprintf(debbuf, "ESC %c", ch);
  2878.                     debug(F110,"HPTERM Set Softkey Default Value",
  2879.                            debbuf,0);
  2880.                 }
  2881.                 if ( debses )
  2882.                     break;
  2883.                 sprintf(string,"%c%c",ESC,ch);
  2884.                 keyi = ch - 'p';
  2885.                 if ( udkfkeys[keyi] ){
  2886.                     free( udkfkeys[keyi] ) ;
  2887.                     udkfkeys[keyi]=NULL;
  2888.                 }
  2889.                 if ( strlen(string) )
  2890.                     udkfkeys[keyi] = strdup(string) ;
  2891.                 break;
  2892.             }
  2893. #ifdef COMMENT
  2894.             case 'x':
  2895.                 break;
  2896.             case 'y':
  2897.                 break;
  2898. #endif /* COMMENT */
  2899.             case 'z':
  2900.                 /* Terminal Self Test */
  2901.                 if ( deblog ) {
  2902.                     sprintf(debbuf, "ESC %c", ch);
  2903.                     debug(F110,"HPTERM Terminal Self Test (unsupported)",
  2904.                            debbuf,0);
  2905.                 }
  2906.                 break;
  2907. #ifdef COMMENT
  2908.             case '{':
  2909.                 break;
  2910.             case '|':
  2911.                 break;
  2912.             case '}':
  2913.                 break;
  2914. #endif /* COMMENT */
  2915.             case '~':
  2916.                 /* Secondary Terminal Status report */
  2917.                 if ( deblog ) {
  2918.                     sprintf(debbuf, "ESC %c", ch);
  2919.                     debug(F110,"HPTERM Secondary Status Report (unsupported)",
  2920.                            debbuf,0);
  2921.                 }
  2922.                 break;
  2923. #ifdef COMMENT
  2924.             case DEL:
  2925.                 break;
  2926. #endif /* COMMENT */
  2927.             default:
  2928.                 sprintf(debbuf,
  2929.                          "ESC %c",ch);
  2930.                 debug(F110,"HPTERM unknown command",debbuf,0);
  2931.             }
  2932.             escstate = ES_NORMAL ;      /* Done parsing escstate sequence */
  2933.         }
  2934.     }
  2935.     else                /* Handle as a normal character */
  2936.     {
  2937.         if ( ch < SP || ch == DEL )
  2938.             hpctrl(ch) ;
  2939.         else if ( !debses) {
  2940.             /* Display the character */
  2941.             if ( !tt_hidattr &&
  2942.                  (attrmode == ATTR_PAGE_MODE || attrmode == ATTR_LINE_MODE) ) {
  2943.                 vtattrib vta = VscrnGetVtCharAttr( VTERM, wherex[VTERM]-1, wherey[VTERM]-1 ) ;
  2944.                 if ( vta.wyseattr ) {
  2945.                     int x=wherex[VTERM]-1 ;
  2946.                     int y=wherey[VTERM]-1 ;
  2947.                     /* we are about to overwrite an attribute */
  2948.                     /* this results in the previous attribute being used for the entire */
  2949.                     /* this and subsequent cells */
  2950.                     vta.wyseattr = FALSE ;
  2951.                     VscrnSetVtCharAttr( VTERM, x, y, vta ) ;
  2952.  
  2953.                     /* now find previous attribute */
  2954.                     while ( !vta.wyseattr ) {
  2955.                         if ( --x < 0 ) {
  2956.                             if ( --y >= 0 )
  2957.                                 x = VscrnGetWidth(VTERM) ;
  2958.                             else {
  2959.                                 x = y = 0 ;
  2960.                                 break;  /* nowhere left to go */
  2961.                             }
  2962.                         }
  2963.                         vta = VscrnGetVtCharAttr( VTERM, x, y ) ;
  2964.                     }
  2965.  
  2966.                     if ( attrmode == ATTR_PAGE_MODE )
  2967.                         ApplyPageAttribute( VTERM, x+1, y+1, vta ) ;
  2968.                     else
  2969.                         ApplyLineAttribute( VTERM, x+1, y+1, vta ) ;
  2970.                 }
  2971.             }
  2972.             else {
  2973.                 vtattrib vta = VscrnGetVtCharAttr( VTERM, wherex[VTERM]-1, wherey[VTERM]-1 ) ;
  2974.                 if ( vta.wyseattr ) {
  2975.                     attrib.wyseattr = TRUE;
  2976.                     wrtch(ch);
  2977.                     attrib.wyseattr = FALSE;
  2978.                 }
  2979.                 else {
  2980.                     wrtch(ch);
  2981.                 }
  2982.             }
  2983.         }
  2984.     }
  2985.     VscrnIsDirty(VTERM) ;
  2986.     if ( attr_y != wherey[VTERM] ) {
  2987.         hpattroff();
  2988.         attr_y = wherey[VTERM];
  2989.     }
  2990. }
  2991. #endif /* NOTERM */
  2992.