home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / pico / osdep / raw.io < prev    next >
Text File  |  1997-02-05  |  4KB  |  179 lines

  1. /*
  2.  * TTY setup routines. These are the TERMIO-style (System V) routines.
  3.  */
  4.  
  5. static struct termio _raw_tty, _original_tty;
  6.  
  7. /*
  8.  * current raw state
  9.  */
  10. static short _inraw = 0;
  11.  
  12. /*
  13.  *  Set up the tty driver
  14.  *
  15.  * Args: state -- which state to put it in. 1 means go into raw (cbreak),
  16.  *                0 out of raw.
  17.  *
  18.  * Result: returns 0 if successful and -1 if not.
  19.  */
  20. int
  21. Raw(state)
  22. int state;
  23. {
  24.     /** state is either ON or OFF, as indicated by call **/
  25.     /* Check return code only on first call. If it fails we're done for and
  26.        if it goes OK the others will probably go OK too. */
  27.  
  28.     if(state == 0 && _inraw){
  29.         /*----- restore state to original -----*/
  30.         if(ioctl(STDIN_FD, TCSETAW, &_original_tty) < 0)
  31.           return(-1);
  32.  
  33.         _inraw = 0;
  34.     }
  35.     else if(state == 1 && ! _inraw){
  36.         /*----- Go into raw mode (cbreak actually) ----*/
  37.         if(ioctl(STDIN_FD, TCGETA, &_original_tty) < 0)
  38.           return(-1);
  39.  
  40.     (void)ioctl(STDIN_FD, TCGETA, &_raw_tty);    /** again! **/
  41.     _raw_tty.c_lflag &= ~(ICANON | ECHO);    /* noecho raw mode  */
  42.      _raw_tty.c_lflag &= ~ISIG;        /* disable signals */
  43.      _raw_tty.c_iflag &= ~ICRNL;        /* turn off CR->NL on input  */
  44.      _raw_tty.c_oflag &= ~ONLCR;        /* turn off NL->CR on output */
  45.     _raw_tty.c_cc[VMIN]  = 1;        /* min # of chars to queue   */
  46.     _raw_tty.c_cc[VTIME] = 0;        /* min time to wait for input*/
  47.     _raw_tty.c_cc[VINTR] = ctrl('C');    /* make it our special char */
  48.     _raw_tty.c_cc[VQUIT] = 0;
  49.     (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  50.     _inraw = 1;
  51.     }
  52.  
  53.     return(0);
  54. }
  55.  
  56.  
  57. /*
  58.  *  Set up the tty driver to use XON/XOFF flow control
  59.  *
  60.  * Args: state -- True to make sure XON/XOFF turned on, FALSE off.
  61.  *
  62.  * Result: none.
  63.  */
  64. void
  65. xonxoff_proc(state)
  66. int state;
  67. {
  68.     if(_inraw){
  69.     if(state){
  70.         if(!(_raw_tty.c_iflag & IXON)){
  71.         _raw_tty.c_iflag |= IXON;    /* turn ON ^S/^Q on input   */
  72.         (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  73.         }
  74.     }
  75.     else{
  76.         if(_raw_tty.c_iflag & IXON){
  77.         _raw_tty.c_iflag &= ~IXON;    /* turn off ^S/^Q on input   */
  78.         (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  79.         }
  80.     }
  81.     }
  82. }
  83.  
  84.  
  85. /*
  86.  *  Set up the tty driver to do LF->CR translation
  87.  *
  88.  * Args: state -- True to turn on translation, false to write raw LF's
  89.  *
  90.  * Result: none.
  91.  */
  92. void
  93. crlf_proc(state)
  94. int state;
  95. {
  96.     if(_inraw){
  97.     if(state){                /* turn ON NL->CR on output */
  98.         if(!(_raw_tty.c_oflag & ONLCR)){
  99.         _raw_tty.c_oflag |= ONLCR;
  100.         (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  101.         }
  102.     }
  103.     else{                    /* turn OFF NL-CR on output */
  104.         if(_raw_tty.c_oflag & ONLCR){
  105.         _raw_tty.c_oflag &= ~ONLCR;
  106.         (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  107.         }
  108.     }
  109.     }
  110. }
  111.  
  112.  
  113. /*
  114.  *  Set up the tty driver to hanle interrupt char
  115.  *
  116.  * Args: state -- True to turn on interrupt char, false to not
  117.  *
  118.  * Result: tty driver that'll send us SIGINT or not
  119.  */
  120. void
  121. intr_proc(state)
  122. int state;
  123. {
  124.     if(_inraw){
  125.     if(state){
  126.         _raw_tty.c_lflag |= ISIG;        /* enable signals */
  127.         (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  128.     }
  129.     else{
  130.         _raw_tty.c_lflag &= ~ISIG;        /* disable signals */
  131.         (void)ioctl(STDIN_FD, TCSETAW, &_raw_tty);
  132.     }
  133.     }
  134. }
  135.  
  136.  
  137. /*
  138.  * Discard any pending input characters
  139.  *
  140.  * Args:  none
  141.  *
  142.  * Result: pending input buffer flushed
  143.  */
  144. void
  145. flush_input()
  146. {
  147.     ioctl(STDIN_FD, TCFLSH, 0);
  148. }
  149.  
  150.  
  151. /*
  152.  * Turn off hi bit stripping
  153.  */
  154. void
  155. bit_strip_off()
  156. {
  157. }
  158.  
  159.  
  160. /*
  161.  * Turn off quit character (^\) if possible
  162.  */
  163. void
  164. quit_char_off()
  165. {
  166. }
  167.  
  168.  
  169. /*
  170.  * Returns TRUE if tty is < 4800, 0 otherwise.
  171.  */
  172. int
  173. ttisslow()
  174. {
  175.     return((_raw_tty.c_cflag&CBAUD) < (unsigned int)B4800);
  176. }
  177.  
  178.  
  179.