home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / convergent / ctconu.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  6KB  |  312 lines

  1. char *connv = "Connect functions CTOS Version-1.00, Summer 1987";
  2.  
  3. /*  C K C O N U  --  Terminal connection to remote system */
  4.  
  5. /* modified for CTOS C2.0 by Joel Dunn, UNC-CH, October 1986 */
  6.  
  7. #include "ctermi.h"
  8.  
  9. extern int local, speed, escape, duplex, parity, flow, seslog, mdmtyp,
  10.             termtype;
  11. extern char ttname[], sesfil[];
  12.  
  13. /* Variables global to this module */
  14. int c;            /* c is a character, but must be signed 
  15.                integer to pass thru -1, which is the
  16.                modem disconnection signal, and is
  17.                different from the character 0377 */
  18. int i, active;
  19.  
  20. char *chstr();
  21.  
  22. /*  C O N E C T  --  Perform terminal connection  */
  23.  
  24. conect() {
  25.     int n;
  26.     char errmsg[50], *erp;
  27.  
  28.     if (!local) {
  29.         printf("Sorry, you must 'set line' first\n");
  30.         return(-2);
  31.     }
  32.     if (speed < 0) {
  33.         printf("Sorry, you must 'set speed' first\n");
  34.         return(-2);
  35.         }
  36.     if ((escape < 0) || (escape > 0177)) {
  37.         printf("Your escape character is not ASCII - %d\n",escape);
  38.         return(-2);
  39.     }
  40.     if (ttopen(ttname,local,mdmtyp) < 0) {
  41.         erp = errmsg;
  42.         sprintf(erp,"Sorry, can't open %s",ttname);
  43.         perror(errmsg);
  44.         return(-2);
  45.         }
  46.         printf("\nConnecting thru %s, speed %d.\r\n",ttname,speed);
  47.     printf("The local escape character is %s (%d).\r\n",chstr(escape),escape);
  48.     printf("Type the local escape character followed by C to get back,\r\n");
  49.     printf("or followed by ? to see other options.\r\n");
  50.     if (seslog) printf("(Session logged to %s.)\r\n",sesfil);
  51.  
  52. /* Condition console terminal and communication line */        
  53.  
  54.         if (conbin(escape) < 0) {
  55.         printf("Sorry, can't condition console terminal\n");
  56.         return(-2);
  57.         }
  58.     if (ttvt(speed,flow) < 0) {
  59.         conres();
  60.         printf("Sorry, Can't condition communication line\n");
  61.         return(-2);
  62.         }
  63.  
  64. /* Select connect function based on terminal type */
  65.     switch (termtype)
  66.         {
  67.         case 0:                    /* TTY */
  68.             contty();
  69.             return(0);
  70.         case 1:                    /* VT100, routines in ckvt100.c */
  71.             convt100();
  72.             return(0);
  73.         default:                     /* other value */
  74.             printf("\n\nInvalid terminal type.\n\n");
  75.             return(-2);
  76.         }
  77.  
  78. }
  79.  
  80. /*  C O N T T Y  --  Connect in TTY mode */
  81. contty()
  82.  
  83. {
  84.     printf("\n\nConnected in TTY Emulation Mode\n");
  85.     active = 1;
  86.     while (((c = ttinc(0)) >= 0) & active)
  87.         {
  88.  
  89. /* read, prints port input */
  90.  
  91.         if (c > 0)
  92.             {
  93.             c &= 0177;        /* Got a char, strip parity. */
  94.             conoc(c);        /* Put it on the screen. */
  95.             if (seslog) zchout(ZSFILE,c);    /* If logging, log it. */
  96.             }
  97.  
  98. /* read, prints keyboard input */
  99.  
  100.         c = coninc(0) & 0177;
  101.         if (c == escape) 
  102.             {       /* Look for escape char */
  103.                 c = coninc(9999) & 0177;
  104.                 doesc(c);
  105.             } 
  106.         else if (c > 0)
  107.                 {        /* Ordinary character */
  108.                     ttoc(dopar(c));    /* Send with desired parity */
  109.                     if (duplex) {    /* Half duplex? */
  110.                     conoc(c);    /* Yes, echo it. */
  111.                     /* And maybe log it. */
  112.                     if (seslog) zchout(ZSFILE,c);
  113.                 }            
  114.                 }
  115.  
  116.         }
  117.  
  118.         if (c < 0) 
  119.             { /* Comm line hangup detected*/
  120.                 printf("\r\nCommunications line failure\r\n");
  121.             }
  122.         conres();            /* Reset the console. */
  123.         printf("\nTTY Emulation Disconnected\n");
  124.         return(0);
  125. }
  126.  
  127. /*  H C O N N E  --  Give help message for connect.  */
  128.  
  129. hconne() {
  130.     int c;
  131.     static char *hlpmsg[] = {"\
  132. \r\nC to close the connection, or:",
  133. "\r\n  S for status",
  134. "\r\n  ? for help",
  135. "\r\n  B to send a BREAK",
  136. "\r\n  0 to send a null",
  137. "\r\n escape character twice to send the escape character.\r\n\r\n",
  138. "" };
  139.  
  140.     conola(hlpmsg);            /* Print the help message. */
  141.     conol("Command>");            /* Prompt for command. */
  142.     c = coninc(9999);
  143.     conoc(c);                /* Echo it. */
  144.     conoll("");
  145.     c &= 0177;                /* Strip any parity. */
  146.     return(c);                /* Return it. */
  147. }
  148.  
  149.  
  150. /*  C H S T R  --  Make a printable string out of control key */
  151.  
  152. static char *
  153. chstr(c) int c; {
  154.     static char s[15];
  155.     char *cp = s;
  156.  
  157.     switch (c)
  158.         {
  159.         case 0:
  160.             sprintf(cp,"HELP");
  161.             break;
  162.         case 1:
  163.             sprintf(cp,"'up arrow'");
  164.             break;
  165.         case 2:
  166.             sprintf(cp,"MARK");
  167.             break;
  168.         case 4:
  169.             sprintf(cp,"FINISH");
  170.             break;
  171.         case 5:
  172.             sprintf(cp,"PREV PAGE");
  173.             break;
  174.         case 7:
  175.             sprintf(cp,"CANCEL");
  176.             break;
  177.         case 8:
  178.             sprintf(cp,"BACKSPACE");
  179.             break;
  180.         case 9:
  181.             sprintf(cp,"TAB");
  182.             break;
  183.         case 10:
  184.             sprintf(cp,"BOUND");
  185.             break;
  186.         case 11:
  187.             sprintf(cp,"'down arrow'");
  188.             break;
  189.         case 12:
  190.             sprintf(cp,"NEXT PAGE");
  191.             break;
  192.         case 13:
  193.             sprintf(cp,"RETURN/NEXT");
  194.             break;
  195.         case 14:
  196.             sprintf(cp,"'left arrow'");
  197.             break;
  198.         case 15:
  199.             sprintf(cp,"MOVE");
  200.             break;
  201.         case 17:
  202.             sprintf(cp,"SCROLL UP");
  203.             break;
  204.         case 18:
  205.             sprintf(cp,"'right arrow'");
  206.             break;
  207.         case 19:
  208.             sprintf(cp,"SCROLL DOWN");
  209.             break;
  210.         case 20:
  211.             sprintf(cp,"COPY");
  212.             break;
  213.         case 21:
  214.             sprintf(cp,"F1");
  215.             break;
  216.         case 22:
  217.             sprintf(cp,"F2");
  218.             break;
  219.         case 23:
  220.             sprintf(cp,"F3");
  221.             break;
  222.         case 24:
  223.             sprintf(cp,"F4");
  224.             break;
  225.         case 25:
  226.             sprintf(cp,"F5");
  227.             break;
  228.         case 26:
  229.             sprintf(cp,"F6");
  230.             break;
  231.         case 27:
  232.             sprintf(cp,"GO");
  233.             break;
  234.         case 28:
  235.             sprintf(cp,"F7");
  236.             break;
  237.         case 29:
  238.             sprintf(cp,"F8");
  239.             break;
  240.         case 30:
  241.             sprintf(cp,"F9");
  242.             break;
  243.         case 31:
  244.             sprintf(cp,"F10");
  245.             break;
  246.         default:
  247.             s[0] = c;
  248.             s[1] = '\0';
  249.             break;
  250.         }
  251.  
  252.     cp = s;
  253.     return(cp);
  254. }
  255.  
  256. /*  D O E S C  --  Process an escape character argument  */
  257.  
  258. doesc(c) char c; {
  259.     int d;
  260.   
  261.     c &= 0177;
  262.     while (1) {
  263.     if (c == escape) {        /* Send escape character */
  264.         d = dopar(c);
  265.         ttoc(d);
  266.         return;
  267.         } else                /* Or else look it up below. */
  268.         if (isupper(c)) c = tolower(c);
  269.  
  270.     switch (c) {
  271.  
  272.     case 'c':            /* Close connection */
  273.     case '\03':
  274.         active = 0;
  275.         conol("\r\n");
  276.         return;
  277.  
  278.     case 'b':            /* Send a BREAK */
  279.     case '\02':
  280.         ttsndb();
  281.         return;
  282.  
  283.     case 's':            /* Status */
  284.     case '\023':
  285.         conol("\r\nConnected thru ");
  286.         conoll(ttname);
  287.         if (seslog) {
  288.         conol(", logging to ");
  289.         conol(sesfil);
  290.             }
  291.         return;
  292.  
  293.     case '?':            /* Help */
  294.         c = hconne();
  295.         continue;
  296.  
  297.     case '0':            /* Send a null */
  298.         c = '\0';
  299.         d = dopar(c);
  300.         ttoc(d);
  301.         return;
  302.  
  303.     case SP:            /* Space, ignore */
  304.         return;
  305.  
  306.     default:            /* Other */
  307.         conoc(BEL);         /* Invalid esc arg, beep */
  308.         return;
  309.         }        
  310.     }
  311. }    
  312.