From: Chet Ramey Date: Fri, 5 Jun 2015 15:49:44 +0000 (-0400) Subject: commit bash-20150521 snapshot X-Git-Tag: bash-4.4-alpha~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bf257a5d95aa7d98d3da1a24be7b5b301716047;p=thirdparty%2Fbash.git commit bash-20150521 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 5f5254264..9c0547f80 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8558,3 +8558,87 @@ lib/readline/bind.c - sv_isrchterm: make sure we check for v[end] == 0 while in the loop looking for whitespace. Bug report and fix from Sergio Durigan Junior + +lib/sh/shmbchar.c + - mbstrlen,mbsmbchar: move calculation of MB_CUR_MAX out of loop; + calculate it once at beginning + +lib/sh/mbscmp.c + - mbscmp: move calculation of MB_CUR_MAX out of loop; calculate it once + at beginning + +lib/sh/mbscasecmp.c + - mbscasecmp: move calculation of MB_CUR_MAX out of loop; calculate it once + at beginning + +lib/sh/shquote.c + - sh_backslash_quote: move calculation of MB_CUR_MAX out of loop; + calculate it once at beginning + +lib/sh/casemod.c + - sh_modcase: move calculation of MB_CUR_MAX out of loop; calculate it once + at beginning + +subst.c + - expand_word_internal: move calculation of MB_CUR_MAX out of loops; + calculate it once at beginning of function (XXX should use + locale_mb_cur_max) + + 5/22 + ---- +lib/readline/rlmbutil.h + - _rl_wcwidth: new function, short-circuits wcwidth calls for ASCII + printable characters, returns 1 for those + - WCWIDTH: call _rl_wcwidth instead of wcwidth + +lib/readline/display.c + - rl_redisplay: move calculation of MB_CUR_MAX out of loop; calculate + it once at beginning. Report and patch from Ole Laursen + + + 5/24 + ---- +lib/readline/text.c + - rl_insert: change to attempt to batch-insert pending typeahead (not + pushed input or input from a macro) that maps to rl_insert. An + attempt to suppress redisplay until readline reads all typeahead -- + pasted input, for instance. Inspired by report from Ole Laursen + . XXX - need to make this a bindable + variable; already controlled by _rl_optimize_typeahead + +lib/readline/rlprivate.h + - _rl_optimize_typeahead: extern declaration + +lib/readline/doc/{hstech.texi,history.3} + - next_history: clarify under what circumstances the history offset is + incremented; suggestion from Glenn Golden + +print_cmd.c + - print_arith_command: should be compiled in if either DPAREN_ARITHMETIC + or ARITH_FOR_COMMAND is defined. Report from Flavio Medeiros + + +flags.c + - change_flag: new variable verbose_flag, set when `v' flag modified; + sets value of echo_input_at_read correspondingly + +flags.h + - verbose_flag: new extern declaration + +shell.c + - long_options: --verbose now sets verbose_flag + - main: set echo_input_at_read from verbose_flag after parsing any + long options + +builtins/fc.def + - fc_builtin: don't unwind-protect echo_input_at_read directly; set it + to 1 before calling fc_execute_file as before, and reset it to value + of global verbose_flag using set_verbose_flag called from an + unwind_protect. Report from isabella parakiss + +builtins/shopt.def + - shopt_set_debug_mode: new function, called when the extdebug shell + option changes. Right now, it sets function_trace_mode when extdebug + is enabled, and turns off when extdebug is disabled. The documentation + has always said that shopt does this. Report from Peng Yu + diff --git a/builtins/fc.def b/builtins/fc.def index cf6b72c75..9d5b342e7 100644 --- a/builtins/fc.def +++ b/builtins/fc.def @@ -158,6 +158,12 @@ static char *fc_readline __P((FILE *)); static void fc_addhist __P((char *)); #endif +static void +set_verbose_flag () +{ + echo_input_at_read = verbose_flag; +} + /* String to execute on a file that we want to edit. */ #define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vi}}" #if defined (STRICT_POSIX) @@ -451,9 +457,9 @@ fc_builtin (list) begin_unwind_frame ("fc builtin"); add_unwind_protect ((Function *)xfree, fn); add_unwind_protect (unlink, fn); - unwind_protect_int (echo_input_at_read); + add_unwind_protect (set_verbose_flag, (char *)NULL); echo_input_at_read = 1; - + retval = fc_execute_file (fn); run_unwind_frame ("fc builtin"); diff --git a/builtins/shopt.def b/builtins/shopt.def index 80e257d1f..b82db630c 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -131,6 +131,8 @@ static int set_restricted_shell __P((char *, int)); static int shopt_set_complete_direxpand __P((char *, int)); #endif +static int shopt_set_debug_mode __P((char *, int)); + static int shopt_login_shell; static int shopt_compat31; static int shopt_compat32; @@ -170,7 +172,7 @@ static struct { { "execfail", &no_exit_on_failed_exec, (shopt_set_func_t *)NULL }, { "expand_aliases", &expand_aliases, (shopt_set_func_t *)NULL }, #if defined (DEBUGGER) - { "extdebug", &debugging_mode, (shopt_set_func_t *)NULL }, + { "extdebug", &debugging_mode, shopt_set_debug_mode }, #endif #if defined (EXTENDED_GLOB) { "extglob", &extended_glob, (shopt_set_func_t *)NULL }, @@ -516,6 +518,16 @@ set_shellopts_after_change (option_name, mode) return (0); } +static int +shopt_set_debug_mode (option_name, mode) + char *option_name; + int mode; +{ +#if defined (DEBUGGER) + function_trace_mode = debugging_mode; +#endif +} + static int shopt_enable_hostname_completion (option_name, mode) char *option_name; diff --git a/configure b/configure index f289541b1..6852a1219 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac for Bash 4.4, version 4.069. +# From configure.ac for Bash 4.4, version 4.070. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for bash 4.4-devel. # @@ -16020,7 +16020,7 @@ solaris2*) LOCAL_CFLAGS=-DSOLARIS ;; lynxos*) LOCAL_CFLAGS=-DRECYCLES_PIDS ;; linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading case "`uname -r`" in - 2.[456789]*|3*) $as_echo "#define PGRP_PIPE 1" >>confdefs.h + 2.[456789]*|[34]*) $as_echo "#define PGRP_PIPE 1" >>confdefs.h ;; esac ;; *qnx6*) LOCAL_CFLAGS="-Dqnx -Dqnx6" LOCAL_LIBS="-lncurses" ;; diff --git a/configure.ac b/configure.ac index df86486b5..80977e0db 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_REVISION([for Bash 4.4, version 4.069])dnl +AC_REVISION([for Bash 4.4, version 4.070])dnl define(bashvers, 4.4) define(relstatus, devel) @@ -1096,7 +1096,7 @@ solaris2*) LOCAL_CFLAGS=-DSOLARIS ;; lynxos*) LOCAL_CFLAGS=-DRECYCLES_PIDS ;; linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading case "`uname -r`" in - 2.[[456789]]*|3*) AC_DEFINE(PGRP_PIPE) ;; + 2.[[456789]]*|[[34]]*) AC_DEFINE(PGRP_PIPE) ;; esac ;; *qnx6*) LOCAL_CFLAGS="-Dqnx -Dqnx6" LOCAL_LIBS="-lncurses" ;; *qnx*) LOCAL_CFLAGS="-Dqnx -F -3s" LOCAL_LDFLAGS="-3s" LOCAL_LIBS="-lunix -lncurses" ;; diff --git a/flags.c b/flags.c index 79d8e1bf9..5704741c4 100644 --- a/flags.c +++ b/flags.c @@ -90,6 +90,7 @@ int unbound_vars_is_error = 0; /* Non-zero means type out input lines after you read them. */ int echo_input_at_read = 0; +int verbose_flag = 0; /* Non-zero means type out the command definition after reading, but before executing. */ @@ -197,7 +198,7 @@ const struct flags_alist shell_flags[] = { #endif /* RESTRICTED_SHELL */ { 't', &just_one_command }, { 'u', &unbound_vars_is_error }, - { 'v', &echo_input_at_read }, + { 'v', &verbose_flag }, { 'x', &echo_command_at_execute }, /* New flags that control non-standard things. */ @@ -297,6 +298,9 @@ change_flag (flag, on_or_off) break; #endif + case 'v': + echo_input_at_read = verbose_flag; + break; } return (old_value); @@ -354,7 +358,7 @@ reset_shell_flags () { mark_modified_vars = exit_immediately_on_error = disallow_filename_globbing = 0; place_keywords_in_env = read_but_dont_execute = just_one_command = 0; - noclobber = unbound_vars_is_error = echo_input_at_read = 0; + noclobber = unbound_vars_is_error = echo_input_at_read = verbose_flag = 0; echo_command_at_execute = jobs_m_flag = forced_interactive = 0; no_symbolic_links = no_invisible_vars = privileged_mode = pipefail_opt = 0; diff --git a/flags.h b/flags.h index d31007b4b..d5ed334e1 100644 --- a/flags.h +++ b/flags.h @@ -44,7 +44,7 @@ extern int mark_modified_vars, errexit_flag, exit_immediately_on_error, disallow_filename_globbing, place_keywords_in_env, read_but_dont_execute, - just_one_command, unbound_vars_is_error, echo_input_at_read, + just_one_command, unbound_vars_is_error, echo_input_at_read, verbose_flag, echo_command_at_execute, no_invisible_vars, noclobber, hashing_enabled, forced_interactive, privileged_mode, jobs_m_flag, asynchronous_notification, interactive_comments, no_symbolic_links, diff --git a/lib/readline/callback.c b/lib/readline/callback.c index 6bb2c3e0d..b2fe3901e 100644 --- a/lib/readline/callback.c +++ b/lib/readline/callback.c @@ -284,7 +284,8 @@ _rl_callback_data_alloc (count) return arg; } -void _rl_callback_data_dispose (arg) +void +_rl_callback_data_dispose (arg) _rl_callback_generic_arg *arg; { xfree (arg); diff --git a/lib/readline/display.c b/lib/readline/display.c index 3c0b7aaee..c6b14fb56 100644 --- a/lib/readline/display.c +++ b/lib/readline/display.c @@ -586,6 +586,7 @@ rl_redisplay () int wc_width; mbstate_t ps; int _rl_wrapped_multicolumn = 0; + int mb_cur_max = MB_CUR_MAX; #endif if (_rl_echoing_p == 0) @@ -764,7 +765,7 @@ rl_redisplay () prompts that exceed two physical lines? Additional logic fix from Edward Catmur */ #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) { n0 = num; temp = local_prompt_len; @@ -802,7 +803,7 @@ rl_redisplay () inv_lbreaks[++newlines] = temp; #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) lpos -= _rl_col_width (local_prompt, n0, num, 1); else #endif @@ -819,7 +820,7 @@ rl_redisplay () lb_linenum = 0; #if defined (HANDLE_MULTIBYTE) in = 0; - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { memset (&ps, 0, sizeof (mbstate_t)); /* XXX - what if wc_bytes ends up <= 0? check for MB_INVALIDCH */ @@ -835,7 +836,7 @@ rl_redisplay () c = (unsigned char)rl_line_buffer[in]; #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { if (MB_INVALIDCH (wc_bytes)) { @@ -944,7 +945,7 @@ rl_redisplay () else { #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { register int i; @@ -980,7 +981,7 @@ rl_redisplay () } #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { in += wc_bytes; /* XXX - what if wc_bytes ends up <= 0? check for MB_INVALIDCH */ @@ -1028,7 +1029,7 @@ rl_redisplay () not the first. */ if (out >= _rl_screenchars) { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) out = _rl_find_prev_mbchar (line, _rl_screenchars, MB_FIND_ANY); else out = _rl_screenchars - 1; @@ -1076,10 +1077,10 @@ rl_redisplay () time update_line is called, then we can assume in our calculations that o_cpos does not need to be adjusted by wrap_offset. */ - if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT()) + if (linenum == 0 && (mb_cur_max > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT()) _rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */ else if (linenum == prompt_last_screen_line && prompt_physical_chars > _rl_screenwidth && - (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && + (mb_cur_max > 1 && rl_byte_oriented == 0) && cpos_adjusted == 0 && _rl_last_c_pos != o_cpos && _rl_last_c_pos > (prompt_last_invisible - _rl_screenwidth - prompt_invis_chars_first_line)) @@ -1096,7 +1097,7 @@ rl_redisplay () (wrap_offset > visible_wrap_offset) && (_rl_last_c_pos < visible_first_line_len)) { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) nleft = _rl_screenwidth - _rl_last_c_pos; else nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos; @@ -1148,7 +1149,7 @@ rl_redisplay () the physical cursor position on the screen stays the same, but the buffer position needs to be adjusted to account for invisible characters. */ - if ((MB_CUR_MAX == 1 || rl_byte_oriented) && cursor_linenum == 0 && wrap_offset) + if ((mb_cur_max == 1 || rl_byte_oriented) && cursor_linenum == 0 && wrap_offset) _rl_last_c_pos += wrap_offset; } @@ -1175,7 +1176,7 @@ rl_redisplay () _rl_output_some_chars ("*", 1); _rl_output_some_chars (local_prompt, nleft); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) _rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft, 1) - wrap_offset + modmark; else _rl_last_c_pos = nleft + modmark; @@ -1199,7 +1200,7 @@ rl_redisplay () if (wrap_offset && cursor_linenum == 0 && nleft < _rl_last_c_pos) { /* TX == new physical cursor position in multibyte locale. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) tx = _rl_col_width (&visible_line[pos], 0, nleft, 1) - visible_wrap_offset; else tx = nleft; @@ -1214,7 +1215,7 @@ rl_redisplay () _rl_last_c_pos as an absolute cursor position, but moving to a point specified by a buffer position (NLEFT) that doesn't take invisible characters into account. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) _rl_move_cursor_relative (nleft, &invisible_line[pos]); else if (nleft != _rl_last_c_pos) _rl_move_cursor_relative (nleft, &invisible_line[pos]); @@ -1295,7 +1296,7 @@ rl_redisplay () _rl_screenwidth + (lmargin ? 0 : wrap_offset), 0); - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && + if ((mb_cur_max > 1 && rl_byte_oriented == 0) && displaying_prompt_first_line && OLD_CPOS_IN_PROMPT()) _rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */ diff --git a/lib/readline/doc/history.3 b/lib/readline/doc/history.3 index c90521937..7ddc26ae3 100644 --- a/lib/readline/doc/history.3 +++ b/lib/readline/doc/history.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Mon Apr 6 14:13:28 EDT 2015 +.\" Last Change: Sun May 24 18:01:17 EDT 2015 .\" -.TH HISTORY 3 "2014 April 6" "GNU History 6.3" +.TH HISTORY 3 "2015 May 24" "GNU History 6.3" .\" .\" File Name macro. This used to be `.PN', for Path Name, .\" but Sun doesn't seem to like that very much. @@ -441,16 +441,11 @@ return a pointer to that entry. If there is no previous entry, return a \fBNULL\fP pointer. .Fn1 "HIST_ENTRY *" next_history "void" -If the current history offset is not already at the end of the history -list, move the current history offset forward to the next history entry. -If the incremented history offset refers to a valid history entry, return -a pointer to that entry. -If there is no next entry, as when the history offset before being -incremented refers to the last valid entry in the history list, return -a \fBNULL\fP pointer. -If this function returns \fBNULL\fP, the current history offset when the -function returns (possibly incremented as described above) -is at the end of the history list. +If the current history offset refers to a valid history entry, +increment the current history offset. +If the possibly-incremented history offset refers to a valid history +entry, return a pointer to that entry; +otherwise, return a \fBNULL\fP pointer. .SS Searching the History List diff --git a/lib/readline/doc/hstech.texi b/lib/readline/doc/hstech.texi index ecae312c0..6deaeee26 100644 --- a/lib/readline/doc/hstech.texi +++ b/lib/readline/doc/hstech.texi @@ -270,16 +270,11 @@ a @code{NULL} pointer. @end deftypefun @deftypefun {HIST_ENTRY *} next_history (void) -If the current history offset is not already at the end of the history -list, move the current history offset forward to the next history entry. -If the incremented history offset refers to a valid history entry, return -a pointer to that entry. -If there is no next entry, as when the history offset before being -incremented refers to the last valid entry in the history list, return -a @code{NULL} pointer. -If this function returns @code{NULL}, the current history offset when the -function returns (possibly incremented as described above) -is at the end of the history list. +If the current history offset refers to a valid history entry, +increment the current history offset. +If the possibly-incremented history offset refers to a valid history +entry, return a pointer to that entry; +otherwise, return a @code{BNULL} pointer. @end deftypefun @node Searching the History List diff --git a/lib/readline/doc/version.texi b/lib/readline/doc/version.texi index 7f29c6880..d7a210194 100644 --- a/lib/readline/doc/version.texi +++ b/lib/readline/doc/version.texi @@ -4,7 +4,7 @@ Copyright (C) 1988-2015 Free Software Foundation, Inc. @set EDITION 6.4 @set VERSION 6.4 -@set UPDATED 6 April 2015 -@set UPDATED-MONTH April 2015 +@set UPDATED 24 May 2015 +@set UPDATED-MONTH May 2015 -@set LASTCHANGE Mon Apr 6 14:13:14 EDT 2015 +@set LASTCHANGE Sun May 24 18:01:45 EDT 2015 diff --git a/lib/readline/input.c b/lib/readline/input.c index b2db99cc4..186443da8 100644 --- a/lib/readline/input.c +++ b/lib/readline/input.c @@ -514,10 +514,6 @@ rl_getc (stream) FD_ZERO (&readfds); FD_SET (fileno (stream), &readfds); result = pselect (fileno (stream) + 1, &readfds, NULL, NULL, NULL, &empty_set); -# if 0 - if (result < 0 && errno == EINTR) - goto handle_error; -# endif #endif if (result >= 0) result = read (fileno (stream), &c, sizeof (unsigned char)); diff --git a/lib/readline/rlmbutil.h b/lib/readline/rlmbutil.h index 0b0a32b90..f0ecfb44a 100644 --- a/lib/readline/rlmbutil.h +++ b/lib/readline/rlmbutil.h @@ -123,13 +123,47 @@ extern int _rl_walphabetic PARAMS((wchar_t)); #define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2) #define MB_NULLWCH(x) ((x) == 0) +/* Try and shortcut the printable ascii characters to cut down the number of + calls to a libc wcwidth() */ +static inline int +_rl_wcwidth (wc) + wchar_t wc; +{ + switch (wc) + { + case ' ': case '!': case '"': case '#': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + return 1; + default: + return wcwidth (wc); + } +} + /* Unicode combining characters range from U+0300 to U+036F */ #define UNICODE_COMBINING_CHAR(x) ((x) >= 768 && (x) <= 879) #if defined (WCWIDTH_BROKEN) -# define WCWIDTH(wc) ((_rl_utf8locale && UNICODE_COMBINING_CHAR(wc)) ? 0 : wcwidth(wc)) +# define WCWIDTH(wc) ((_rl_utf8locale && UNICODE_COMBINING_CHAR(wc)) ? 0 : _rl_wcwidth(wc)) #else -# define WCWIDTH(wc) wcwidth(wc) +# define WCWIDTH(wc) _rl_wcwidth(wc) #endif #if defined (WCWIDTH_BROKEN) diff --git a/lib/readline/rlprivate.h b/lib/readline/rlprivate.h index d9f726a13..15e2809a3 100644 --- a/lib/readline/rlprivate.h +++ b/lib/readline/rlprivate.h @@ -545,6 +545,9 @@ extern int _rl_screenchars; extern int _rl_terminal_can_insert; extern int _rl_term_autowrap; +/* text.c */ +extern int _rl_optimize_typeahead; + /* undo.c */ extern int _rl_doing_an_undo; extern int _rl_undo_group_level; diff --git a/lib/readline/text.c b/lib/readline/text.c index 7f1f076df..f2bb22466 100644 --- a/lib/readline/text.c +++ b/lib/readline/text.c @@ -71,6 +71,8 @@ static int _rl_char_search_callback PARAMS((_rl_callback_generic_arg *)); rl_insert_text. Text blocks larger than this are divided. */ #define TEXT_COUNT_MAX 1024 +int _rl_optimize_typeahead = 1; /* rl_insert tries to read typeahead */ + /* **************************************************************** */ /* */ /* Insert and Delete */ @@ -890,8 +892,42 @@ int rl_insert (count, c) int count, c; { - return (rl_insert_mode == RL_IM_INSERT ? _rl_insert_char (count, c) - : _rl_overwrite_char (count, c)); + int r, n, x; + + r = (rl_insert_mode == RL_IM_INSERT) ? _rl_insert_char (count, c) : _rl_overwrite_char (count, c); + + /* XXX -- attempt to batch-insert pending input that maps to self-insert */ + x = 0; + n = (unsigned short)-2; + while (_rl_optimize_typeahead && + (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) && + _rl_pushed_input_available () == 0 && + _rl_input_queued (0) && + (n = rl_read_key ()) > 0 && + _rl_keymap[(unsigned char)n].type == ISFUNC && + _rl_keymap[(unsigned char)n].function == rl_insert) + { + r = (rl_insert_mode == RL_IM_INSERT) ? _rl_insert_char (1, n) : _rl_overwrite_char (1, n); + /* _rl_insert_char keeps its own set of pending characters to compose a + complete multibyte character, and only returns 1 if it sees a character + that's part of a multibyte character but too short to complete one. We + can try to read another character in the hopes that we will get the + next one or just punt. Right now we try to read another character. + We don't want to call rl_insert_next if _rl_insert_char has already + stored the character in the pending_bytes array because that will + result in doubled input. */ + n = (unsigned short)-2; + x++; /* count of bytes of typeahead read, currently unused */ + if (r == 1) /* read partial multibyte character */ + continue; + if (rl_done || r != 0) + break; + } + + if (n != (unsigned short)-2) /* -2 = sentinel value for having inserted N */ + r = rl_execute_next (n); + + return r; } /* Insert the next typed character verbatim. */ diff --git a/lib/sh/casemod.c b/lib/sh/casemod.c index b1711b8a9..c12cbe981 100644 --- a/lib/sh/casemod.c +++ b/lib/sh/casemod.c @@ -112,7 +112,7 @@ sh_modcase (string, pat, flags) #if defined (HANDLE_MULTIBYTE) wchar_t nwc; char mb[MB_LEN_MAX+1]; - int mlen; + int mlen, mb_cur_max; size_t m; mbstate_t state; #endif @@ -130,6 +130,7 @@ sh_modcase (string, pat, flags) start = 0; end = strlen (string); + mb_cur_max = MB_CUR_MAX; ret = (char *)xmalloc (2*end + 1); retind = 0; @@ -209,7 +210,7 @@ sh_modcase (string, pat, flags) /* Can't short-circuit, some locales have multibyte upper and lower case equivalents of single-byte ascii characters (e.g., Turkish) */ - if (MB_CUR_MAX == 1) + if (mb_cur_max == 1) { singlebyte: switch (nop) diff --git a/lib/sh/mbscasecmp.c b/lib/sh/mbscasecmp.c index 3828164e4..ff5b6f243 100644 --- a/lib/sh/mbscasecmp.c +++ b/lib/sh/mbscasecmp.c @@ -35,17 +35,18 @@ mbscasecmp (mbs1, mbs2) const char *mbs1; const char *mbs2; { - int len1, len2; + int len1, len2, mb_cur_max; wchar_t c1, c2, l1, l2; len1 = len2 = 0; /* Reset multibyte characters to their initial state. */ (void) mblen ((char *) NULL, 0); + mb_cur_max = MB_CUR_MAX; do { - len1 = mbtowc (&c1, mbs1, MB_CUR_MAX); - len2 = mbtowc (&c2, mbs2, MB_CUR_MAX); + len1 = mbtowc (&c1, mbs1, mb_cur_max); + len2 = mbtowc (&c2, mbs2, mb_cur_max); if (len1 == 0) return len2 == 0 ? 0 : -1; diff --git a/lib/sh/mbscmp.c b/lib/sh/mbscmp.c index e0eae5dcc..711f768f1 100644 --- a/lib/sh/mbscmp.c +++ b/lib/sh/mbscmp.c @@ -32,17 +32,18 @@ mbscmp (mbs1, mbs2) const char *mbs1; const char *mbs2; { - int len1, len2; + int len1, len2, mb_cur_max; wchar_t c1, c2; len1 = len2 = 0; /* Reset multibyte characters to their initial state. */ (void) mblen ((char *) NULL, 0); + mb_cur_max = MB_CUR_MAX; do { - len1 = mbtowc (&c1, mbs1, MB_CUR_MAX); - len2 = mbtowc (&c2, mbs2, MB_CUR_MAX); + len1 = mbtowc (&c1, mbs1, mb_cur_max); + len2 = mbtowc (&c2, mbs2, mb_cur_max); if (len1 == 0) return len2 == 0 ? 0 : -1; diff --git a/lib/sh/shmbchar.c b/lib/sh/shmbchar.c index 042c9f140..1bf68701e 100644 --- a/lib/sh/shmbchar.c +++ b/lib/sh/shmbchar.c @@ -43,10 +43,11 @@ mbstrlen (s) { size_t clen, nc; mbstate_t mbs = { 0 }, mbsbak = { 0 }; - int f; + int f, mb_cur_max; nc = 0; - while (*s && (clen = (f = is_basic (*s)) ? 1 : mbrlen(s, MB_CUR_MAX, &mbs)) != 0) + mb_cur_max = MB_CUR_MAX; + while (*s && (clen = (f = is_basic (*s)) ? 1 : mbrlen(s, mb_cur_max, &mbs)) != 0) { if (MB_INVALIDCH(clen)) { @@ -71,13 +72,15 @@ mbsmbchar (s) char *t; size_t clen; mbstate_t mbs = { 0 }; + int mb_cur_max; + mb_cur_max = MB_CUR_MAX; for (t = (char *)s; *t; t++) { if (is_basic (*t)) continue; - clen = mbrlen (t, MB_CUR_MAX, &mbs); + clen = mbrlen (t, mb_cur_max, &mbs); if (clen == 0) return 0; diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c index 4f13ab399..782a1f56c 100644 --- a/lib/sh/shquote.c +++ b/lib/sh/shquote.c @@ -233,7 +233,7 @@ sh_backslash_quote (string, table, flags) char *table; int flags; { - int c; + int c, mb_cur_max; size_t slen; char *result, *r, *s, *backslash_table, *send; DECLARE_MBSTATE; @@ -243,6 +243,8 @@ sh_backslash_quote (string, table, flags) result = (char *)xmalloc (2 * slen + 1); backslash_table = table ? table : (char *)bstab; + mb_cur_max = MB_CUR_MAX; + for (r = result, s = string; s && (c = *s); s++) { #if defined (HANDLE_MULTIBYTE) @@ -253,7 +255,7 @@ sh_backslash_quote (string, table, flags) *r++ = c; continue; } - if (MB_CUR_MAX > 1 && is_basic (c) == 0) + if (mb_cur_max > 1 && is_basic (c) == 0) { COPY_CHAR_P (r, s, send); s--; /* compensate for auto-increment in loop above */ diff --git a/print_cmd.c b/print_cmd.c index 000118ac6..b4ddc9539 100644 --- a/print_cmd.c +++ b/print_cmd.c @@ -803,7 +803,7 @@ print_if_command (if_command) newline ("fi"); } -#if defined (DPAREN_ARITHMETIC) +#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND) void print_arith_command (arith_cmd_list) WORD_LIST *arith_cmd_list; diff --git a/shell.c b/shell.c index 2b3f0ca41..aab2e21cd 100644 --- a/shell.c +++ b/shell.c @@ -262,7 +262,7 @@ static const struct { #if defined (RESTRICTED_SHELL) { "restricted", Int, &restricted, (char **)0x0 }, #endif - { "verbose", Int, &echo_input_at_read, (char **)0x0 }, + { "verbose", Int, &verbose_flag, (char **)0x0 }, { "version", Int, &do_version, (char **)0x0 }, #if defined (WORDEXP_OPTION) { "wordexp", Int, &wordexp_only, (char **)0x0 }, @@ -460,7 +460,7 @@ main (argc, argv, env) /* Find full word arguments first. */ arg_index = parse_long_options (argv, arg_index, argc); - + if (want_initial_help) { show_shell_usage (stdout, 1); @@ -473,6 +473,8 @@ main (argc, argv, env) exit (EXECUTION_SUCCESS); } + echo_input_at_read = verbose_flag; /* --verbose given */ + /* All done with full word options; do standard shell option parsing.*/ this_command_name = shell_name; /* for error reporting */ arg_index = parse_shell_options (argv, arg_index, argc); diff --git a/subst.c b/subst.c index 388e58828..62308a578 100644 --- a/subst.c +++ b/subst.c @@ -2501,7 +2501,7 @@ list_string (string, separators, quoted) extract a word, stopping at a separator skip sequences of spc, tab, or nl as long as they are separators This obeys the field splitting rules in Posix.2. */ - slen = (MB_CUR_MAX > 1) ? strlen (string) : 1; + slen = (MB_CUR_MAX > 1) ? STRLEN (string) : 1; for (result = (WORD_LIST *)NULL, sindex = 0; string[sindex]; ) { /* Don't need string length in ADVANCE_CHAR or string_extract_verbatim @@ -2632,7 +2632,7 @@ get_word_from_string (stringp, separators, endptr) sindex = 0; /* Don't need string length in ADVANCE_CHAR or string_extract_verbatim unless multibyte chars are possible. */ - slen = (MB_CUR_MAX > 1) ? strlen (s) : 1; + slen = (MB_CUR_MAX > 1) ? STRLEN (s) : 1; current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags); /* Set ENDPTR to the first character after the end of the word. */ @@ -8642,6 +8642,7 @@ expand_word_internal (word, quoted, isexp, contains_dollar_at, expanded_somethin int split_on_spaces; int tflag; int pflags; /* flags passed to param_expand */ + int mb_cur_max; int assignoff; /* If assignment, offset of `=' */ @@ -8678,9 +8679,11 @@ expand_word_internal (word, quoted, isexp, contains_dollar_at, expanded_somethin string = word->word; if (string == 0) goto finished_with_string; + mb_cur_max = MB_CUR_MAX; + /* Don't need the string length for the SADD... and COPY_ macros unless multibyte characters are possible. */ - string_size = (MB_CUR_MAX > 1) ? strlen (string) : 1; + string_size = (mb_cur_max > 1) ? strlen (string) : 1; if (contains_dollar_at) *contains_dollar_at = 0; @@ -8702,7 +8705,7 @@ expand_word_internal (word, quoted, isexp, contains_dollar_at, expanded_somethin case CTLESC: sindex++; #if HANDLE_MULTIBYTE - if (MB_CUR_MAX > 1 && string[sindex]) + if (mb_cur_max > 1 && string[sindex]) { SADD_MBQCHAR_BODY(temp, string, sindex, string_size); } @@ -9210,10 +9213,10 @@ add_twochars: else { #if HANDLE_MULTIBYTE - if (MB_CUR_MAX > 1) + if (mb_cur_max > 1) sindex--; - if (MB_CUR_MAX > 1) + if (mb_cur_max > 1) { SADD_MBQCHAR_BODY(temp, string, sindex, string_size); }