home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / beav.1.40.lzh / BEAV140 / termio_osk.c < prev    next >
Text File  |  1995-06-14  |  3KB  |  119 lines

  1. /*
  2.  * The functions in this file negotiate with the operating system for
  3.  * characters, and write characters in a barely buffered fashion on the display.
  4.  * All operating systems.
  5.  */
  6.  
  7. #include    <sys/types.h>    /* 1.13 */
  8. #include    "def.h"
  9.  
  10. #ifdef OSK
  11. #include    <signal.h>
  12. #include    <errno.h>
  13. #include    <sgstat.h>
  14. int kbdflgs;            /* saved keyboard fd flags  */
  15. int kbdpoll;            /* in O_NDELAY mode         */
  16. unsigned int kbdqp;     /* there is a char in kbdq  */
  17. unsigned char kbdq;        /* char we've already read  */
  18. struct  sgbuf  otermio;    /* original terminal characteristics */
  19. struct  sgbuf  ntermio;    /* charactoristics to use inside */
  20.  
  21. int     nrow;                   /* Terminal size, rows.         */
  22. int     ncol;                   /* Terminal size, columns.      */
  23.  
  24. /*
  25.  * This function is called once to set up the terminal device streams.
  26.  * On VMS, it translates TT until it finds the terminal, then assigns
  27.  * a channel to it and sets it raw. On CPM it is a no-op.
  28.  */
  29. ttopen()
  30. {
  31.     _gs_opt(0,&otermio);
  32.     _gs_opt(0,&ntermio);
  33.     ntermio.sg_pause = 0;
  34.     ntermio.sg_kbich = 0;
  35.     ntermio.sg_kbach = 0;
  36.     ntermio.sg_eofch = 0;
  37.     ntermio.sg_psch = 0;
  38.     ntermio.sg_dulnch = 0;
  39.     ntermio.sg_rlnch = 0;
  40.     ntermio.sg_dlnch = 0;
  41.     ntermio.sg_echo = 0;
  42.     _ss_opt(0,&ntermio);
  43.     kbdflgs = 0; /*fcntl( 0, F_GETFL, 0 );*/
  44.     kbdpoll = FALSE;
  45.     /* on all screens we are not sure of the initial position
  46.        of the cursor                    */
  47.     ttrow = 999;
  48.     ttcol = 999;
  49.     nrow = NROW;
  50.     ncol = NCOL;
  51. }
  52.  
  53. /*
  54.  * This function gets called just before we go back home to the command
  55.  * interpreter. On VMS it puts the terminal back in a reasonable state.
  56.  * Another no-operation on CPM.
  57.  */
  58. ttclose()
  59. {
  60.     _ss_opt(0,&otermio);
  61. }
  62.  
  63. /*
  64.  * Write a character to the display. On VMS, terminal output is buffered, and
  65.  * we just put the characters in the big array, after checking for overflow.
  66.  * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
  67.  * MS-DOS (use the very very raw console output routine).
  68.  */
  69. ttputc(c)
  70. {
  71.     putc(c, stdout);
  72. }
  73.  
  74. /*
  75.  * Flush terminal buffer. Does real work where the terminal output is buffered
  76.  * up. A no-operation on systems where byte at a time terminal I/O is done.
  77.  */
  78. ttflush()
  79. {
  80.    fflush(stdout);
  81. }
  82.  
  83. /*
  84.  * Read a character from the terminal, performing no editing and doing no echo
  85.  * at all. More complex in VMS that almost anyplace else, which figures. Very
  86.  * simple on CPM, because the system can do exactly what you want.
  87.  */
  88. ttgetc()
  89. {
  90.     if( kbdqp )
  91.         kbdqp = FALSE;
  92.     else
  93.     {
  94.         if( kbdpoll) /*  && fcntl( 0, F_SETFL, kbdflgs ) < 0 ) */
  95.             return FALSE;
  96.         kbdpoll = FALSE;
  97.         while (read(0, &kbdq, 1) != 1)
  98.             ;
  99.     }
  100.     return ( kbdq );
  101. }
  102.  
  103. /* typahead():    Check to see if any characters are already in the
  104.         keyboard buffer
  105. */
  106. ttkeyready ()
  107. {
  108.     if( !kbdqp )
  109.     {
  110.         if( !kbdpoll && (_gs_rdy(0) < 0) )
  111.             return(FALSE);
  112.         kbdpoll = TRUE;    /*  fix in 1.13 */
  113.         kbdqp = (1 == read( 0, &kbdq, 1 ));
  114.     }
  115.     return ( kbdqp );
  116. }
  117. #endif
  118.  
  119.