/* Simple test program that uses readline in callback mode. Whenever * rlwrap misbehaves, please run this program to make sure it is not * a readline problem. * * compile with gcc -otest rltest4.c -lreadline -lncurses */ #include #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() { using_history(); rl_callback_handler_install("Enter a line: ", &line_handler); while (1) { fd_set fds; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); if (select(FD_SETSIZE, &fds, NULL, NULL, NULL) < 0) exit(1); rl_callback_read_char(); } /* not reached */ return 42; }