1 /* Standard include files. stdio.h is required. */
6 /* Used for select(2) */
8 #include <sys/select.h>
13 /* Standard readline include files. */
14 #if defined (READLINE_LIBRARY)
15 # include "readline.h"
18 # include <readline/readline.h>
19 # include <readline/history.h>
24 static void cb_linehandler (char *);
27 const char *prompt
= "rltest$ ";
29 /* Callback function called for each line when accept-line executed, EOF
30 seen, or EOF character read. This sets a flag and returns; it could
33 cb_linehandler (char *line
)
35 /* Can use ^D (stty eof) or `exit' to exit. */
36 if (line
== NULL
|| strcmp (line
, "exit") == 0)
41 /* This function needs to be called to reset the terminal settings,
42 and calling it from the line handler keeps one extra prompt from
44 rl_callback_handler_remove ();
52 printf ("input line: %s\n", line
);
58 main (int c
, char **v
)
63 /* Install the line handler. */
64 rl_callback_handler_install (prompt
, cb_linehandler
);
66 /* Enter a simple event loop. This waits until something is available
67 to read on readline's input stream (defaults to standard input) and
68 calls the builtin character read callback to read it. It does not
69 have to modify the user's terminal settings. */
74 FD_SET (fileno (rl_instream
), &fds
);
76 r
= select (FD_SETSIZE
, &fds
, NULL
, NULL
, NULL
);
77 if (r
< 0 && errno
!= EINTR
)
79 perror ("rltest: select");
80 rl_callback_handler_remove ();
84 if (FD_ISSET (fileno (rl_instream
), &fds
))
85 rl_callback_read_char ();
88 printf ("rltest: Event loop has exited\n");
This page took 0.035254 seconds and 4 git commands to generate.