"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "examples/rl-callbacktest.c" between
readline-7.0-rc1.tar.gz and readline-7.0-rc2.tar.gz

About: GNU Readline library - get a line from a user with editing. Release candidate.

rl-callbacktest.c  (readline-7.0-rc1):rl-callbacktest.c  (readline-7.0-rc2)
/* Standard include files. stdio.h is required. */ /* Standard include files. stdio.h is required. */
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <locale.h>
/* Used for select(2) */ /* Used for select(2) */
#include <sys/types.h> #include <sys/types.h>
#include <sys/select.h> #include <sys/select.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
/* Standard readline include files. */ /* Standard readline include files. */
#if defined (READLINE_LIBRARY) #if defined (READLINE_LIBRARY)
# include "readline.h" # include "readline.h"
# include "history.h" # include "history.h"
#else #else
# include <readline/readline.h> # include <readline/readline.h>
# include <readline/history.h> # include <readline/history.h>
#endif #endif
extern int errno; extern int errno;
static void cb_linehandler (char *); static void cb_linehandler (char *);
static void signandler (int);
int running; int running, sigwinch_received;
const char *prompt = "rltest$ "; const char *prompt = "rltest$ ";
/* Handle SIGWINCH and window size changes when readline is not active and
reading a character. */
static void
sighandler (int sig)
{
sigwinch_received = 1;
}
/* Callback function called for each line when accept-line executed, EOF /* Callback function called for each line when accept-line executed, EOF
seen, or EOF character read. This sets a flag and returns; it could seen, or EOF character read. This sets a flag and returns; it could
also call exit(3). */ also call exit(3). */
static void static void
cb_linehandler (char *line) cb_linehandler (char *line)
{ {
/* Can use ^D (stty eof) or `exit' to exit. */ /* Can use ^D (stty eof) or `exit' to exit. */
if (line == NULL || strcmp (line, "exit") == 0) if (line == NULL || strcmp (line, "exit") == 0)
{ {
if (line == 0) if (line == 0)
skipping to change at line 63 skipping to change at line 75
free (line); free (line);
} }
} }
int int
main (int c, char **v) main (int c, char **v)
{ {
fd_set fds; fd_set fds;
int r; int r;
setlocale (LC_ALL, "");
/* Handle SIGWINCH */
signal (SIGWINCH, sighandler);
/* Install the line handler. */ /* Install the line handler. */
rl_callback_handler_install (prompt, cb_linehandler); rl_callback_handler_install (prompt, cb_linehandler);
/* Enter a simple event loop. This waits until something is available /* Enter a simple event loop. This waits until something is available
to read on readline's input stream (defaults to standard input) and to read on readline's input stream (defaults to standard input) and
calls the builtin character read callback to read it. It does not calls the builtin character read callback to read it. It does not
have to modify the user's terminal settings. */ have to modify the user's terminal settings. */
running = 1; running = 1;
while (running) while (running)
{ {
FD_ZERO (&fds); FD_ZERO (&fds);
FD_SET (fileno (rl_instream), &fds); FD_SET (fileno (rl_instream), &fds);
r = select (FD_SETSIZE, &fds, NULL, NULL, NULL); r = select (FD_SETSIZE, &fds, NULL, NULL, NULL);
if (r < 0 && errno != EINTR) if (r < 0 && errno != EINTR)
{ {
perror ("rltest: select"); perror ("rltest: select");
rl_callback_handler_remove (); rl_callback_handler_remove ();
break; break;
} }
if (sigwinch_received)
{
rl_resize_terminal ();
sigwinch_received = 0;
}
if (r < 0)
continue;
if (FD_ISSET (fileno (rl_instream), &fds)) if (FD_ISSET (fileno (rl_instream), &fds))
rl_callback_read_char (); rl_callback_read_char ();
} }
printf ("rltest: Event loop has exited\n"); printf ("rltest: Event loop has exited\n");
return 0; return 0;
} }
 End of changes. 7 change blocks. 
1 lines changed or deleted 25 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS