home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / os9 / os9con.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  4KB  |  114 lines

  1. /*
  2.  * os9con.c connect for os9 kermit
  3.  */
  4.  
  5. #include "os9inc.h"
  6.  
  7. /* 06/30/85 ral Adapt for server kermit, improve raw/cooked modes    
  8.  *              and spawning shell
  9.  * 
  10.  * 12/05/85 ral add OSK ifdef's
  11.  *
  12.  * Os9 connect code by Bradley Bosch and Robert Larson  
  13.  */
  14.  
  15. static struct sgbuf     insave,         /* Input scf save status */
  16.                         outsave;        /* Output scf save status */
  17.  
  18. int
  19. get_action()
  20. {
  21.         char    chr;
  22.         int     nwrt;
  23.  
  24.         printmsg(" %c \l", escchr);
  25.         read(0, &chr, 1);
  26.         switch (chr) {
  27.         case '!':
  28.                 cook(1,&outsave);       /* restore to cooked mode */
  29.                 cook(0,&insave);        /* Must be in reverse order of save */
  30.                 if (os9fork("shell", 1, "\n", 1, 1, 0) == -1)
  31.                         printmsg("can't escape to shell.");
  32.                 else
  33.                         wait(0);
  34.                 raw(0,&insave);         /* put it back to raw for packets */
  35.                 raw(1,&outsave);
  36.                 return (0);
  37.         case 'q':
  38.         case 'c':
  39.         case 'C':
  40.                 return (1);
  41.         default :
  42.                 /* case escchr: */
  43.                 if (chr == escchr)
  44.                         write (ttyfd, &escchr, 1);
  45.                 return (0);
  46.         }
  47. }
  48.  
  49. /*
  50.  *  c o n n e c t
  51.  *
  52.  *  Establish a virtual terminal connection with the remote host, over an
  53.  *  assigned tty line. 
  54.  */
  55.  
  56. connect()
  57. {
  58.         /* Two processes cannot do I/O to the  */
  59.         /* same port at the same time in OS-9, */
  60.         /* so we do some strange things here.  */
  61.         char    cbuf[256];
  62.         char    *buf = cbuf;
  63.         int     cnt;
  64.         int     flag;
  65.         int     i;
  66.  
  67.         if (remot) {           /* Nothing to connect to in remote mode */
  68.                 printmsg("No line specified for connection.");
  69.                 return;
  70.         }
  71.         raw(0,&insave);                 /* Put input in raw mode */
  72.         raw(1,&outsave);                /* Put output in raw mode */
  73.         printmsg("connected escchr=%c ...\r\l", escchr);
  74.         for (;;) {
  75. #ifdef OSK
  76.                 while ((cnt=getstat(1, ttyfd)) > 0){
  77. #else
  78.                 while ((cnt=getstat(1, ttyfd)) >= 0){
  79. #endif
  80.                     if(cnt > 1) {
  81. #ifdef OSK   /* impossible for cnt to exceed 255 on os9/6809 */
  82.                         if(cnt > 255) cnt = 255;
  83. #endif
  84.                         if((cnt=read(ttyfd, buf, cnt)) != -1) {
  85.                             for(i=0; i<cnt;)
  86.                                 buf[i++] &= 0177;
  87.                             write(1, buf, cnt);
  88.                         }
  89.                     } else {
  90.                         if(read(ttyfd, buf, 1) != -1){
  91.                             buf[0] &= 0177;         /* mask off high bit */
  92.                             write(1, buf, 1);
  93.                         }
  94.                     }
  95.                 }
  96. #ifdef OSK
  97.                 if ( getstat(1, 0) > 0 ) {
  98. #else
  99.                 if ( getstat(1, 0) >= 0 ) {
  100. #endif
  101.                         cnt = read(0, cbuf, 1);
  102.                         if (((*cbuf) & 0177) != escchr)
  103.                                 write(ttyfd, cbuf, cnt);
  104.                         else if (get_action())
  105.                                 break; 
  106.                 }
  107.                 tsleep(1);              /* give the other processes a chance */
  108.         } 
  109.  
  110.         cook(1, &outsave);              /* restore scf status */
  111.         cook(0, &insave);               /* Must be done in opposite order! */
  112.         printmsg("disconnected.");
  113. }
  114.