| 138 | return c; |
| 139 | } |
| 140 | static void fe_init (void) |
| 141 | { |
| 142 | fe_is_initialized=TRUE; |
| 143 | if ((!fe_use_fgets) && (isatty (STDIN_FILENO))) |
| 144 | { |
| 145 | /* Make sure stdin is a terminal. */ |
| 146 | char *term=getenv("TERM"); |
| 147 | |
| 148 | /*setup echo*/ |
| 149 | if(isatty(STDOUT_FILENO)) |
| 150 | { |
| 151 | fe_stdout_is_tty=1; |
| 152 | fe_echo=stdout; |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | fe_stdout_is_tty=0; |
| 157 | char *tty_name=ttyname(fileno(stdin)); |
| 158 | if (tty_name!=NULL) |
| 159 | fe_echo = fopen( tty_name, "w" ); |
| 160 | else |
| 161 | fe_echo = NULL; |
| 162 | if (fe_echo==NULL) |
| 163 | { |
| 164 | fe_echo=stdout; |
| 165 | printf("stdin is a tty, but ttyname fails\n"); |
| 166 | return; |
| 167 | } |
| 168 | } |
| 169 | /* Save the terminal attributes so we can restore them later. */ |
| 170 | { |
| 171 | struct termios tattr; |
| 172 | tcgetattr (STDIN_FILENO, &fe_saved_attributes); |
| 173 | #ifdef HAVE_FEREAD |
| 174 | #ifdef HAVE_ATEXIT |
| 175 | atexit(fe_reset_fe); |
| 176 | #else |
| 177 | on_exit(fe_reset_fe,NULL); |
| 178 | #endif |
| 179 | #endif |
| 180 | |
| 181 | /* Set the funny terminal modes. */ |
| 182 | tcgetattr (STDIN_FILENO, &tattr); |
| 183 | tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ |
| 184 | tattr.c_cc[VMIN] = 1; |
| 185 | tattr.c_cc[VTIME] = 0; |
| 186 | tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr); |
| 187 | /*ospeed=cfgetospeed(&tattr);*/ |
| 188 | } |
| 189 | if(term==NULL) |
| 190 | { |
| 191 | printf("need TERM\n"); |
| 192 | } |
| 193 | else if(tgetent(termcap_buff,term)<=0) |
| 194 | { |
| 195 | printf("could not access termcap data base\n"); |
| 196 | } |
| 197 | else |
no test coverage detected