]> git.ipfire.org Git - thirdparty/readline.git/commitdiff
ANSI C changes; fix for rl_getc and signals that arrive before it gets called in...
authorChet Ramey <chet.ramey@case.edu>
Tue, 10 Jan 2023 20:39:41 +0000 (15:39 -0500)
committerChet Ramey <chet.ramey@case.edu>
Tue, 10 Jan 2023 20:39:41 +0000 (15:39 -0500)
31 files changed:
bind.c
complete.c
display.c
funmap.c
gettimeofday.c
histexpand.c
histfile.c
history.c
histsearch.c
input.c
isearch.c
kill.c
macro.c
mbutil.c
misc.c
posixtime.h
readline.c
readline.h
rldefs.h
rlmbutil.h
rlprivate.h
search.c
signals.c
support/wcwidth.c
tcap.h
terminal.c
text.c
tilde.c
undo.c
util.c
vi_mode.c

diff --git a/bind.c b/bind.c
index 971116a90c58ef1ad5d27b4718f6db89fc7b6026..967789381f27e6051fdc0e5018d9e6725f166afb 100644 (file)
--- a/bind.c
+++ b/bind.c
@@ -1,6 +1,6 @@
 /* bind.c -- key binding and startup file support for the readline library. */
 
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.
@@ -1247,7 +1247,7 @@ const char *rl_readline_name = "other";
 /* Stack of previous values of parsing_conditionalized_out. */
 static unsigned char *if_stack = (unsigned char *)NULL;
 static int if_stack_depth;
-static int if_stack_size;
+static size_t if_stack_size;
 
 /* Push _rl_parsing_conditionalized_out, and set parser state based
    on ARGS. */
@@ -1672,7 +1672,6 @@ rl_parse_and_bind (char *string)
   if (_rl_stricmp (string, "set") == 0)
     {
       char *var, *value, *e;
-      int s;
 
       var = string + i;
       /* Make VAR point to start of variable name. */
@@ -1850,7 +1849,7 @@ rl_parse_and_bind (char *string)
   if (*funname == '\'' || *funname == '"')
     {
       char useq[2];
-      int fl = strlen (funname);
+      size_t fl = strlen (funname);
 
       useq[0] = key; useq[1] = '\0';
       if (fl && funname[fl - 1] == *funname)
@@ -2678,7 +2677,7 @@ rl_invoking_keyseqs_in_map (rl_command_func_t *function, Keymap map)
 {
   register int key;
   char **result;
-  int result_index, result_size;
+  size_t result_index, result_size;
 
   result = (char **)NULL;
   result_index = result_size = 0;
@@ -2875,9 +2874,9 @@ rl_dump_functions (int count, int key)
 static void
 _rl_macro_dumper_internal (int print_readably, Keymap map, char *prefix)
 {
-  register int key;
+  int key;
   char *keyname, *out;
-  int prefix_len;
+  size_t prefix_len;
 
   for (key = 0; key < KEYMAP_SIZE; key++)
     {
index 61461c90e637e0b6f63e7d593878cf17bd555578..fe0b8798fd24c618a0ff912da86b587c6247a3c6 100644 (file)
@@ -2037,9 +2037,25 @@ rl_complete_internal (int what_to_do)
 
   text = rl_copy_text (start, end);
   matches = gen_completion_matches (text, start, end, our_func, found_quote, quote_char);
+  /* If TEXT contains quote characters, it will be dequoted as part of
+     generating the matches, and the matches will not contain any quote
+     characters. We need to dequote TEXT before performing the comparison.
+     Since compare_match performs the dequoting, and we only want to do it
+     once, we don't call compare_matches after dequoting TEXT; we call
+     strcmp directly. */
   /* nontrivial_lcd is set if the common prefix adds something to the word
      being completed. */
-  nontrivial_lcd = matches && compare_match (text, matches[0]) != 0;
+  if (rl_filename_completion_desired && rl_filename_quoting_desired &&
+      rl_completion_found_quote && rl_filename_dequoting_function)
+    {
+      char *t;
+      t = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
+      xfree (text);
+      text = t;
+      nontrivial_lcd = matches && strcmp (text, matches[0]) != 0;
+    }
+  else
+    nontrivial_lcd = matches && strcmp (text, matches[0]) != 0;
   if (what_to_do == '!' || what_to_do == '@')
     tlen = strlen (text);
   xfree (text);
@@ -2206,7 +2222,7 @@ rl_completion_matches (const char *text, rl_compentry_func_t *entry_function)
   register int i;
 
   /* Number of slots in match_list. */
-  int match_list_size;
+  size_t match_list_size;
 
   /* The list of matches. */
   char **match_list;
@@ -2467,7 +2483,8 @@ rl_filename_completion_function (const char *text, int state)
   static char *users_dirname = (char *)NULL;
   static int filename_len;
   char *temp, *dentry, *convfn;
-  int dirlen, dentlen, convlen;
+  size_t dirlen;
+  int dentlen, convlen;
   int tilde_dirname;
   struct dirent *entry;
 
@@ -2588,6 +2605,7 @@ rl_filename_completion_function (const char *text, int state)
   /* Now that we have some state, we can read the directory. */
 
   entry = (struct dirent *)NULL;
+  convfn = dentry = 0;
   while (directory && (entry = readdir (directory)))
     {
       convfn = dentry = entry->d_name;
@@ -2837,7 +2855,7 @@ rl_menu_complete (int count, int ignore)
   static int full_completion = 0;      /* set to 1 if menu completion should reinitialize on next call */
   static int orig_start, orig_end;
   static char quote_char;
-  static int delimiter, cstate;
+  static int delimiter;
 
   /* The first time through, we generate the list of matches and set things
      up to insert them. */
index 2d3747f252367283e1e62a94de4043833e8bf5f8..1ebb2eb5f19435897bab993bb495ef2799ba80bb 100644 (file)
--- a/display.c
+++ b/display.c
@@ -664,8 +664,8 @@ rl_expand_prompt (char *prompt)
 static void
 realloc_line (int minsize)
 {
-  int minimum_size;
-  int newsize, delta;
+  size_t minimum_size;
+  size_t newsize, delta;
 
   minimum_size = DEFAULT_LINE_BUFFER_SIZE;
   if (minsize < minimum_size)
@@ -809,7 +809,7 @@ rl_redisplay (void)
 {
   int in, out, c, linenum, cursor_linenum;
   int inv_botlin, lb_botlin, lb_linenum, o_cpos;
-  int newlines, lpos, temp, n0, num, prompt_lines_estimate;
+  int newlines, lpos, temp, num, prompt_lines_estimate;
   char *prompt_this_line;
   char cur_face;
   int hl_begin, hl_end;
@@ -2732,7 +2732,6 @@ int
 rl_forced_update_display (void)
 {
   register char *temp;
-  register int tlen;
 
   if (visible_line)
     memset (visible_line, 0, line_size);
index 8b1cb4028db7fb0afe1e677d08d2a0ee12cac007..0095c6bfafb7905bd6b285f77939ca4e75e48fc3 100644 (file)
--- a/funmap.c
+++ b/funmap.c
@@ -49,7 +49,7 @@ typedef int QSFUNC ();
 extern int _rl_qsort_string_compare (char **, char **);
 
 FUNMAP **funmap;
-static int funmap_size;
+static size_t funmap_size;
 static int funmap_entry;
 
 /* After initializing the function map, this is the index of the first
@@ -251,7 +251,7 @@ const char **
 rl_funmap_names (void)
 {
   const char **result;
-  int result_size, result_index;
+  size_t result_size, result_index;
 
   /* Make sure that the function map has been initialized. */
   rl_initialize_funmap ();
index 5c2815ee94f645d253c52778bee97264932ec16c..1b78dcb2f47286573e824c579fe7937ca9d5186d 100644 (file)
@@ -1,6 +1,6 @@
 /* gettimeofday.c - gettimeofday replacement using time() */
 
-/* Copyright (C) 2020 Free Software Foundation, Inc.
+/* Copyright (C) 2020, 2022 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 #if !defined (HAVE_GETTIMEOFDAY)
 
 #include "posixtime.h"
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
 
-/* A version of gettimeofday that just sets tv_sec from time(3) */
+/* A version of gettimeofday that just sets tv_sec from time(3) on Unix-like
+   systems that don't have it, or a version for Win32 systems. */
 int
 gettimeofday (struct timeval *restrict tv, void *restrict tz)
 {
+#if !defined (_WIN32)
   tv->tv_sec = (time_t) time ((time_t *)0);
   tv->tv_usec = 0;
+#else
+  /* EPOCH is the number of 100 nanosecond intervals from
+    January 1, 1601 (UTC) to January 1, 1970.
+    (the correct value has 9 trailing zeros) */
+  static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
+
+  SYSTEMTIME  system_time;
+  FILETIME    file_time;
+  uint64_t    time;
+
+  GetSystemTime(&system_time);
+  SystemTimeToFileTime(&system_time, &file_time);
+  time =  ((uint64_t)file_time.dwLowDateTime);
+  time += ((uint64_t)file_time.dwHighDateTime) << 32;
+
+  tp->tv_sec  = (long) ((time - EPOCH) / 10000000L);
+  tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
+#endif
+
   return 0;
 }
 #endif
index 8ab68091e64cd750c58d785f2aa1a05a061a3d9b..4e9d4477be2a52d6baa43c0c3a36468a2384116d 100644 (file)
@@ -1,6 +1,6 @@
 /* histexpand.c -- history expansion. */
 
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2021,2023 Free Software Foundation, Inc.
 
    This file contains the GNU History Library (History), a set of
    routines for managing the text of previously typed lines.
@@ -70,12 +70,12 @@ static int subst_rhs_len;
    specifications from word designators.  Static for now */
 static char *history_event_delimiter_chars = HISTORY_EVENT_DELIMITERS;
 
-static char *get_history_word_specifier (char *, char *, int *);
+static char *get_history_word_specifier (const char *, char *, int *);
 static int history_tokenize_word (const char *, int);
 static char **history_tokenize_internal (const char *, int, int *);
 static char *history_substring (const char *, int, int);
 static void freewords (char **, int);
-static char *history_find_word (char *, int);
+static char *history_find_word (const char *, int);
 
 static char *quote_breaks (char *);
 
@@ -319,7 +319,7 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote)
    to the closing single quote.  FLAGS currently used to allow backslash
    to escape a single quote (e.g., for bash $'...'). */
 static void
-hist_string_extract_single_quoted (char *string, int *sindex, int flags)
+hist_string_extract_single_quoted (const char *string, int *sindex, int flags)
 {
   register int i;
 
@@ -374,7 +374,7 @@ quote_breaks (char *s)
 }
 
 static char *
-hist_error(char *s, int start, int current, int errtype)
+hist_error(const char *s, int start, int current, int errtype)
 {
   char *temp;
   const char *emsg;
@@ -434,7 +434,7 @@ hist_error(char *s, int start, int current, int errtype)
    subst_rhs is allowed to be set to the empty string. */
 
 static char *
-get_subst_pattern (char *str, int *iptr, int delimiter, int is_rhs, int *lenptr)
+get_subst_pattern (const char *str, int *iptr, int delimiter, int is_rhs, int *lenptr)
 {
   register int si, i, j, k;
   char *s;
@@ -527,12 +527,12 @@ postproc_subst_rhs (void)
    *END_INDEX_PTR, and the expanded specifier in *RET_STRING. */
 /* need current line for !# */
 static int
-history_expand_internal (char *string, int start, int qc, int *end_index_ptr, char **ret_string, char *current_line)
+history_expand_internal (const char *string, int start, int qc, int *end_index_ptr, char **ret_string, char *current_line)
 {
   int i, n, starting_index;
   int substitute_globally, subst_bywords, want_quotes, print_only;
   char *event, *temp, *result, *tstr, *t, c, *word_spec;
-  int result_len;
+  size_t result_len;
 #if defined (HANDLE_MULTIBYTE)
   mbstate_t ps;
 
@@ -881,7 +881,7 @@ history_expand_internal (char *string, int start, int qc, int *end_index_ptr, ch
 #define ADD_STRING(s) \
        do \
          { \
-           int sl = strlen (s); \
+           size_t sl = strlen (s); \
            j += sl; \
            if (j >= result_len) \
              { \
@@ -906,12 +906,13 @@ history_expand_internal (char *string, int start, int qc, int *end_index_ptr, ch
 int
 history_expand (char *hstring, char **output)
 {
-  register int j;
-  int i, r, l, passc, cc, modified, eindex, only_printing, dquote, squote, flag;
+  int j;
+  int i, r, passc, cc, modified, eindex, only_printing, dquote, squote, flag;
+  size_t l;
   char *string;
 
   /* The output string, and its length. */
-  int result_len;
+  size_t result_len;
   char *result;
 
 #if defined (HANDLE_MULTIBYTE)
@@ -1303,7 +1304,7 @@ history_expand (char *hstring, char **output)
    CALLER_INDEX is the offset in SPEC to start looking; it is updated
    to point to just after the last character parsed. */
 static char *
-get_history_word_specifier (char *spec, char *from, int *caller_index)
+get_history_word_specifier (const char *spec, char *from, int *caller_index)
 {
   register int i = *caller_index;
   int first, last;
@@ -1418,7 +1419,7 @@ history_arg_extract (int first, int last, const char *string)
 {
   register int i, len;
   char *result;
-  int size, offset;
+  size_t size, offset;
   char **list;
 
   /* XXX - think about making history_tokenize return a struct array,
@@ -1475,7 +1476,7 @@ history_arg_extract (int first, int last, const char *string)
 static int
 history_tokenize_word (const char *string, int ind)
 {
-  register int i, j;
+  int i, j;
   int delimiter, nestdelim, delimopen;
 
   i = ind;
@@ -1627,7 +1628,8 @@ static char **
 history_tokenize_internal (const char *string, int wind, int *indp)
 {
   char **result;
-  register int i, start, result_index, size;
+  int i, start, result_index;
+  size_t size;
 
   /* If we're searching for a string that's not part of a word (e.g., " "),
      make sure we set *INDP to a reasonable value. */
@@ -1636,7 +1638,7 @@ history_tokenize_internal (const char *string, int wind, int *indp)
 
   /* Get a token, and stuff it into RESULT.  The tokens are split
      exactly where the shell would split them. */
-  for (i = result_index = size = 0, result = (char **)NULL; string[i]; )
+  for (i = result_index = 0, size = 0, result = (char **)NULL; string[i]; )
     {
       /* Skip leading whitespace. */
       for (; string[i] && fielddelim (string[i]); i++)
@@ -1696,7 +1698,7 @@ freewords (char **words, int start)
    in the history line LINE.  Used to save the word matched by the
    last history !?string? search. */
 static char *
-history_find_word (char *line, int ind)
+history_find_word (const char *line, int ind)
 {
   char **words, *s;
   int i, wind;
index 3bfec5500db515ebafc2310555019711bdd93f4a..d299b5e0f0998d4679d990a1d295f5ceed6cb40b 100644 (file)
@@ -153,7 +153,7 @@ history_filename (const char *filename)
 {
   char *return_val;
   const char *home;
-  int home_len;
+  size_t home_len;
 
   return_val = filename ? savestring (filename) : (char *)NULL;
 
@@ -190,7 +190,6 @@ history_backupfile (const char *filename)
   char *ret, linkbuf[PATH_MAX+1];
   size_t len;
   ssize_t n;
-  struct stat fs;
 
   fn = filename;  
 #if defined (HAVE_READLINK)
@@ -218,7 +217,6 @@ history_tempfile (const char *filename)
   char *ret, linkbuf[PATH_MAX+1];
   size_t len;
   ssize_t n;
-  struct stat fs;
   int pid;
 
   fn = filename;  
@@ -530,6 +528,8 @@ history_truncate_file (const char *fname, int lines)
   file = filename ? open (filename, O_RDONLY|O_BINARY, 0666) : -1;
   rv = exists = 0;
 
+  orig_lines = lines;
+
   /* Don't try to truncate non-regular files. */
   if (file == -1 || fstat (file, &finfo) == -1)
     {
@@ -587,7 +587,6 @@ history_truncate_file (const char *fname, int lines)
       goto truncate_exit;
     }
 
-  orig_lines = lines;
   /* Count backwards from the end of buffer until we have passed
      LINES lines.  bp1 is set funny initially.  But since bp[1] can't
      be a comment character (since it's off the end) and *bp can't be
@@ -680,7 +679,7 @@ history_do_write (const char *filename, int nelements, int overwrite)
   register int i;
   char *output, *tempname, *histname;
   int file, mode, rv, exists;
-  struct stat finfo, nfinfo;
+  struct stat finfo;
 #ifdef HISTORY_USE_MMAP
   size_t cursize;
 
@@ -718,8 +717,8 @@ history_do_write (const char *filename, int nelements, int overwrite)
      Suggested by Peter Ho (peter@robosts.oxford.ac.uk). */
   {
     HIST_ENTRY **the_history;  /* local */
-    register int j;
-    int buffer_size;
+    size_t j;
+    size_t buffer_size;
     char *buffer;
 
     the_history = history_list ();
index 81d4c1687b659045f9da5b3b82c58ff9bb4d37b7..781f124a04b208a1b4d2bfc73c564ec54a7fdc7d 100644 (file)
--- a/history.c
+++ b/history.c
@@ -283,8 +283,6 @@ add_history (const char *string)
 
   if (history_stifled && (history_length == history_max_entries))
     {
-      register int i;
-
       /* If the history is stifled, and history_length is zero,
         and it equals history_max_entries, we don't save items. */
       if (history_length == 0)
index b62c06b7bf066a32fcc4b24bc8b3aa8c8910488c..7e5b2501755fbef075daa6d0cc9b23a8836675d2 100644 (file)
@@ -66,10 +66,11 @@ static int history_search_internal (const char *, int, int);
 static int
 history_search_internal (const char *string, int direction, int flags)
 {
-  register int i, reverse;
-  register char *line;
-  register int line_index;
-  int string_len, anchored, patsearch;
+  int i, reverse;
+  char *line;
+  int line_index;
+  size_t string_len;
+  int anchored, patsearch;
   HIST_ENTRY **the_history;    /* local */
 
   i = history_offset;
diff --git a/input.c b/input.c
index 17ad5fe760511139fd4815a543870319231ef793..186e0fac7415cb821f6f7c73319f31795fdb8598 100644 (file)
--- a/input.c
+++ b/input.c
@@ -150,7 +150,7 @@ int rl_set_timeout (unsigned int, unsigned int);
 int rl_timeout_remaining (unsigned int *, unsigned int *);
 
 int _rl_timeout_init (void);
-int _rl_timeout_sigalrm_handler (void);
+int _rl_timeout_handle_sigalrm (void);
 #if defined (RL_TIMEOUT_USE_SELECT)
 int _rl_timeout_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *, const sigset_t *);
 #endif
@@ -811,7 +811,7 @@ rl_read_key (void)
 int
 rl_getc (FILE *stream)
 {
-  int result;
+  int result, ostate, osig;
   unsigned char c;
   int fd;
 #if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
@@ -822,8 +822,22 @@ rl_getc (FILE *stream)
   fd = fileno (stream);
   while (1)
     {
+      osig = _rl_caught_signal;
+      ostate = rl_readline_state;
+
       RL_CHECK_SIGNALS ();
 
+#if defined (READLINE_CALLBACKS)
+      /* Do signal handling post-processing here, but just in callback mode
+        for right now because the signal cleanup can change some of the
+        callback state, and we need to either let the application have a
+        chance to react or abort some current operation that gets cleaned
+        up by rl_callback_sigcleanup(). If not, we'll just run through the
+        loop again. */
+      if (osig != 0 && (ostate & RL_STATE_CALLBACK))
+       goto postproc_signal;
+#endif
+
       /* We know at this point that _rl_caught_signal == 0 */
 
 #if defined (__MINGW32__)
@@ -887,6 +901,9 @@ rl_getc (FILE *stream)
 /* fprintf(stderr, "rl_getc: result = %d errno = %d\n", result, errno); */
 
 handle_error:
+      osig = _rl_caught_signal;
+      ostate = rl_readline_state;
+
       /* If the error that we received was EINTR, then try again,
         this is simply an interrupted system call to read ().  We allow
         the read to be interrupted if we caught SIGHUP, SIGTERM, or any
@@ -927,8 +944,17 @@ handle_error:
         RL_CHECK_SIGNALS ();
 #endif  /* SIGALRM */
 
+postproc_signal:
+      /* POSIX says read(2)/pselect(2)/select(2) don't return EINTR for any
+        reason other than being interrupted by a signal, so we can safely
+        call the application's signal event hook. */
       if (rl_signal_event_hook)
        (*rl_signal_event_hook) ();
+#if defined (READLINE_CALLBACKS)
+      else if (osig == SIGINT && (ostate & RL_STATE_CALLBACK) && (ostate & (RL_STATE_ISEARCH|RL_STATE_NSEARCH|RL_STATE_NUMERICARG)))
+        /* just these cases for now */
+        _rl_abort_internal ();
+#endif
     }
 }
 
index 8e7fc01bdded7cf788dd7e851d75099e6a5a4512..375618174f958bb5dbbc08f9efc00836138a2284 100644 (file)
--- a/isearch.c
+++ b/isearch.c
@@ -6,7 +6,7 @@
 /*                                                                 */
 /* **************************************************************** */
 
-/* Copyright (C) 1987-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
@@ -150,7 +150,7 @@ static void
 rl_display_search (char *search_string, int flags, int where)
 {
   char *message;
-  int msglen, searchlen;
+  size_t msglen, searchlen;
 
   searchlen = (search_string && *search_string) ? strlen (search_string) : 0;
 
@@ -340,7 +340,7 @@ _rl_search_getchar (_rl_search_cxt *cxt)
 int
 _rl_isearch_dispatch (_rl_search_cxt *cxt, int c)
 {
-  int n, wstart, wlen, limit, cval, incr;
+  int n, wstart, wlen, limit, cval;
   char *paste;
   size_t pastelen;
   int j;
@@ -725,13 +725,13 @@ opcode_dispatch:
 #if defined (HANDLE_MULTIBYTE)
       if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
        {
-         int j;
+         int w;
 
          if (cxt->mb[0] == 0 || cxt->mb[1] == 0)
            cxt->search_string[cxt->search_string_index++] = cxt->mb[0];
          else
-           for (j = 0; j < wlen; )
-             cxt->search_string[cxt->search_string_index++] = cxt->mb[j++];
+           for (w = 0; w < wlen; )
+             cxt->search_string[cxt->search_string_index++] = cxt->mb[w++];
        }
       else
 #endif
diff --git a/kill.c b/kill.c
index 995212564b3df682738f2f2b8e699048867964c0..659e57fd4cc6a41f6294dd5427e0091379a51a92 100644 (file)
--- a/kill.c
+++ b/kill.c
@@ -1,6 +1,6 @@
 /* kill.c -- kill ring management. */
 
-/* Copyright (C) 1994-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1994-2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
@@ -756,8 +756,8 @@ _rl_bracketed_text (size_t *lenp)
 int
 rl_bracketed_paste_begin (int count, int key)
 {
-  int retval, c;
-  size_t len, cap;
+  int retval;
+  size_t len;
   char *buf;
 
   buf = _rl_bracketed_text (&len);
@@ -774,7 +774,7 @@ int
 _rl_read_bracketed_paste_prefix (int c)
 {
   char pbuf[BRACK_PASTE_SLEN+1], *pbpref;
-  int key, ind, j;
+  int key, ind;
 
   pbpref = BRACK_PASTE_PREF;           /* XXX - debugging */
   if (c != pbpref[0])
@@ -846,7 +846,7 @@ _rl_bracketed_read_key ()
 int
 _rl_bracketed_read_mbstring (char *mb, int mlen)
 {
-  int c, r;
+  int c;
 
   c = _rl_bracketed_read_key ();
   if (c < 0)
diff --git a/macro.c b/macro.c
index 231a24bcda3d2a865f7c4890010cfd0e8dcd5ca5..9ac258d51abfca8e6a7317fd0904b3a6e315e1a9 100644 (file)
--- a/macro.c
+++ b/macro.c
@@ -69,7 +69,7 @@ static int executing_macro_index;
 static char *current_macro = (char *)NULL;
 
 /* The size of the buffer allocated to current_macro. */
-static int current_macro_size;
+static size_t current_macro_size;
 
 /* The index at which characters are being added to current_macro. */
 static int current_macro_index;
index 47e9100a68cc3eb525cd1a90f4ac1c05421ff074..11cf2293b198343a5d93e59e4d72b79d99f52d8e 100644 (file)
--- a/mbutil.c
+++ b/mbutil.c
@@ -1,6 +1,6 @@
 /* mbutil.c -- readline multibyte character utility functions */
 
-/* Copyright (C) 2001-2021 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2021,2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
@@ -148,7 +148,7 @@ _rl_utf8_mblen (const char *s, size_t n)
 }
 
 static int
-_rl_find_next_mbchar_internal (char *string, int seed, int count, int find_non_zero)
+_rl_find_next_mbchar_internal (const char *string, int seed, int count, int find_non_zero)
 {
   size_t tmp, len;
   mbstate_t ps;
@@ -228,7 +228,7 @@ _rl_find_next_mbchar_internal (char *string, int seed, int count, int find_non_z
 }
 
 static inline int
-_rl_test_nonzero (char *string, int ind, int len)
+_rl_test_nonzero (const char *string, int ind, int len)
 {
   size_t tmp;
   WCHAR_T wc;
@@ -242,9 +242,8 @@ _rl_test_nonzero (char *string, int ind, int len)
 
 /* experimental -- needs to handle zero-width characters better */
 static int
-_rl_find_prev_utf8char (char *string, int seed, int find_non_zero)
+_rl_find_prev_utf8char (const char *string, int seed, int find_non_zero)
 {
-  char *s;
   unsigned char b;
   int save, prev;
   size_t len;
@@ -288,7 +287,7 @@ _rl_find_prev_utf8char (char *string, int seed, int find_non_zero)
 }  
 
 /*static*/ int
-_rl_find_prev_mbchar_internal (char *string, int seed, int find_non_zero)
+_rl_find_prev_mbchar_internal (const char *string, int seed, int find_non_zero)
 {
   mbstate_t ps;
   int prev, non_zero_prev, point, length;
@@ -356,7 +355,7 @@ _rl_find_prev_mbchar_internal (char *string, int seed, int find_non_zero)
    if an invalid multibyte sequence was encountered. It returns (size_t)(-2) 
    if it couldn't parse a complete  multibyte character.  */
 int
-_rl_get_char_len (char *src, mbstate_t *ps)
+_rl_get_char_len (const char *src, mbstate_t *ps)
 {
   size_t tmp, l;
   int mb_cur_max;
@@ -368,7 +367,7 @@ _rl_get_char_len (char *src, mbstate_t *ps)
   else
     {
       mb_cur_max = MB_CUR_MAX;
-      tmp = mbrlen((const char *)src, (l < mb_cur_max) ? l : mb_cur_max, ps);
+      tmp = mbrlen(src, (l < mb_cur_max) ? l : mb_cur_max, ps);
     }
   if (tmp == (size_t)(-2))
     {
@@ -394,7 +393,7 @@ _rl_get_char_len (char *src, mbstate_t *ps)
 /* compare the specified two characters. If the characters matched,
    return 1. Otherwise return 0. */
 int
-_rl_compare_chars (char *buf1, int pos1, mbstate_t *ps1, char *buf2, int pos2, mbstate_t *ps2)
+_rl_compare_chars (const char *buf1, int pos1, mbstate_t *ps1, const char *buf2, int pos2, mbstate_t *ps2)
 {
   int i, w1, w2;
 
@@ -417,7 +416,7 @@ _rl_compare_chars (char *buf1, int pos1, mbstate_t *ps1, char *buf2, int pos2, m
    if point is invalid (point < 0 || more than string length),
    it returns -1 */
 int
-_rl_adjust_point (char *string, int point, mbstate_t *ps)
+_rl_adjust_point (const char *string, int point, mbstate_t *ps)
 {
   size_t tmp;
   int length, pos;
@@ -457,7 +456,7 @@ _rl_adjust_point (char *string, int point, mbstate_t *ps)
 }
 
 int
-_rl_is_mbchar_matched (char *string, int seed, int end, char *mbchar, int length)
+_rl_is_mbchar_matched (const char *string, int seed, int end, char *mbchar, int length)
 {
   int i;
 
@@ -471,12 +470,12 @@ _rl_is_mbchar_matched (char *string, int seed, int end, char *mbchar, int length
 }
 
 WCHAR_T
-_rl_char_value (char *buf, int ind)
+_rl_char_value (const char *buf, int ind)
 {
   size_t tmp;
   WCHAR_T wc;
   mbstate_t ps;
-  int l;
+  size_t l;
 
   if (MB_LEN_MAX == 1 || rl_byte_oriented)
     return ((WCHAR_T) buf[ind]);
@@ -500,7 +499,7 @@ _rl_char_value (char *buf, int ind)
    characters. */
 #undef _rl_find_next_mbchar
 int
-_rl_find_next_mbchar (char *string, int seed, int count, int flags)
+_rl_find_next_mbchar (const char *string, int seed, int count, int flags)
 {
 #if defined (HANDLE_MULTIBYTE)
   return _rl_find_next_mbchar_internal (string, seed, count, flags);
@@ -514,7 +513,7 @@ _rl_find_next_mbchar (char *string, int seed, int count, int flags)
    we look for non-zero-width multibyte characters. */
 #undef _rl_find_prev_mbchar
 int
-_rl_find_prev_mbchar (char *string, int seed, int flags)
+_rl_find_prev_mbchar (const char *string, int seed, int flags)
 {
 #if defined (HANDLE_MULTIBYTE)
   return _rl_find_prev_mbchar_internal (string, seed, flags);
diff --git a/misc.c b/misc.c
index dddd499c0e08ff24a6b8d9ac97b436143d67bbb8..e9bbfa260d3dc352f420eddbb6706133ae5481af 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -383,8 +383,6 @@ rl_maybe_save_line (void)
 int
 _rl_free_saved_history_line (void)
 {
-  UNDO_LIST *orig;
-
   if (_rl_saved_line_for_history)
     {
       if (rl_undo_list && rl_undo_list == (UNDO_LIST *)_rl_saved_line_for_history->data)
index 8d5f42611de9e95336aac1433a78f69f435fa557..319cb168e34caef14525f8b8a50458347d88bcff 100644 (file)
@@ -1,6 +1,6 @@
 /* posixtime.h -- wrapper for time.h, sys/times.h mess. */
 
-/* Copyright (C) 1999-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1999-2022 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -49,7 +49,7 @@ struct timeval
 #endif
 
 #if !HAVE_GETTIMEOFDAY
-extern int gettimeofday PARAMS((struct timeval * restrict, void * restrict));
+extern int gettimeofday (struct timeval * restrict, void * restrict);
 #endif
 
 /* These exist on BSD systems, at least. */
index 6f538454391f82d59d501ed2691203f5a41cf4aa..65eb54e9e2db7da3f60ce87677c3f6f5d07111e7 100644 (file)
@@ -1,7 +1,7 @@
 /* readline.c -- a general facility for reading lines of input
    with emacs style editing and completion. */
 
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
@@ -262,7 +262,7 @@ _rl_keyseq_cxt *_rl_kscxt = 0;
 
 int rl_executing_key;
 char *rl_executing_keyseq = 0;
-int _rl_executing_keyseq_size = 0;
+size_t _rl_executing_keyseq_size = 0;
 
 struct _rl_cmd _rl_pending_command;
 struct _rl_cmd *_rl_command_to_execute = (struct _rl_cmd *)NULL;
@@ -590,7 +590,8 @@ readline_internal_charloop (void)
        {
          (*rl_redisplay_function) ();
          _rl_want_redisplay = 0;
-         memcpy ((void *)_rl_top_level, (void *)olevel, sizeof (procenv_t));
+         if (RL_ISSTATE (RL_STATE_CALLBACK))
+           memcpy ((void *)_rl_top_level, (void *)olevel, sizeof (procenv_t));
 
          /* If we longjmped because of a timeout, handle it here. */
          if (RL_ISSTATE (RL_STATE_TIMEOUT))
index cac269f0b433ca795a929e0c4c4ebde42446f7de..259e6b4b29b78cdf8e0632f9f51c6333bf730e56 100644 (file)
@@ -939,7 +939,7 @@ struct readline_state {
   char *prompt;
 
   /* global state */
-  int rlstate;
+  int rlstate;         /* XXX -- needs to be unsigned long */
   int done;
   Keymap kmap;
 
index dfb1320fdc5a4c29683eda49ccfcdd2c14f7baa2..c67b3857ed564fcb4707ce0337e9273e0ee94abe 100644 (file)
--- a/rldefs.h
+++ b/rldefs.h
@@ -40,7 +40,7 @@
 #  if defined (HAVE_TERMIO_H)
 #    define TERMIO_TTY_DRIVER
 #  else
-#    if !defined (__MINGW32__) && !defined (_WIN32)
+#    if !defined (__MINGW32__) && !defined (_MSC_VER)
 #      define NEW_TTY_DRIVER
 #    else
 #      define NO_TTY_DRIVER
index d9060572e5821f6811d1482b741b8490357c85cb..42d47c3d382f384af5c6ca588b9814b4ad7aec10 100644 (file)
 #define MB_FIND_ANY    0x00
 #define MB_FIND_NONZERO        0x01
 
-extern int _rl_find_prev_mbchar (char *, int, int);
-extern int _rl_find_next_mbchar (char *, int, int, int);
+extern int _rl_find_prev_mbchar (const char *, int, int);
+extern int _rl_find_next_mbchar (const char *, int, int, int);
 
 #ifdef HANDLE_MULTIBYTE
 
-extern int _rl_compare_chars (char *, int, mbstate_t *, char *, int, mbstate_t *);
-extern int _rl_get_char_len (char *, mbstate_t *);
-extern int _rl_adjust_point (char *, int, mbstate_t *);
+extern int _rl_compare_chars (const char *, int, mbstate_t *, const char *, int, mbstate_t *);
+extern int _rl_get_char_len (const char *, mbstate_t *);
+extern int _rl_adjust_point (const char *, int, mbstate_t *);
 
 extern int _rl_read_mbchar (char *, int);
 extern int _rl_read_mbstring (int, char *, int);
 
-extern int _rl_is_mbchar_matched (char *, int, int, char *, int);
+extern int _rl_is_mbchar_matched (const char *, int, int, char *, int);
 
-extern WCHAR_T _rl_char_value (char *, int);
+extern WCHAR_T _rl_char_value (const char *, int);
 extern int _rl_walphabetic (WCHAR_T);
 
 #define _rl_to_wupper(wc)      (iswlower (wc) ? towupper (wc) : (wc))
index 806766131a0d6b4085b4775a6f8be1ed954949ad..15a75c5bb28bf1dcb8d028eb1e00596e6293f448 100644 (file)
@@ -570,7 +570,7 @@ extern procenv_t _rl_top_level;
 extern _rl_keyseq_cxt *_rl_kscxt;
 extern int _rl_keyseq_timeout;
 
-extern int _rl_executing_keyseq_size;
+extern size_t _rl_executing_keyseq_size;
 
 extern rl_hook_func_t *_rl_internal_startup_hook;
 
index eea2301115ef6b9e757b50db93b98c20cab7215a..43c66b1bc1d68593e6a0971687228a2e375f7343 100644 (file)
--- a/search.c
+++ b/search.c
@@ -65,7 +65,7 @@ static int _rl_history_search_len;
 static int _rl_history_search_flags;
 
 static char *history_search_string;
-static int history_string_size;
+static size_t history_string_size;
 
 static void make_history_line_current (HIST_ENTRY *);
 static int noninc_search_from_pos (char *, int, int, int, int *);
index 9df365e48e4cd5b0602668e579f1274a43c647d8..ec835e5aa68ebacaa498f942282860e4db949c59 100644 (file)
--- a/signals.c
+++ b/signals.c
@@ -622,7 +622,6 @@ rl_check_signals (void)
 /* **************************************************************** */
 
 #if defined (HAVE_POSIX_SIGNALS)
-static sigset_t sigint_set, sigint_oset;
 static sigset_t sigwinch_set, sigwinch_oset;
 #else /* !HAVE_POSIX_SIGNALS */
 #  if defined (HAVE_BSD_SIGNALS)
index 0f5ec995796f4813abbcf4972aec0378ab74722a..e8b5308564debbc825fbd2c2421f629aa6c58020 100644 (file)
@@ -70,8 +70,13 @@ struct interval {
   int last;
 };
 
+/* Needs WCHAR_T from rlmbutil.h */
+#ifndef WCHAR_T
+#  define WCHAR_t wchar_t
+#endif
+
 /* auxiliary function for binary search in interval table */
-static int bisearch(wchar_t ucs, const struct interval *table, int max) {
+static int bisearch(WCHAR_T ucs, const struct interval *table, int max) {
   int min = 0;
   int mid;
 
@@ -123,7 +128,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) {
  * in ISO 10646.
  */
 
-int mk_wcwidth(wchar_t ucs)
+int mk_wcwidth(WCHAR_T ucs)
 {
   /* sorted list of non-overlapping intervals of non-spacing characters */
   /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
@@ -208,7 +213,7 @@ int mk_wcwidth(wchar_t ucs)
 }
 
 
-int mk_wcswidth(const wchar_t *pwcs, size_t n)
+int mk_wcswidth(const WCHAR_T *pwcs, size_t n)
 {
   int w, width = 0;
 
@@ -231,7 +236,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n)
  * the traditional terminal character-width behaviour. It is not
  * otherwise recommended for general use.
  */
-int mk_wcwidth_cjk(wchar_t ucs)
+int mk_wcwidth_cjk(WCHAR_T ucs)
 {
   /* sorted list of non-overlapping intervals of East Asian Ambiguous
    * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
@@ -299,7 +304,7 @@ int mk_wcwidth_cjk(wchar_t ucs)
 }
 
 
-int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n)
+int mk_wcswidth_cjk(const WCHAR_T *pwcs, size_t n)
 {
   int w, width = 0;
 
diff --git a/tcap.h b/tcap.h
index 859e6eed5aabed599a3fb4c4ac43fe537c7e67d1..1121061b8ecef23ff4847f2611cccd27ffbc8563 100644 (file)
--- a/tcap.h
+++ b/tcap.h
@@ -46,14 +46,14 @@ extern char *UP, *BC;
 
 extern short ospeed;
 
-extern int tgetent ();
-extern int tgetflag ();
-extern int tgetnum ();
-extern char *tgetstr ();
+extern int tgetent PARAMS((char *, const char *));
+extern int tgetflag PARAMS((const char *));
+extern int tgetnum PARAMS((const char *));
+extern char *tgetstr PARAMS((const char *, char **));
 
-extern int tputs ();
+extern int tputs PARAMS((const char *, int, int (*)(int));
 
-extern char *tgoto ();
+extern char *tgoto PARAMS((const char *, int, int));
 
 #endif /* HAVE_TERMCAP_H */
 
index 9997161f818e934875d12fec50e7f1caccfd5ec0..2c13c402bac3a26880804a012e3c8857ddd8ecf0 100644 (file)
@@ -69,7 +69,7 @@
 #include "rlshell.h"
 #include "xmalloc.h"
 
-#if defined (__MINGW32__)
+#if defined (_WIN32)
 #  include <windows.h>
 #  include <wincon.h>
 
@@ -229,7 +229,7 @@ _emx_get_screensize (int *swp, int *shp)
 }
 #endif
 
-#if defined (__MINGW32__)
+#if defined (_WIN32)
 static void
 _win_get_screensize (int *swp, int *shp)
 {
@@ -272,7 +272,7 @@ _rl_get_screen_size (int tty, int ignore_env)
 
 #if defined (__EMX__)
   _emx_get_screensize (&wc, &wr);
-#elif defined (__MINGW32__)
+#elif defined (_WIN32) && !defined (__CYGWIN__)
   _win_get_screensize (&wc, &wr);
 #endif
 
diff --git a/text.c b/text.c
index 91c3f330d897d03c88ad3459fbcdf090acb4f2fd..abe99b341435ab63c4dd21963106413957ecc568 100644 (file)
--- a/text.c
+++ b/text.c
@@ -1,6 +1,6 @@
 /* text.c -- text handling commands for readline. */
 
-/* Copyright (C) 1987-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
diff --git a/tilde.c b/tilde.c
index d678a31ab2735a95b60906fd979e60cfe63c8056..c31f921393441c5ab8063c08cb73435869a2c29a 100644 (file)
--- a/tilde.c
+++ b/tilde.c
@@ -1,6 +1,6 @@
 /* tilde.c -- Tilde expansion code (~/foo := $HOME/foo). */
 
-/* Copyright (C) 1988-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1988-2020,2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.
@@ -160,8 +160,9 @@ tilde_find_prefix (const char *string, int *len)
 static int
 tilde_find_suffix (const char *string)
 {
-  register int i, j, string_len;
-  register char **suffixes;
+  int i, j;
+  size_t string_len;
+  char **suffixes;
 
   suffixes = tilde_additional_suffixes;
   string_len = strlen (string);
@@ -189,7 +190,7 @@ char *
 tilde_expand (const char *string)
 {
   char *result;
-  int result_size, result_index;
+  size_t result_size, result_index;
 
   result_index = result_size = 0;
   if (result = strchr (string, '~'))
@@ -200,7 +201,7 @@ tilde_expand (const char *string)
   /* Scan through STRING expanding tildes as we come to them. */
   while (1)
     {
-      register int start, end;
+      int start, end;
       char *tilde_word, *expansion;
       int len;
 
@@ -318,7 +319,7 @@ static char *
 glue_prefix_and_suffix (char *prefix, const char *suffix, int suffind)
 {
   char *ret;
-  int plen, slen;
+  size_t plen, slen;
 
   plen = (prefix && *prefix) ? strlen (prefix) : 0;
   slen = strlen (suffix + suffind);
diff --git a/undo.c b/undo.c
index e4c457dce328a210c0a77e94903421f3f3251b74..c9c2a5b2d327ecda500eda00dcdd2bee247c23bb 100644 (file)
--- a/undo.c
+++ b/undo.c
@@ -116,7 +116,7 @@ _rl_free_undo_list (UNDO_LIST *ul)
 void
 rl_free_undo_list (void)
 {
-  UNDO_LIST *release, *orig_list;
+  UNDO_LIST *orig_list;
 
   orig_list = rl_undo_list;
   _rl_free_undo_list (rl_undo_list);
diff --git a/util.c b/util.c
index 2e986db0a5ed34350ce5155ec66468adfc7e8de2..d481b8561eff7e44cc24b3caa23aa601978db4cb 100644 (file)
--- a/util.c
+++ b/util.c
@@ -321,7 +321,8 @@ _rl_errmsg (format, arg1, arg2)
 char *
 _rl_strindex (const char *s1, const char *s2)
 {
-  register int i, l, len;
+  int i;
+  size_t l, len;
 
   for (i = 0, l = strlen (s2), len = strlen (s1); (len - i) >= l; i++)
     if (_rl_strnicmp (s1 + i, s2, l) == 0)
index 3a033bab46f8eb9c3eca32145adc0fe325bdf0be..96523c731dc360afa25581dfbada94a1571e8d27 100644 (file)
--- a/vi_mode.c
+++ b/vi_mode.c
@@ -1,7 +1,7 @@
 /* vi_mode.c -- A vi emulation mode for Bash.
    Derived from code written by Jeff Sparkes (jsparkes@bnr.ca).  */
 
-/* Copyright (C) 1987-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
@@ -101,9 +101,8 @@ static int vi_replace_count;
 /* If non-zero, we have text inserted after a c[motion] command that put
    us implicitly into insert mode.  Some people want this text to be
    attached to the command so that it is `redoable' with `.'. */
-static int vi_continued_command;
 static char *vi_insert_buffer;
-static int vi_insert_buffer_size;
+static size_t vi_insert_buffer_size;
 
 static int _rl_vi_last_repeat = 1;
 static int _rl_vi_last_arg_sign = 1;
@@ -1340,7 +1339,6 @@ _rl_vi_domove_callback (_rl_vimotion_cxt *m)
 int
 rl_vi_domove (int x, int *ignore)
 {
-  int r;
   _rl_vimotion_cxt *m;
 
   m = _rl_vimvcxt;