/* Simple test program that uses readline in callback mode, using * read() and then rl_stuff_char(). Whenever rlwrap misbehaves, please * run this program to make sure it is not a readline problem. * * compile with gcc -otest rltest1.c -lreadline -lncurses */ #include #include #include #include #include void show_history_list() { HISTORY_STATE *state = history_get_history_state(); int i; printf("History list now:\n"); for (i=0; i < state->length; i++) { printf("%d: '%s'%s\n", i, state->entries[i]->line, (i == state->offset? "*":"")); } } void line_handler(char *line) { if (!line) exit (0); add_history(line); printf("You typed: '%s'\n", line); show_history_list(); } int main() { char c; using_history(); rl_callback_handler_install("Enter a line: ", &line_handler); while (read(STDIN_FILENO, &c, 1)) { if (! rl_stuff_char(c)) { fprintf (stderr, "\nDisappointingly, I couldn't even stuff a single '%c' " "into readline's 512-byte long input queue, giving up :-(\n", c); exit(1); } rl_stuff_char(c); rl_callback_read_char(); } return 0; }