From: Chet Ramey Date: Sun, 4 Dec 2011 03:45:24 +0000 (-0500) Subject: commit bash-20060215 snapshot X-Git-Tag: bash-3.2-alpha~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0cc62c12d76db433ef6c07669df4dd1f004e9156;p=thirdparty%2Fbash.git commit bash-20060215 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index eaebf0126..f354a0d3c 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -12958,7 +12958,7 @@ bashline.c and bash_directory_expansion lib/readline/doc/rltech.texi - - add note to description of rl_direcotory_completion_hook that it + - add note to description of rl_directory_completion_hook that it needs to dequote the directory name even if no other expansions are performed @@ -13082,4 +13082,27 @@ lib/readline/bind.c functions using the ANYOTHERKEY binding code. variables.c - - shells running in posix mode do not set $HOME, as POSIX requires + - shells running in posix mode do not set $HOME, as POSIX apparently + requires + + 2/15 + ---- +braces.c + - mkseq() now takes the increment as an argument; changed callers + + 2/16 + ---- +builtins/hash.def + - print `hash table empty' message to stdout instead of stderr + + 2/17 + ---- +lib/readline/readline.c + - when resetting rl_prompt in rl_set_prompt, make sure rl_display_prompt + is set when the function returns + + 2/18 + ---- +lib/readline/display.c + - further fixes to _rl_make_prompt_for_search from Eric Blake to deal + with multiple calls to expand_prompt diff --git a/CWRU/CWRU.chlog~ b/CWRU/CWRU.chlog~ index 97457ffd2..2540fc54e 100644 --- a/CWRU/CWRU.chlog~ +++ b/CWRU/CWRU.chlog~ @@ -13080,3 +13080,28 @@ lib/readline/bind.c bound to a portion of the passed key sequence without processing the entire thing. We can bind maps with existing non-map functions using the ANYOTHERKEY binding code. + +variables.c + - shells running in posix mode do not set $HOME, as POSIX requires + + 2/15 + ---- +braces.c + - mkseq() now takes the increment as an argument; changed callers + + 2/16 + ---- +builtins/hash.def + - print `hash table empty' message to stdout instead of stderr + + 2/17 + ---- +lib/readline/readline.c + - when resetting rl_prompt in rl_set_prompt, make sure rl_display_prompt + is set when the function returns + + 2/18 + ---- +lib/readline/display.c + - further fixes to _rl_make_prompt_for_search from Eric Blake to deal + with multiple calls to expand_prompt diff --git a/braces.c b/braces.c index 3bac869b4..e2b008ed2 100644 --- a/braces.c +++ b/braces.c @@ -61,7 +61,7 @@ int brace_arg_separator = ','; static int brace_gobbler __P((char *, size_t, int *, int)); static char **expand_amble __P((char *, size_t, int)); static char **expand_seqterm __P((char *, size_t)); -static char **mkseq __P((int, int, int)); +static char **mkseq __P((int, int, int, int)); static char **array_concat __P((char **, char **)); #else static int brace_gobbler (); @@ -291,16 +291,22 @@ expand_amble (text, tlen, flags) #define ST_CHAR 2 static char ** -mkseq (start, end, type) - int start, end, type; +mkseq (start, end, incr, type) + int start, end, incr, type; { - int n, incr, i; + int n, i; char **result, *t; n = abs (end - start) + 1; result = strvec_create (n + 1); - incr = (start < end) ? 1 : -1; + if (incr == 0) + incr = 1; + + if (start > end && incr > 0) + incr = -incr; + else if (start < end && incr < 0) + incr = -incr; /* Make sure we go through the loop at least once, so {3..3} prints `3' */ i = 0; @@ -380,7 +386,7 @@ expand_seqterm (text, tlen) rhs_v = tr; } - result = mkseq (lhs_v, rhs_v, lhs_t); + result = mkseq (lhs_v, rhs_v, 1, lhs_t); free (lhs); free (rhs); diff --git a/builtins/hash.def b/builtins/hash.def index b29595219..7f24c034c 100644 --- a/builtins/hash.def +++ b/builtins/hash.def @@ -125,7 +125,7 @@ hash_builtin (list) if (list == 0 && expunge_hash_table == 0) { if (print_hashed_commands (list_portably) == 0) - fprintf (stderr, _("%s: hash table empty\n"), this_command_name); + printf (_("%s: hash table empty\n"), this_command_name); return (EXECUTION_SUCCESS); } diff --git a/builtins/hash.def~ b/builtins/hash.def~ new file mode 100644 index 000000000..b29595219 --- /dev/null +++ b/builtins/hash.def~ @@ -0,0 +1,271 @@ +This file is hash.def, from which is created hash.c. +It implements the builtin "hash" in Bash. + +Copyright (C) 1987-2003 Free Software Foundation, Inc. + +This file is part of GNU Bash, the Bourne Again SHell. + +Bash is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Bash is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with Bash; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. + +$PRODUCES hash.c + +$BUILTIN hash +$FUNCTION hash_builtin +$SHORT_DOC hash [-lr] [-p pathname] [-dt] [name ...] +For each NAME, the full pathname of the command is determined and +remembered. If the -p option is supplied, PATHNAME is used as the +full pathname of NAME, and no path search is performed. The -r +option causes the shell to forget all remembered locations. The -d +option causes the shell to forget the remembered location of each NAME. +If the -t option is supplied the full pathname to which each NAME +corresponds is printed. If multiple NAME arguments are supplied with +-t, the NAME is printed before the hashed full pathname. The -l option +causes output to be displayed in a format that may be reused as input. +If no arguments are given, information about remembered commands is displayed. +$END + +#include + +#include + +#include "../bashtypes.h" + +#if defined (HAVE_UNISTD_H) +# include +#endif + +#include + +#include "../bashansi.h" +#include "../bashintl.h" + +#include "../shell.h" +#include "../builtins.h" +#include "../flags.h" +#include "../findcmd.h" +#include "../hashcmd.h" +#include "common.h" +#include "bashgetopt.h" + +extern int dot_found_in_search; +extern char *this_command_name; + +static int add_hashed_command __P((char *, int)); +static int print_hash_info __P((BUCKET_CONTENTS *)); +static int print_portable_hash_info __P((BUCKET_CONTENTS *)); +static int print_hashed_commands __P((int)); +static int list_hashed_filename_targets __P((WORD_LIST *, int)); + +/* Print statistics on the current state of hashed commands. If LIST is + not empty, then rehash (or hash in the first place) the specified + commands. */ +int +hash_builtin (list) + WORD_LIST *list; +{ + int expunge_hash_table, list_targets, list_portably, delete, opt; + char *w, *pathname; + + if (hashing_enabled == 0) + { + builtin_error (_("hashing disabled")); + return (EXECUTION_FAILURE); + } + + expunge_hash_table = list_targets = list_portably = delete = 0; + pathname = (char *)NULL; + reset_internal_getopt (); + while ((opt = internal_getopt (list, "dlp:rt")) != -1) + { + switch (opt) + { + case 'd': + delete = 1; + break; + case 'l': + list_portably = 1; + break; + case 'p': + pathname = list_optarg; + break; + case 'r': + expunge_hash_table = 1; + break; + case 't': + list_targets = 1; + break; + default: + builtin_usage (); + return (EX_USAGE); + } + } + list = loptend; + + /* hash -t requires at least one argument. */ + if (list == 0 && list_targets) + { + sh_needarg ("-t"); + return (EXECUTION_FAILURE); + } + + /* We want hash -r to be silent, but hash -- to print hashing info, so + we test expunge_hash_table. */ + if (list == 0 && expunge_hash_table == 0) + { + if (print_hashed_commands (list_portably) == 0) + fprintf (stderr, _("%s: hash table empty\n"), this_command_name); + + return (EXECUTION_SUCCESS); + } + + if (expunge_hash_table) + phash_flush (); + + /* If someone runs `hash -r -t xyz' he will be disappointed. */ + if (list_targets) + return (list_hashed_filename_targets (list, list_portably)); + +#if defined (RESTRICTED_SHELL) + if (restricted && pathname && strchr (pathname, '/')) + { + sh_restricted (pathname); + return (EXECUTION_FAILURE); + } +#endif + + for (opt = EXECUTION_SUCCESS; list; list = list->next) + { + /* Add, remove or rehash the specified commands. */ + w = list->word->word; + if (pathname) + { + if (is_directory (pathname)) + { +#ifdef EISDIR + builtin_error ("%s: %s", pathname, strerror (EISDIR)); +#else + builtin_error ("%s: is a directory", pathname); +#endif + opt = EXECUTION_FAILURE; + } + else + phash_insert (w, pathname, 0, 0); + } + else if (absolute_program (w)) + continue; + else if (delete) + { + if (phash_remove (w)) + { + sh_notfound (w); + opt = EXECUTION_FAILURE; + } + } + else if (add_hashed_command (w, 0)) + opt = EXECUTION_FAILURE; + } + + fflush (stdout); + return (opt); +} + +static int +add_hashed_command (w, quiet) + char *w; + int quiet; +{ + int rv; + char *full_path; + + rv = 0; + if (find_function (w) == 0 && find_shell_builtin (w) == 0) + { + full_path = find_user_command (w); + if (full_path && executable_file (full_path)) + phash_insert (w, full_path, dot_found_in_search, 0); + else + { + if (quiet == 0) + sh_notfound (w); + rv++; + } + FREE (full_path); + } + return (rv); +} + +/* Print information about current hashed info. */ +static int +print_hash_info (item) + BUCKET_CONTENTS *item; +{ + printf ("%4d\t%s\n", item->times_found, pathdata(item)->path); + return 0; +} + +static int +print_portable_hash_info (item) + BUCKET_CONTENTS *item; +{ + printf ("builtin hash -p %s %s\n", pathdata(item)->path, item->key); + return 0; +} + +static int +print_hashed_commands (fmt) + int fmt; +{ + if (hashed_filenames == 0 || HASH_ENTRIES (hashed_filenames) == 0) + return (0); + + if (fmt == 0) + printf ("hits\tcommand\n"); + hash_walk (hashed_filenames, fmt ? print_portable_hash_info : print_hash_info); + return (1); +} + +static int +list_hashed_filename_targets (list, fmt) + WORD_LIST *list; + int fmt; +{ + int all_found, multiple; + char *target; + WORD_LIST *l; + + all_found = 1; + multiple = list->next != 0; + + for (l = list; l; l = l->next) + { + target = phash_search (l->word->word); + if (target == 0) + { + all_found = 0; + sh_notfound (l->word->word); + continue; + } + if (fmt) + printf ("builtin hash -p %s %s\n", target, l->word->word); + else + { + if (multiple) + printf ("%s\t", l->word->word); + printf ("%s\n", target); + } + } + + return (all_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE); +} diff --git a/lib/readline/display.c b/lib/readline/display.c index 28abadeb7..34005739f 100644 --- a/lib/readline/display.c +++ b/lib/readline/display.c @@ -1662,10 +1662,11 @@ rl_on_new_line_with_prompt () int rl_forced_update_display () { + register char *temp; + if (visible_line) { - register char *temp = visible_line; - + temp = visible_line; while (*temp) *temp++ = '\0'; } @@ -1997,20 +1998,36 @@ _rl_make_prompt_for_search (pchar) int pchar; { int len; - char *pmt; + char *pmt, *p; rl_save_prompt (); - len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; - pmt = (char *)xmalloc (len + 2); - if (len) - strcpy (pmt, rl_prompt); - pmt[len] = pchar; - pmt[len+1] = '\0'; + /* We've saved the prompt, and can do anything with the various prompt + strings we need before they're restored. We want the unexpanded + portion of the prompt string after any final newline. */ + p = rl_prompt ? strrchr (rl_prompt, '\n') : 0; + if (p == 0) + { + len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; + pmt = (char *)xmalloc (len + 2); + if (len) + strcpy (pmt, rl_prompt); + pmt[len] = pchar; + pmt[len+1] = '\0'; + } + else + { + p++; + len = strlen (p); + pmt = (char *)xmalloc (len + 2); + if (len) + strcpy (pmt, p); + pmt[len] = pchar; + pmt[len+1] = '\0'; + } /* will be overwritten by expand_prompt, called from rl_message */ prompt_physical_chars = saved_physical_chars + 1; - return pmt; } diff --git a/lib/readline/display.c~ b/lib/readline/display.c~ index b349a0f52..396666d4f 100644 --- a/lib/readline/display.c~ +++ b/lib/readline/display.c~ @@ -1390,15 +1390,6 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) } } -if (*old == 0 && *new != 0) - { - fprintf (stderr, "old == 0x%x new = 0x%x\r\n", old, new); - fprintf (stderr, "omax == %d nmax = %d\r\n", omax, nmax); - fprintf (stderr, "ne == 0x%x nfd = 0x%x\r\n", ne, nfd); - fprintf (stderr, "oe == 0x%x ofd = 0x%x\r\n", oe, ofd); - fprintf (stderr, "ols == 0x%x nls = 0x%x\r\n", ols, nls); - } - /* count of invisible characters in the current invisible line. */ current_invis_chars = W_OFFSET (current_line, wrap_offset); if (_rl_last_v_pos != current_line) @@ -1671,10 +1662,11 @@ rl_on_new_line_with_prompt () int rl_forced_update_display () { + register char *temp; + if (visible_line) { - register char *temp = visible_line; - + temp = visible_line; while (*temp) *temp++ = '\0'; } diff --git a/lib/readline/readline.c b/lib/readline/readline.c index 874eae96e..5eaaf4743 100644 --- a/lib/readline/readline.c +++ b/lib/readline/readline.c @@ -282,6 +282,7 @@ rl_set_prompt (prompt) { FREE (rl_prompt); rl_prompt = prompt ? savestring (prompt) : (char *)NULL; + rl_display_prompt = rl_prompt ? rl_prompt : ""; rl_visible_prompt_length = rl_expand_prompt (rl_prompt); return 0; diff --git a/lib/readline/readline.c~ b/lib/readline/readline.c~ index 1899a6a62..874eae96e 100644 --- a/lib/readline/readline.c~ +++ b/lib/readline/readline.c~ @@ -1095,7 +1095,7 @@ bind_arrow_keys_internal (map) rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line); rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line); -#if 1 /* was defined (__MINGW32__)*/ +#if defined (__MINGW32__) rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history); rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history); rl_bind_keyseq_if_unbound ("\340M", rl_forward_char);