kbdtermio.c

Go to the documentation of this file.
00001 
00002 /* SIGTSTP defines job control */
00003 
00004 /* if there is job control then we need termios.h instead of termio.h */
00005 #include <signal.h>
00006 #ifdef SIGTSTP
00007 #define TERMIOS
00008 #endif
00009 
00010 #ifndef WIN32
00011 #include <unistd.h>
00012 #include <sys/ioctl.h>
00013 #ifdef TERMIOS
00014 #include <termios.h>
00015 static struct termios orig_termio, rl_termio;
00016 #else
00017 #include <termio.h>
00018 static struct termio orig_termio, rl_termio;
00019 #endif /* TERMIOS */
00020 static int term_set = 0;                /* =1 if rl_termio set */
00021 #endif /* WIN32 */
00022 
00023 void set_termio( )
00024 {
00025 #ifndef WIN32
00026         if (!isatty( STDIN_FILENO))
00027                 return;
00028         if (term_set == 0) {
00029 #ifdef TERMIOS
00030 #ifdef TCGETS
00031                 ioctl( 0, TCGETS, &orig_termio);
00032 #else /* TCGETS */
00033                 tcgetattr( 0, &orig_termio);
00034 #endif /* TCGETS */
00035 #else /* TERMIOS */
00036                 ioctl( 0, TCGETA, &orig_termio);
00037 #endif /* TERMIOS */
00038                 rl_termio = orig_termio;
00039                 rl_termio.c_iflag &= ~(BRKINT | PARMRK | INPCK | IXON | IXOFF);
00040                 rl_termio.c_iflag |= (IGNBRK | IGNPAR);
00041 
00042 #ifndef darwin                                  /* ONOCR unimplemented in Darwin */
00043                 rl_termio.c_oflag &= ~(ONOCR);
00044 #endif
00045                 rl_termio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | NOFLSH);
00046                 rl_termio.c_lflag |= (ISIG);
00047                 rl_termio.c_cc[VMIN] = 1;
00048                 rl_termio.c_cc[VTIME] = 0;
00049 #ifdef VSUSP
00050 
00051 /* disable suspending process on ^Z */
00052                 rl_termio.c_cc[VSUSP] = 0;
00053 #endif /* VSUSP */
00054 #ifdef TERMIOS
00055 #ifdef TCSETSW
00056                 ioctl( 0, TCSETSW, &rl_termio);
00057 #else /* TCSETSW */
00058                 tcsetattr( 0, TCSADRAIN, &rl_termio);
00059 #endif /* TCSETSW */
00060 #else /* TERMIOS */
00061                 ioctl( 0, TCSETAW, &rl_termio);
00062 #endif /* TERMIOS */
00063                 term_set = 1;
00064 #ifdef KEYPAD
00065                 putc( 033, stderr);
00066                 putc( '=', stderr);
00067 #endif
00068         }
00069 #endif /* WIN32 */
00070 }
00071 
00072 void reset_termio( )
00073 {
00074 #ifndef WIN32
00075         if (!isatty( STDIN_FILENO))
00076                 return;
00077         if (term_set == 1) {
00078 #ifdef TERMIOS
00079 #ifdef TCSETSW
00080                 ioctl( 0, TCSETSW, &orig_termio);
00081 #else /* TCSETSW */
00082                 tcsetattr( 0, TCSADRAIN, &orig_termio);
00083 #endif /* TCSETSW */
00084 #else /* TERMIOS */
00085                 ioctl( 0, TCSETAW, &orig_termio);
00086 #endif /* TERMIOS */
00087                 term_set = 0;
00088 #ifdef KEYPAD
00089                 putc( 033, stderr);
00090                 putc( '>', stderr);
00091 #endif
00092         }
00093 #endif /* WIN32 */
00094 }

Generated on Tue Mar 13 15:15:40 2007 for SIC by  doxygen 1.5.1