00001
00002
00003
00004
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
00020 static int term_set = 0;
00021 #endif
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
00033 tcgetattr( 0, &orig_termio);
00034 #endif
00035 #else
00036 ioctl( 0, TCGETA, &orig_termio);
00037 #endif
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
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
00052 rl_termio.c_cc[VSUSP] = 0;
00053 #endif
00054 #ifdef TERMIOS
00055 #ifdef TCSETSW
00056 ioctl( 0, TCSETSW, &rl_termio);
00057 #else
00058 tcsetattr( 0, TCSADRAIN, &rl_termio);
00059 #endif
00060 #else
00061 ioctl( 0, TCSETAW, &rl_termio);
00062 #endif
00063 term_set = 1;
00064 #ifdef KEYPAD
00065 putc( 033, stderr);
00066 putc( '=', stderr);
00067 #endif
00068 }
00069 #endif
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
00082 tcsetattr( 0, TCSADRAIN, &orig_termio);
00083 #endif
00084 #else
00085 ioctl( 0, TCSETAW, &orig_termio);
00086 #endif
00087 term_set = 0;
00088 #ifdef KEYPAD
00089 putc( 033, stderr);
00090 putc( '>', stderr);
00091 #endif
00092 }
00093 #endif
00094 }