4d8 /* Readline routines */ #include #include #include #include #include #include static struct termios tty, old_tty; static unsigned char *line_read = (unsigned char*)NULL; static unsigned char *deftext; int set_echo(void) { /* If ECHO was previously off, we need to turn it on */ /* temporarily to make readline display the characters */ tcgetattr(STDIN_FILENO, &tty); if (! (tty.c_lflag & ECHO)) { old_tty = tty; tty.c_lflag |= ECHO; tcsetattr(STDIN_FILENO, TCSANOW, &tty); return 1; } return 0; } int set_deftext(void) { if (deftext) { rl_insert_text (deftext); deftext = (unsigned char*)NULL; rl_startup_hook = (Function *)NULL; } } unsigned char *rl_gets(unsigned char *pmt, unsigned char *dflt) { int tty_changed; tty_changed = set_echo(); if (line_read) { free(line_read); line_read = (unsigned char*)NULL; } if (dflt != NULL) { deftext = dflt; rl_startup_hook = set_deftext; } line_read = readline(pmt); if (tty_changed) tcsetattr(STDIN_FILENO, TCSANOW, &old_tty); return (line_read); } . 0