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

  1. /*  C K O A D M . C  --  ADM-3A 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 "ckoadm.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
  53. adminc(void)
  54. {
  55.     extern int pmask, cmask;
  56.     extern int tt_utf8;
  57.     int ch;
  58.  
  59.   loop:
  60.     ch = ttinc(0);
  61.     if ( ch < 0 )
  62.         return ch;
  63.  
  64.     if ( seslog )
  65.         logchar(ch);
  66.  
  67.     /* Handle the UTF8 conversion if we are in that mode */
  68.     if ( tt_utf8 ) {
  69.         USHORT * ucs2 = NULL;
  70.         int rc = utf8_to_ucs2( (CHAR)(ch & 0xFF), &ucs2 );
  71.         if ( rc > 0 )
  72.             goto loop;
  73.         else if ( rc < 0 )
  74.             ch = 0xfffd;
  75.         else
  76.             ch = *ucs2;
  77.     }
  78.  
  79.     if ( !xprint ) {
  80. #ifndef NOXFER
  81.         autodown(ch);
  82. #endif /* NOXFER */
  83.         autoexitchk(ch);
  84.     }
  85.     ch = ch & pmask & cmask;
  86.     debugses(ch);
  87.     if (printon && (is_xprint() || is_uprint()))
  88.         prtchar(ch);
  89.     return ch;
  90. }
  91.  
  92. void
  93. admctrl( int ch )
  94. {
  95.     int i,j;
  96.  
  97.     if ( !xprint ) {
  98.     switch ( ch ) {
  99.     case SOH:
  100.     case STX:
  101.     case ETX:
  102.     case EOT:
  103.         debug(F111,"ADM-3A","unused Ctrl",ch);
  104.         break;
  105.     case ENQ: /* Answerback Message */
  106.         if ( debses )
  107.             break;
  108.         sendcharsduplex(answerback,strlen(answerback), FALSE) ;
  109.         break;
  110.     case ACK:
  111.         debug(F111,"ADM-3A","unused Ctrl",ch);
  112.         break;
  113.     case BEL:
  114.         if ( debses )
  115.             break;
  116.         bleep(BP_BEL);
  117.         break;
  118.     case BS:
  119.         /* Cursor Left */
  120.         if ( debses )
  121.             break;
  122.         cursorleft(0) ;
  123.         break;
  124.     case HT:
  125.         debug(F111,"ADM-3A","unused Ctrl",ch);
  126.         break;
  127.     case LF:
  128.         /* Linefeed */
  129.         if ( debses )
  130.             break;
  131.         wrtch((CHAR)LF);
  132.         break;
  133.     case VT:
  134.         if ( debses )
  135.             break;
  136.         cursorup(0);
  137.         break;
  138.     case FF:
  139.         if ( debses )
  140.             break;
  141.         cursorright(0);
  142.         break;
  143.     case CR:
  144.         if ( debses )
  145.             break;
  146.         wrtch((char) CR);
  147.         break;
  148.     case SO: /* lock keyboard */
  149.         if ( debses )
  150.             break;
  151.         keylock = TRUE;
  152.         break;
  153.     case SI: /* unlock keyboard */
  154.         if ( debses )
  155.             break;
  156.         keylock = FALSE;
  157.         break;
  158.     case DLE:
  159.     case DC1:
  160.     case DC2:
  161.     case DC3:
  162.     case DC4:
  163.     case NAK:
  164.     case SYN:
  165.     case ETB:
  166.     case CAN:
  167.         debug(F111,"ADM-3A","unused Ctrl",ch);
  168.         break;
  169.     case ESC:
  170.         debug(F111,"ADM-3A","ESC",ch);
  171.         if ( debses )
  172.             break;
  173.         escstate = ES_GOTESC;
  174.         break;
  175.     case XEM:
  176.         debug(F111,"ADM-3A","unused Ctrl",ch);
  177.         break;
  178.     case SUB: /* Clear Screen */
  179.         if ( debses )
  180.             break;
  181.         cleartermscreen(VTERM);
  182.         break;
  183.     case XFS:
  184.     case XGS:
  185.         debug(F111,"ADM-3A","unused Ctrl",ch);
  186.         break;
  187.     case XRS: /* Home cursor */
  188.         if ( debses )
  189.             break;
  190.         lgotoxy(VTERM,1,1);
  191.         break;
  192.     case US:
  193.     default:
  194.         debug(F111,"ADM-3A","unused Ctrl",ch);
  195.     }
  196.     } /* !xprint */
  197.     else {
  198.         switch ( ch ) {
  199.         default:
  200.             break; /* There are no print commands */
  201.         }
  202.     }
  203. }
  204.  
  205. void
  206. admascii( int ch )
  207. {
  208.     int i,j,k,n,x,y,z;
  209.     vtattrib attr ;
  210.     viocell blankvcell;
  211.  
  212.     if (printon && (is_xprint() || is_uprint()))
  213.         prtchar(ch);
  214.  
  215.     if ( escstate == ES_GOTESC )/* Process character as part of an escstate sequence */
  216.     {
  217.         escstate = ES_ESCSEQ ;
  218.         switch ( ch ) {
  219.         case '=': {
  220.             /* Absolute cursor position */
  221.             int col, line ;
  222.             line  = adminc();
  223. #ifdef NETCONN
  224. #ifdef TCPSOCKET
  225.             if ( network && IS_TELNET() && !TELOPT_U(TELOPT_BINARY) && line == CR ) {
  226.                 /* Handle TELNET CR-NUL or CR-LF if necessary */
  227.                 int dummy = ttinc(0);
  228.                 debug(F111,"ADM-3A","Addr cursor in page found CR",dummy);
  229.                 if ( dummy != NUL )
  230.                     ttpush = dummy;
  231.             }
  232. #endif /* TCPSOCKET */
  233. #endif /* NETCONN */
  234.             col = adminc();
  235. #ifdef COMMENT
  236.         /* Is this really necessary?  Who cares if the next character is a NUL now that */
  237.         /* we know that the sequence is complete?                                       */
  238. #ifdef NETCONN
  239. #ifdef TCPSOCKET
  240.             if ( network && IS_TELNET() && !TELOPT_U(TELOPT_BINARY) && col == CR ) {
  241.                 /* Handle TELNET CR-NUL or CR-LF if necessary */
  242.                 int dummy = ttinc(0);
  243.                 debug(F111,"ADM-3A","Addr cursor in page found CR",dummy);
  244.                 if ( dummy != NUL )
  245.                     ttpush = dummy;
  246.             }
  247. #endif /* TCPSOCKET */
  248. #endif /* NETCONN */
  249. #endif /* COMMENT */
  250.             if ( debses )
  251.                 break;
  252.             lgotoxy(VTERM,(col-SP)+1,(line-SP)+1);
  253.             break;
  254.         }
  255.         case 'T': /* ADM 5 - clear to end of line with SP */
  256.             debug(F110,"ADM-5","Clear to End of Line with SP",0);
  257.             if ( debses )
  258.                 break;
  259.             clrtoeoln( VTERM, SP );
  260.             break;
  261.         case 'Y': /* ADM 5 - clear to end of page with SP */
  262.             debug(F110,"ADM-5","Clear to Screen of Line with SP",0);
  263.             if ( debses )
  264.                 break;
  265.             clreoscr_escape( VTERM, SP );
  266.             break;
  267.         case '(': /* ADM 5 - restore standard intensity */
  268.             debug(F110,"ADM-5","Restore Standard Intensity",0);
  269.             if ( debses )
  270.                 break;
  271.             break;
  272.         case ')': /* ADM 5 - set reduced intensity */
  273.             debug(F110,"ADM-5","Set Reduced Intensity",0);
  274.             if ( debses )
  275.                 break;
  276.             break;
  277.         case 'G': /* ADM 5 - toggle reverse intensity */
  278.             debug(F110,"ADM-5","Toggle Reverse Intensity",0);
  279.             if ( debses )
  280.                 break;
  281.             break;
  282.         default:
  283.             debug(F111,"ADM-3A","unknown ESC sequence",ch);
  284.         }
  285.         escstate = ES_NORMAL ;
  286.     }
  287.     else {            /* Handle as a normal character */
  288.         if ( ch < SP )
  289.             admctrl(ch) ;
  290.         else if ( !debses && ch != DEL ) {
  291.             wrtch(ch);
  292.         }
  293.     }
  294.     VscrnIsDirty(VTERM) ;
  295. }
  296. #endif /* NOTERM */
  297.  
  298.