From: Chet Ramey Date: Wed, 25 Jan 2023 16:43:30 +0000 (-0500) Subject: cleanups for using rl_input_available_hook with callback mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d77e3904850abba9d0d166e4d31bc9fb2dc35c26;p=thirdparty%2Freadline.git cleanups for using rl_input_available_hook with callback mode --- diff --git a/doc/history.3 b/doc/history.3 index 06419cf..082bf42 100644 --- a/doc/history.3 +++ b/doc/history.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Fri Jul 17 09:43:01 EDT 2020 +.\" Last Change: Thu Jan 19 17:20:59 EST 2023 .\" -.TH HISTORY 3 "2020 July 17" "GNU History 8.1" +.TH HISTORY 3 "2023 January 19" "GNU History 8.2" .\" .\" File Name macro. This used to be `.PN', for Path Name, .\" but Sun doesn't seem to like that very much. @@ -40,8 +40,8 @@ .SH NAME history \- GNU History Library .SH COPYRIGHT -.if t The GNU History Library is Copyright \(co 1989-2020 by the Free Software Foundation, Inc. -.if n The GNU History Library is Copyright (C) 1989-2020 by the Free Software Foundation, Inc. +.if t The GNU History Library is Copyright \(co 1989-2023 by the Free Software Foundation, Inc. +.if n The GNU History Library is Copyright (C) 1989-2023 by the Free Software Foundation, Inc. .SH DESCRIPTION Many programs read input from the user a line at a time. The GNU History library is able to keep track of those lines, associate arbitrary @@ -530,7 +530,7 @@ Returns 0 on success, or \fBerrno\fP on failure. These functions implement history expansion. -.Fn2 int history_expand "char *string" "char **output" +.Fn2 int history_expand "const char *string" "char **output" Expand \fIstring\fP, placing the result into \fIoutput\fP, a pointer to a string. Returns: .RS diff --git a/doc/history.texi b/doc/history.texi index 721118b..c15e957 100644 --- a/doc/history.texi +++ b/doc/history.texi @@ -12,7 +12,7 @@ This document describes the GNU History library a programming tool that provides a consistent user interface for recalling lines of previously typed input. -Copyright @copyright{} 1988--2022 Free Software Foundation, Inc. +Copyright @copyright{} 1988--2023 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document diff --git a/doc/hstech.texi b/doc/hstech.texi index da6417b..7a6d762 100644 --- a/doc/hstech.texi +++ b/doc/hstech.texi @@ -1,7 +1,7 @@ @ignore This file documents the user interface to the GNU History library. -Copyright (C) 1988-2022 Free Software Foundation, Inc. +Copyright (C) 1988-2023 Free Software Foundation, Inc. Authored by Brian Fox and Chet Ramey. Permission is granted to make and distribute verbatim copies of this manual @@ -369,7 +369,7 @@ Returns 0 on success, or @code{errno} on failure. These functions implement history expansion. -@deftypefun int history_expand (char *string, char **output) +@deftypefun int history_expand (const char *string, char **output) Expand @var{string}, placing the result into @var{output}, a pointer to a string (@pxref{History Interaction}). Returns: @table @code diff --git a/doc/rltech.texi b/doc/rltech.texi index a93f77d..f40bc2b 100644 --- a/doc/rltech.texi +++ b/doc/rltech.texi @@ -476,6 +476,8 @@ The default hook checks @code{rl_instream}; if an application is using a different input source, it should set the hook appropriately. Readline queries for available input when implementing intra-key-sequence timeouts during input and incremental searches. +This function must return zero if there is no input available, and non-zero +if input is available. This may use an application-specific timeout before returning a value; Readline uses the value passed to @code{rl_set_keyboard_input_timeout()} or the value of the user-settable @var{keyseq-timeout} variable. diff --git a/doc/version.texi b/doc/version.texi index d310273..2b80d34 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,11 +1,11 @@ @ignore -Copyright (C) 1988-2022 Free Software Foundation, Inc. +Copyright (C) 1988-2023 Free Software Foundation, Inc. @end ignore @set EDITION 8.2 @set VERSION 8.2 -@set UPDATED 19 September 2022 -@set UPDATED-MONTH September 2022 +@set UPDATED 21 January 2023 +@set UPDATED-MONTH January 2023 -@set LASTCHANGE Mon Sep 19 11:15:16 EDT 2022 +@set LASTCHANGE Sat Jan 21 17:10:44 EST 2023 diff --git a/histexpand.c b/histexpand.c index 4e9d447..38a4953 100644 --- a/histexpand.c +++ b/histexpand.c @@ -904,7 +904,7 @@ history_expand_internal (const char *string, int start, int qc, int *end_index_p while (0) int -history_expand (char *hstring, char **output) +history_expand (const char *hstring, char **output) { int j; int i, r, passc, cc, modified, eindex, only_printing, dquote, squote, flag; @@ -966,7 +966,7 @@ history_expand (char *hstring, char **output) memset (&ps, 0, sizeof (mbstate_t)); #endif - string = hstring; + string = (char *)hstring; /* If not quick substitution, still maybe have to do expansion. */ /* `!' followed by one of the characters in history_no_expand_chars diff --git a/history.h b/history.h index 5208f9a..9c2b099 100644 --- a/history.h +++ b/history.h @@ -232,7 +232,7 @@ extern int history_truncate_file (const char *, int); If an error occurred in expansion, then OUTPUT contains a descriptive error message. */ -extern int history_expand (char *, char **); +extern int history_expand (const char *, char **); /* Extract a string segment consisting of the FIRST through LAST arguments present in STRING. Arguments are broken up as in diff --git a/input.c b/input.c index 186e0fa..229474f 100644 --- a/input.c +++ b/input.c @@ -138,13 +138,7 @@ win32_isatty (int fd) /* Readline timeouts */ -/* I don't know how to set a timeout for _getch() in MinGW32, so we use - SIGALRM. */ -#if (defined (HAVE_PSELECT) || defined (HAVE_SELECT)) && !defined (__MINGW32__) -# define RL_TIMEOUT_USE_SELECT -#else -# define RL_TIMEOUT_USE_SIGALRM -#endif +/* We now define RL_TIMEOUT_USE_SELECT or RL_TIMEOUT_USE_SIGALRM in rlprivate.h */ int rl_set_timeout (unsigned int, unsigned int); int rl_timeout_remaining (unsigned int *, unsigned int *); @@ -259,37 +253,44 @@ rl_gather_tyi (void) input = 0; tty = fileno (rl_instream); + /* Move this up here to give it first shot, but it can't set chars_avail */ + /* XXX - need rl_chars_available_hook? */ + if (rl_input_available_hook) + { + result = (*rl_input_available_hook) (); + if (result == 0) + result = -1; + } + #if defined (HAVE_PSELECT) || defined (HAVE_SELECT) - FD_ZERO (&readfds); - FD_ZERO (&exceptfds); - FD_SET (tty, &readfds); - FD_SET (tty, &exceptfds); - USEC_TO_TIMEVAL (_keyboard_input_timeout, timeout); + if (result == -1) + { + FD_ZERO (&readfds); + FD_ZERO (&exceptfds); + FD_SET (tty, &readfds); + FD_SET (tty, &exceptfds); + USEC_TO_TIMEVAL (_keyboard_input_timeout, timeout); #if defined (RL_TIMEOUT_USE_SELECT) - result = _rl_timeout_select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout, NULL); + result = _rl_timeout_select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout, NULL); #else - result = select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout); + result = select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout); #endif - if (result <= 0) - return 0; /* Nothing to read. */ + if (result <= 0) + return 0; /* Nothing to read. */ + } #endif - result = -1; - errno = 0; #if defined (FIONREAD) - result = ioctl (tty, FIONREAD, &chars_avail); - if (result == -1 && errno == EIO) - return -1; if (result == -1) - chars_avail = 0; -#endif - - if (result == -1 && rl_input_available_hook) { - result = (*rl_input_available_hook) (); - if (result == 0) - result = -1; + errno = 0; + result = ioctl (tty, FIONREAD, &chars_avail); + if (result == -1 && errno == EIO) + return -1; + if (result == -1) + chars_avail = 0; } +#endif #if defined (O_NDELAY) if (result == -1) @@ -315,8 +316,11 @@ rl_gather_tyi (void) #if defined (__MINGW32__) /* Use getch/_kbhit to check for available console input, in the same way that we read it normally. */ - chars_avail = isatty (tty) ? _kbhit () : 0; - result = 0; + if (result == -1) + { + chars_avail = isatty (tty) ? _kbhit () : 0; + result = 0; + } #endif /* If there's nothing available, don't waste time trying to read @@ -658,7 +662,7 @@ rl_timeout_remaining (unsigned int *secs, unsigned int *usecs) /* This should only be called if RL_TIMEOUT_USE_SELECT is defined. */ -#if defined (HAVE_PSELECT) || defined (HAVE_SELECT) +#if defined (RL_TIMEOUT_USE_SELECT) int _rl_timeout_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout, const sigset_t *sigmask) { diff --git a/rlprivate.h b/rlprivate.h index 15a75c5..77a4d8c 100644 --- a/rlprivate.h +++ b/rlprivate.h @@ -303,8 +303,22 @@ extern int _rl_pushed_input_available (void); extern int _rl_timeout_init (void); extern int _rl_timeout_handle_sigalrm (void); -#if defined (_POSIXSELECT_H_) && !defined (__MINGW32__) && (defined (HAVE_SELECT) || defined (HAVE_PSELECT)) + +#if defined (_POSIXSELECT_H_) /* use as a sentinel for fd_set, struct timeval, and sigset_t definitions */ + +#if defined (__MINGW32__) +# define RL_TIMEOUT_USE_SIGALRM +#elif defined (HAVE_SELECT) || defined (HAVE_PSELECT) +# define RL_TIMEOUT_USE_SELECT +#elif defined (_MSC_VER) +/* can't use select/pselect or SIGALRM, so no timeouts */ +#else +# define RL_TIMEOUT_USE_SIGALRM +#endif + +#endif +#if defined (RL_TIMEOUT_USE_SELECT) extern int _rl_timeout_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *, const sigset_t *); #endif