From 6dc203b86571ef8434ad07305f0dd8c3811a21c5 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Fri, 14 Aug 2020 14:34:20 -0400 Subject: [PATCH] commit bash-20200812 snapshot --- CWRU/CWRU.chlog | 16 ++++++++++++++++ builtins/declare.def | 6 +++--- builtins/fc.def | 23 ++++++++++++++++++++++- builtins/setattr.def | 2 +- flags.c | 6 +----- flags.h | 2 +- tests/history.right | 4 ++-- tests/history.tests | 2 +- variables.c | 20 ++++++++++++++++++-- 9 files changed, 65 insertions(+), 16 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 8f93f008..3958e86d 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8873,3 +8873,19 @@ builtins/fc.def specifications, clamp them at the beginning or end of the history list, as appropriate, per POSIX. Report and fix from Martijn Dekker + + 8/12 + ---- +builtins/fc.def + - fc_gethnum: return HIST_NOTFOUND (new error) if the string is not a + number and doesn't correspond to any command in the history list + - fc_builtin: print a "no command found" error message if fc_gethnum + returns HIST_NOTFOUND + + 8/14 + ---- +flags.c + - no_invisible_vars: removed undocumented `-I' flag + +{flags,variables}.c,flags.h,builtins/{declare,setattr.def} + - no_invisible_vars: remove all references diff --git a/builtins/declare.def b/builtins/declare.def index 98878243..21e4516d 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -727,20 +727,20 @@ restart_new_var_name: if (flags_on & att_assoc) { var = make_new_assoc_variable (name); - if (var && offset == 0 && no_invisible_vars == 0) + if (var && offset == 0) VSETATTR (var, att_invisible); } else if ((flags_on & att_array) || making_array_special) { var = make_new_array_variable (name); - if (var && offset == 0 && no_invisible_vars == 0) + if (var && offset == 0) VSETATTR (var, att_invisible); } else #endif { var = mkglobal ? bind_global_variable (name, (char *)NULL, ASS_FORCE) : bind_variable (name, (char *)NULL, ASS_FORCE); - if (var && offset == 0 && no_invisible_vars == 0) + if (var && offset == 0) VSETATTR (var, att_invisible); } if (var == 0) diff --git a/builtins/fc.def b/builtins/fc.def index 901091ff..7ebbc5c0 100644 --- a/builtins/fc.def +++ b/builtins/fc.def @@ -88,6 +88,7 @@ extern int errno; #define HIST_INVALID INT_MIN #define HIST_ERANGE INT_MIN+1 +#define HIST_NOTFOUND INT_MIN+2 extern int unlink PARAMS((const char *)); @@ -358,6 +359,16 @@ fc_builtin (list) sh_erange ((char *)NULL, _("history specification")); return (EXECUTION_FAILURE); } + else if (histbeg == HIST_ERANGE || histend == HIST_ERANGE) + { + sh_erange ((char *)NULL, _("history specification")); + return (EXECUTION_FAILURE); + } + else if (histbeg == HIST_NOTFOUND || histend == HIST_NOTFOUND) + { + builtin_error (_("no command found")); + return (EXECUTION_FAILURE); + } /* We don't throw an error for line specifications out of range, per POSIX */ if (histbeg < 0) @@ -392,6 +403,16 @@ fc_builtin (list) sh_erange ((char *)NULL, _("history specification")); return (EXECUTION_FAILURE); } + else if (histbeg == HIST_ERANGE || histend == HIST_ERANGE) + { + sh_erange ((char *)NULL, _("history specification")); + return (EXECUTION_FAILURE); + } + else if (histbeg == HIST_NOTFOUND || histend == HIST_NOTFOUND) + { + builtin_error (_("no command found")); + return (EXECUTION_FAILURE); + } /* We don't throw an error for line specifications out of range, per POSIX */ if (histbeg < 0) @@ -602,7 +623,7 @@ fc_gethnum (command, hlist, mode) if (STREQN (command, histline (j), clen)) return (j); } - return (-1); + return (HIST_NOTFOUND); } /* Locate the most recent history line which begins with diff --git a/builtins/setattr.def b/builtins/setattr.def index e43f7091..a193462d 100644 --- a/builtins/setattr.def +++ b/builtins/setattr.def @@ -645,7 +645,7 @@ set_var_attribute (name, attribute, undo) if (var == 0) { var = bind_variable (name, (char *)NULL, 0); - if (var && no_invisible_vars == 0) + if (var) VSETATTR (var, att_invisible); } else if (var->context != 0) diff --git a/flags.c b/flags.c index 187c2e98..983f9a50 100644 --- a/flags.c +++ b/flags.c @@ -112,9 +112,6 @@ int no_symbolic_links = 0; int lexical_scoping = 0; #endif -/* Non-zero means no such thing as invisible variables. */ -int no_invisible_vars = 0; - /* Non-zero means look up and remember command names in a hash table, */ int hashing_enabled = 1; @@ -201,7 +198,6 @@ const struct flags_alist shell_flags[] = { #if defined (BANG_HISTORY) { 'H', &histexp_flag }, #endif /* BANG_HISTORY */ - { 'I', &no_invisible_vars }, { 'P', &no_symbolic_links }, { 'T', &function_trace_mode }, {0, (int *)NULL} @@ -349,7 +345,7 @@ reset_shell_flags () place_keywords_in_env = read_but_dont_execute = just_one_command = 0; noclobber = unbound_vars_is_error = 0; echo_command_at_execute = jobs_m_flag = forced_interactive = 0; - no_symbolic_links = no_invisible_vars = 0; + no_symbolic_links = 0; privileged_mode = pipefail_opt = 0; error_trace_mode = function_trace_mode = 0; diff --git a/flags.h b/flags.h index c0a2a08d..a3b5daa9 100644 --- a/flags.h +++ b/flags.h @@ -45,7 +45,7 @@ extern int disallow_filename_globbing, place_keywords_in_env, read_but_dont_execute, just_one_command, unbound_vars_is_error, echo_input_at_read, verbose_flag, - echo_command_at_execute, no_invisible_vars, noclobber, + echo_command_at_execute, noclobber, hashing_enabled, forced_interactive, privileged_mode, jobs_m_flag, asynchronous_notification, interactive_comments, no_symbolic_links, function_trace_mode, error_trace_mode, pipefail_opt; diff --git a/tests/history.right b/tests/history.right index b24e72e9..6652156c 100644 --- a/tests/history.right +++ b/tests/history.right @@ -97,11 +97,11 @@ line 2 for history 6 HISTFILE=$TMPDIR/newhistory 7 echo displaying \$HISTFILE after history -a 8 cat $HISTFILE -1 for i in one two three; do echo $i; done +./history.tests: line 90: fc: no command found 15 echo line 2 for history 16 unset HISTSIZE 17 unset HISTFILE - 18 # no longer an out-of-range error + 18 # now an out-of-range error because of the one=two not found in history aa ab ac echo xx xb xc xx xb xc diff --git a/tests/history.tests b/tests/history.tests index 187d2a23..53321f05 100644 --- a/tests/history.tests +++ b/tests/history.tests @@ -86,7 +86,7 @@ unset HISTFILE fc -l 4 fc -l 4 8 -# no longer an out-of-range error +# now an out-of-range error because of the one=two not found in history fc -l one=two three=four 502 history 4 diff --git a/variables.c b/variables.c index 7b7e5739..770de113 100644 --- a/variables.c +++ b/variables.c @@ -1958,6 +1958,22 @@ initialize_dynamic_variables () /* */ /* **************************************************************** */ +#if 0 /* not yet */ +int +var_isset (var) + SHELL_VAR *var; +{ + return (var->value != 0); +} + +int +var_isunset (var) + SHELL_VAR *var; +{ + return (var->value == 0); +} +#endif + /* How to get a pointer to the shell variable or function named NAME. HASHED_VARS is a pointer to the hash table containing the list of interest (either variables or functions). */ @@ -2731,7 +2747,7 @@ set_local_var_flags: /* value_cell will be 0 if localvar_inherit == 0 or there was no old variable with the same name or the old variable was invisible */ - if (was_tmpvar == 0 && no_invisible_vars == 0 && value_cell (new_var) == 0) + if (was_tmpvar == 0 && value_cell (new_var) == 0) VSETATTR (new_var, att_invisible); /* XXX */ return (new_var); } @@ -4032,7 +4048,7 @@ delete_all_variables (hashed_vars) if (!entry) \ { \ entry = bind_variable (name, "", 0); \ - if (!no_invisible_vars && entry) entry->attributes |= att_invisible; \ + if (entry) entry->attributes |= att_invisible; \ } \ } \ while (0)