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

  1. /*  C K O A V A . C  --  AVATAR 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 "ckocon.h"
  24. #include "ckoava.h"
  25.  
  26. extern bool keyclick ;
  27. extern int  cursorena[], keylock, duplex, duplex_sav, screenon ;
  28. extern int  printon, aprint, uprint, cprint, xprint, seslog ;
  29. extern int  insertmode, tnlm ;
  30. extern int  escstate, debses, decscnm, tt_cursor ;
  31. extern int  tt_type, tt_type_mode, tt_max, tt_answer, tt_status[VNUM], tt_szchng[] ;
  32. extern int  tt_cols[], tt_rows[], tt_wrap ;
  33. extern int  wherex[], wherey[], margintop, marginbot ;
  34. extern int  marginbell, marginbellcol ;
  35. extern char answerback[], htab[] ;
  36. extern struct tt_info_rec tt_info[] ;
  37. extern vtattrib attrib ;
  38. extern unsigned char attribute;
  39.  
  40. extern int autoscroll, protect ;
  41.  
  42. int
  43. avainc( int striphighbit )
  44. {
  45.     extern int pmask, cmask;
  46.     extern int tt_utf8;
  47.     int ch;
  48.  
  49.   loop:
  50.     ch = ttinc(0);
  51.     if ( ch < 0 )
  52.         return ch;
  53.  
  54.     if ( seslog )
  55.         logchar(ch);
  56.  
  57.     /* Handle the UTF8 conversion if we are in that mode */
  58.     if ( tt_utf8 ) {
  59.         USHORT * ucs2 = NULL;
  60.         int rc = utf8_to_ucs2( (CHAR)(ch & 0xFF), &ucs2 );
  61.         if ( rc > 0 )
  62.             goto loop;
  63.         else if ( rc < 0 )
  64.             ch = 0xfffd;
  65.         else
  66.             ch = *ucs2;
  67.     }
  68.  
  69.     if ( !xprint ) {
  70. #ifndef NOXFER
  71.         autodown(ch);
  72. #endif /* NOXFER */
  73.         autoexitchk(ch);
  74.     }
  75.     debugses(ch);
  76.     if ( striphighbit )
  77.         ch &= 0x7F ;
  78.     ch = ch & pmask & cmask;
  79.     if (printon && (is_xprint() || is_uprint()))
  80.         prtchar(ch);
  81.     return ch;
  82. }
  83.  
  84. void
  85. avatar(void)
  86. {
  87.     int i,j;
  88.     int ch = avainc(1) ;
  89.  
  90.     switch ( ch ) {
  91.         /* These are AVATAR/0 commands */
  92.  
  93.     case SOH: {
  94.         /* 1 - set current attribute */
  95.         int attr = avainc(1) ;
  96.         if ( debses )
  97.             break;
  98.         attribute = attr ;
  99.         attrib.blinking = FALSE ;
  100.         insertmode = FALSE ;
  101.         break;
  102.     }
  103.     case STX:
  104.         /* 0 - turn blink on */
  105.         if ( debses )
  106.             break;
  107.         attrib.blinking = TRUE ;
  108.         insertmode = FALSE ;
  109.         break;
  110.     case ETX:
  111.         /* 0 - move cursor up one line */
  112.         if ( debses )
  113.             break;
  114.         cursorup(0);
  115.         insertmode = FALSE ;
  116.         break;
  117.     case EOT:
  118.         /* 0 - move cursor down one line */
  119.         if ( debses )
  120.             break;
  121.         cursordown(0);
  122.         insertmode = FALSE ;
  123.         break;
  124.     case ENQ: {
  125.         /* 0 - move cursor left one column */
  126.         if ( debses )
  127.             break;
  128.         cursorleft(0) ;
  129.         insertmode = FALSE ;
  130.         break;
  131.     }
  132.     case ACK:
  133.         /* 0 - move cursor right one column */
  134.         if ( debses )
  135.             break;
  136.         cursorright(0) ;
  137.         insertmode = FALSE ;
  138.         break;
  139.  
  140.     case BEL:
  141.         /* 0 - clear to end of line */
  142.         if ( debses )
  143.             break;
  144.         clrtoeoln(VTERM,SP);
  145.         insertmode = FALSE ;
  146.         break;
  147.     case BS: {
  148.         /* 2 - locate cursor position */
  149.         int row, col ;
  150.         row = avainc(1) ;
  151.         col = avainc(1) ;
  152.         if ( debses )
  153.             break;
  154.         lgotoxy( VTERM, col, row ) ;
  155.         insertmode = FALSE ;
  156.         break;
  157.     }
  158.  
  159.         /* Now we start the AVATAR/0+ commands */
  160.     case HT:
  161.         /* 0 - turn insert mode on */
  162.         if ( debses )
  163.             break;
  164.         insertmode = TRUE ;
  165.         break;
  166.     case LF: {
  167.         /* 5 - scroll area up */
  168.         int numlines, upper, left, lower, right ;
  169.         viocell cell ;
  170.  
  171.         numlines = avainc(1) ;
  172.         upper = avainc(1) ;
  173.         left = avainc(1) ;
  174.         lower = avainc(1) ;
  175.         right = avainc(1) ;
  176.  
  177.         if ( debses )
  178.             break;
  179.  
  180.         cell.c = SP ;
  181.         cell.a = attribute ;
  182.  
  183.         VscrnScrollUp( VTERM, upper-1, left-1, lower-1, right-1,
  184.                        numlines, cell ) ;
  185.         break;
  186.     }
  187.     case VT: {
  188.         /* 5 - scroll area down */
  189.         int numlines, upper, left, lower, right ;
  190.         viocell cell ;
  191.  
  192.         numlines = avainc(1) ;
  193.         upper = avainc(1) ;
  194.         left = avainc(1) ;
  195.         lower = avainc(1) ;
  196.         right = avainc(1) ;
  197.         if ( debses )
  198.             break;
  199.  
  200.         cell.c = SP ;
  201.         cell.a = attribute ;
  202.  
  203.         VscrnScrollDn( VTERM, upper-1, left-1, lower-1, right-1,
  204.                        numlines, cell ) ;
  205.         break;
  206.     }
  207.     case FF: {
  208.         /* 3 - clear area, set current attribute */
  209.         int attr, lines, cols ;
  210.         int x, y ;
  211.         viocell cell ;
  212.  
  213.         attr = avainc(1) ;
  214.         lines = avainc(1) ;
  215.         cols = avainc(1) ;
  216.  
  217.         if ( debses )
  218.             break;
  219.  
  220.         attribute = attr ;
  221.         attrib.blinking = FALSE ;
  222.  
  223.         cell.c = SP ;
  224.         cell.a = attribute ;
  225.  
  226.         for ( y=0 ; y < lines ; y++ )
  227.             for ( x=0 ; x < cols ; x++ )
  228.                 VscrnWrtCell( VTERM, cell, attrib,
  229.                               wherey[VTERM]-1+y,
  230.                               wherex[VTERM]-1+x ) ;
  231.         break;
  232.     }
  233.     case CR: {
  234.         /* 4 - initialize area, set current attribute */
  235.         int attr, ch, lines, cols ;
  236.         int x, y ;
  237.         viocell cell ;
  238.  
  239.         attr = avainc(0) ;
  240.         ch = avainc(1) ;
  241.         lines = avainc(1) ;
  242.         cols = avainc(1) ;
  243.  
  244.         if ( debses )
  245.             break;
  246.  
  247.         attribute = attr ;
  248.         attrib.blinking = FALSE ;
  249.  
  250.         cell.c = ch ;
  251.         cell.a = attribute ;
  252.  
  253.         for ( y=0 ; y < lines ; y++ )
  254.             for ( x=0 ; x < cols ; x++ )
  255.                 VscrnWrtCell( VTERM, cell, attrib,
  256.                               wherey[VTERM]-1+y,
  257.                               wherex[VTERM]-1+x ) ;
  258.         break;
  259.     }
  260.     case SO: {
  261.         /* 0 - delete character, scroll eol left */
  262.         viocell cell ;
  263.         if ( debses )
  264.             break;
  265.         cell.c = SP ;
  266.         cell.a = attribute ;
  267.         VscrnScrollLf(VTERM, wherey[VTERM] - 1,
  268.                        wherex[VTERM] - 1,
  269.                        wherey[VTERM] - 1,
  270.                        VscrnGetWidth(VTERM) - 1,
  271.                        1, cell ) ;
  272.         break;
  273.     }
  274.  
  275. #ifdef AVATAR1
  276.         /* And now AVATAR/1 commands */
  277.     case SI:
  278.         /* 0 - turn clockwise mode on */
  279.         if ( debses )
  280.             break;
  281.         break;
  282.     case DLE:
  283.         /* ? - dummy call, NOP */
  284.         if ( debses )
  285.             break;
  286.         break;
  287. #endif /* AVATAR1 */
  288.     case DC1: {
  289.         /* 1 - query the driver */
  290.         int query = avainc(1) ;
  291.         if ( debses )
  292.             break;
  293.         if ( query == DC1 ) {
  294.             sendchars("AVT0, Kermit ANSI-BBS Terminal\r",31);
  295.         }
  296.         break;
  297.     }
  298. #ifdef AVATAR1
  299.     case DC2:
  300.         /* 0 - reset the driver */
  301.         if ( debses )
  302.             break;
  303.         break;
  304.     case DC3: {
  305.         /* 3 - sound a tone */
  306.         int tone, octave, duration ;
  307.         tone = avainc(1) ;
  308.         octave = avainc(1);
  309.         duration = avainc(1);
  310.  
  311.         if ( debses )
  312.             break;
  313.         break;
  314.     }
  315.     case DC4: {
  316.         /* 1 - highlight cursor position */
  317.         int attr = avainc(1);
  318.         if ( debses )
  319.             break;
  320.         break;
  321.     }
  322.     case NAK: {
  323.         /* 2 - hightlight a window */
  324.         int window, attr ;
  325.         window = avainc(1);
  326.         attr = avainc(1);
  327.         if ( debses )
  328.             break;
  329.         break;
  330.     }
  331.     case SYN: {
  332.         /* 6 - define a window */
  333.         int window, attr, c,d,e,f ;
  334.         window = avainc(1);
  335.         attr = avainc(1);
  336.         c=avainc(1);
  337.         d=avainc(1);
  338.         e=avainc(1);
  339.         f=avainc(1);
  340.         if ( debses )
  341.             break;
  342.         break;
  343.     }
  344.     case ETB:
  345.         /* 0 - flush input */
  346.         if ( debses )
  347.             break;
  348.         break;
  349.     case CAN: {
  350.         /* 1 - switch to a window */
  351.         int window = avainc(1);
  352.         if ( debses )
  353.             break;
  354.         break;
  355.     }
  356. #endif /* AVATAR1 */
  357.  
  358.     case XEM: {
  359.         /* * - repeat pattern */
  360.         int ch, count;
  361.         ch = avainc(1) ;
  362.         if ( debses )
  363.             break;
  364.         count = avainc(1) ;
  365.         while ( count-- )
  366.             wrtch(ch);
  367.         break;
  368.     }
  369.  
  370. #ifdef AVATAR1
  371.     case SUB:
  372.         /* ? - reserved  */
  373.         if ( debses )
  374.             break;
  375.         break;
  376. #endif /* AVATAR1 */
  377.  
  378.     case ESC:
  379.         /* ? - reserved for ANSI */
  380.         escstate = ES_GOTESC ;
  381.         break;
  382.  
  383. #ifdef AVATAR1
  384.     case XFS:
  385.         /* 0 - go to sleep */
  386.         if ( debses )
  387.             break;
  388.         break;
  389.     case XGS:
  390.         /* 0 - wake up */
  391.         if ( debses )
  392.             break;
  393.         break;
  394.     case XRS:
  395.         /* 0 - start vertical mode */
  396.         if ( debses )
  397.             break;
  398.         break;
  399.     case US:
  400.         /* 0 - end vertical mode */
  401.         if ( debses )
  402.             break;
  403.         break;
  404.     case SP:
  405.         /* 0 - reserved */
  406.         break;
  407.     case '!': {
  408.         /* 4 - poke */
  409.         int ch, attr, c, d ;
  410.         ch = avainc(1);
  411.         attr = avainc(1) ;
  412.         c = avainc(1) ;
  413.         d = avainc(1) ;
  414.         if ( debses )
  415.             break;
  416.         break;
  417.     }
  418.     case '"':
  419.         /* - 0 - do not wrap at eol (wrap off)         */
  420.         tt_wrap = FALSE ;
  421.         break;
  422.     case '#':
  423.         /* - 0 - switch direction at eol (wrap zigzag) */
  424.         break;
  425.     case '$':
  426.         /* - 0 - wrap at eol (wrap on)                 */
  427.         tt_wrap = TRUE ;
  428.         break;
  429.     case '%':
  430.         /* - 0 - reverse LF action                     */
  431.         break;
  432.     case '&':
  433.         /* - 0 - normalize LF action                   */
  434.         break;
  435.     case '\'':   {
  436.         /* - 1 - set cursor type                       */
  437.         int type = avainc(1);
  438.         if ( debses )
  439.             break;
  440.         break;
  441.     }
  442.     case '(':
  443.         /* - 0 - do not print in reverse               */
  444.         break;
  445.     case ')':
  446.         /* - 0 - print in reverse                      */
  447.         break;
  448.     case '*':   {
  449.         /* - 1 - make system pause                     */
  450.         int duration = avainc(1) ;
  451.         if ( debses )
  452.             break;
  453.         break;
  454.     }
  455.     case '+':
  456.         /* - 0 - insert line                           */
  457.         break;
  458.     case ',':
  459.         /* - 0 - insert column                         */
  460.         break;
  461.     case '-':
  462.         /* - 0 - delete line                           */
  463.         break;
  464.     case '.':
  465.         /* - 0 - delete column                         */
  466.         break;
  467.     case '/':  {
  468.         /* - 1 - set/reset static mode                 */
  469.         int mode = avainc(1) ;
  470.         if ( debses )
  471.             break;
  472.         break;
  473.     }
  474.     case '0':   {
  475.         /* - 1 - highlight eol                         */
  476.         int attr = avainc(1) ;
  477.         if ( debses )
  478.             break;
  479.         break;
  480.     }
  481.     case '1':   {
  482.         /* - 1 - highlight bol                         */
  483.         int attr = avainc(1) ;
  484.         if ( debses )
  485.             break;
  486.         break;
  487.     }
  488.     case ':': {
  489.         /* - 1 - keyboard mode                         */
  490.         int mode = avainc(1) ;
  491.         if ( debses )
  492.             break;
  493.         break;
  494.     }
  495.     case ';':
  496.         /* - ? - <reserved>                            */
  497.         break;
  498.     case '<':    {
  499.         /* - 5 - scroll area left                      */
  500.         int a, b, c, d, e ;
  501.         a = avainc(1);
  502.         b = avainc(1);
  503.         c = avainc(1);
  504.         d = avainc(1);
  505.         e = avainc(1);
  506.         if ( debses )
  507.             break;
  508.         break;
  509.     }
  510.     case '=':    {
  511.         /* - 1 - set parser mode (cooked or raw)       */
  512.         int mode = avainc(1);
  513.         if ( debses )
  514.             break;
  515.         break;
  516.     }
  517.     case '>':   {
  518.         /* - 5 - scroll area right                     */
  519.         int a, b, c, d, e ;
  520.         a = avainc(1);
  521.         b = avainc(1);
  522.         c = avainc(1);
  523.         d = avainc(1);
  524.         e = avainc(1);
  525.         if ( debses )
  526.             break;
  527.         break;
  528.     }
  529.     case '?':   {
  530.         /* - 2 - peek                                  */
  531.         int a, b ;
  532.         a = avainc(1);
  533.         b = avainc(1);
  534.         if ( debses )
  535.             break;
  536.         break;
  537.     }
  538. #endif  /* AVATAR1 */
  539.     }
  540. }
  541. #endif /* NOTERM */
  542.  
  543.