.\" 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.
.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
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
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
@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
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
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.
@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
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;
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
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
/* 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 *);
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)
#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
/* 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)
{
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