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

  1. char *connv = "Connect Command, V4.2(008) 5 Jul 85";
  2.  
  3. /*  C K V C O N  --  Dumb terminal connection to remote system, for VMS  */
  4. /*
  5.  Adapted from the Unix C-Kermit connect module by S. Rubenstein for systems
  6.  without fork().  This version of conect() uses contti(&c, &src) to return
  7.  when a character is available from either the console or the comm line,
  8.  to allow sending/receiving without breaking connection.
  9. */
  10. #include "ckcker.h"
  11. #include <stdio.h>
  12. #include <ctype.h>
  13. #include <signal.h>
  14. #include <setjmp.h>
  15.  
  16. #ifndef SIGUSR1
  17. #define SIGUSR1 16
  18. #endif
  19.  
  20. extern int local, speed, escape, duplex, parity, flow, seslog, mdmtyp;
  21. extern char ttname[], sesfil[];
  22.  
  23. int i, active;                /* Variables global to this module */
  24. char *chstr();
  25.  
  26. #define LBUFL 100            /* Line buffer */
  27. char lbuf[LBUFL];
  28.  
  29.  
  30. /*  C O N E C T  --  Perform terminal connection  */
  31.  
  32. conect() {
  33.     int pid,             /* process id of child (modem reader) */
  34.     parent_id,        /* process id of parent (keyboard reader) */
  35.     n;
  36.     int c;            /* c is a character, but must be signed 
  37.                    integer to pass thru -1, which is the
  38.                    modem disconnection signal, and is
  39.                    different from the character 0377 */
  40.     char errmsg[50], *erp;
  41.  
  42.     if (!local) {
  43.         printf("Sorry, you must 'set line' first\n");
  44.         return(-2);
  45.     }
  46.     if (speed < 0) {
  47.         printf("Sorry, you must 'set speed' first\n");
  48.         return(-2);
  49.         }
  50.     if ((escape < 0) || (escape > 0177)) {
  51.         printf("Your escape character is not ASCII - %d\n",escape);
  52.         return(-2);
  53.     }
  54.     if (ttopen(ttname,&local,mdmtyp) < 0) {
  55.         erp = errmsg;
  56.         sprintf(erp,"Sorry, can't open %s",ttname);
  57.         perror(errmsg);
  58.         return(-2);
  59.         }
  60.         printf("Connecting thru %s, speed %d.\r\n",ttname,speed);
  61.     printf("The escape character is %s (%d).\r\n",chstr(escape),escape);
  62.     printf("Type the escape character followed by C to get back,\r\n");
  63.     printf("or followed by ? to see other options.\r\n");
  64.     if (seslog) printf("(Session logged to %s.)\r\n",sesfil);
  65.  
  66. /* Condition console terminal and communication line */        
  67.  
  68.         if (conbin(escape) < 0) {
  69.         printf("Sorry, can't condition console terminal\n");
  70.         return(-2);
  71.         }
  72.     if (ttvt(speed,flow) < 0) {
  73.         conres();
  74.         printf("Sorry, Can't condition communication line\n");
  75.         return(-2);
  76.         }
  77.  
  78. /* cont'd... */
  79.  
  80.  
  81. /* ...connect, cont'd */
  82.  
  83.     active = 1;
  84.     do {
  85.         int src;
  86.  
  87.         contti(&c, &src);
  88.         if (src < 0) {         /* Comm line hangup or other error */
  89.         printf("\r\nC-Kermit: Communications line failure\r\n");
  90.         active = 0;
  91.         } else if (src) {        /* Character from comm. line */
  92.         c &= 0177;        /* Got a char, strip parity. */
  93.         conoc(c);        /* Put it on the screen. */
  94.         if (seslog) zchout(ZSFILE,c); /* If logging, log it. */
  95.         n = ttchk();    /* Any more left in buffer? */
  96.         if (n > 0) {
  97.             if (n > LBUFL) n = LBUFL;  /* Get them all at once. */
  98.             if ((n = ttxin(n,lbuf)) > 0) {
  99.                 for (i = 0; i < n; i++) lbuf[i] &= 0177;
  100.                 conxo(n,lbuf);
  101.                 if (seslog) zsoutx(ZSFILE,lbuf,n);
  102.             }
  103.         }
  104.         } else {            /* Character from console */
  105.         c &= 0177;
  106.         if (c == escape) {    /* Look for escape char */
  107.             c = coninc(0) & 0177;
  108.             doesc(c);
  109.         } else {        /* Ordinary character */
  110.             ttoc(dopar(c));
  111.             if (duplex) {    /* Half duplex? */
  112.             conoc(c);    /* Yes, also echo it. */
  113.             if (seslog) zchout(ZSFILE,c);    /* And maybe log it. */
  114.                     }            
  115.         }
  116.         }
  117.     } while (active);
  118.     cancio();
  119.     conres();
  120.     printf("\r\nC-Kermit Disconnected\r\n");
  121.     return(0);
  122. }
  123.  
  124.  
  125. /*  H C O N N E  --  Give help message for connect.  */
  126.  
  127. hconne() {
  128.     int c;
  129.     static char *hlpmsg[] = {
  130. " ",
  131. "\r\nC to close the connection, or:",
  132. "\r\n  0 (zero) to send a null",
  133. "\r\n  B to send a BREAK",
  134. "\r\n  H to hangup and close connection",
  135. "\r\n  S for status",
  136. "\r\n  ? for help",
  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(0);
  143.     conoc(c);                /* Echo it. */
  144.     conoll("");
  145.     doesc(c);
  146. }
  147.  
  148.  
  149. /*  C H S T R  --  Make a printable string out of a character  */
  150.  
  151. char *
  152. chstr(c) int c; {
  153.     static char s[8];
  154.     char *cp = s;
  155.  
  156.     if (c < SP) {
  157.     sprintf(cp,"CTRL-%c",ctl(c));
  158.     } else sprintf(cp,"'%c'\n",c);
  159.     cp = s;
  160.     return(cp);
  161. }
  162.  
  163.  
  164. /*  D O E S C  --  Process an escape character argument  */
  165.  
  166. doesc(c) char c; {
  167.     int d;
  168.   
  169.     c &= 0177;
  170.  
  171.     if (c == escape) {              /* Send escape character */
  172.         d = dopar(c);
  173.         ttoc(d);
  174.     } else {
  175.                                     /* Or else look it up below. */
  176.         if (isupper(c)) c = tolower(c);
  177.         if (iscntrl(c)) c += 'a' - '\001';
  178.         
  179.         if (c == 'c') {                 /* Close connection */
  180.             active = 0;
  181.             conol("\r\n");
  182.         } else if (c == 'b') {          /* Send a BREAK */
  183.             ttsndb();
  184.         } else if (c == 'h') {          /* Hang up the line */
  185.             tthang();
  186.         } else if (c == 's') {          /* Status */
  187.             conol("\r\nConnected thru ");
  188.             conoll(ttname);
  189.             if (seslog) {
  190.                 conol(", logging to ");
  191.                 conol(sesfil);
  192.             }
  193.         } else if (c == '?') {          /* Help */
  194.         hconne();
  195.         } else if (c == '0') {          /* Send a null */
  196.             c = '\0';
  197.             d = dopar(c);
  198.             ttoc(d);
  199.         } else if (c != SP) {           /* Space, ignore */
  200.             conoc(BEL);                 /* Invalid esc arg, beep */
  201.         }
  202.     }           
  203. }    
  204.