]> git.ipfire.org Git - thirdparty/readline.git/commitdiff
cleanups for using rl_input_available_hook with callback mode
authorChet Ramey <chet.ramey@case.edu>
Wed, 25 Jan 2023 16:43:30 +0000 (11:43 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 25 Jan 2023 16:43:30 +0000 (11:43 -0500)
doc/history.3
doc/history.texi
doc/hstech.texi
doc/rltech.texi
doc/version.texi
histexpand.c
history.h
input.c
rlprivate.h

index 06419cff564359ef8b3f633a1de83ca148bedfc3..082bf42d6fe82c01d65605fb3593e07ea2353e9c 100644 (file)
@@ -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
index 721118bce1e8bfb9a9bbf75da627c22fb5ef458e..c15e95779a71a263ef409f87347e98b4e4eeb344 100644 (file)
@@ -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
index da6417b48fda487e24853fab3d7176912ba89e10..7a6d7627be933248a24c0b86f1b46e7e1503d704 100644 (file)
@@ -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
index a93f77dabf81de0d9575aaf0947747f3f0bc96d5..f40bc2bd552691a5e5cf7d8e1de1e8a230a2e048 100644 (file)
@@ -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.
index d310273405152877ce211fe53d644851f6fad667..2b80d343b9b9d4e9dfdeeafe2d115031289201c7 100644 (file)
@@ -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
index 4e9d4477be2a52d6baa43c0c3a36468a2384116d..38a4953137180aec3f7af22975857b273b7fa442 100644 (file)
@@ -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
index 5208f9a463b2a18c5a6e9ee32d120980e989eaaf..9c2b099041de22e61b8404faae065f3aaa92a4d4 100644 (file)
--- 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 186e0fac7415cb821f6f7c73319f31795fdb8598..229474fff6dcca8efa6de670780d862267149a07 100644 (file)
--- 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)
 {
index 15a75c5bb28bf1dcb8d028eb1e00596e6293f448..77a4d8c6ca8ca80a58daa01d86f16fca576dee1c 100644 (file)
@@ -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