From: Chet Ramey Date: Tue, 10 Jan 2023 20:39:41 +0000 (-0500) Subject: ANSI C changes; fix for rl_getc and signals that arrive before it gets called in... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4ebdc06601fb54297435d2e286d901cba1cd6c6;p=thirdparty%2Freadline.git ANSI C changes; fix for rl_getc and signals that arrive before it gets called in callback mode --- diff --git a/bind.c b/bind.c index 971116a..9677893 100644 --- 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++) { diff --git a/complete.c b/complete.c index 61461c9..fe0b879 100644 --- a/complete.c +++ b/complete.c @@ -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. */ diff --git a/display.c b/display.c index 2d3747f..1ebb2eb 100644 --- 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); diff --git a/funmap.c b/funmap.c index 8b1cb40..0095c6b 100644 --- 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 (); diff --git a/gettimeofday.c b/gettimeofday.c index 5c2815e..1b78dcb 100644 --- a/gettimeofday.c +++ b/gettimeofday.c @@ -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. @@ -23,13 +23,37 @@ #if !defined (HAVE_GETTIMEOFDAY) #include "posixtime.h" +#if HAVE_STDINT_H +#include +#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 diff --git a/histexpand.c b/histexpand.c index 8ab6809..4e9d447 100644 --- a/histexpand.c +++ b/histexpand.c @@ -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; diff --git a/histfile.c b/histfile.c index 3bfec55..d299b5e 100644 --- a/histfile.c +++ b/histfile.c @@ -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 (); diff --git a/history.c b/history.c index 81d4c16..781f124 100644 --- 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) diff --git a/histsearch.c b/histsearch.c index b62c06b..7e5b250 100644 --- a/histsearch.c +++ b/histsearch.c @@ -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 17ad5fe..186e0fa 100644 --- 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 } } diff --git a/isearch.c b/isearch.c index 8e7fc01..3756181 100644 --- 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 9952125..659e57f 100644 --- 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 231a24b..9ac258d 100644 --- 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; diff --git a/mbutil.c b/mbutil.c index 47e9100..11cf229 100644 --- 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 dddd499..e9bbfa2 100644 --- 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) diff --git a/posixtime.h b/posixtime.h index 8d5f426..319cb16 100644 --- a/posixtime.h +++ b/posixtime.h @@ -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. */ diff --git a/readline.c b/readline.c index 6f53845..65eb54e 100644 --- a/readline.c +++ b/readline.c @@ -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)) diff --git a/readline.h b/readline.h index cac269f..259e6b4 100644 --- a/readline.h +++ b/readline.h @@ -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; diff --git a/rldefs.h b/rldefs.h index dfb1320..c67b385 100644 --- 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 diff --git a/rlmbutil.h b/rlmbutil.h index d906057..42d47c3 100644 --- a/rlmbutil.h +++ b/rlmbutil.h @@ -104,21 +104,21 @@ #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)) diff --git a/rlprivate.h b/rlprivate.h index 8067661..15a75c5 100644 --- a/rlprivate.h +++ b/rlprivate.h @@ -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; diff --git a/search.c b/search.c index eea2301..43c66b1 100644 --- 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 *); diff --git a/signals.c b/signals.c index 9df365e..ec835e5 100644 --- 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) diff --git a/support/wcwidth.c b/support/wcwidth.c index 0f5ec99..e8b5308 100644 --- a/support/wcwidth.c +++ b/support/wcwidth.c @@ -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 859e6ee..1121061 100644 --- 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 */ diff --git a/terminal.c b/terminal.c index 9997161..2c13c40 100644 --- a/terminal.c +++ b/terminal.c @@ -69,7 +69,7 @@ #include "rlshell.h" #include "xmalloc.h" -#if defined (__MINGW32__) +#if defined (_WIN32) # include # include @@ -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 91c3f33..abe99b3 100644 --- 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 d678a31..c31f921 100644 --- 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 e4c457d..c9c2a5b 100644 --- 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 2e986db..d481b85 100644 --- 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) diff --git a/vi_mode.c b/vi_mode.c index 3a033ba..96523c7 100644 --- 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;