]>
Commit | Line | Data |
---|---|---|
ccc6cda3 JA |
1 | /* **************************************************************** */ |
2 | /* */ | |
3 | /* Testing Readline */ | |
4 | /* */ | |
5 | /* **************************************************************** */ | |
6 | ||
d166f048 JA |
7 | #if defined (HAVE_CONFIG_H) |
8 | #include <config.h> | |
9 | #endif | |
10 | ||
ccc6cda3 JA |
11 | #include <stdio.h> |
12 | #include <sys/types.h> | |
bb70624e JA |
13 | |
14 | #ifdef READLINE_LIBRARY | |
15 | # include "readline.h" | |
16 | # include "history.h" | |
17 | #else | |
18 | # include <readline/readline.h> | |
19 | # include <readline/history.h> | |
20 | #endif | |
ccc6cda3 | 21 | |
cce855bc JA |
22 | extern HIST_ENTRY **history_list (); |
23 | ||
ccc6cda3 JA |
24 | main () |
25 | { | |
cce855bc JA |
26 | char *temp, *prompt; |
27 | int done; | |
28 | ||
29 | temp = (char *)NULL; | |
30 | prompt = "readline$ "; | |
31 | done = 0; | |
ccc6cda3 JA |
32 | |
33 | while (!done) | |
34 | { | |
35 | temp = readline (prompt); | |
36 | ||
37 | /* Test for EOF. */ | |
38 | if (!temp) | |
39 | exit (1); | |
40 | ||
41 | /* If there is anything on the line, print it and remember it. */ | |
42 | if (*temp) | |
43 | { | |
44 | fprintf (stderr, "%s\r\n", temp); | |
45 | add_history (temp); | |
46 | } | |
47 | ||
48 | /* Check for `command' that we handle. */ | |
49 | if (strcmp (temp, "quit") == 0) | |
50 | done = 1; | |
51 | ||
52 | if (strcmp (temp, "list") == 0) | |
53 | { | |
cce855bc | 54 | HIST_ENTRY **list; |
ccc6cda3 | 55 | register int i; |
cce855bc JA |
56 | |
57 | list = history_list (); | |
ccc6cda3 JA |
58 | if (list) |
59 | { | |
60 | for (i = 0; list[i]; i++) | |
cce855bc | 61 | fprintf (stderr, "%d: %s\r\n", i, list[i]->line); |
ccc6cda3 JA |
62 | } |
63 | } | |
64 | free (temp); | |
65 | } | |
cce855bc | 66 | exit (0); |
ccc6cda3 | 67 | } |