michael@428: Index: assoc.c michael@428: --- assoc.c.orig 2009-08-06 02:19:40.000000000 +0200 michael@428: +++ assoc.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -77,6 +77,11 @@ michael@428: b = hash_search (key, hash, HASH_CREATE); michael@428: if (b == 0) michael@428: return -1; michael@428: + /* If we are overwriting an existing element's value, we're not going to michael@428: + use the key. Nothing in the array assignment code path frees the key michael@428: + string, so we can free it here to avoid a memory leak. */ michael@428: + if (b->key != key) michael@428: + free (key); michael@428: FREE (b->data); michael@428: b->data = value ? savestring (value) : (char *)0; michael@428: return (0); michael@428: Index: bashline.c michael@428: --- bashline.c.orig 2011-01-16 21:32:47.000000000 +0100 michael@428: +++ bashline.c 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -121,6 +121,9 @@ michael@428: static int filename_completion_ignore __P((char **)); michael@428: static int bash_push_line __P((void)); michael@428: michael@428: +static rl_icppfunc_t *save_directory_hook __P((void)); michael@428: +static void reset_directory_hook __P((rl_icppfunc_t *)); michael@428: + michael@428: static void cleanup_expansion_error __P((void)); michael@428: static void maybe_make_readline_line __P((char *)); michael@428: static void set_up_new_line __P((char *)); michael@428: @@ -243,10 +246,17 @@ michael@428: /* Perform spelling correction on directory names during word completion */ michael@428: int dircomplete_spelling = 0; michael@428: michael@428: +/* Expand directory names during word/filename completion. */ michael@428: +int dircomplete_expand = 0; michael@428: +int dircomplete_expand_relpath = 0; michael@428: + michael@428: static char *bash_completer_word_break_characters = " \t\n\"'@><=;|&(:"; michael@428: static char *bash_nohostname_word_break_characters = " \t\n\"'><=;|&(:"; michael@428: /* )) */ michael@428: michael@428: +static const char *default_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{~"; /*}*/ michael@428: +static char *custom_filename_quote_characters = 0; michael@428: + michael@428: static rl_hook_func_t *old_rl_startup_hook = (rl_hook_func_t *)NULL; michael@428: michael@428: static int dot_in_path = 0; michael@428: @@ -501,7 +511,7 @@ michael@428: michael@428: /* Tell the completer that we might want to follow symbolic links or michael@428: do other expansion on directory names. */ michael@428: - rl_directory_rewrite_hook = bash_directory_completion_hook; michael@428: + set_directory_hook (); michael@428: michael@428: rl_filename_rewrite_hook = bash_filename_rewrite_hook; michael@428: michael@428: @@ -529,7 +539,7 @@ michael@428: enable_hostname_completion (perform_hostname_completion); michael@428: michael@428: /* characters that need to be quoted when appearing in filenames. */ michael@428: - rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{~"; /*}*/ michael@428: + rl_filename_quote_characters = default_filename_quote_characters; michael@428: michael@428: rl_filename_quoting_function = bash_quote_filename; michael@428: rl_filename_dequoting_function = bash_dequote_filename; michael@428: @@ -564,8 +574,10 @@ michael@428: tilde_initialize (); michael@428: rl_attempted_completion_function = attempt_shell_completion; michael@428: rl_completion_entry_function = NULL; michael@428: - rl_directory_rewrite_hook = bash_directory_completion_hook; michael@428: rl_ignore_some_completions_function = filename_completion_ignore; michael@428: + rl_filename_quote_characters = default_filename_quote_characters; michael@428: + michael@428: + set_directory_hook (); michael@428: } michael@428: michael@428: /* Contains the line to push into readline. */ michael@428: @@ -1279,6 +1291,9 @@ michael@428: matches = (char **)NULL; michael@428: rl_ignore_some_completions_function = filename_completion_ignore; michael@428: michael@428: + rl_filename_quote_characters = default_filename_quote_characters; michael@428: + set_directory_hook (); michael@428: + michael@428: /* Determine if this could be a command word. It is if it appears at michael@428: the start of the line (ignoring preceding whitespace), or if it michael@428: appears after a character that separates commands. It cannot be a michael@428: @@ -1591,6 +1606,12 @@ michael@428: } michael@428: else michael@428: { michael@428: + if (dircomplete_expand && dot_or_dotdot (filename_hint)) michael@428: + { michael@428: + dircomplete_expand = 0; michael@428: + set_directory_hook (); michael@428: + dircomplete_expand = 1; michael@428: + } michael@428: mapping_over = 4; michael@428: goto inner; michael@428: } michael@428: @@ -1791,6 +1812,9 @@ michael@428: michael@428: inner: michael@428: val = rl_filename_completion_function (filename_hint, istate); michael@428: + if (mapping_over == 4 && dircomplete_expand) michael@428: + set_directory_hook (); michael@428: + michael@428: istate = 1; michael@428: michael@428: if (val == 0) michael@428: @@ -2693,6 +2717,52 @@ michael@428: return conv; michael@428: } michael@428: michael@428: +/* Functions to save and restore the appropriate directory hook */ michael@428: +/* This is not static so the shopt code can call it */ michael@428: +void michael@428: +set_directory_hook () michael@428: +{ michael@428: + if (dircomplete_expand) michael@428: + { michael@428: + rl_directory_completion_hook = bash_directory_completion_hook; michael@428: + rl_directory_rewrite_hook = (rl_icppfunc_t *)0; michael@428: + } michael@428: + else michael@428: + { michael@428: + rl_directory_rewrite_hook = bash_directory_completion_hook; michael@428: + rl_directory_completion_hook = (rl_icppfunc_t *)0; michael@428: + } michael@428: +} michael@428: + michael@428: +static rl_icppfunc_t * michael@428: +save_directory_hook () michael@428: +{ michael@428: + rl_icppfunc_t *ret; michael@428: + michael@428: + if (dircomplete_expand) michael@428: + { michael@428: + ret = rl_directory_completion_hook; michael@428: + rl_directory_completion_hook = (rl_icppfunc_t *)NULL; michael@428: + } michael@428: + else michael@428: + { michael@428: + ret = rl_directory_rewrite_hook; michael@428: + rl_directory_rewrite_hook = (rl_icppfunc_t *)NULL; michael@428: + } michael@428: + michael@428: + return ret; michael@428: +} michael@428: + michael@428: +static void michael@428: +restore_directory_hook (hookf) michael@428: + rl_icppfunc_t *hookf; michael@428: +{ michael@428: + if (dircomplete_expand) michael@428: + rl_directory_completion_hook = hookf; michael@428: + else michael@428: + rl_directory_rewrite_hook = hookf; michael@428: +} michael@428: + michael@428: /* Handle symbolic link references and other directory name michael@428: expansions while hacking completion. This should return 1 if it modifies michael@428: the DIRNAME argument, 0 otherwise. It should make sure not to modify michael@428: @@ -2702,20 +2772,31 @@ michael@428: char **dirname; michael@428: { michael@428: char *local_dirname, *new_dirname, *t; michael@428: - int return_value, should_expand_dirname; michael@428: + int return_value, should_expand_dirname, nextch, closer; michael@428: WORD_LIST *wl; michael@428: struct stat sb; michael@428: michael@428: - return_value = should_expand_dirname = 0; michael@428: + return_value = should_expand_dirname = nextch = closer = 0; michael@428: local_dirname = *dirname; michael@428: michael@428: - if (mbschr (local_dirname, '$')) michael@428: - should_expand_dirname = 1; michael@428: + if (t = mbschr (local_dirname, '$')) michael@428: + { michael@428: + should_expand_dirname = '$'; michael@428: + nextch = t[1]; michael@428: + /* Deliberately does not handle the deprecated $[...] arithmetic michael@428: + expansion syntax */ michael@428: + if (nextch == '(') michael@428: + closer = ')'; michael@428: + else if (nextch == '{') michael@428: + closer = '}'; michael@428: + else michael@428: + nextch = 0; michael@428: + } michael@428: else michael@428: { michael@428: t = mbschr (local_dirname, '`'); michael@428: if (t && unclosed_pair (local_dirname, strlen (local_dirname), "`") == 0) michael@428: - should_expand_dirname = 1; michael@428: + should_expand_dirname = '`'; michael@428: } michael@428: michael@428: #if defined (HAVE_LSTAT) michael@428: @@ -2739,6 +2820,23 @@ michael@428: free (new_dirname); michael@428: dispose_words (wl); michael@428: local_dirname = *dirname; michael@428: + /* XXX - change rl_filename_quote_characters here based on michael@428: + should_expand_dirname/nextch/closer. This is the only place michael@428: + custom_filename_quote_characters is modified. */ michael@428: + if (rl_filename_quote_characters && *rl_filename_quote_characters) michael@428: + { michael@428: + int i, j, c; michael@428: + i = strlen (default_filename_quote_characters); michael@428: + custom_filename_quote_characters = xrealloc (custom_filename_quote_characters, i+1); michael@428: + for (i = j = 0; c = default_filename_quote_characters[i]; i++) michael@428: + { michael@428: + if (c == should_expand_dirname || c == nextch || c == closer) michael@428: + continue; michael@428: + custom_filename_quote_characters[j++] = c; michael@428: + } michael@428: + custom_filename_quote_characters[j] = '\0'; michael@428: + rl_filename_quote_characters = custom_filename_quote_characters; michael@428: + } michael@428: } michael@428: else michael@428: { michael@428: @@ -2758,11 +2856,31 @@ michael@428: local_dirname = *dirname = new_dirname; michael@428: } michael@428: michael@428: + /* no_symbolic_links == 0 -> use (default) logical view of the file system. michael@428: + local_dirname[0] == '.' && local_dirname[1] == '/' means files in the michael@428: + current directory (./). michael@428: + local_dirname[0] == '.' && local_dirname[1] == 0 means relative pathnames michael@428: + in the current directory (e.g., lib/sh). michael@428: + XXX - should we do spelling correction on these? */ michael@428: + michael@428: + /* This is test as it was in bash-4.2: skip relative pathnames in current michael@428: + directory. Change test to michael@428: + (local_dirname[0] != '.' || (local_dirname[1] && local_dirname[1] != '/')) michael@428: + if we want to skip paths beginning with ./ also. */ michael@428: if (no_symbolic_links == 0 && (local_dirname[0] != '.' || local_dirname[1])) michael@428: { michael@428: char *temp1, *temp2; michael@428: int len1, len2; michael@428: michael@428: + /* If we have a relative path michael@428: + (local_dirname[0] != '/' && local_dirname[0] != '.') michael@428: + that is canonical after appending it to the current directory, then michael@428: + temp1 = temp2+'/' michael@428: + That is, michael@428: + strcmp (temp1, temp2) == 0 michael@428: + after adding a slash to temp2 below. It should be safe to not michael@428: + change those. michael@428: + */ michael@428: t = get_working_directory ("symlink-hook"); michael@428: temp1 = make_absolute (local_dirname, t); michael@428: free (t); michael@428: @@ -2797,7 +2915,15 @@ michael@428: temp2[len2 + 1] = '\0'; michael@428: } michael@428: } michael@428: - return_value |= STREQ (local_dirname, temp2) == 0; michael@428: + michael@428: + /* dircomplete_expand_relpath == 0 means we want to leave relative michael@428: + pathnames that are unchanged by canonicalization alone. michael@428: + *local_dirname != '/' && *local_dirname != '.' == relative pathname michael@428: + (consistent with general.c:absolute_pathname()) michael@428: + temp1 == temp2 (after appending a slash to temp2) means the pathname michael@428: + is not changed by canonicalization as described above. */ michael@428: + if (dircomplete_expand_relpath || ((local_dirname[0] != '/' && local_dirname[0] != '.') && STREQ (temp1, temp2) == 0)) michael@428: + return_value |= STREQ (local_dirname, temp2) == 0; michael@428: free (local_dirname); michael@428: *dirname = temp2; michael@428: free (temp1); michael@428: @@ -3002,12 +3128,13 @@ michael@428: michael@428: orig_func = rl_completion_entry_function; michael@428: orig_attempt_func = rl_attempted_completion_function; michael@428: - orig_dir_func = rl_directory_rewrite_hook; michael@428: orig_ignore_func = rl_ignore_some_completions_function; michael@428: orig_rl_completer_word_break_characters = rl_completer_word_break_characters; michael@428: + michael@428: + orig_dir_func = save_directory_hook (); michael@428: + michael@428: rl_completion_entry_function = rl_filename_completion_function; michael@428: rl_attempted_completion_function = (rl_completion_func_t *)NULL; michael@428: - rl_directory_rewrite_hook = (rl_icppfunc_t *)NULL; michael@428: rl_ignore_some_completions_function = filename_completion_ignore; michael@428: rl_completer_word_break_characters = " \t\n\"\'"; michael@428: michael@428: @@ -3015,10 +3142,11 @@ michael@428: michael@428: rl_completion_entry_function = orig_func; michael@428: rl_attempted_completion_function = orig_attempt_func; michael@428: - rl_directory_rewrite_hook = orig_dir_func; michael@428: rl_ignore_some_completions_function = orig_ignore_func; michael@428: rl_completer_word_break_characters = orig_rl_completer_word_break_characters; michael@428: michael@428: + restore_directory_hook (orig_dir_func); michael@428: + michael@428: return r; michael@428: } michael@428: michael@428: Index: bashline.h michael@428: --- bashline.h.orig 2009-01-04 20:32:22.000000000 +0100 michael@428: +++ bashline.h 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -33,10 +33,15 @@ michael@428: extern void bashline_reinitialize __P((void)); michael@428: extern int bash_re_edit __P((char *)); michael@428: michael@428: +extern void bashline_set_event_hook __P((void)); michael@428: +extern void bashline_reset_event_hook __P((void)); michael@428: + michael@428: extern int bind_keyseq_to_unix_command __P((char *)); michael@428: michael@428: extern char **bash_default_completion __P((const char *, int, int, int, int)); michael@428: michael@428: +void set_directory_hook __P((void)); michael@428: + michael@428: /* Used by programmable completion code. */ michael@428: extern char *command_word_completion_function __P((const char *, int)); michael@428: extern char *bash_groupname_completion_function __P((const char *, int)); michael@428: Index: builtins/declare.def michael@428: --- builtins/declare.def.orig 2010-05-31 00:25:21.000000000 +0200 michael@428: +++ builtins/declare.def 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -513,6 +513,11 @@ michael@428: *subscript_start = '['; /* ] */ michael@428: var = assign_array_element (name, value, 0); /* XXX - not aflags */ michael@428: *subscript_start = '\0'; michael@428: + if (var == 0) /* some kind of assignment error */ michael@428: + { michael@428: + assign_error++; michael@428: + NEXT_VARIABLE (); michael@428: + } michael@428: } michael@428: else if (simple_array_assign) michael@428: { michael@428: Index: builtins/fc.def michael@428: --- builtins/fc.def.orig 2010-05-31 00:25:38.000000000 +0200 michael@428: +++ builtins/fc.def 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -304,7 +304,7 @@ michael@428: last_hist = i - rh - hist_last_line_added; michael@428: michael@428: /* XXX */ michael@428: - if (saved_command_line_count > 0 && i == last_hist && hlist[last_hist] == 0) michael@428: + if (i == last_hist && hlist[last_hist] == 0) michael@428: while (last_hist >= 0 && hlist[last_hist] == 0) michael@428: last_hist--; michael@428: if (last_hist < 0) michael@428: @@ -475,7 +475,7 @@ michael@428: HIST_ENTRY **hlist; michael@428: { michael@428: int sign, n, clen, rh; michael@428: - register int i, j; michael@428: + register int i, j, last_hist; michael@428: register char *s; michael@428: michael@428: sign = 1; michael@428: @@ -495,7 +495,15 @@ michael@428: has been enabled (interactive or not) should use it in the last_hist michael@428: calculation as if it were on. */ michael@428: rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list); michael@428: - i -= rh + hist_last_line_added; michael@428: + last_hist = i - rh - hist_last_line_added; michael@428: + michael@428: + if (i == last_hist && hlist[last_hist] == 0) michael@428: + while (last_hist >= 0 && hlist[last_hist] == 0) michael@428: + last_hist--; michael@428: + if (last_hist < 0) michael@428: + return (-1); michael@428: + michael@428: + i = last_hist; michael@428: michael@428: /* No specification defaults to most recent command. */ michael@428: if (command == NULL) michael@428: Index: builtins/printf.def michael@428: --- builtins/printf.def.orig 2010-11-23 16:02:55.000000000 +0100 michael@428: +++ builtins/printf.def 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -255,6 +255,8 @@ michael@428: #endif michael@428: { michael@428: vflag = 1; michael@428: + if (vbsize == 0) michael@428: + vbuf = xmalloc (vbsize = 16); michael@428: vblen = 0; michael@428: if (vbuf) michael@428: vbuf[0] = 0; michael@428: @@ -465,6 +467,9 @@ michael@428: secs = shell_start_time; /* roughly $SECONDS */ michael@428: else michael@428: secs = arg; michael@428: +#if defined (HAVE_TZSET) michael@428: + sv_tz ("TZ"); /* XXX -- just make sure */ michael@428: +#endif michael@428: tm = localtime (&secs); michael@428: n = strftime (timebuf, sizeof (timebuf), timefmt, tm); michael@428: free (timefmt); michael@428: Index: builtins/read.def michael@428: --- builtins/read.def.orig 2011-01-04 17:43:36.000000000 +0100 michael@428: +++ builtins/read.def 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -642,6 +642,12 @@ michael@428: xfree (input_string); michael@428: return EXECUTION_FAILURE; /* readonly or noassign */ michael@428: } michael@428: + if (assoc_p (var)) michael@428: + { michael@428: + builtin_error (_("%s: cannot convert associative to indexed array"), arrayname); michael@428: + xfree (input_string); michael@428: + return EXECUTION_FAILURE; /* existing associative array */ michael@428: + } michael@428: array_flush (array_cell (var)); michael@428: michael@428: alist = list_string (input_string, ifs_chars, 0); michael@428: @@ -731,7 +737,7 @@ michael@428: xfree (t1); michael@428: } michael@428: else michael@428: - var = bind_read_variable (varname, t); michael@428: + var = bind_read_variable (varname, t ? t : ""); michael@428: } michael@428: else michael@428: { michael@428: @@ -792,7 +798,7 @@ michael@428: xfree (t); michael@428: } michael@428: else michael@428: - var = bind_read_variable (list->word->word, input_string); michael@428: + var = bind_read_variable (list->word->word, input_string ? input_string : ""); michael@428: michael@428: if (var) michael@428: { michael@428: Index: builtins/shopt.def michael@428: --- builtins/shopt.def.orig 2010-07-03 04:42:44.000000000 +0200 michael@428: +++ builtins/shopt.def 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -61,6 +61,10 @@ michael@428: #include "common.h" michael@428: #include "bashgetopt.h" michael@428: michael@428: +#if defined (READLINE) michael@428: +# include "../bashline.h" michael@428: +#endif michael@428: + michael@428: #if defined (HISTORY) michael@428: # include "../bashhist.h" michael@428: #endif michael@428: @@ -94,7 +98,7 @@ michael@428: extern int hist_verify, history_reediting, perform_hostname_completion; michael@428: extern int no_empty_command_completion; michael@428: extern int force_fignore; michael@428: -extern int dircomplete_spelling; michael@428: +extern int dircomplete_spelling, dircomplete_expand; michael@428: michael@428: extern int enable_hostname_completion __P((int)); michael@428: #endif michael@428: @@ -121,6 +125,10 @@ michael@428: static int set_restricted_shell __P((char *, int)); michael@428: #endif michael@428: michael@428: +#if defined (READLINE) michael@428: +static int shopt_set_complete_direxpand __P((char *, int)); michael@428: +#endif michael@428: + michael@428: static int shopt_login_shell; michael@428: static int shopt_compat31; michael@428: static int shopt_compat32; michael@428: @@ -150,6 +158,7 @@ michael@428: { "compat40", &shopt_compat40, set_compatibility_level }, michael@428: { "compat41", &shopt_compat41, set_compatibility_level }, michael@428: #if defined (READLINE) michael@428: + { "direxpand", &dircomplete_expand, shopt_set_complete_direxpand }, michael@428: { "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL }, michael@428: #endif michael@428: { "dotglob", &glob_dot_filenames, (shopt_set_func_t *)NULL }, michael@428: @@ -535,6 +544,17 @@ michael@428: return 0; michael@428: } michael@428: michael@428: +#if defined (READLINE) michael@428: +static int michael@428: +shopt_set_complete_direxpand (option_name, mode) michael@428: + char *option_name; michael@428: + int mode; michael@428: +{ michael@428: + set_directory_hook (); michael@428: + return 0; michael@428: +} michael@428: +#endif michael@428: + michael@428: #if defined (RESTRICTED_SHELL) michael@428: /* Don't allow the value of restricted_shell to be modified. */ michael@428: michael@428: Index: command.h michael@428: --- command.h.orig 2010-08-03 01:36:51.000000000 +0200 michael@428: +++ command.h 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -97,6 +97,7 @@ michael@428: #define W_HASCTLESC 0x200000 /* word contains literal CTLESC characters */ michael@428: #define W_ASSIGNASSOC 0x400000 /* word looks like associative array assignment */ michael@428: #define W_ARRAYIND 0x800000 /* word is an array index being expanded */ michael@428: +#define W_ASSNGLOBAL 0x1000000 /* word is a global assignment to declare (declare/typeset -g) */ michael@428: michael@428: /* Possible values for subshell_environment */ michael@428: #define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */ michael@428: Index: doc/bash.1 michael@428: --- doc/bash.1.orig 2011-01-16 21:31:39.000000000 +0100 michael@428: +++ doc/bash.1 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -8948,6 +8948,16 @@ michael@428: quoted. This is the behavior of posix mode through version 4.1. michael@428: The default bash behavior remains as in previous versions. michael@428: .TP 8 michael@428: +.B direxpand michael@428: +If set, michael@428: +.B bash michael@428: +replaces directory names with the results of word expansion when performing michael@428: +filename completion. This changes the contents of the readline editing michael@428: +buffer. michael@428: +If not set, michael@428: +.B bash michael@428: +attempts to preserve what the user typed. michael@428: +.TP 8 michael@428: .B dirspell michael@428: If set, michael@428: .B bash michael@428: Index: doc/bashref.texi michael@428: --- doc/bashref.texi.orig 2011-01-16 21:31:57.000000000 +0100 michael@428: +++ doc/bashref.texi 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -4535,6 +4535,13 @@ michael@428: quoted. This is the behavior of @sc{posix} mode through version 4.1. michael@428: The default Bash behavior remains as in previous versions. michael@428: michael@428: +@item direxpand michael@428: +If set, Bash michael@428: +replaces directory names with the results of word expansion when performing michael@428: +filename completion. This changes the contents of the readline editing michael@428: +buffer. michael@428: +If not set, Bash attempts to preserve what the user typed. michael@428: + michael@428: @item dirspell michael@428: If set, Bash michael@428: attempts spelling correction on directory names during word completion michael@428: Index: error.c michael@428: --- error.c.orig 2009-08-22 04:31:31.000000000 +0200 michael@428: +++ error.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -200,7 +200,11 @@ michael@428: michael@428: va_end (args); michael@428: if (exit_immediately_on_error) michael@428: - exit_shell (1); michael@428: + { michael@428: + if (last_command_exit_value == 0) michael@428: + last_command_exit_value = 1; michael@428: + exit_shell (last_command_exit_value); michael@428: + } michael@428: } michael@428: michael@428: void michael@428: Index: execute_cmd.c michael@428: --- execute_cmd.c.orig 2011-02-09 23:32:25.000000000 +0100 michael@428: +++ execute_cmd.c 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -2196,6 +2196,7 @@ michael@428: if (ignore_return && cmd) michael@428: cmd->flags |= CMD_IGNORE_RETURN; michael@428: michael@428: +#if defined (JOB_CONTROL) michael@428: lastpipe_flag = 0; michael@428: begin_unwind_frame ("lastpipe-exec"); michael@428: lstdin = -1; michael@428: @@ -2204,7 +2205,7 @@ michael@428: current shell environment. */ michael@428: if (lastpipe_opt && job_control == 0 && asynchronous == 0 && pipe_out == NO_PIPE && prev > 0) michael@428: { michael@428: - lstdin = move_to_high_fd (0, 0, 255); michael@428: + lstdin = move_to_high_fd (0, 1, -1); michael@428: if (lstdin > 0) michael@428: { michael@428: do_piping (prev, pipe_out); michael@428: @@ -2215,15 +2216,19 @@ michael@428: lastpipe_jid = stop_pipeline (0, (COMMAND *)NULL); /* XXX */ michael@428: add_unwind_protect (lastpipe_cleanup, lastpipe_jid); michael@428: } michael@428: - cmd->flags |= CMD_LASTPIPE; michael@428: + if (cmd) michael@428: + cmd->flags |= CMD_LASTPIPE; michael@428: } michael@428: if (prev >= 0) michael@428: add_unwind_protect (close, prev); michael@428: +#endif michael@428: michael@428: exec_result = execute_command_internal (cmd, asynchronous, prev, pipe_out, fds_to_close); michael@428: michael@428: +#if defined (JOB_CONTROL) michael@428: if (lstdin > 0) michael@428: restore_stdin (lstdin); michael@428: +#endif michael@428: michael@428: if (prev >= 0) michael@428: close (prev); michael@428: @@ -2246,7 +2251,9 @@ michael@428: unfreeze_jobs_list (); michael@428: } michael@428: michael@428: +#if defined (JOB_CONTROL) michael@428: discard_unwind_frame ("lastpipe-exec"); michael@428: +#endif michael@428: michael@428: return (exec_result); michael@428: } michael@428: @@ -3575,13 +3582,13 @@ michael@428: { michael@428: WORD_LIST *w; michael@428: struct builtin *b; michael@428: - int assoc; michael@428: + int assoc, global; michael@428: michael@428: if (words == 0) michael@428: return; michael@428: michael@428: b = 0; michael@428: - assoc = 0; michael@428: + assoc = global = 0; michael@428: michael@428: for (w = words; w; w = w->next) michael@428: if (w->word->flags & W_ASSIGNMENT) michael@428: @@ -3598,12 +3605,17 @@ michael@428: #if defined (ARRAY_VARS) michael@428: if (assoc) michael@428: w->word->flags |= W_ASSIGNASSOC; michael@428: + if (global) michael@428: + w->word->flags |= W_ASSNGLOBAL; michael@428: #endif michael@428: } michael@428: #if defined (ARRAY_VARS) michael@428: /* Note that we saw an associative array option to a builtin that takes michael@428: assignment statements. This is a bit of a kludge. */ michael@428: - else if (w->word->word[0] == '-' && strchr (w->word->word, 'A')) michael@428: + else if (w->word->word[0] == '-' && (strchr (w->word->word+1, 'A') || strchr (w->word->word+1, 'g'))) michael@428: +#else michael@428: + else if (w->word->word[0] == '-' && strchr (w->word->word+1, 'g')) michael@428: +#endif michael@428: { michael@428: if (b == 0) michael@428: { michael@428: @@ -3613,10 +3625,11 @@ michael@428: else if (b && (b->flags & ASSIGNMENT_BUILTIN)) michael@428: words->word->flags |= W_ASSNBLTIN; michael@428: } michael@428: - if (words->word->flags & W_ASSNBLTIN) michael@428: + if ((words->word->flags & W_ASSNBLTIN) && strchr (w->word->word+1, 'A')) michael@428: assoc = 1; michael@428: + if ((words->word->flags & W_ASSNBLTIN) && strchr (w->word->word+1, 'g')) michael@428: + global = 1; michael@428: } michael@428: -#endif michael@428: } michael@428: michael@428: /* Return 1 if the file found by searching $PATH for PATHNAME, defaulting michael@428: Index: expr.c michael@428: --- expr.c.orig 2010-12-21 17:12:13.000000000 +0100 michael@428: +++ expr.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -476,19 +476,23 @@ michael@428: michael@428: if (special) michael@428: { michael@428: + if ((op == DIV || op == MOD) && value == 0) michael@428: + { michael@428: + if (noeval == 0) michael@428: + evalerror (_("division by 0")); michael@428: + else michael@428: + value = 1; michael@428: + } michael@428: + michael@428: switch (op) michael@428: { michael@428: case MUL: michael@428: lvalue *= value; michael@428: break; michael@428: case DIV: michael@428: - if (value == 0) michael@428: - evalerror (_("division by 0")); michael@428: lvalue /= value; michael@428: break; michael@428: case MOD: michael@428: - if (value == 0) michael@428: - evalerror (_("division by 0")); michael@428: lvalue %= value; michael@428: break; michael@428: case PLUS: michael@428: @@ -804,7 +808,12 @@ michael@428: val2 = exppower (); michael@428: michael@428: if (((op == DIV) || (op == MOD)) && (val2 == 0)) michael@428: - evalerror (_("division by 0")); michael@428: + { michael@428: + if (noeval == 0) michael@428: + evalerror (_("division by 0")); michael@428: + else michael@428: + val2 = 1; michael@428: + } michael@428: michael@428: if (op == MUL) michael@428: val1 *= val2; michael@428: Index: lib/glob/gmisc.c michael@428: --- lib/glob/gmisc.c.orig 2011-02-05 22:11:17.000000000 +0100 michael@428: +++ lib/glob/gmisc.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -77,8 +77,8 @@ michael@428: wchar_t *wpat; michael@428: size_t wmax; michael@428: { michael@428: - wchar_t wc, *wbrack; michael@428: - int matlen, t, in_cclass, in_collsym, in_equiv; michael@428: + wchar_t wc; michael@428: + int matlen, bracklen, t, in_cclass, in_collsym, in_equiv; michael@428: michael@428: if (*wpat == 0) michael@428: return (0); michael@428: @@ -118,58 +118,80 @@ michael@428: break; michael@428: case L'[': michael@428: /* scan for ending `]', skipping over embedded [:...:] */ michael@428: - wbrack = wpat; michael@428: + bracklen = 1; michael@428: wc = *wpat++; michael@428: do michael@428: { michael@428: if (wc == 0) michael@428: { michael@428: - matlen += wpat - wbrack - 1; /* incremented below */ michael@428: - break; michael@428: + wpat--; /* back up to NUL */ michael@428: + matlen += bracklen; michael@428: + goto bad_bracket; michael@428: } michael@428: else if (wc == L'\\') michael@428: { michael@428: - wc = *wpat++; michael@428: - if (*wpat == 0) michael@428: - break; michael@428: + /* *wpat == backslash-escaped character */ michael@428: + bracklen++; michael@428: + /* If the backslash or backslash-escape ends the string, michael@428: + bail. The ++wpat skips over the backslash escape */ michael@428: + if (*wpat == 0 || *++wpat == 0) michael@428: + { michael@428: + matlen += bracklen; michael@428: + goto bad_bracket; michael@428: + } michael@428: } michael@428: else if (wc == L'[' && *wpat == L':') /* character class */ michael@428: { michael@428: wpat++; michael@428: + bracklen++; michael@428: in_cclass = 1; michael@428: } michael@428: else if (in_cclass && wc == L':' && *wpat == L']') michael@428: { michael@428: wpat++; michael@428: + bracklen++; michael@428: in_cclass = 0; michael@428: } michael@428: else if (wc == L'[' && *wpat == L'.') /* collating symbol */ michael@428: { michael@428: wpat++; michael@428: + bracklen++; michael@428: if (*wpat == L']') /* right bracket can appear as collating symbol */ michael@428: - wpat++; michael@428: + { michael@428: + wpat++; michael@428: + bracklen++; michael@428: + } michael@428: in_collsym = 1; michael@428: } michael@428: else if (in_collsym && wc == L'.' && *wpat == L']') michael@428: { michael@428: wpat++; michael@428: + bracklen++; michael@428: in_collsym = 0; michael@428: } michael@428: else if (wc == L'[' && *wpat == L'=') /* equivalence class */ michael@428: { michael@428: wpat++; michael@428: + bracklen++; michael@428: if (*wpat == L']') /* right bracket can appear as equivalence class */ michael@428: - wpat++; michael@428: + { michael@428: + wpat++; michael@428: + bracklen++; michael@428: + } michael@428: in_equiv = 1; michael@428: } michael@428: else if (in_equiv && wc == L'=' && *wpat == L']') michael@428: { michael@428: wpat++; michael@428: + bracklen++; michael@428: in_equiv = 0; michael@428: } michael@428: + else michael@428: + bracklen++; michael@428: } michael@428: while ((wc = *wpat++) != L']'); michael@428: matlen++; /* bracket expression can only match one char */ michael@428: +bad_bracket: michael@428: break; michael@428: } michael@428: } michael@428: @@ -213,8 +235,8 @@ michael@428: char *pat; michael@428: size_t max; michael@428: { michael@428: - char c, *brack; michael@428: - int matlen, t, in_cclass, in_collsym, in_equiv; michael@428: + char c; michael@428: + int matlen, bracklen, t, in_cclass, in_collsym, in_equiv; michael@428: michael@428: if (*pat == 0) michael@428: return (0); michael@428: @@ -254,58 +276,80 @@ michael@428: break; michael@428: case '[': michael@428: /* scan for ending `]', skipping over embedded [:...:] */ michael@428: - brack = pat; michael@428: + bracklen = 1; michael@428: c = *pat++; michael@428: do michael@428: { michael@428: if (c == 0) michael@428: { michael@428: - matlen += pat - brack - 1; /* incremented below */ michael@428: - break; michael@428: + pat--; /* back up to NUL */ michael@428: + matlen += bracklen; michael@428: + goto bad_bracket; michael@428: } michael@428: else if (c == '\\') michael@428: { michael@428: - c = *pat++; michael@428: - if (*pat == 0) michael@428: - break; michael@428: + /* *pat == backslash-escaped character */ michael@428: + bracklen++; michael@428: + /* If the backslash or backslash-escape ends the string, michael@428: + bail. The ++pat skips over the backslash escape */ michael@428: + if (*pat == 0 || *++pat == 0) michael@428: + { michael@428: + matlen += bracklen; michael@428: + goto bad_bracket; michael@428: + } michael@428: } michael@428: else if (c == '[' && *pat == ':') /* character class */ michael@428: { michael@428: pat++; michael@428: + bracklen++; michael@428: in_cclass = 1; michael@428: } michael@428: else if (in_cclass && c == ':' && *pat == ']') michael@428: { michael@428: pat++; michael@428: + bracklen++; michael@428: in_cclass = 0; michael@428: } michael@428: else if (c == '[' && *pat == '.') /* collating symbol */ michael@428: { michael@428: pat++; michael@428: + bracklen++; michael@428: if (*pat == ']') /* right bracket can appear as collating symbol */ michael@428: - pat++; michael@428: + { michael@428: + pat++; michael@428: + bracklen++; michael@428: + } michael@428: in_collsym = 1; michael@428: } michael@428: else if (in_collsym && c == '.' && *pat == ']') michael@428: { michael@428: pat++; michael@428: + bracklen++; michael@428: in_collsym = 0; michael@428: } michael@428: else if (c == '[' && *pat == '=') /* equivalence class */ michael@428: { michael@428: pat++; michael@428: + bracklen++; michael@428: if (*pat == ']') /* right bracket can appear as equivalence class */ michael@428: - pat++; michael@428: + { michael@428: + pat++; michael@428: + bracklen++; michael@428: + } michael@428: in_equiv = 1; michael@428: } michael@428: else if (in_equiv && c == '=' && *pat == ']') michael@428: { michael@428: pat++; michael@428: + bracklen++; michael@428: in_equiv = 0; michael@428: } michael@428: + else michael@428: + bracklen++; michael@428: } michael@428: while ((c = *pat++) != ']'); michael@428: matlen++; /* bracket expression can only match one char */ michael@428: +bad_bracket: michael@428: break; michael@428: } michael@428: } michael@428: Index: lib/readline/callback.c michael@428: --- lib/readline/callback.c.orig 2010-06-06 18:18:58.000000000 +0200 michael@428: +++ lib/readline/callback.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -148,6 +148,9 @@ michael@428: eof = _rl_vi_domove_callback (_rl_vimvcxt); michael@428: /* Should handle everything, including cleanup, numeric arguments, michael@428: and turning off RL_STATE_VIMOTION */ michael@428: + if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) michael@428: + _rl_internal_char_cleanup (); michael@428: + michael@428: return; michael@428: } michael@428: #endif michael@428: Index: lib/readline/vi_mode.c michael@428: --- lib/readline/vi_mode.c.orig 2010-11-21 01:51:39.000000000 +0100 michael@428: +++ lib/readline/vi_mode.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -1114,7 +1114,7 @@ michael@428: rl_beg_of_line (1, c); michael@428: _rl_vi_last_motion = c; michael@428: RL_UNSETSTATE (RL_STATE_VIMOTION); michael@428: - return (0); michael@428: + return (vidomove_dispatch (m)); michael@428: } michael@428: #if defined (READLINE_CALLBACKS) michael@428: /* XXX - these need to handle rl_universal_argument bindings */ michael@428: Index: lib/sh/zread.c michael@428: --- lib/sh/zread.c.orig 2009-03-02 14:54:45.000000000 +0100 michael@428: +++ lib/sh/zread.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -160,14 +160,13 @@ michael@428: zsyncfd (fd) michael@428: int fd; michael@428: { michael@428: - off_t off; michael@428: - int r; michael@428: + off_t off, r; michael@428: michael@428: off = lused - lind; michael@428: r = 0; michael@428: if (off > 0) michael@428: r = lseek (fd, -off, SEEK_CUR); michael@428: michael@428: - if (r >= 0) michael@428: + if (r != -1) michael@428: lused = lind = 0; michael@428: } michael@428: Index: parse.y michael@428: --- parse.y.orig 2011-01-02 21:48:11.000000000 +0100 michael@428: +++ parse.y 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -2499,7 +2499,7 @@ michael@428: We do this only if it is time to do so. Notice that only here michael@428: is the mail alarm reset; nothing takes place in check_mail () michael@428: except the checking of mail. Please don't change this. */ michael@428: - if (prompt_is_ps1 && time_to_check_mail ()) michael@428: + if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ()) michael@428: { michael@428: check_mail (); michael@428: reset_mail_timer (); michael@428: @@ -3842,6 +3842,7 @@ michael@428: int flags; michael@428: { michael@428: sh_parser_state_t ps; michael@428: + sh_input_line_state_t ls; michael@428: int orig_ind, nc, sflags; michael@428: char *ret, *s, *ep, *ostring; michael@428: michael@428: @@ -3849,10 +3850,12 @@ michael@428: orig_ind = *indp; michael@428: ostring = string; michael@428: michael@428: +/*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/ michael@428: sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE; michael@428: if (flags & SX_NOLONGJMP) michael@428: sflags |= SEVAL_NOLONGJMP; michael@428: save_parser_state (&ps); michael@428: + save_input_line_state (&ls); michael@428: michael@428: /*(*/ michael@428: parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/ michael@428: @@ -3861,6 +3864,8 @@ michael@428: michael@428: restore_parser_state (&ps); michael@428: reset_parser (); michael@428: + /* reset_parser clears shell_input_line and associated variables */ michael@428: + restore_input_line_state (&ls); michael@428: if (interactive) michael@428: token_to_read = 0; michael@428: michael@428: @@ -5135,6 +5140,9 @@ michael@428: case 'A': michael@428: /* Make the current time/date into a string. */ michael@428: (void) time (&the_time); michael@428: +#if defined (HAVE_TZSET) michael@428: + sv_tz ("TZ"); /* XXX -- just make sure */ michael@428: +#endif michael@428: tm = localtime (&the_time); michael@428: michael@428: if (c == 'd') michael@428: @@ -5905,6 +5913,12 @@ michael@428: ps->expand_aliases = expand_aliases; michael@428: ps->echo_input_at_read = echo_input_at_read; michael@428: michael@428: + ps->token = token; michael@428: + ps->token_buffer_size = token_buffer_size; michael@428: + /* Force reallocation on next call to read_token_word */ michael@428: + token = 0; michael@428: + token_buffer_size = 0; michael@428: + michael@428: return (ps); michael@428: } michael@428: michael@428: @@ -5946,6 +5960,42 @@ michael@428: michael@428: expand_aliases = ps->expand_aliases; michael@428: echo_input_at_read = ps->echo_input_at_read; michael@428: + michael@428: + FREE (token); michael@428: + token = ps->token; michael@428: + token_buffer_size = ps->token_buffer_size; michael@428: +} michael@428: + michael@428: +sh_input_line_state_t * michael@428: +save_input_line_state (ls) michael@428: + sh_input_line_state_t *ls; michael@428: +{ michael@428: + if (ls == 0) michael@428: + ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t)); michael@428: + if (ls == 0) michael@428: + return ((sh_input_line_state_t *)NULL); michael@428: + michael@428: + ls->input_line = shell_input_line; michael@428: + ls->input_line_size = shell_input_line_size; michael@428: + ls->input_line_len = shell_input_line_len; michael@428: + ls->input_line_index = shell_input_line_index; michael@428: + michael@428: + /* force reallocation */ michael@428: + shell_input_line = 0; michael@428: + shell_input_line_size = shell_input_line_len = shell_input_line_index = 0; michael@428: +} michael@428: + michael@428: +void michael@428: +restore_input_line_state (ls) michael@428: + sh_input_line_state_t *ls; michael@428: +{ michael@428: + FREE (shell_input_line); michael@428: + shell_input_line = ls->input_line; michael@428: + shell_input_line_size = ls->input_line_size; michael@428: + shell_input_line_len = ls->input_line_len; michael@428: + shell_input_line_index = ls->input_line_index; michael@428: + michael@428: + set_line_mbstate (); michael@428: } michael@428: michael@428: /************************************************ michael@428: Index: patchlevel.h michael@428: --- patchlevel.h.orig 2010-06-13 02:14:48.000000000 +0200 michael@428: +++ patchlevel.h 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -25,6 +25,6 @@ michael@428: regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh michael@428: looks for to find the patch level (for the sccs version string). */ michael@428: michael@428: -#define PATCHLEVEL 0 michael@428: +#define PATCHLEVEL 29 michael@428: michael@428: #endif /* _PATCHLEVEL_H_ */ michael@428: Index: pathexp.c michael@428: --- pathexp.c.orig 2010-08-14 05:21:57.000000000 +0200 michael@428: +++ pathexp.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -196,7 +196,7 @@ michael@428: { michael@428: if ((qflags & QGLOB_FILENAME) && pathname[i+1] == '/') michael@428: continue; michael@428: - if ((qflags & QGLOB_REGEXP) && ere_char (pathname[i+1]) == 0) michael@428: + if (pathname[i+1] != CTLESC && (qflags & QGLOB_REGEXP) && ere_char (pathname[i+1]) == 0) michael@428: continue; michael@428: temp[j++] = '\\'; michael@428: i++; michael@428: Index: print_cmd.c michael@428: --- print_cmd.c.orig 2010-05-31 00:34:08.000000000 +0200 michael@428: +++ print_cmd.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -315,6 +315,7 @@ michael@428: cprintf ("( "); michael@428: skip_this_indent++; michael@428: make_command_string_internal (command->value.Subshell->command); michael@428: + PRINT_DEFERRED_HEREDOCS (""); michael@428: cprintf (" )"); michael@428: break; michael@428: michael@428: @@ -592,6 +593,7 @@ michael@428: newline ("do\n"); michael@428: indentation += indentation_amount; michael@428: make_command_string_internal (arith_for_command->action); michael@428: + PRINT_DEFERRED_HEREDOCS (""); michael@428: semicolon (); michael@428: indentation -= indentation_amount; michael@428: newline ("done"); michael@428: @@ -653,6 +655,7 @@ michael@428: } michael@428: michael@428: make_command_string_internal (group_command->command); michael@428: + PRINT_DEFERRED_HEREDOCS (""); michael@428: michael@428: if (inside_function_def) michael@428: { michael@428: Index: shell.h michael@428: --- shell.h.orig 2011-01-07 04:16:55.000000000 +0100 michael@428: +++ shell.h 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -136,6 +136,9 @@ michael@428: int parser_state; michael@428: int *token_state; michael@428: michael@428: + char *token; michael@428: + int token_buffer_size; michael@428: + michael@428: /* input line state -- line number saved elsewhere */ michael@428: int input_line_terminator; michael@428: int eof_encountered; michael@428: @@ -166,6 +169,16 @@ michael@428: michael@428: } sh_parser_state_t; michael@428: michael@428: +typedef struct _sh_input_line_state_t { michael@428: + char *input_line; michael@428: + int input_line_index; michael@428: + int input_line_size; michael@428: + int input_line_len; michael@428: +} sh_input_line_state_t; michael@428: + michael@428: /* Let's try declaring these here. */ michael@428: extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *)); michael@428: extern void restore_parser_state __P((sh_parser_state_t *)); michael@428: + michael@428: +extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *)); michael@428: +extern void restore_input_line_state __P((sh_input_line_state_t *)); michael@428: Index: sig.c michael@428: --- sig.c.orig 2010-11-23 14:21:22.000000000 +0100 michael@428: +++ sig.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -46,6 +46,7 @@ michael@428: michael@428: #if defined (READLINE) michael@428: # include "bashline.h" michael@428: +# include michael@428: #endif michael@428: michael@428: #if defined (HISTORY) michael@428: @@ -62,6 +63,7 @@ michael@428: #if defined (HISTORY) michael@428: extern int history_lines_this_session; michael@428: #endif michael@428: +extern int no_line_editing; michael@428: michael@428: extern void initialize_siglist (); michael@428: michael@428: @@ -505,7 +507,10 @@ michael@428: { michael@428: #if defined (HISTORY) michael@428: /* XXX - will inhibit history file being written */ michael@428: - history_lines_this_session = 0; michael@428: +# if defined (READLINE) michael@428: + if (interactive_shell == 0 || interactive == 0 || (sig != SIGHUP && sig != SIGTERM) || no_line_editing || (RL_ISSTATE (RL_STATE_READCMD) == 0)) michael@428: +# endif michael@428: + history_lines_this_session = 0; michael@428: #endif michael@428: terminate_immediately = 0; michael@428: termsig_handler (sig); michael@428: Index: subst.c michael@428: --- subst.c.orig 2011-01-02 22:12:51.000000000 +0100 michael@428: +++ subst.c 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -366,6 +366,11 @@ michael@428: f &= ~W_ASSNBLTIN; michael@428: fprintf (stderr, "W_ASSNBLTIN%s", f ? "|" : ""); michael@428: } michael@428: + if (f & W_ASSNGLOBAL) michael@428: + { michael@428: + f &= ~W_ASSNGLOBAL; michael@428: + fprintf (stderr, "W_ASSNGLOBAL%s", f ? "|" : ""); michael@428: + } michael@428: if (f & W_COMPASSIGN) michael@428: { michael@428: f &= ~W_COMPASSIGN; michael@428: @@ -1379,10 +1384,12 @@ michael@428: slen = strlen (string + *sindex) + *sindex; michael@428: michael@428: /* The handling of dolbrace_state needs to agree with the code in parse.y: michael@428: - parse_matched_pair() */ michael@428: - dolbrace_state = 0; michael@428: - if (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) michael@428: - dolbrace_state = (flags & SX_POSIXEXP) ? DOLBRACE_QUOTE : DOLBRACE_PARAM; michael@428: + parse_matched_pair(). The different initial value is to handle the michael@428: + case where this function is called to parse the word in michael@428: + ${param op word} (SX_WORD). */ michael@428: + dolbrace_state = (flags & SX_WORD) ? DOLBRACE_WORD : DOLBRACE_PARAM; michael@428: + if ((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) && (flags & SX_POSIXEXP)) michael@428: + dolbrace_state = DOLBRACE_QUOTE; michael@428: michael@428: i = *sindex; michael@428: while (c = string[i]) michael@428: @@ -2801,7 +2808,7 @@ michael@428: } michael@428: else if (assign_list) michael@428: { michael@428: - if (word->flags & W_ASSIGNARG) michael@428: + if ((word->flags & W_ASSIGNARG) && (word->flags & W_ASSNGLOBAL) == 0) michael@428: aflags |= ASS_MKLOCAL; michael@428: if (word->flags & W_ASSIGNASSOC) michael@428: aflags |= ASS_MKASSOC; michael@428: @@ -3371,7 +3378,7 @@ michael@428: if (string == 0 || *string == '\0') michael@428: return (WORD_LIST *)NULL; michael@428: michael@428: - td.flags = 0; michael@428: + td.flags = W_NOSPLIT2; /* no splitting, remove "" and '' */ michael@428: td.word = string; michael@428: tresult = call_expand_word_internal (&td, quoted, 1, dollar_at_p, has_dollar_at); michael@428: return (tresult); michael@428: @@ -3704,7 +3711,10 @@ michael@428: break; michael@428: } michael@428: else if (string[i] == CTLNUL) michael@428: - i++; michael@428: + { michael@428: + i++; michael@428: + continue; michael@428: + } michael@428: michael@428: prev_i = i; michael@428: ADVANCE_CHAR (string, slen, i); michael@428: @@ -4156,7 +4166,7 @@ michael@428: simple = (wpat[0] != L'\\' && wpat[0] != L'*' && wpat[0] != L'?' && wpat[0] != L'['); michael@428: #if defined (EXTENDED_GLOB) michael@428: if (extended_glob) michael@428: - simple |= (wpat[1] != L'(' || (wpat[0] != L'*' && wpat[0] != L'?' && wpat[0] != L'+' && wpat[0] != L'!' && wpat[0] != L'@')); /*)*/ michael@428: + simple &= (wpat[1] != L'(' || (wpat[0] != L'*' && wpat[0] != L'?' && wpat[0] != L'+' && wpat[0] != L'!' && wpat[0] != L'@')); /*)*/ michael@428: #endif michael@428: michael@428: /* If the pattern doesn't match anywhere in the string, go ahead and michael@428: @@ -4607,6 +4617,7 @@ michael@428: if (ifs_firstc == 0) michael@428: #endif michael@428: word->flags |= W_NOSPLIT; michael@428: + word->flags |= W_NOSPLIT2; michael@428: result = call_expand_word_internal (word, quoted, 0, (int *)NULL, (int *)NULL); michael@428: expand_no_split_dollar_star = 0; michael@428: michael@428: @@ -5798,6 +5809,16 @@ michael@428: is the only expansion that creates more than one word. */ michael@428: if (qdollaratp && ((hasdol && quoted) || l->next)) michael@428: *qdollaratp = 1; michael@428: + /* If we have a quoted null result (QUOTED_NULL(temp)) and the word is michael@428: + a quoted null (l->next == 0 && QUOTED_NULL(l->word->word)), the michael@428: + flags indicate it (l->word->flags & W_HASQUOTEDNULL), and the michael@428: + expansion is quoted (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) michael@428: + (which is more paranoia than anything else), we need to return the michael@428: + quoted null string and set the flags to indicate it. */ michael@428: + if (l->next == 0 && (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) && QUOTED_NULL(temp) && QUOTED_NULL(l->word->word) && (l->word->flags & W_HASQUOTEDNULL)) michael@428: + { michael@428: + w->flags |= W_HASQUOTEDNULL; michael@428: + } michael@428: dispose_words (l); michael@428: } michael@428: else if ((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) && hasdol) michael@428: @@ -7176,7 +7197,7 @@ michael@428: { michael@428: /* Extract the contents of the ${ ... } expansion michael@428: according to the Posix.2 rules. */ michael@428: - value = extract_dollar_brace_string (string, &sindex, quoted, (c == '%' || c == '#') ? SX_POSIXEXP : 0); michael@428: + value = extract_dollar_brace_string (string, &sindex, quoted, (c == '%' || c == '#' || c =='/' || c == '^' || c == ',' || c ==':') ? SX_POSIXEXP|SX_WORD : SX_WORD); michael@428: if (string[sindex] == RBRACE) michael@428: sindex++; michael@428: else michael@428: @@ -7268,6 +7289,7 @@ michael@428: default: michael@428: case '\0': michael@428: bad_substitution: michael@428: + last_command_exit_value = EXECUTION_FAILURE; michael@428: report_error (_("%s: bad substitution"), string ? string : "??"); michael@428: FREE (value); michael@428: FREE (temp); michael@428: Index: subst.h michael@428: --- subst.h.orig 2010-12-03 02:21:29.000000000 +0100 michael@428: +++ subst.h 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -56,6 +56,7 @@ michael@428: #define SX_NOLONGJMP 0x0040 /* don't longjmp on fatal error */ michael@428: #define SX_ARITHSUB 0x0080 /* extracting $(( ... )) (currently unused) */ michael@428: #define SX_POSIXEXP 0x0100 /* extracting new Posix pattern removal expansions in extract_dollar_brace_string */ michael@428: +#define SX_WORD 0x0200 /* extracting word in ${param op word} */ michael@428: michael@428: /* Remove backslashes which are quoting backquotes from STRING. Modifies michael@428: STRING, and returns a pointer to it. */ michael@428: Index: support/shobj-conf michael@428: --- support/shobj-conf.orig 2009-10-28 14:20:21.000000000 +0100 michael@428: +++ support/shobj-conf 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -157,7 +157,7 @@ michael@428: ;; michael@428: michael@428: # Darwin/MacOS X michael@428: -darwin[89]*|darwin10*) michael@428: +darwin[89]*|darwin1[012]*) michael@428: SHOBJ_STATUS=supported michael@428: SHLIB_STATUS=supported michael@428: michael@428: @@ -186,7 +186,7 @@ michael@428: SHLIB_LIBSUFF='dylib' michael@428: michael@428: case "${host_os}" in michael@428: - darwin[789]*|darwin10*) SHOBJ_LDFLAGS='' michael@428: + darwin[789]*|darwin1[012]*) SHOBJ_LDFLAGS='' michael@428: SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' michael@428: ;; michael@428: *) SHOBJ_LDFLAGS='-dynamic' michael@428: Index: tests/shopt.right michael@428: --- tests/shopt.right.orig 2010-07-03 05:36:30.000000000 +0200 michael@428: +++ tests/shopt.right 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -12,6 +12,7 @@ michael@428: shopt -u compat32 michael@428: shopt -u compat40 michael@428: shopt -u compat41 michael@428: +shopt -u direxpand michael@428: shopt -u dirspell michael@428: shopt -u dotglob michael@428: shopt -u execfail michael@428: @@ -68,6 +69,7 @@ michael@428: shopt -u compat32 michael@428: shopt -u compat40 michael@428: shopt -u compat41 michael@428: +shopt -u direxpand michael@428: shopt -u dirspell michael@428: shopt -u dotglob michael@428: shopt -u execfail michael@428: @@ -101,6 +103,7 @@ michael@428: compat32 off michael@428: compat40 off michael@428: compat41 off michael@428: +direxpand off michael@428: dirspell off michael@428: dotglob off michael@428: execfail off michael@428: Index: variables.c michael@428: --- variables.c.orig 2011-01-25 02:07:48.000000000 +0100 michael@428: +++ variables.c 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -3653,6 +3653,22 @@ michael@428: return n; michael@428: } michael@428: michael@428: +int michael@428: +chkexport (name) michael@428: + char *name; michael@428: +{ michael@428: + SHELL_VAR *v; michael@428: + michael@428: + v = find_variable (name); michael@428: + if (v && exported_p (v)) michael@428: + { michael@428: + array_needs_making = 1; michael@428: + maybe_make_export_env (); michael@428: + return 1; michael@428: + } michael@428: + return 0; michael@428: +} michael@428: + michael@428: void michael@428: maybe_make_export_env () michael@428: { michael@428: @@ -4214,7 +4230,7 @@ michael@428: { "TEXTDOMAIN", sv_locale }, michael@428: { "TEXTDOMAINDIR", sv_locale }, michael@428: michael@428: -#if defined (HAVE_TZSET) && defined (PROMPT_STRING_DECODE) michael@428: +#if defined (HAVE_TZSET) michael@428: { "TZ", sv_tz }, michael@428: #endif michael@428: michael@428: @@ -4558,12 +4574,13 @@ michael@428: } michael@428: #endif /* HISTORY */ michael@428: michael@428: -#if defined (HAVE_TZSET) && defined (PROMPT_STRING_DECODE) michael@428: +#if defined (HAVE_TZSET) michael@428: void michael@428: sv_tz (name) michael@428: char *name; michael@428: { michael@428: - tzset (); michael@428: + if (chkexport (name)) michael@428: + tzset (); michael@428: } michael@428: #endif michael@428: michael@428: Index: variables.h michael@428: --- variables.h.orig 2010-12-03 02:22:01.000000000 +0100 michael@428: +++ variables.h 2012-06-27 10:31:02.000000000 +0200 michael@428: @@ -313,6 +313,7 @@ michael@428: michael@428: extern void sort_variables __P((SHELL_VAR **)); michael@428: michael@428: +extern int chkexport __P((char *)); michael@428: extern void maybe_make_export_env __P((void)); michael@428: extern void update_export_env_inplace __P((char *, int, char *)); michael@428: extern void put_command_name_into_env __P((char *)); michael@428: Index: y.tab.c michael@428: --- y.tab.c.orig 2011-01-04 15:57:56.000000000 +0100 michael@428: +++ y.tab.c 2012-06-27 10:31:03.000000000 +0200 michael@428: @@ -4811,7 +4811,7 @@ michael@428: We do this only if it is time to do so. Notice that only here michael@428: is the mail alarm reset; nothing takes place in check_mail () michael@428: except the checking of mail. Please don't change this. */ michael@428: - if (prompt_is_ps1 && time_to_check_mail ()) michael@428: + if (prompt_is_ps1 && parse_and_execute_level == 0 && time_to_check_mail ()) michael@428: { michael@428: check_mail (); michael@428: reset_mail_timer (); michael@428: @@ -6154,6 +6154,7 @@ michael@428: int flags; michael@428: { michael@428: sh_parser_state_t ps; michael@428: + sh_input_line_state_t ls; michael@428: int orig_ind, nc, sflags; michael@428: char *ret, *s, *ep, *ostring; michael@428: michael@428: @@ -6161,10 +6162,12 @@ michael@428: orig_ind = *indp; michael@428: ostring = string; michael@428: michael@428: +/*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/ michael@428: sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE; michael@428: if (flags & SX_NOLONGJMP) michael@428: sflags |= SEVAL_NOLONGJMP; michael@428: save_parser_state (&ps); michael@428: + save_input_line_state (&ls); michael@428: michael@428: /*(*/ michael@428: parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/ michael@428: @@ -6173,6 +6176,8 @@ michael@428: michael@428: restore_parser_state (&ps); michael@428: reset_parser (); michael@428: + /* reset_parser clears shell_input_line and associated variables */ michael@428: + restore_input_line_state (&ls); michael@428: if (interactive) michael@428: token_to_read = 0; michael@428: michael@428: @@ -7447,6 +7452,9 @@ michael@428: case 'A': michael@428: /* Make the current time/date into a string. */ michael@428: (void) time (&the_time); michael@428: +#if defined (HAVE_TZSET) michael@428: + sv_tz ("TZ"); /* XXX -- just make sure */ michael@428: +#endif michael@428: tm = localtime (&the_time); michael@428: michael@428: if (c == 'd') michael@428: @@ -8217,6 +8225,12 @@ michael@428: ps->expand_aliases = expand_aliases; michael@428: ps->echo_input_at_read = echo_input_at_read; michael@428: michael@428: + ps->token = token; michael@428: + ps->token_buffer_size = token_buffer_size; michael@428: + /* Force reallocation on next call to read_token_word */ michael@428: + token = 0; michael@428: + token_buffer_size = 0; michael@428: + michael@428: return (ps); michael@428: } michael@428: michael@428: @@ -8258,6 +8272,42 @@ michael@428: michael@428: expand_aliases = ps->expand_aliases; michael@428: echo_input_at_read = ps->echo_input_at_read; michael@428: + michael@428: + FREE (token); michael@428: + token = ps->token; michael@428: + token_buffer_size = ps->token_buffer_size; michael@428: +} michael@428: + michael@428: +sh_input_line_state_t * michael@428: +save_input_line_state (ls) michael@428: + sh_input_line_state_t *ls; michael@428: +{ michael@428: + if (ls == 0) michael@428: + ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t)); michael@428: + if (ls == 0) michael@428: + return ((sh_input_line_state_t *)NULL); michael@428: + michael@428: + ls->input_line = shell_input_line; michael@428: + ls->input_line_size = shell_input_line_size; michael@428: + ls->input_line_len = shell_input_line_len; michael@428: + ls->input_line_index = shell_input_line_index; michael@428: + michael@428: + /* force reallocation */ michael@428: + shell_input_line = 0; michael@428: + shell_input_line_size = shell_input_line_len = shell_input_line_index = 0; michael@428: +} michael@428: + michael@428: +void michael@428: +restore_input_line_state (ls) michael@428: + sh_input_line_state_t *ls; michael@428: +{ michael@428: + FREE (shell_input_line); michael@428: + shell_input_line = ls->input_line; michael@428: + shell_input_line_size = ls->input_line_size; michael@428: + shell_input_line_len = ls->input_line_len; michael@428: + shell_input_line_index = ls->input_line_index; michael@428: + michael@428: + set_line_mbstate (); michael@428: } michael@428: michael@428: /************************************************