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

  1. /*
  2.     TERM_C - QL-Kermit terminal emulation
  3.  
  4.     Loosely based on ckucon.c, (C) Columbia University
  5. */
  6.  
  7.  
  8. /* Include files */
  9.  
  10. #include "ram1_ker_h"                            /* Kermit definitions */
  11.  
  12. #include "flp1_fcntl_h"                          /* File opening modes */
  13.  
  14.  
  15. /* External variables */
  16.  
  17. extern int ttychid;                              /* QDOS channel ID for comms line */
  18.  
  19. extern bool echo;                                /* Local echo flag */
  20. extern char enter[2];                            /* What to send for ENTER */
  21.  
  22.  
  23. /* DOCONNECT - dumb terminal emulator */
  24.  
  25. doconnect()
  26. {
  27.     char *conname = "con_";                      /* Name of emulation window */
  28.     unsigned char tchar;                         /* Character temporary */
  29.     int conchid;                                 /* QDOS channel ID for window */
  30.     int confd;                                   /* FD for window */
  31.     bool cnflg;                                  /* In progress flag */
  32.  
  33.     confd = open(conname,O_RDWR);                /* Open emulation window */
  34.     if (confd<0)
  35.     {
  36.          error("Cannot open window %s",conname);
  37.          return(0);
  38.     }
  39.     conchid = (int) getchid(confd);              /* Now get the QDOS ID for it */
  40.  
  41.     sd_curs(fgetchid(stdin),-1);                 /* Disable the console cursor */
  42.     cls(conchid);                                /* Clear the window */
  43.     printf("Type F2 to return to command mode\n");
  44.     sd_cure(conchid,-1);                         /* Enable cursor in it */
  45.  
  46.     cnflg = TRUE;
  47.     while (cnflg)                                /* Loop until F1 pressed */
  48.     {
  49.          if (!io_pend(conchid,0))                /* If key pressed, */
  50.          {
  51.               if (!io_fbyte(conchid,0,&tchar))   /* read it */
  52.               {
  53.                    switch(tchar)
  54.                    {
  55. case F2:                cnflg = FALSE;           /* Exit */
  56.                         endcase;
  57.  
  58. case F3:                tchar = '\0';            /* NUL */
  59.                         goto send;
  60.  
  61. case F4:                tchar = '\003';          /* CTRL-C */
  62.                         goto send;
  63.  
  64. case F5:                tchar = '\177';          /* DEL */
  65.                         goto send;
  66.  
  67. case LF:                if (echo) io_sbyte(conchid,0,LF);
  68.                         io_sbyte(ttychid,0,enter[0]);
  69.                         if (enter[1]!=0) io_sbyte(ttychid,0,enter[1]);
  70.                         endcase;
  71.  
  72. send:
  73. default:                io_sbyte(ttychid,0,tchar);
  74.                         if (echo) io_sbyte(conchid,0,tchar);
  75.                         endcase;
  76.                    }
  77.               }
  78.          }
  79.  
  80.          if (!io_pend(ttychid,0))                /* If line character there, */
  81.          {
  82.               if (!io_fbyte(ttychid,0,&tchar))
  83.                    io_sbyte(conchid,0,tchar);    /* copy it to screen */
  84.          }
  85.     }
  86.  
  87.     close(confd);                                /* Finished, drop the window */
  88.     sd_cure(fgetchid(stdin),-1);                 /* Cursor back to stdin */
  89.     printf("\n");
  90.     return(0);
  91. }
  92.