home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckohzl.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  12KB  |  472 lines

  1. /*  C K O H Z L . C  --  Hazeltine 1500 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 "ckohzl.h"
  26. #ifdef NETCONN
  27. #ifdef TCPSOCKET
  28. #include "ckcnet.h"
  29. extern int network, nettype, ttnproto, u_binary;
  30. #endif /* TCPSOCKET */
  31. #endif /* NETCONN */
  32.  
  33. extern bool keyclick ;
  34. extern int  cursorena[], keylock, duplex, duplex_sav, screenon ;
  35. extern int  printon, aprint, uprint, xprint, cprint, seslog ;
  36. extern int  insertmode, tnlm ;
  37. extern int  escstate, debses, decscnm, tt_cursor ;
  38. extern int  tt_type, tt_type_mode, tt_max, tt_answer, tt_status[VNUM], tt_szchng[] ;
  39. extern int  tt_cols[], tt_rows[], tt_wrap ;
  40. extern int  wherex[], wherey[], margintop, marginbot ;
  41. extern int  marginbell, marginbellcol ;
  42. extern char answerback[], htab[] ;
  43. extern struct tt_info_rec tt_info[] ;
  44. extern vtattrib attrib ;
  45. extern unsigned char attribute;
  46. extern int ttpush;
  47. extern int autoscroll, protect ;
  48.  
  49. extern struct _vtG G[];
  50. extern struct _vtG *GL, *GR;
  51.  
  52. int hzesc = 1;
  53.  
  54. int hzgraphics = 0;
  55. static USHORT
  56. xlhzgrph( CHAR c ) {
  57.     USHORT cx = 0 ;
  58.     extern struct _vtG *GNOW;
  59.     extern int win95lucida;
  60.     extern int win95hsl;
  61.  
  62.     if ( isunicode() ) {
  63.         cx = (*xl_u[TX_HZ1500])(c) ;
  64.         if ( win95hsl && cx >= 0x23BA && cx <= 0x23BD )
  65.             cx = tx_hslsub(cx);
  66.         else if ( cx >= 0xE000 && cx <= 0xF8FF )
  67.             cx = tx_usub(cx);
  68.         if (win95lucida && cx > 0x017f)
  69.             cx = tx_lucidasub(cx);
  70.     }
  71.     else
  72.     {
  73.         cx = (*xl_u[TX_HZ1500])(c) ;
  74.         if ( GNOW->itol )
  75.             cx = (*GNOW->itol)(cx);
  76.     }
  77.     return(cx);
  78. }
  79.  
  80.  
  81. int
  82. hzlinc(void)
  83. {
  84.     extern int pmask, cmask;
  85.     extern int tt_utf8;
  86.     int ch;
  87.  
  88.   loop:
  89.     ch = ttinc(0);
  90.     if ( ch < 0 )
  91.         return ch;
  92.  
  93.     if ( seslog )
  94.         logchar(ch);
  95.  
  96.     /* Handle the UTF8 conversion if we are in that mode */
  97.     if ( tt_utf8 ) {
  98.         USHORT * ucs2 = NULL;
  99.         int rc = utf8_to_ucs2( (CHAR)(ch & 0xFF), &ucs2 );
  100.         if ( rc > 0 )
  101.             goto loop;
  102.         else if ( rc < 0 )
  103.             ch = 0xfffd;
  104.         else
  105.             ch = *ucs2;
  106.     }
  107.  
  108.     if ( !xprint ) {
  109. #ifndef NOXFER
  110.         autodown(ch);
  111. #endif /* NOXFER */
  112.         autoexitchk(ch);
  113.     }
  114.     ch = ch & pmask & cmask;
  115.     debugses(ch);
  116.     if (printon && (is_xprint() || is_uprint()))
  117.         prtchar(ch);
  118.     return ch;
  119. }
  120.  
  121. void
  122. hzlctrl( int ch )
  123. {
  124.     int i,j;
  125.  
  126.     if ( !xprint ) {
  127.     switch ( ch ) {
  128.     case SOH:
  129.     case STX:
  130.     case ETX:
  131.     case EOT:
  132.     case ENQ:
  133.     case ACK:
  134.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  135.         break;
  136.     case BEL:
  137.         if ( debses )
  138.             break;
  139.         bleep(BP_BEL);
  140.         break;
  141.     case BS:
  142.         /* Cursor Left */
  143.         if ( debses )
  144.             break;
  145.         cursorleft(0) ;
  146.         break;
  147.     case HT:
  148.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  149.         break;
  150.     case LF:
  151.         /* Linefeed */
  152.         if ( debses )
  153.             break;
  154.         wrtch((CHAR)LF);
  155.         break;
  156.     case VT:
  157.     case FF:
  158.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  159.         break;
  160.     case CR:
  161.         if ( debses )
  162.             break;
  163.         wrtch((char) CR);
  164.         break;
  165.     case SO:
  166.     case SI:
  167.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  168.         break;
  169.     case DLE: {
  170.         /* Cursor right */
  171.         if ( debses )
  172.             break;
  173.         cursorright(0);
  174.         break;
  175.     }
  176.     case DC1:
  177.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  178.         break;
  179.     case DC2:
  180.         /* WY30 defines this as Copy Print */
  181.         /* transparent printer with screen display */
  182.         if ( debses )
  183.             break;
  184.         cprint = TRUE ;
  185.         if ( !printon )
  186.             printeron() ;
  187.         break;
  188.     case DC3:
  189.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  190.         break;
  191.     case DC4:
  192.         /* Turn all print modes off */
  193.         if ( debses )
  194.             break;
  195.         xprint = cprint = FALSE ;
  196.         setaprint(FALSE);
  197.         if ( !uprint && !xprint && !cprint && !aprint && printon )
  198.             printeroff();
  199.         break;
  200.     case NAK:
  201.     case SYN:
  202.     case ETB:
  203.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  204.         break;
  205.     case CAN:
  206.         /* Transparent print on */
  207.         if ( debses )
  208.             break;
  209.         xprint = TRUE ;
  210.         if ( !printon )
  211.             printeron() ;
  212.         break;
  213.     case ESC:
  214.         debug(F111,"Hazeltine 1500","ESC",ch);
  215.         if ( debses )
  216.             break;
  217.  
  218.         if ( hzesc || ISWYSE(tt_type) ) {
  219.             debug(F110,"Hazeltine 1500","treating escape as tilde",0);
  220.             escstate = ES_GOTTILDE;
  221.         }
  222.         break;
  223.     case XEM:
  224.     case SUB:
  225.     case XFS:
  226.     case XGS:
  227.     case XRS:
  228.     case US:
  229.     default:
  230.         debug(F111,"Hazeltine 1500","unused Ctrl",ch);
  231.     }
  232.     } /* !xprint */
  233.     else {
  234.         switch ( ch ) {
  235.         case DC4:
  236.             /* Turn all print modes off */
  237.             if ( debses )
  238.                 break;
  239.             xprint = cprint = FALSE ;
  240.             setaprint(FALSE);
  241.             if ( !uprint && !xprint && !cprint && !aprint && printon )
  242.                 printeroff();
  243.             break;
  244.         }
  245.     }
  246. }
  247.  
  248. void
  249. hzlascii( int ch )
  250. {
  251.     int i,j,k,n,x,y,z;
  252.     vtattrib attr ;
  253.     viocell blankvcell;
  254.  
  255.     if (printon && (is_xprint() || is_uprint()))
  256.         prtchar(ch);
  257.  
  258.     if ( escstate == ES_GOTTILDE )/* Process character as part of an escstate sequence */
  259.     {
  260.         escstate = ES_TILDESEQ ;
  261.         switch ( ch ) {
  262.         case VT:
  263.             /* Cursor down */
  264.             if ( debses )
  265.                 break;
  266.             cursordown(0);
  267.             break;
  268.         case FF:
  269.             /* Cursor Up */
  270.             if ( debses )
  271.                 break;
  272.             cursorup(0);
  273.             break;
  274.         case SI:
  275.             /* Erase to EOL */
  276.             if ( debses )
  277.                 break;
  278.             clrtoeoln(VTERM,SP);
  279.             break;
  280.         case ENQ: {
  281.             /* Read cursor address in absolute position */
  282.             char buf[4] ;
  283.             if ( debses )
  284.                 break;
  285.             buf[0] = wherex[VTERM] < SP ? wherex[VTERM] + '`' : wherex[VTERM] ;
  286.             buf[1] = wherey[VTERM] < SP ? wherey[VTERM] + '`' : wherey[VTERM] ;
  287.             buf[2] = CR ;
  288.             buf[3] = NUL ;
  289.             sendchars(buf,3);
  290.             break;
  291.         }
  292.         case DC1: {
  293.             /* Absolute cursor position */
  294.             int col, line ;
  295.             col  = hzlinc();
  296. #ifdef NETCONN
  297. #ifdef TCPSOCKET
  298.             if ( network && IS_TELNET() && !TELOPT_U(TELOPT_BINARY) && col == CR ) {
  299.                 /* Handle TELNET CR-NUL or CR-LF if necessary */
  300.                 int dummy = ttinc(0);
  301.                 debug(F111,"Hazeltine 1500","Addr cursor in page found CR",dummy);
  302.                 if ( dummy != NUL )
  303.                     ttpush = dummy;
  304.             }
  305. #endif /* TCPSOCKET */
  306. #endif /* NETCONN */
  307.             line = hzlinc();
  308. #ifdef COMMENT
  309.         /* Is this really necessary?  Who cares if the next character is a NUL now that */
  310.         /* we know that the sequence is complete?                                       */
  311. #ifdef NETCONN
  312. #ifdef TCPSOCKET
  313.             if ( network && IS_TELNET() && !TELOPT_U(TELOPT_BINARY) && line == CR ) {
  314.                 /* Handle TELNET CR-NUL or CR-LF if necessary */
  315.                 int dummy = ttinc(0);
  316.                 debug(F111,"Hazeltine 1500","Addr cursor in page found CR",dummy);
  317.                 if ( dummy != NUL )
  318.                     ttpush = dummy;
  319.             }
  320. #endif /* TCPSOCKET */
  321. #endif /* NETCONN */
  322. #endif /* COMMENT */
  323.             if ( debses )
  324.                 break;
  325.             lgotoxy(VTERM,(col>='`'?col-'`':col)+1,(line>='`'?line-'`':line)+1);
  326.             break;
  327.         }
  328.         case DC2:
  329.             /* Home cursor */
  330.             if ( debses )
  331.                 break;
  332.             lgotoxy(VTERM,1,1);
  333.             break;
  334.         case DC3:
  335.             /* Delete Line */
  336.             if ( debses )
  337.                 break;
  338.             VscrnScroll(VTERM,
  339.                          UPWARD,
  340.                          wherey[VTERM] - 1,
  341.                          marginbot - 1,
  342.                          1,
  343.                          FALSE,
  344.                          SP);
  345.             break;
  346.         case ETB: {
  347.             /* Home Cursor and Clear Screen to Protected Spaces */
  348.             int xs = VscrnGetWidth(VTERM);
  349.             int ys = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  350.             vtattrib vta = {0,0,0,0,0,1,0,0,0,0,0}; /* Protected */
  351.             if ( debses )
  352.                 break;
  353.             clrscreen( VTERM, SP ) ;
  354.             lgotoxy(VTERM,1,1);       /* and home the cursor */
  355.             for ( y = 0 ; y < ys ; y++ )
  356.                 for ( x = 0 ; x < xs ; x++ )
  357.                     VscrnSetVtCharAttr( VTERM, x, y, vta ) ;
  358.             protect = FALSE ;
  359.             insertmode = FALSE ;
  360.             break;
  361.         }
  362.         case CAN:
  363.             /* Erase unprotected to EOS */
  364.             if ( debses )
  365.                 break;
  366.             selclreoscr_escape(VTERM,SP);
  367.             break;
  368.         case SUB:
  369.             /* Insert Line */
  370.             if ( debses )
  371.                 break;
  372.             VscrnScroll(VTERM,
  373.                          DOWNWARD,
  374.                          wherey[VTERM] - 1,
  375.                          marginbot - 1,
  376.                          1,
  377.                          FALSE,
  378.                          SP);
  379.             break;
  380.         case XFS:
  381.             /* Home Cursor and Clear Screen to spaces */
  382.             if ( debses )
  383.                 break;
  384.             cleartermscreen(VTERM);
  385.             break;
  386.         case XGS:
  387.             /* Home Cursor and Clear Unprotected Screen to Spaces - JEFFA */
  388.             if ( debses )
  389.                 break;
  390.             selclrscreen(VTERM,SP);
  391.             lgotoxy(VTERM,1,1);       /* and home the cursor */
  392.             break;
  393.         case 'F':
  394.             /* Enter graphics mode */
  395.             if ( debses )
  396.                 break;
  397.             hzgraphics = 1;
  398.             break;
  399.         case 'G':
  400.             /* Exit graphics mode */
  401.             if ( debses )
  402.                 break;
  403.             hzgraphics = 0;
  404.             break;
  405.         case ACK:
  406.             /* Key Lock */
  407.             if ( debses )
  408.                 break;
  409.             keylock = TRUE ;
  410.             break;
  411.         case NAK:
  412.             /* Unlock Keys */
  413.             if ( debses )
  414.                 break;
  415.             keylock = FALSE ;
  416.             break;
  417.         case US:
  418.             /* Write-protect mode off */
  419.             if ( debses )
  420.                 break;
  421.             attrib.unerasable = FALSE;
  422.             break;
  423.         case XEM:
  424.             /* Write-protect mode on */
  425.             if ( debses )
  426.                 break;
  427.             attrib.unerasable = TRUE;
  428.             break;
  429.         case '1':
  430.             /* Enable Keyclick */
  431.             if ( debses )
  432.                 break;
  433.             setkeyclick(TRUE);
  434.             break;
  435.         case '2':
  436.             /* Disable Keyclick */
  437.             if ( debses )
  438.                 break;
  439.             setkeyclick(FALSE);
  440.             break;
  441.         case '~':
  442.             /* Tilde Tilde does not change the escape state */
  443.             return;
  444.         default:
  445.             debug(F111,"Hazeltine 1500","unknown ESC sequence",ch);
  446.             /* if the original terminal type is Wyse, then see if it is */
  447.             /* one of the enhanced wyse escape sequences.               */
  448.             if ( ISWYSE(tt_type) ) {
  449.                 debug(F110,"Hazeltine 1500","attempting Wyse ESC sequence",0);
  450.                 escstate = ES_GOTESC;
  451.                 wyseascii(ch);
  452.             }
  453.         }
  454.         escstate = ES_NORMAL ;
  455.     } else if ( escstate == ES_GOTESC ) {
  456.         wyseascii(ch);
  457.     } else {            /* Handle as a normal character */
  458.         if ( ch == '~' )
  459.             escstate = ES_GOTTILDE ;
  460.         else if ( ch < SP )
  461.             hzlctrl(ch) ;
  462.         else if ( !debses && ch != DEL ) {
  463.             if ( hzgraphics )
  464.                 ch = xlhzgrph( ch ) ;
  465.             wrtch(ch);
  466.         }
  467.     }
  468.     VscrnIsDirty(VTERM) ;
  469. }
  470. #endif /* NOTERM */
  471.  
  472.