home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / extra / uxconu.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  3KB  |  113 lines

  1. /*
  2.  * connect command for "standard" unix
  3.  *
  4.  */
  5.  
  6. /*
  7.  *  c o n n e c t
  8.  *
  9.  *  Establish a virtual terminal connection with the remote host, over an
  10.  *  assigned tty line. 
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <ctype.h>
  15. #include <sgtty.h>
  16.  
  17. #define TRUE 1
  18. #define FALSE 0
  19. #define ctl(x) ((x) ^ 64)
  20. #define unpar(ch) ((ch) & 127)
  21.  
  22. extern int remote, ttyfd, lecho, speed;
  23. extern char escchr;
  24.  
  25. connect()
  26. {
  27.     int pid,                /* Holds process id of child */
  28.     tt2fd,                /* FD for the console tty */
  29.     connected;            /* Boolean connect flag */
  30.     char bel = '\07',
  31.     c;
  32.  
  33.     struct sgttyb oldcon;        /* [???] should this be here? */
  34.  
  35.     if (remote)                /* Nothing to connect to in remote */
  36.     {                    /* mode, so just return */
  37.     printmsg("No line specified for connection.");
  38.     return;
  39.     }
  40.  
  41.     speed = 0;                /* Don't set the console's speed */
  42.     tt2fd = ttopen(0);            /* Open up the console */
  43.     ttbin(tt2fd,&oldcon);        /* Put it in binary */
  44.  
  45.     pid = fork();           /* Start fork to get typeout from remote host */
  46.  
  47.     if (!pid)            /* child1: read remote output */
  48.     {
  49.      while (1)
  50.      {
  51.       char c;
  52.       read(ttyfd,&c,1);            /* read a character */
  53.       write(1,&c,1);            /* write to terminal */
  54.      }
  55.     }
  56. /* resume parent: read from terminal and send out port */
  57.       printmsg("connected...\r");
  58.       connected = TRUE;        /* Put us in "connect mode" */
  59.       while (connected)
  60.       {
  61.       read(tt2fd,&c,1);        /* Get a character */
  62.       c = unpar(c);        /* Turn off the parity */
  63.       if (c == escchr)        /* Check for escape character */
  64.       {
  65.           read(tt2fd,&c,1);
  66.           c = unpar(c);        /* Turn off the parity */
  67.           if (c == escchr)
  68.           {
  69.           c = dopar(c);    /* Do parity if the user requested */
  70.           write(ttyfd,&c,1);
  71.           }
  72.           else
  73.           switch (toupper(c))
  74.           {
  75.           case 'C':
  76.               connected = FALSE;
  77.               write(tt2fd,"\r\n",2);
  78.               break;
  79.  
  80.           case 'H':
  81.             {
  82.               char hlpbuf[100],e;
  83.               sprintf(hlpbuf,"\r\n C to close the connection\r\n");
  84.               write(tt2fd,hlpbuf,strlen(hlpbuf));
  85.               e = escchr;
  86.               if (e < ' ') {
  87.                 write(tt2fd,"^",1);
  88.                 e = ctl(e); }
  89.               sprintf(hlpbuf,"%c to send itself\r\n",e);
  90.                     write(tt2fd,hlpbuf,strlen(hlpbuf));
  91.             }
  92.               break;
  93.  
  94.           default:
  95.               write(tt2fd,&bel,1);
  96.               break;
  97.           }
  98.       }
  99.       else
  100.       {                /* If not escape charater, */
  101.           if (lecho) write(1,&c,1); /* Echo char if requested */
  102.           c = dopar(c);        /* Do parity if the user requested */
  103.           write(ttyfd,&c,1);    /* write it out */
  104.           c = NULL;        /* Nullify it (why?) */
  105.       }
  106.       }
  107.       kill(pid,9);            /* Done, kill the child */
  108.       while (wait(0) != -1);        /* and bury him */
  109.       ttres(tt2fd,&oldcon);
  110.       printmsg("disconnected.");
  111.       return;                /* Done */
  112. }
  113.