commit bash-20120629 snapshot

This commit is contained in:
Chet Ramey
2012-07-07 12:26:10 -04:00
parent c74f63f39f
commit d42cb8c15b
37 changed files with 20781 additions and 63 deletions
+108
View File
@@ -14055,3 +14055,111 @@ lib/glob/glob.c
<svdb@stack.nl>, fix from Andreas Schwab <schwab@linux-m68k.org>
- call run_pending_traps after each call to QUIT or test of
interrupt_state, like we do in mainline shell code
- glob_vector: don't call QUIT; in `if (lose)' code block; just free
memory, return NULL, and let callers deal with interrupt_state or
other signals and traps
6/25
----
lib/readline/input.c
- rl_read_key: restructure the loop that calls the event hook a little,
so that the hook is called only after rl_gather_tyi returns no input,
and any pending input is returned first. This results in better
efficiency for processing pending input without calling the hook
on every input character as bash-4.1 did. From a report from
Max Horn <max@quendi.de>
6/26
----
trap.c
- signal_is_pending: return TRUE if SIG argument has been received and
a trap is waiting to execute
trap.h
- signal_is_pending: extern declaration
lib/glob/glob.c
- glob_vector: check for pending SIGINT trap each time through the loop,
just like we check for interrupt_state or terminating_signal, and
set `lose = 1' so we clean up after ourselves and interrupt the
operation before running the trap. This may require a change later,
maybe call run_pending_traps and do that if run_pending_traps returns?
variables.c
- sv_histtimefmt: set history_comment_character to default (`#') if
it's 0 when we're turning on history timestamps. The history code
uses the history comment character to prefix timestamps, and
leaving it at 0 effectively removes them from the history. From a
report to help-bash by Dennis Williamson <dennistwilliamson@gmail.com>
6/27
----
lib/readline/signals.c
- rl_maybe_restore_sighandler: new function, sets handler for SIG to
HANDLER->sa_handler only if it's not SIG_IGN. Needs to be called
on same signals set using rl_maybe_set_sighandler, which does not
override an existing SIG_IGN handler (SIGALRM is ok since it does
the check inline; doesn't mess with SIGWINCH)
6/30
----
variables.h
- additional defines for the new `nameref' variable attribute
(att_nameref): nameref_p, nameref_cell, var_setref
variables.c
- find_variable_nameref: resolve SHELL_VAR V through chain of namerefs
- find_variable_last_nameref: resolve variable NAME until last in a
chain of possibly more than one nameref starting at shell_variables
- find_global_variable_last_nameref: resolve variable NAME until last
in a chain of possibly more than one nameref starting at
global_variables
- find_nameref_at_context: resolve SHELL_VAR V through chain of namerefs
in a specific variable context (usually a local variable hash table)
- find_variable_nameref_context: resolve SHELL_VAR V through chain of
namerefs following a chain of varible contexts
- find_variable_last_nameref_context: resolve SHELL_VAR V as in
find_variable_last_context, but return the final nameref instead of
what the final nameref resolves to
- find_variable_tempenv, find_variable_notempenv, find_global_variable,
find_shell_variable, find_variable: modified to follow namerefs
- find_global_variable_noref: look up a global variable without following
any namerefs
- find_variable_noref: look up a shell variable without following any
namerefs
- bind_variable_internal: modify to follow a chain of namerefs in the
global variables table; change to handle assignments to a nameref by
following nameref chain
- bind_variable: modify to follow chain of namerefs when binding to a
local variable
- unbind_variable: changes to unset nameref variables (unsets both
nameref and variable it resolves to)
subst.c
- parameter_brace_expand_word: change to handle expanding nameref whose
value is x[n]
- parameter_brace_expand_indir: change to expand in ksh93-compatible
way if variable to be indirected is nameref and a simple (non-array)
expansion
- param_expand: change to expand $foo where foo is a nameref whose value
is x[n]
execute_cmd.c
- execute_for_command: changes to implement ksh93 semantics when index
variable is a nameref
builtins/setattr.def
- show_var_attributes: change to add `n' to flags list if att_nameref
is set
builtins/set.def
- unset_builtin: changes to error messages to follow nameref variables
builtins/declare.def
- document new -n option
- declare_internal: new `-n' and `+n' options
- declare_internal: handle declare -n var[=value] and
declare +n var[=value] for existing and non-existant variables.
Enforce restriction that nameref variables cannot be arrays.
Implement semi-peculiar ksh93 semantics for typeset +n ref=value
+82
View File
@@ -14053,3 +14053,85 @@ lib/glob/glob.c
- glob_filename: check for interrupts before returning if glob_vector
returns NULL or an error. Bug reported by Serge van den Boom
<svdb@stack.nl>, fix from Andreas Schwab <schwab@linux-m68k.org>
- call run_pending_traps after each call to QUIT or test of
interrupt_state, like we do in mainline shell code
- glob_vector: don't call QUIT; in `if (lose)' code block; just free
memory, return NULL, and let callers deal with interrupt_state or
other signals and traps
6/25
----
lib/readline/input.c
- rl_read_key: restructure the loop that calls the event hook a little,
so that the hook is called only after rl_gather_tyi returns no input,
and any pending input is returned first. This results in better
efficiency for processing pending input without calling the hook
on every input character as bash-4.1 did. From a report from
Max Horn <max@quendi.de>
6/26
----
trap.c
- signal_is_pending: return TRUE if SIG argument has been received and
a trap is waiting to execute
trap.h
- signal_is_pending: extern declaration
lib/glob/glob.c
- glob_vector: check for pending SIGINT trap each time through the loop,
just like we check for interrupt_state or terminating_signal, and
set `lose = 1' so we clean up after ourselves and interrupt the
operation before running the trap. This may require a change later,
maybe call run_pending_traps and do that if run_pending_traps returns?
variables.c
- sv_histtimefmt: set history_comment_character to default (`#') if
it's 0 when we're turning on history timestamps. The history code
uses the history comment character to prefix timestamps, and
leaving it at 0 effectively removes them from the history. From a
report to help-bash by Dennis Williamson <dennistwilliamson@gmail.com>
6/27
----
lib/readline/signals.c
- rl_maybe_restore_sighandler: new function, sets handler for SIG to
HANDLER->sa_handler only if it's not SIG_IGN. Needs to be called
on same signals set using rl_maybe_set_sighandler, which does not
override an existing SIG_IGN handler (SIGALRM is ok since it does
the check inline; doesn't mess with SIGWINCH)
6/30
----
variables.h
- additional defines for the new `nameref' variable attribute
(att_nameref): nameref_p, nameref_cell, var_setref
variables.c
- find_variable_nameref: resolve SHELL_VAR V through chain of namerefs
- find_variable_last_nameref: resolve variable NAME until last in a
chain of possibly more than one nameref starting at shell_variables
- find_global_variable_last_nameref: resolve variable NAME until last
in a chain of possibly more than one nameref starting at
global_variables
- find_nameref_at_context: resolve SHELL_VAR V through chain of namerefs
in a specific variable context (usually a local variable hash table)
- find_variable_nameref_context: resolve SHELL_VAR V through chain of
namerefs following a chain of varible contexts
- find_variable_last_nameref_context: resolve SHELL_VAR V as in
find_variable_last_context, but return the final nameref instead of
what the final nameref resolves to
- find_variable_tempenv, find_variable_notempenv, find_global_variable,
find_shell_variable, find_variable: modified to follow namerefs
- find_global_variable_noref: look up a global variable without following
any namerefs
- find_variable_noref: look up a shell variable without following any
namerefs
- bind_variable_internal: modify to follow a chain of namerefs in the
global variables table; change to handle assignments to a nameref by
following nameref chain
- bind_variable: modify to follow chain of namerefs when binding to a
local variable
- unbind_variable: changes to unset nameref variables (unsets both
nameref and variable it resolves to)
+8
View File
@@ -962,6 +962,13 @@ tests/mapfile.tests f
tests/mapfile1.sub f
tests/more-exp.tests f
tests/more-exp.right f
tests/nameref.tests f
tests/nameref1.sub f
tests/nameref2.sub f
tests/nameref3.sub f
tests/nameref4.sub f
tests/nameref5.sub f
tests/nameref.right f
tests/new-exp.tests f
tests/new-exp1.sub f
tests/new-exp2.sub f
@@ -1083,6 +1090,7 @@ tests/run-jobs f
tests/run-lastpipe f
tests/run-mapfile f
tests/run-more-exp f
tests/run-nameref f
tests/run-new-exp f
tests/run-nquote f
tests/run-nquote1 f
+1222
View File
File diff suppressed because it is too large Load Diff
+8
View File
@@ -330,6 +330,14 @@ find_or_make_array_variable (name, flags)
SHELL_VAR *var;
var = find_variable (name);
if (var == 0)
{
/* See if we have a nameref pointing to a variable that hasn't been
created yet. */
var = find_variable_last_nameref (name);
if (var && nameref_p (var))
var = (flags & 2) ? make_new_assoc_variable (nameref_cell (var)) : make_new_array_variable (nameref_cell (var));
}
if (var == 0)
var = (flags & 2) ? make_new_assoc_variable (name) : make_new_array_variable (name);
+1121
View File
File diff suppressed because it is too large Load Diff
+94 -7
View File
@@ -1,7 +1,7 @@
This file is declare.def, from which is created declare.c.
It implements the builtins "declare" and "local" in Bash.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
Copyright (C) 1987-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -22,7 +22,7 @@ $PRODUCES declare.c
$BUILTIN declare
$FUNCTION declare_builtin
$SHORT_DOC declare [-aAfFgilrtux] [-p] [name[=value] ...]
$SHORT_DOC declare [-aAfFgilnrtux] [-p] [name[=value] ...]
Set variable values and attributes.
Declare variables and give them attributes. If no NAMEs are given,
@@ -41,6 +41,7 @@ Options which set attributes:
-A to make NAMEs associative arrays (if supported)
-i to make NAMEs have the `integer' attribute
-l to convert NAMEs to lower case on assignment
-n make NAME a reference to the variable named by its value
-r to make NAMEs readonly
-t to make NAMEs have the `trace' attribute
-u to convert NAMEs to upper case on assignment
@@ -127,9 +128,9 @@ local_builtin (list)
}
#if defined (ARRAY_VARS)
# define DECLARE_OPTS "+acfgilprtuxAF"
# define DECLARE_OPTS "+acfgilnprtuxAF"
#else
# define DECLARE_OPTS "+cfgilprtuxF"
# define DECLARE_OPTS "+cfgilnprtuxF"
#endif
/* The workhorse function. */
@@ -139,12 +140,13 @@ declare_internal (list, local_var)
int local_var;
{
int flags_on, flags_off, *flags;
int any_failed, assign_error, pflag, nodefs, opt, mkglobal;
int any_failed, assign_error, pflag, nodefs, opt, mkglobal, onref, offref;
char *t, *subscript_start;
SHELL_VAR *var;
SHELL_VAR *var, *refvar;
FUNCTION_DEF *shell_fn;
flags_on = flags_off = any_failed = assign_error = pflag = nodefs = mkglobal = 0;
refvar = (SHELL_VAR *)NULL;
reset_internal_getopt ();
while ((opt = internal_getopt (list, DECLARE_OPTS)) != EOF)
{
@@ -186,6 +188,9 @@ declare_internal (list, local_var)
case 'i':
*flags |= att_integer;
break;
case 'n':
*flags |= att_nameref;
break;
case 'r':
*flags |= att_readonly;
break;
@@ -334,6 +339,7 @@ declare_internal (list, local_var)
/* XXX - this has consequences when we're making a local copy of a
variable that was in the temporary environment. Watch out
for this. */
refvar = (SHELL_VAR *)NULL;
if (variable_context && mkglobal == 0 && ((flags_on & att_function) == 0))
{
#if defined (ARRAY_VARS)
@@ -343,7 +349,31 @@ declare_internal (list, local_var)
var = make_local_array_variable (name, making_array_special);
else
#endif
var = make_local_variable (name);
#if 0
/* XXX - this doesn't work right yet. */
/* See below for rationale for doing this. */
if (flags_on & att_nameref)
{
/* See if we are trying to modify an existing nameref variable */
var = find_variable_last_nameref (name);
if (var && nameref_p (var) == 0)
var = make_local_variable (name);
}
else if (flags_off & att_nameref)
{
var = (SHELL_VAR *)NULL;
/* See if we are trying to modify an existing nameref variable */
refvar = find_variable_last_nameref (name);
if (refvar && nameref_p (refvar) == 0)
refvar = 0;
if (refvar)
var = make_local_variable (nameref_cell (refvar));
if (var == 0)
var = make_local_variable (name);
}
else
#endif
var = make_local_variable (name);
if (var == 0)
{
any_failed++;
@@ -415,6 +445,33 @@ declare_internal (list, local_var)
else /* declare -[aAirx] name [name...] */
{
/* Non-null if we just created or fetched a local variable. */
/* Here's what ksh93 seems to do. If we are modifying an existing
nameref variable, we don't follow the nameref chain past the last
nameref, and we set the nameref variable's value so future
references to that variable will return the value of the variable
we're assigning right now. */
if (var == 0 && (flags_on & att_nameref))
{
/* See if we are trying to modify an existing nameref variable */
var = mkglobal ? find_global_variable_last_nameref (name) : find_variable_last_nameref (name);
if (var && nameref_p (var) == 0)
var = 0;
}
/* However, if we're turning off the nameref attribute on an existing
nameref variable, we first follow the nameref chain to the end,
modify the value of the variable this nameref variable references,
*CHANGING ITS VALUE AS A SIDE EFFECT* then turn off the nameref
flag *LEAVING THE NAMEREF VARIABLE'S VALUE UNCHANGED* */
else if (var == 0 && (flags_off & att_nameref))
{
/* See if we are trying to modify an existing nameref variable */
refvar = mkglobal ? find_global_variable_last_nameref (name) : find_variable_last_nameref (name);
if (refvar && nameref_p (refvar) == 0)
refvar = 0;
if (refvar)
var = mkglobal ? find_global_variable (nameref_cell (refvar)) : find_variable (nameref_cell (refvar));
}
if (var == 0)
var = mkglobal ? find_global_variable (name) : find_variable (name);
@@ -501,6 +558,23 @@ declare_internal (list, local_var)
var = convert_var_to_array (var);
#endif /* ARRAY_VARS */
/* XXX - we note that we are turning on nameref attribute and defer
setting it until the assignment has been made so we don't do an
inadvertent nameref lookup. Might have to do the same thing for
flags_off&att_nameref. */
/* XXX - ksh93 makes it an error to set a readonly nameref variable
using a single typeset command. */
onref = (flags_on & att_nameref);
flags_on &= ~att_nameref;
if (array_p (var) || assoc_p (var)
|| (offset && compound_array_assign)
|| simple_array_assign)
onref = 0; /* array variables may not be namerefs */
/* ksh93 seems to do this */
offref = (flags_off & att_nameref);
flags_off &= ~att_nameref;
VSETATTR (var, flags_on);
VUNSETATTR (var, flags_off);
@@ -516,6 +590,8 @@ declare_internal (list, local_var)
if (var == 0) /* some kind of assignment error */
{
assign_error++;
flags_on |= onref;
flags_off |= offref;
NEXT_VARIABLE ();
}
}
@@ -562,6 +638,17 @@ declare_internal (list, local_var)
}
}
/* Turn on nameref attribute we deferred above. */
/* XXX - should we turn on the noassign attribute for consistency with
ksh93 when we turn on the nameref attribute? */
VSETATTR (var, onref);
flags_on |= onref;
VUNSETATTR (var, offref);
flags_off |= offref;
/* Yuck. ksh93 compatibility */
if (refvar)
VUNSETATTR (refvar, flags_off);
stupidly_hack_special_variables (name);
NEXT_VARIABLE ();
+659
View File
@@ -0,0 +1,659 @@
This file is declare.def, from which is created declare.c.
It implements the builtins "declare" and "local" in Bash.
Copyright (C) 1987-2012 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES declare.c
$BUILTIN declare
$FUNCTION declare_builtin
$SHORT_DOC declare [-aAfFgilnrtux] [-p] [name[=value] ...]
Set variable values and attributes.
Declare variables and give them attributes. If no NAMEs are given,
display the attributes and values of all variables.
Options:
-f restrict action or display to function names and definitions
-F restrict display to function names only (plus line number and
source file when debugging)
-g create global variables when used in a shell function; otherwise
ignored
-p display the attributes and value of each NAME
Options which set attributes:
-a to make NAMEs indexed arrays (if supported)
-A to make NAMEs associative arrays (if supported)
-i to make NAMEs have the `integer' attribute
-l to convert NAMEs to lower case on assignment
-n make NAME a reference to the variable named by its value
-r to make NAMEs readonly
-t to make NAMEs have the `trace' attribute
-u to convert NAMEs to upper case on assignment
-x to make NAMEs export
Using `+' instead of `-' turns off the given attribute.
Variables with the integer attribute have arithmetic evaluation (see
the `let' command) performed when the variable is assigned a value.
When used in a function, `declare' makes NAMEs local, as with the `local'
command. The `-g' option suppresses this behavior.
Exit Status:
Returns success unless an invalid option is supplied or an error occurs.
$END
$BUILTIN typeset
$FUNCTION declare_builtin
$SHORT_DOC typeset [-aAfFgilrtux] [-p] name[=value] ...
Set variable values and attributes.
Obsolete. See `help declare'.
$END
#include <config.h>
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#include <stdio.h>
#include "../bashansi.h"
#include "../bashintl.h"
#include "../shell.h"
#include "common.h"
#include "builtext.h"
#include "bashgetopt.h"
extern int array_needs_making;
extern int posixly_correct;
static int declare_internal __P((register WORD_LIST *, int));
/* Declare or change variable attributes. */
int
declare_builtin (list)
register WORD_LIST *list;
{
return (declare_internal (list, 0));
}
$BUILTIN local
$FUNCTION local_builtin
$SHORT_DOC local [option] name[=value] ...
Define local variables.
Create a local variable called NAME, and give it VALUE. OPTION can
be any option accepted by `declare'.
Local variables can only be used within a function; they are visible
only to the function where they are defined and its children.
Exit Status:
Returns success unless an invalid option is supplied, an error occurs,
or the shell is not executing a function.
$END
int
local_builtin (list)
register WORD_LIST *list;
{
if (variable_context)
return (declare_internal (list, 1));
else
{
builtin_error (_("can only be used in a function"));
return (EXECUTION_FAILURE);
}
}
#if defined (ARRAY_VARS)
# define DECLARE_OPTS "+acfgilnprtuxAF"
#else
# define DECLARE_OPTS "+cfgilnprtuxF"
#endif
/* The workhorse function. */
static int
declare_internal (list, local_var)
register WORD_LIST *list;
int local_var;
{
int flags_on, flags_off, *flags;
int any_failed, assign_error, pflag, nodefs, opt, mkglobal, onref, offref;
char *t, *subscript_start;
SHELL_VAR *var, *refvar;
FUNCTION_DEF *shell_fn;
flags_on = flags_off = any_failed = assign_error = pflag = nodefs = mkglobal = 0;
refvar = (SHELL_VAR *)NULL;
reset_internal_getopt ();
while ((opt = internal_getopt (list, DECLARE_OPTS)) != EOF)
{
flags = list_opttype == '+' ? &flags_off : &flags_on;
switch (opt)
{
case 'a':
#if defined (ARRAY_VARS)
*flags |= att_array;
break;
#else
builtin_usage ();
return (EX_USAGE);
#endif
case 'A':
#if defined (ARRAY_VARS)
*flags |= att_assoc;
break;
#else
builtin_usage ();
return (EX_USAGE);
#endif
case 'p':
if (local_var == 0)
pflag++;
break;
case 'F':
nodefs++;
*flags |= att_function;
break;
case 'f':
*flags |= att_function;
break;
case 'g':
if (flags == &flags_on)
mkglobal = 1;
break;
case 'i':
*flags |= att_integer;
break;
case 'n':
*flags |= att_nameref;
break;
case 'r':
*flags |= att_readonly;
break;
case 't':
*flags |= att_trace;
break;
case 'x':
*flags |= att_exported;
array_needs_making = 1;
break;
#if defined (CASEMOD_ATTRS)
# if defined (CASEMOD_CAPCASE)
case 'c':
*flags |= att_capcase;
if (flags == &flags_on)
flags_off |= att_uppercase|att_lowercase;
break;
# endif
case 'l':
*flags |= att_lowercase;
if (flags == &flags_on)
flags_off |= att_capcase|att_uppercase;
break;
case 'u':
*flags |= att_uppercase;
if (flags == &flags_on)
flags_off |= att_capcase|att_lowercase;
break;
#endif /* CASEMOD_ATTRS */
default:
builtin_usage ();
return (EX_USAGE);
}
}
list = loptend;
/* If there are no more arguments left, then we just want to show
some variables. */
if (list == 0) /* declare -[aAfFirtx] */
{
/* Show local variables defined at this context level if this is
the `local' builtin. */
if (local_var)
{
register SHELL_VAR **vlist;
register int i;
vlist = all_local_variables ();
if (vlist)
{
for (i = 0; vlist[i]; i++)
print_assignment (vlist[i]);
free (vlist);
}
}
else if (pflag && (flags_on == 0 || flags_on == att_function))
show_all_var_attributes (flags_on == 0, nodefs);
else if (flags_on == 0)
return (set_builtin ((WORD_LIST *)NULL));
else
set_or_show_attributes ((WORD_LIST *)NULL, flags_on, nodefs);
return (sh_chkwrite (EXECUTION_SUCCESS));
}
if (pflag) /* declare -p [-aAfFirtx] name [name...] */
{
for (any_failed = 0; list; list = list->next)
{
pflag = show_name_attributes (list->word->word, nodefs);
if (pflag)
{
sh_notfound (list->word->word);
any_failed++;
}
}
return (sh_chkwrite (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS));
}
#define NEXT_VARIABLE() free (name); list = list->next; continue
/* There are arguments left, so we are making variables. */
while (list) /* declare [-aAfFirx] name [name ...] */
{
char *value, *name;
int offset, aflags;
#if defined (ARRAY_VARS)
int making_array_special, compound_array_assign, simple_array_assign;
#endif
name = savestring (list->word->word);
offset = assignment (name, 0);
aflags = 0;
if (offset) /* declare [-aAfFirx] name=value */
{
name[offset] = '\0';
value = name + offset + 1;
if (name[offset - 1] == '+')
{
aflags |= ASS_APPEND;
name[offset - 1] = '\0';
}
}
else
value = "";
#if defined (ARRAY_VARS)
compound_array_assign = simple_array_assign = 0;
subscript_start = (char *)NULL;
if (t = strchr (name, '[')) /* ] */
{
/* If offset != 0 we have already validated any array reference */
if (offset == 0 && valid_array_reference (name) == 0)
{
sh_invalidid (name);
assign_error++;
NEXT_VARIABLE ();
}
subscript_start = t;
*t = '\0';
making_array_special = 1;
}
else
making_array_special = 0;
#endif
/* If we're in posix mode or not looking for a shell function (since
shell function names don't have to be valid identifiers when the
shell's not in posix mode), check whether or not the argument is a
valid, well-formed shell identifier. */
if ((posixly_correct || (flags_on & att_function) == 0) && legal_identifier (name) == 0)
{
sh_invalidid (name);
assign_error++;
NEXT_VARIABLE ();
}
/* If VARIABLE_CONTEXT has a non-zero value, then we are executing
inside of a function. This means we should make local variables,
not global ones. */
/* XXX - this has consequences when we're making a local copy of a
variable that was in the temporary environment. Watch out
for this. */
refvar = (SHELL_VAR *)NULL;
if (variable_context && mkglobal == 0 && ((flags_on & att_function) == 0))
{
#if defined (ARRAY_VARS)
if (flags_on & att_assoc)
var = make_local_assoc_variable (name);
else if ((flags_on & att_array) || making_array_special)
var = make_local_array_variable (name, making_array_special);
else
#endif
#if 0
/* XXX - this doesn't work right yet. */
/* See below for rationale for doing this. */
if (flags_on & att_nameref)
{
/* See if we are trying to modify an existing nameref variable */
var = find_variable_last_nameref (name);
if (var && nameref_p (var) == 0)
var = make_local_variable (name);
}
else if (flags_off & att_nameref)
{
var = (SHELL_VAR *)NULL;
/* See if we are trying to modify an existing nameref variable */
refvar = find_variable_last_nameref (name);
if (refvar && nameref_p (refvar) == 0)
refvar = 0;
if (refvar)
var = make_local_variable (nameref_cell (refvar));
if (var == 0)
var = make_local_variable (name);
}
else
#endif
var = make_local_variable (name);
if (var == 0)
{
any_failed++;
NEXT_VARIABLE ();
}
}
else
var = (SHELL_VAR *)NULL;
/* If we are declaring a function, then complain about it in some way.
We don't let people make functions by saying `typeset -f foo=bar'. */
/* There should be a way, however, to let people look at a particular
function definition by saying `typeset -f foo'. */
if (flags_on & att_function)
{
if (offset) /* declare -f [-rix] foo=bar */
{
builtin_error (_("cannot use `-f' to make functions"));
free (name);
return (EXECUTION_FAILURE);
}
else /* declare -f [-rx] name [name...] */
{
var = find_function (name);
if (var)
{
if (readonly_p (var) && (flags_off & att_readonly))
{
builtin_error (_("%s: readonly function"), name);
any_failed++;
NEXT_VARIABLE ();
}
/* declare -[Ff] name [name...] */
if (flags_on == att_function && flags_off == 0)
{
#if defined (DEBUGGER)
if (nodefs && debugging_mode)
{
shell_fn = find_function_def (var->name);
if (shell_fn)
printf ("%s %d %s\n", var->name, shell_fn->line, shell_fn->source_file);
else
printf ("%s\n", var->name);
}
else
#endif /* DEBUGGER */
{
t = nodefs ? var->name
: named_function_string (name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL);
printf ("%s\n", t);
any_failed = sh_chkwrite (any_failed);
}
}
else /* declare -[fF] -[rx] name [name...] */
{
VSETATTR (var, flags_on);
VUNSETATTR (var, flags_off);
}
}
else
any_failed++;
NEXT_VARIABLE ();
}
}
else /* declare -[aAirx] name [name...] */
{
/* Non-null if we just created or fetched a local variable. */
/* Here's what ksh93 seems to do. If we are modifying an existing
nameref variable, we don't follow the nameref chain past the last
nameref, and we set the nameref variable's value so future
references to that variable will return the value of the variable
we're assigning right now. */
if (var == 0 && (flags_on & att_nameref))
{
/* See if we are trying to modify an existing nameref variable */
var = mkglobal ? find_global_variable_last_nameref (name) : find_variable_last_nameref (name);
if (var && nameref_p (var) == 0)
var = 0;
}
/* However, if we're turning off the nameref attribute on an existing
nameref variable, we first follow the nameref chain to the end,
modify the value of the variable this nameref variable references,
*CHANGING ITS VALUE AS A SIDE EFFECT* then turn off the nameref
flag *LEAVING THE NAMEREF VARIABLE'S VALUE UNCHANGED* */
else if (var == 0 && (flags_off & att_nameref))
{
/* See if we are trying to modify an existing nameref variable */
refvar = mkglobal ? find_global_variable_last_nameref (name) : find_variable_last_nameref (name);
if (refvar && nameref_p (refvar) == 0)
refvar = 0;
if (refvar)
var = mkglobal ? find_global_variable (nameref_cell (refvar)) : find_variable (nameref_cell (refvar));
}
if (var == 0)
var = mkglobal ? find_global_variable (name) : find_variable (name);
if (var == 0)
{
#if defined (ARRAY_VARS)
if (flags_on & att_assoc)
var = make_new_assoc_variable (name);
else if ((flags_on & att_array) || making_array_special)
var = make_new_array_variable (name);
else
#endif
if (offset)
var = bind_variable (name, "", 0);
else
{
var = bind_variable (name, (char *)NULL, 0);
VSETATTR (var, att_invisible);
}
}
/* Cannot use declare +r to turn off readonly attribute. */
if (readonly_p (var) && (flags_off & att_readonly))
{
sh_readonly (name);
any_failed++;
NEXT_VARIABLE ();
}
/* Cannot use declare to assign value to readonly or noassign
variable. */
if ((readonly_p (var) || noassign_p (var)) && offset)
{
if (readonly_p (var))
sh_readonly (name);
assign_error++;
NEXT_VARIABLE ();
}
#if defined (ARRAY_VARS)
if ((making_array_special || (flags_on & (att_array|att_assoc)) || array_p (var) || assoc_p (var)) && offset)
{
int vlen;
vlen = STRLEN (value);
if (value[0] == '(' && value[vlen-1] == ')')
compound_array_assign = 1;
else
simple_array_assign = 1;
}
/* Cannot use declare +a name or declare +A name to remove an
array variable. */
if (((flags_off & att_array) && array_p (var)) || ((flags_off & att_assoc) && assoc_p (var)))
{
builtin_error (_("%s: cannot destroy array variables in this way"), name);
any_failed++;
NEXT_VARIABLE ();
}
if ((flags_on & att_array) && assoc_p (var))
{
builtin_error (_("%s: cannot convert associative to indexed array"), name);
any_failed++;
NEXT_VARIABLE ();
}
if ((flags_on & att_assoc) && array_p (var))
{
builtin_error (_("%s: cannot convert indexed to associative array"), name);
any_failed++;
NEXT_VARIABLE ();
}
/* declare -A name[[n]] makes name an associative array variable. */
if (flags_on & att_assoc)
{
if (assoc_p (var) == 0)
var = convert_var_to_assoc (var);
}
/* declare -a name[[n]] or declare name[n] makes name an indexed
array variable. */
else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
var = convert_var_to_array (var);
#endif /* ARRAY_VARS */
/* XXX - we note that we are turning on nameref attribute and defer
setting it until the assignment has been made so we don't do an
inadvertent nameref lookup. Might have to do the same thing for
flags_off&att_nameref. */
/* XXX - ksh93 makes it an error to have a readonly nameref variable */
onref = (flags_on & att_nameref);
flags_on &= ~att_nameref;
if (array_p (var) || assoc_p (var)
|| (offset && compound_array_assign)
|| simple_array_assign)
onref = 0; /* array variables may not be namerefs */
/* ksh93 seems to do this */
offref = (flags_off & att_nameref);
flags_off &= ~att_nameref;
VSETATTR (var, flags_on);
VUNSETATTR (var, flags_off);
#if defined (ARRAY_VARS)
if (offset && compound_array_assign)
assign_array_var_from_string (var, value, aflags);
else if (simple_array_assign && subscript_start)
{
/* declare [-aA] name[N]=value */
*subscript_start = '['; /* ] */
var = assign_array_element (name, value, 0); /* XXX - not aflags */
*subscript_start = '\0';
if (var == 0) /* some kind of assignment error */
{
assign_error++;
flags_on |= onref;
flags_off |= offref;
NEXT_VARIABLE ();
}
}
else if (simple_array_assign)
{
/* let bind_{array,assoc}_variable take care of this. */
if (assoc_p (var))
bind_assoc_variable (var, name, savestring ("0"), value, aflags);
else
bind_array_variable (name, 0, value, aflags);
}
else
#endif
/* bind_variable_value duplicates the essential internals of
bind_variable() */
if (offset)
bind_variable_value (var, value, aflags);
/* If we found this variable in the temporary environment, as with
`var=value declare -x var', make sure it is treated identically
to `var=value export var'. Do the same for `declare -r' and
`readonly'. Preserve the attributes, except for att_tempvar. */
/* XXX -- should this create a variable in the global scope, or
modify the local variable flags? ksh93 has it modify the
global scope.
Need to handle case like in set_var_attribute where a temporary
variable is in the same table as the function local vars. */
if ((flags_on & (att_exported|att_readonly)) && tempvar_p (var))
{
SHELL_VAR *tv;
char *tvalue;
tv = find_tempenv_variable (var->name);
if (tv)
{
tvalue = var_isset (var) ? savestring (value_cell (var)) : savestring ("");
tv = bind_variable (var->name, tvalue, 0);
tv->attributes |= var->attributes & ~att_tempvar;
if (tv->context > 0)
VSETATTR (tv, att_propagate);
free (tvalue);
}
VSETATTR (var, att_propagate);
}
}
/* Turn on nameref attribute we deferred above. */
/* XXX - should we turn on the noassign attribute for consistency with
ksh93 when we turn on the nameref attribute? */
VSETATTR (var, onref);
flags_on |= onref;
VUNSETATTR (var, offref);
flags_off |= offref;
/* Yuck. ksh93 compatibility */
if (refvar)
VUNSETATTR (refvar, flags_off);
stupidly_hack_special_variables (name);
NEXT_VARIABLE ();
}
return (assign_error ? EX_BADASSIGN
: ((any_failed == 0) ? EXECUTION_SUCCESS
: EXECUTION_FAILURE));
}
+2 -2
View File
@@ -833,7 +833,7 @@ unset_builtin (list)
if (var && readonly_p (var))
{
builtin_error (_("%s: cannot unset: readonly %s"),
name, unset_function ? "function" : "variable");
var->name, unset_function ? "function" : "variable");
NEXT_VARIABLE ();
}
@@ -844,7 +844,7 @@ unset_builtin (list)
{
if (array_p (var) == 0 && assoc_p (var) == 0)
{
builtin_error (_("%s: not an array variable"), name);
builtin_error (_("%s: not an array variable"), var->name);
NEXT_VARIABLE ();
}
else
+878
View File
@@ -0,0 +1,878 @@
This file is set.def, from which is created set.c.
It implements the "set" and "unset" builtins in Bash.
Copyright (C) 1987-2011 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES set.c
#include <config.h>
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#include <stdio.h>
#include "../bashansi.h"
#include "../bashintl.h"
#include "../shell.h"
#include "../flags.h"
#include "common.h"
#include "bashgetopt.h"
#if defined (READLINE)
# include "../input.h"
# include "../bashline.h"
# include <readline/readline.h>
#endif
#if defined (HISTORY)
# include "../bashhist.h"
#endif
extern int posixly_correct, ignoreeof, eof_encountered_limit;
#if defined (HISTORY)
extern int dont_save_function_defs;
#endif
#if defined (READLINE)
extern int no_line_editing;
#endif /* READLINE */
$BUILTIN set
$FUNCTION set_builtin
$SHORT_DOC set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
Set or unset values of shell options and positional parameters.
Change the value of shell attributes and positional parameters, or
display the names and values of shell variables.
Options:
-a Mark variables which are modified or created for export.
-b Notify of job termination immediately.
-e Exit immediately if a command exits with a non-zero status.
-f Disable file name generation (globbing).
-h Remember the location of commands as they are looked up.
-k All assignment arguments are placed in the environment for a
command, not just those that precede the command name.
-m Job control is enabled.
-n Read commands but do not execute them.
-o option-name
Set the variable corresponding to option-name:
allexport same as -a
braceexpand same as -B
#if defined (READLINE)
emacs use an emacs-style line editing interface
#endif /* READLINE */
errexit same as -e
errtrace same as -E
functrace same as -T
hashall same as -h
#if defined (BANG_HISTORY)
histexpand same as -H
#endif /* BANG_HISTORY */
#if defined (HISTORY)
history enable command history
#endif
ignoreeof the shell will not exit upon reading EOF
interactive-comments
allow comments to appear in interactive commands
keyword same as -k
#if defined (JOB_CONTROL)
monitor same as -m
#endif
noclobber same as -C
noexec same as -n
noglob same as -f
nolog currently accepted but ignored
#if defined (JOB_CONTROL)
notify same as -b
#endif
nounset same as -u
onecmd same as -t
physical same as -P
pipefail the return value of a pipeline is the status of
the last command to exit with a non-zero status,
or zero if no command exited with a non-zero status
posix change the behavior of bash where the default
operation differs from the Posix standard to
match the standard
privileged same as -p
verbose same as -v
#if defined (READLINE)
vi use a vi-style line editing interface
#endif /* READLINE */
xtrace same as -x
-p Turned on whenever the real and effective user ids do not match.
Disables processing of the $ENV file and importing of shell
functions. Turning this option off causes the effective uid and
gid to be set to the real uid and gid.
-t Exit after reading and executing one command.
-u Treat unset variables as an error when substituting.
-v Print shell input lines as they are read.
-x Print commands and their arguments as they are executed.
#if defined (BRACE_EXPANSION)
-B the shell will perform brace expansion
#endif /* BRACE_EXPANSION */
-C If set, disallow existing regular files to be overwritten
by redirection of output.
-E If set, the ERR trap is inherited by shell functions.
#if defined (BANG_HISTORY)
-H Enable ! style history substitution. This flag is on
by default when the shell is interactive.
#endif /* BANG_HISTORY */
-P If set, do not resolve symbolic links when executing commands
such as cd which change the current directory.
-T If set, the DEBUG trap is inherited by shell functions.
-- Assign any remaining arguments to the positional parameters.
If there are no remaining arguments, the positional parameters
are unset.
- Assign any remaining arguments to the positional parameters.
The -x and -v options are turned off.
Using + rather than - causes these flags to be turned off. The
flags can also be used upon invocation of the shell. The current
set of flags may be found in $-. The remaining n ARGs are positional
parameters and are assigned, in order, to $1, $2, .. $n. If no
ARGs are given, all shell variables are printed.
Exit Status:
Returns success unless an invalid option is given.
$END
typedef int setopt_set_func_t __P((int, char *));
typedef int setopt_get_func_t __P((char *));
static void print_minus_o_option __P((char *, int, int));
static void print_all_shell_variables __P((void));
static int set_ignoreeof __P((int, char *));
static int set_posix_mode __P((int, char *));
#if defined (READLINE)
static int set_edit_mode __P((int, char *));
static int get_edit_mode __P((char *));
#endif
#if defined (HISTORY)
static int bash_set_history __P((int, char *));
#endif
static const char * const on = "on";
static const char * const off = "off";
/* A struct used to match long options for set -o to the corresponding
option letter or internal variable. The functions can be called to
dynamically generate values. */
const struct {
char *name;
int letter;
int *variable;
setopt_set_func_t *set_func;
setopt_get_func_t *get_func;
} o_options[] = {
{ "allexport", 'a', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (BRACE_EXPANSION)
{ "braceexpand",'B', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif
#if defined (READLINE)
{ "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
#endif
{ "errexit", 'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "errtrace", 'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "functrace", 'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "hashall", 'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (BANG_HISTORY)
{ "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif /* BANG_HISTORY */
#if defined (HISTORY)
{ "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL },
#endif
{ "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },
{ "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "keyword", 'k', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (JOB_CONTROL)
{ "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif
{ "noclobber", 'C', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "noexec", 'n', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "noglob", 'f', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (HISTORY)
{ "nolog", '\0', &dont_save_function_defs, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif
#if defined (JOB_CONTROL)
{ "notify", 'b', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif /* JOB_CONTROL */
{ "nounset", 'u', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "onecmd", 't', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "physical", 'P', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "pipefail", '\0', &pipefail_opt, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "posix", '\0', &posixly_correct, set_posix_mode, (setopt_get_func_t *)NULL },
{ "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "verbose", 'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (READLINE)
{ "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
#endif
{ "xtrace", 'x', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{(char *)NULL, 0 , (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
};
#define N_O_OPTIONS (sizeof (o_options) / sizeof (o_options[0]))
#define GET_BINARY_O_OPTION_VALUE(i, name) \
((o_options[i].get_func) ? (*o_options[i].get_func) (name) \
: (*o_options[i].variable))
#define SET_BINARY_O_OPTION_VALUE(i, onoff, name) \
((o_options[i].set_func) ? (*o_options[i].set_func) (onoff, name) \
: (*o_options[i].variable = (onoff == FLAG_ON)))
int
minus_o_option_value (name)
char *name;
{
register int i;
int *on_or_off;
for (i = 0; o_options[i].name; i++)
{
if (STREQ (name, o_options[i].name))
{
if (o_options[i].letter)
{
on_or_off = find_flag (o_options[i].letter);
return ((on_or_off == FLAG_UNKNOWN) ? -1 : *on_or_off);
}
else
return (GET_BINARY_O_OPTION_VALUE (i, name));
}
}
return (-1);
}
#define MINUS_O_FORMAT "%-15s\t%s\n"
static void
print_minus_o_option (name, value, pflag)
char *name;
int value, pflag;
{
if (pflag == 0)
printf (MINUS_O_FORMAT, name, value ? on : off);
else
printf ("set %co %s\n", value ? '-' : '+', name);
}
void
list_minus_o_opts (mode, reusable)
int mode, reusable;
{
register int i;
int *on_or_off, value;
for (i = 0; o_options[i].name; i++)
{
if (o_options[i].letter)
{
value = 0;
on_or_off = find_flag (o_options[i].letter);
if (on_or_off == FLAG_UNKNOWN)
on_or_off = &value;
if (mode == -1 || mode == *on_or_off)
print_minus_o_option (o_options[i].name, *on_or_off, reusable);
}
else
{
value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name);
if (mode == -1 || mode == value)
print_minus_o_option (o_options[i].name, value, reusable);
}
}
}
char **
get_minus_o_opts ()
{
char **ret;
int i;
ret = strvec_create (N_O_OPTIONS + 1);
for (i = 0; o_options[i].name; i++)
ret[i] = o_options[i].name;
ret[i] = (char *)NULL;
return ret;
}
static int
set_ignoreeof (on_or_off, option_name)
int on_or_off;
char *option_name;
{
ignoreeof = on_or_off == FLAG_ON;
unbind_variable ("ignoreeof");
if (ignoreeof)
bind_variable ("IGNOREEOF", "10", 0);
else
unbind_variable ("IGNOREEOF");
sv_ignoreeof ("IGNOREEOF");
return 0;
}
static int
set_posix_mode (on_or_off, option_name)
int on_or_off;
char *option_name;
{
posixly_correct = on_or_off == FLAG_ON;
if (posixly_correct == 0)
unbind_variable ("POSIXLY_CORRECT");
else
bind_variable ("POSIXLY_CORRECT", "y", 0);
sv_strict_posix ("POSIXLY_CORRECT");
return (0);
}
#if defined (READLINE)
/* Magic. This code `knows' how readline handles rl_editing_mode. */
static int
set_edit_mode (on_or_off, option_name)
int on_or_off;
char *option_name;
{
int isemacs;
if (on_or_off == FLAG_ON)
{
rl_variable_bind ("editing-mode", option_name);
if (interactive)
with_input_from_stdin ();
no_line_editing = 0;
}
else
{
isemacs = rl_editing_mode == 1;
if ((isemacs && *option_name == 'e') || (!isemacs && *option_name == 'v'))
{
if (interactive)
with_input_from_stream (stdin, "stdin");
no_line_editing = 1;
}
}
return 1-no_line_editing;
}
static int
get_edit_mode (name)
char *name;
{
return (*name == 'e' ? no_line_editing == 0 && rl_editing_mode == 1
: no_line_editing == 0 && rl_editing_mode == 0);
}
#endif /* READLINE */
#if defined (HISTORY)
static int
bash_set_history (on_or_off, option_name)
int on_or_off;
char *option_name;
{
if (on_or_off == FLAG_ON)
{
enable_history_list = 1;
bash_history_enable ();
if (history_lines_this_session == 0)
load_history ();
}
else
{
enable_history_list = 0;
bash_history_disable ();
}
return (1 - enable_history_list);
}
#endif
int
set_minus_o_option (on_or_off, option_name)
int on_or_off;
char *option_name;
{
register int i;
for (i = 0; o_options[i].name; i++)
{
if (STREQ (option_name, o_options[i].name))
{
if (o_options[i].letter == 0)
{
SET_BINARY_O_OPTION_VALUE (i, on_or_off, option_name);
return (EXECUTION_SUCCESS);
}
else
{
if (change_flag (o_options[i].letter, on_or_off) == FLAG_ERROR)
{
sh_invalidoptname (option_name);
return (EXECUTION_FAILURE);
}
else
return (EXECUTION_SUCCESS);
}
}
}
sh_invalidoptname (option_name);
return (EX_USAGE);
}
static void
print_all_shell_variables ()
{
SHELL_VAR **vars;
vars = all_shell_variables ();
if (vars)
{
print_var_list (vars);
free (vars);
}
/* POSIX.2 does not allow function names and definitions to be output when
`set' is invoked without options (PASC Interp #202). */
if (posixly_correct == 0)
{
vars = all_shell_functions ();
if (vars)
{
print_func_list (vars);
free (vars);
}
}
}
void
set_shellopts ()
{
char *value;
char tflag[N_O_OPTIONS];
int vsize, i, vptr, *ip, exported;
SHELL_VAR *v;
for (vsize = i = 0; o_options[i].name; i++)
{
tflag[i] = 0;
if (o_options[i].letter)
{
ip = find_flag (o_options[i].letter);
if (ip && *ip)
{
vsize += strlen (o_options[i].name) + 1;
tflag[i] = 1;
}
}
else if (GET_BINARY_O_OPTION_VALUE (i, o_options[i].name))
{
vsize += strlen (o_options[i].name) + 1;
tflag[i] = 1;
}
}
value = (char *)xmalloc (vsize + 1);
for (i = vptr = 0; o_options[i].name; i++)
{
if (tflag[i])
{
strcpy (value + vptr, o_options[i].name);
vptr += strlen (o_options[i].name);
value[vptr++] = ':';
}
}
if (vptr)
vptr--; /* cut off trailing colon */
value[vptr] = '\0';
v = find_variable ("SHELLOPTS");
/* Turn off the read-only attribute so we can bind the new value, and
note whether or not the variable was exported. */
if (v)
{
VUNSETATTR (v, att_readonly);
exported = exported_p (v);
}
else
exported = 0;
v = bind_variable ("SHELLOPTS", value, 0);
/* Turn the read-only attribute back on, and turn off the export attribute
if it was set implicitly by mark_modified_vars and SHELLOPTS was not
exported before we bound the new value. */
VSETATTR (v, att_readonly);
if (mark_modified_vars && exported == 0 && exported_p (v))
VUNSETATTR (v, att_exported);
free (value);
}
void
parse_shellopts (value)
char *value;
{
char *vname;
int vptr;
vptr = 0;
while (vname = extract_colon_unit (value, &vptr))
{
set_minus_o_option (FLAG_ON, vname);
free (vname);
}
}
void
initialize_shell_options (no_shellopts)
int no_shellopts;
{
char *temp;
SHELL_VAR *var;
if (no_shellopts == 0)
{
var = find_variable ("SHELLOPTS");
/* set up any shell options we may have inherited. */
if (var && imported_p (var))
{
temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var));
if (temp)
{
parse_shellopts (temp);
free (temp);
}
}
}
/* Set up the $SHELLOPTS variable. */
set_shellopts ();
}
/* Reset the values of the -o options that are not also shell flags. This is
called from execute_cmd.c:initialize_subshell() when setting up a subshell
to run an executable shell script without a leading `#!'. */
void
reset_shell_options ()
{
#if defined (HISTORY)
remember_on_history = enable_history_list = 1;
#endif
ignoreeof = 0;
}
/* Set some flags from the word values in the input list. If LIST is empty,
then print out the values of the variables instead. If LIST contains
non-flags, then set $1 - $9 to the successive words of LIST. */
int
set_builtin (list)
WORD_LIST *list;
{
int on_or_off, flag_name, force_assignment, opts_changed, rv, r;
register char *arg;
char s[3];
if (list == 0)
{
print_all_shell_variables ();
return (sh_chkwrite (EXECUTION_SUCCESS));
}
/* Check validity of flag arguments. */
rv = EXECUTION_SUCCESS;
reset_internal_getopt ();
while ((flag_name = internal_getopt (list, optflags)) != -1)
{
switch (flag_name)
{
case '?':
builtin_usage ();
return (list_optopt == '?' ? EXECUTION_SUCCESS : EX_USAGE);
default:
break;
}
}
/* Do the set command. While the list consists of words starting with
'-' or '+' treat them as flags, otherwise, start assigning them to
$1 ... $n. */
for (force_assignment = opts_changed = 0; list; )
{
arg = list->word->word;
/* If the argument is `--' or `-' then signal the end of the list
and remember the remaining arguments. */
if (arg[0] == '-' && (!arg[1] || (arg[1] == '-' && !arg[2])))
{
list = list->next;
/* `set --' unsets the positional parameters. */
if (arg[1] == '-')
force_assignment = 1;
/* Until told differently, the old shell behaviour of
`set - [arg ...]' being equivalent to `set +xv [arg ...]'
stands. Posix.2 says the behaviour is marked as obsolescent. */
else
{
change_flag ('x', '+');
change_flag ('v', '+');
opts_changed = 1;
}
break;
}
if ((on_or_off = *arg) && (on_or_off == '-' || on_or_off == '+'))
{
while (flag_name = *++arg)
{
if (flag_name == '?')
{
builtin_usage ();
return (EXECUTION_SUCCESS);
}
else if (flag_name == 'o') /* -+o option-name */
{
char *option_name;
WORD_LIST *opt;
opt = list->next;
if (opt == 0)
{
list_minus_o_opts (-1, (on_or_off == '+'));
rv = sh_chkwrite (rv);
continue;
}
option_name = opt->word->word;
if (option_name == 0 || *option_name == '\0' ||
*option_name == '-' || *option_name == '+')
{
list_minus_o_opts (-1, (on_or_off == '+'));
continue;
}
list = list->next; /* Skip over option name. */
opts_changed = 1;
if ((r = set_minus_o_option (on_or_off, option_name)) != EXECUTION_SUCCESS)
{
set_shellopts ();
return (r);
}
}
else if (change_flag (flag_name, on_or_off) == FLAG_ERROR)
{
s[0] = on_or_off;
s[1] = flag_name;
s[2] = '\0';
sh_invalidopt (s);
builtin_usage ();
set_shellopts ();
return (EXECUTION_FAILURE);
}
opts_changed = 1;
}
}
else
{
break;
}
list = list->next;
}
/* Assigning $1 ... $n */
if (list || force_assignment)
remember_args (list, 1);
/* Set up new value of $SHELLOPTS */
if (opts_changed)
set_shellopts ();
return (rv);
}
$BUILTIN unset
$FUNCTION unset_builtin
$SHORT_DOC unset [-f] [-v] [name ...]
Unset values and attributes of shell variables and functions.
For each NAME, remove the corresponding variable or function.
Options:
-f treat each NAME as a shell function
-v treat each NAME as a shell variable
Without options, unset first tries to unset a variable, and if that fails,
tries to unset a function.
Some variables cannot be unset; also see `readonly'.
Exit Status:
Returns success unless an invalid option is given or a NAME is read-only.
$END
#define NEXT_VARIABLE() any_failed++; list = list->next; continue;
int
unset_builtin (list)
WORD_LIST *list;
{
int unset_function, unset_variable, unset_array, opt, any_failed;
char *name;
unset_function = unset_variable = unset_array = any_failed = 0;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "fv")) != -1)
{
switch (opt)
{
case 'f':
unset_function = 1;
break;
case 'v':
unset_variable = 1;
break;
default:
builtin_usage ();
return (EX_USAGE);
}
}
list = loptend;
if (unset_function && unset_variable)
{
builtin_error (_("cannot simultaneously unset a function and a variable"));
return (EXECUTION_FAILURE);
}
while (list)
{
SHELL_VAR *var;
int tem;
#if defined (ARRAY_VARS)
char *t;
#endif
name = list->word->word;
#if defined (ARRAY_VARS)
unset_array = 0;
if (!unset_function && valid_array_reference (name))
{
t = strchr (name, '[');
*t++ = '\0';
unset_array++;
}
#endif
/* Get error checking out of the way first. The low-level functions
just perform the unset, relying on the caller to verify. */
/* Bash allows functions with names which are not valid identifiers
to be created when not in posix mode, so check only when in posix
mode when unsetting a function. */
if (((unset_function && posixly_correct) || !unset_function) && legal_identifier (name) == 0)
{
sh_invalidid (name);
NEXT_VARIABLE ();
}
/* Only search for functions here if -f supplied. */
var = unset_function ? find_function (name) : find_variable (name);
/* Some variables (but not functions yet) cannot be unset, period. */
if (var && unset_function == 0 && non_unsettable_p (var))
{
builtin_error (_("%s: cannot unset"), name);
NEXT_VARIABLE ();
}
/* Posix.2 says try variables first, then functions. If we would
find a function after unsuccessfully searching for a variable,
note that we're acting on a function now as if -f were
supplied. The readonly check below takes care of it. */
if (var == 0 && unset_variable == 0 && unset_function == 0)
{
if (var = find_function (name))
unset_function = 1;
}
/* Posix.2 says that unsetting readonly variables is an error. */
if (var && readonly_p (var))
{
builtin_error (_("%s: cannot unset: readonly %s"),
name, unset_function ? "function" : "variable");
NEXT_VARIABLE ();
}
/* Unless the -f option is supplied, the name refers to a variable. */
#if defined (ARRAY_VARS)
if (var && unset_array)
{
if (array_p (var) == 0 && assoc_p (var) == 0)
{
builtin_error (_("%s: not an array variable"), name);
NEXT_VARIABLE ();
}
else
{
tem = unbind_array_element (var, t);
if (tem == -1)
any_failed++;
}
}
else
#endif /* ARRAY_VARS */
tem = unset_function ? unbind_func (name) : unbind_variable (name);
/* This is what Posix.2 says: ``If neither -f nor -v
is specified, the name refers to a variable; if a variable by
that name does not exist, a function by that name, if any,
shall be unset.'' */
if (tem == -1 && unset_function == 0 && unset_variable == 0)
tem = unbind_func (name);
/* SUSv3, POSIX.1-2001 say: ``Unsetting a variable or function that
was not previously set shall not be considered an error.'' */
if (unset_function == 0)
stupidly_hack_special_variables (name);
list = list->next;
}
return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
}
+4 -1
View File
@@ -1,7 +1,7 @@
This file is setattr.def, from which is created setattr.c.
It implements the builtins "export" and "readonly", in Bash.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
Copyright (C) 1987-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -368,6 +368,9 @@ show_var_attributes (var, pattr, nodefs)
if (integer_p (var))
flags[i++] = 'i';
if (nameref_p (var))
flags[i++] = 'n';
if (readonly_p (var))
flags[i++] = 'r';
+517
View File
@@ -0,0 +1,517 @@
This file is setattr.def, from which is created setattr.c.
It implements the builtins "export" and "readonly", in Bash.
Copyright (C) 1987-2010 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES setattr.c
#include <config.h>
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#include <stdio.h>
#include "../bashansi.h"
#include "../bashintl.h"
#include "../shell.h"
#include "common.h"
#include "bashgetopt.h"
extern int posixly_correct;
extern int array_needs_making;
extern char *this_command_name;
extern sh_builtin_func_t *this_shell_builtin;
#ifdef ARRAY_VARS
extern int declare_builtin __P((WORD_LIST *));
#endif
#define READONLY_OR_EXPORT \
(this_shell_builtin == readonly_builtin || this_shell_builtin == export_builtin)
$BUILTIN export
$FUNCTION export_builtin
$SHORT_DOC export [-fn] [name[=value] ...] or export -p
Set export attribute for shell variables.
Marks each NAME for automatic export to the environment of subsequently
executed commands. If VALUE is supplied, assign VALUE before exporting.
Options:
-f refer to shell functions
-n remove the export property from each NAME
-p display a list of all exported variables and functions
An argument of `--' disables further option processing.
Exit Status:
Returns success unless an invalid option is given or NAME is invalid.
$END
/* For each variable name in LIST, make that variable appear in the
environment passed to simple commands. If there is no LIST, then
print all such variables. An argument of `-n' says to remove the
exported attribute from variables named in LIST. An argument of
-f indicates that the names present in LIST refer to functions. */
int
export_builtin (list)
register WORD_LIST *list;
{
return (set_or_show_attributes (list, att_exported, 0));
}
$BUILTIN readonly
$FUNCTION readonly_builtin
$SHORT_DOC readonly [-aAf] [name[=value] ...] or readonly -p
Mark shell variables as unchangeable.
Mark each NAME as read-only; the values of these NAMEs may not be
changed by subsequent assignment. If VALUE is supplied, assign VALUE
before marking as read-only.
Options:
-a refer to indexed array variables
-A refer to associative array variables
-f refer to shell functions
-p display a list of all readonly variables and functions
An argument of `--' disables further option processing.
Exit Status:
Returns success unless an invalid option is given or NAME is invalid.
$END
/* For each variable name in LIST, make that variable readonly. Given an
empty LIST, print out all existing readonly variables. */
int
readonly_builtin (list)
register WORD_LIST *list;
{
return (set_or_show_attributes (list, att_readonly, 0));
}
#if defined (ARRAY_VARS)
# define ATTROPTS "aAfnp"
#else
# define ATTROPTS "fnp"
#endif
/* For each variable name in LIST, make that variable have the specified
ATTRIBUTE. An arg of `-n' says to remove the attribute from the the
remaining names in LIST (doesn't work for readonly). */
int
set_or_show_attributes (list, attribute, nodefs)
register WORD_LIST *list;
int attribute, nodefs;
{
register SHELL_VAR *var;
int assign, undo, any_failed, assign_error, opt;
int functions_only, arrays_only, assoc_only;
int aflags;
char *name;
#if defined (ARRAY_VARS)
WORD_LIST *nlist, *tlist;
WORD_DESC *w;
#endif
functions_only = arrays_only = assoc_only = 0;
undo = any_failed = assign_error = 0;
/* Read arguments from the front of the list. */
reset_internal_getopt ();
while ((opt = internal_getopt (list, ATTROPTS)) != -1)
{
switch (opt)
{
case 'n':
undo = 1;
break;
case 'f':
functions_only = 1;
break;
#if defined (ARRAY_VARS)
case 'a':
arrays_only = 1;
break;
case 'A':
assoc_only = 1;
break;
#endif
case 'p':
break;
default:
builtin_usage ();
return (EX_USAGE);
}
}
list = loptend;
if (list)
{
if (attribute & att_exported)
array_needs_making = 1;
/* Cannot undo readonly status, silently disallowed. */
if (undo && (attribute & att_readonly))
attribute &= ~att_readonly;
while (list)
{
name = list->word->word;
if (functions_only) /* xxx -f name */
{
var = find_function (name);
if (var == 0)
{
builtin_error (_("%s: not a function"), name);
any_failed++;
}
else
SETVARATTR (var, attribute, undo);
list = list->next;
continue;
}
/* xxx [-np] name[=value] */
assign = assignment (name, 0);
aflags = 0;
if (assign)
{
name[assign] = '\0';
if (name[assign - 1] == '+')
{
aflags |= ASS_APPEND;
name[assign - 1] = '\0';
}
}
if (legal_identifier (name) == 0)
{
sh_invalidid (name);
if (assign)
assign_error++;
else
any_failed++;
list = list->next;
continue;
}
if (assign) /* xxx [-np] name=value */
{
name[assign] = '=';
if (aflags & ASS_APPEND)
name[assign - 1] = '+';
#if defined (ARRAY_VARS)
/* Let's try something here. Turn readonly -a xxx=yyy into
declare -ra xxx=yyy and see what that gets us. */
if (arrays_only || assoc_only)
{
tlist = list->next;
list->next = (WORD_LIST *)NULL;
w = arrays_only ? make_word ("-ra") : make_word ("-rA");
nlist = make_word_list (w, list);
opt = declare_builtin (nlist);
if (opt != EXECUTION_SUCCESS)
assign_error++;
list->next = tlist;
dispose_word (w);
free (nlist);
}
else
#endif
/* This word has already been expanded once with command
and parameter expansion. Call do_assignment_no_expand (),
which does not do command or parameter substitution. If
the assignment is not performed correctly, flag an error. */
if (do_assignment_no_expand (name) == 0)
assign_error++;
name[assign] = '\0';
if (aflags & ASS_APPEND)
name[assign - 1] = '\0';
}
set_var_attribute (name, attribute, undo);
list = list->next;
}
}
else
{
SHELL_VAR **variable_list;
register int i;
if ((attribute & att_function) || functions_only)
{
variable_list = all_shell_functions ();
if (attribute != att_function)
attribute &= ~att_function; /* so declare -xf works, for example */
}
else
variable_list = all_shell_variables ();
#if defined (ARRAY_VARS)
if (attribute & att_array)
{
arrays_only++;
if (attribute != att_array)
attribute &= ~att_array;
}
else if (attribute & att_assoc)
{
assoc_only++;
if (attribute != att_assoc)
attribute &= ~att_assoc;
}
#endif
if (variable_list)
{
for (i = 0; var = variable_list[i]; i++)
{
#if defined (ARRAY_VARS)
if (arrays_only && array_p (var) == 0)
continue;
else if (assoc_only && assoc_p (var) == 0)
continue;
#endif
if ((var->attributes & attribute))
{
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
if (any_failed = sh_chkwrite (any_failed))
break;
}
}
free (variable_list);
}
}
return (assign_error ? EX_BADASSIGN
: ((any_failed == 0) ? EXECUTION_SUCCESS
: EXECUTION_FAILURE));
}
/* Show all variable variables (v == 1) or functions (v == 0) with
attributes. */
int
show_all_var_attributes (v, nodefs)
int v, nodefs;
{
SHELL_VAR **variable_list, *var;
int any_failed;
register int i;
variable_list = v ? all_shell_variables () : all_shell_functions ();
if (variable_list == 0)
return (EXECUTION_SUCCESS);
for (i = any_failed = 0; var = variable_list[i]; i++)
{
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
if (any_failed = sh_chkwrite (any_failed))
break;
}
free (variable_list);
return (any_failed == 0 ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
}
/* Show the attributes for shell variable VAR. If NODEFS is non-zero,
don't show function definitions along with the name. If PATTR is
non-zero, it indicates we're being called from `export' or `readonly'.
In POSIX mode, this prints the name of the calling builtin (`export'
or `readonly') instead of `declare', and doesn't print function defs
when called by `export' or `readonly'. */
int
show_var_attributes (var, pattr, nodefs)
SHELL_VAR *var;
int pattr, nodefs;
{
char flags[16], *x;
int i;
i = 0;
/* pattr == 0 means we are called from `declare'. */
if (pattr == 0 || posixly_correct == 0)
{
#if defined (ARRAY_VARS)
if (array_p (var))
flags[i++] = 'a';
if (assoc_p (var))
flags[i++] = 'A';
#endif
if (function_p (var))
flags[i++] = 'f';
if (integer_p (var))
flags[i++] = 'i';
if (nameref_p (var))
flags[i++] = 'n';
if (readonly_p (var))
flags[i++] = 'r';
if (trace_p (var))
flags[i++] = 't';
if (exported_p (var))
flags[i++] = 'x';
if (capcase_p (var))
flags[i++] = 'c';
if (lowercase_p (var))
flags[i++] = 'l';
if (uppercase_p (var))
flags[i++] = 'u';
}
else
{
#if defined (ARRAY_VARS)
if (array_p (var))
flags[i++] = 'a';
if (assoc_p (var))
flags[i++] = 'A';
#endif
if (function_p (var))
flags[i++] = 'f';
}
flags[i] = '\0';
/* If we're printing functions with definitions, print the function def
first, then the attributes, instead of printing output that can't be
reused as input to recreate the current state. */
if (function_p (var) && nodefs == 0 && (pattr == 0 || posixly_correct == 0))
{
printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
nodefs++;
if (pattr == 0 && i == 1 && flags[0] == 'f')
return 0; /* don't print `declare -f name' */
}
if (pattr == 0 || posixly_correct == 0)
printf ("declare -%s ", i ? flags : "-");
else if (i)
printf ("%s -%s ", this_command_name, flags);
else
printf ("%s ", this_command_name);
#if defined (ARRAY_VARS)
if (array_p (var))
print_array_assignment (var, 1);
else if (assoc_p (var))
print_assoc_assignment (var, 1);
else
#endif
/* force `readonly' and `export' to not print out function definitions
when in POSIX mode. */
if (nodefs || (function_p (var) && pattr != 0 && posixly_correct))
printf ("%s\n", var->name);
else if (function_p (var))
printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
else if (invisible_p (var) || var_isset (var) == 0)
printf ("%s\n", var->name);
else
{
x = sh_double_quote (value_cell (var));
printf ("%s=%s\n", var->name, x);
free (x);
}
return (0);
}
int
show_name_attributes (name, nodefs)
char *name;
int nodefs;
{
SHELL_VAR *var;
var = find_variable_tempenv (name);
if (var && invisible_p (var) == 0)
{
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
return (0);
}
else
return (1);
}
void
set_var_attribute (name, attribute, undo)
char *name;
int attribute, undo;
{
SHELL_VAR *var, *tv;
char *tvalue;
if (undo)
var = find_variable (name);
else
{
tv = find_tempenv_variable (name);
/* XXX -- need to handle case where tv is a temp variable in a
function-scope context, since function_env has been merged into
the local variables table. */
if (tv && tempvar_p (tv))
{
tvalue = var_isset (tv) ? savestring (value_cell (tv)) : savestring ("");
var = bind_variable (tv->name, tvalue, 0);
var->attributes |= tv->attributes & ~att_tempvar;
VSETATTR (tv, att_propagate);
if (var->context != 0)
VSETATTR (var, att_propagate);
SETVARATTR (tv, attribute, undo); /* XXX */
stupidly_hack_special_variables (tv->name);
free (tvalue);
}
else
{
var = find_variable_notempenv (name);
if (var == 0)
{
var = bind_variable (name, (char *)NULL, 0);
VSETATTR (var, att_invisible);
}
else if (var->context != 0)
VSETATTR (var, att_propagate);
}
}
if (var)
SETVARATTR (var, attribute, undo);
if (var && (exported_p (var) || (attribute & att_exported)))
array_needs_making++; /* XXX */
}
+8 -5
View File
@@ -2588,11 +2588,7 @@ execute_for_command (for_command)
/* Save this command unless it's a trap command and we're not running
a debug trap. */
#if 0
if (signal_in_progress (DEBUG_TRAP) == 0 && (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0)))
#else
if (signal_in_progress (DEBUG_TRAP) == 0 && running_trap == 0)
#endif
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
@@ -2607,7 +2603,14 @@ execute_for_command (for_command)
#endif
this_command_name = (char *)NULL;
v = bind_variable (identifier, list->word->word, 0);
/* XXX - special ksh93 for command index variable handling */
v = find_variable_last_nameref (identifier);
if (v && nameref_p (v))
{
v = bind_variable_value (v, list->word->word, 0);
}
else
v = bind_variable (identifier, list->word->word, 0);
if (readonly_p (v) || noassign_p (v))
{
line_number = save_line_number;
+3 -12
View File
@@ -118,6 +118,8 @@ extern time_t shell_start_time;
extern char *glob_argv_flags;
#endif
extern int job_control; /* XXX */
extern int close __P((int));
/* Static functions defined and used in this file. */
@@ -754,7 +756,6 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
command->value.Simple->flags |= CMD_STDIN_REDIR;
line_number_for_err_trap = line_number = command->value.Simple->line;
itrace("execute_command_internal: set line_number_for_err_trap = %d", line_number_for_err_trap);
exec_result =
execute_simple_command (command->value.Simple, pipe_in, pipe_out,
asynchronous, fds_to_close);
@@ -803,7 +804,6 @@ itrace("execute_command_internal: set line_number_for_err_trap = %d", line_numbe
only the failure of a simple command. */
if (was_error_trap && ignore_return == 0 && invert == 0 && pipe_in == NO_PIPE && pipe_out == NO_PIPE && exec_result != EXECUTION_SUCCESS)
{
itrace("execute_command_internal: line_number = %d line_number_for_err_trap = %d save_line_number = %d", line_number, line_number_for_err_trap, save_line_number);
last_command_exit_value = exec_result;
line_number = line_number_for_err_trap;
run_error_trap ();
@@ -2319,8 +2319,8 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
if (ignore_return && cmd)
cmd->flags |= CMD_IGNORE_RETURN;
#if defined (JOB_CONTROL)
lastpipe_flag = 0;
begin_unwind_frame ("lastpipe-exec");
lstdin = -1;
/* If the `lastpipe' option is set with shopt, and job control is not
@@ -2344,14 +2344,11 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
}
if (prev >= 0)
add_unwind_protect (close, prev);
#endif
exec_result = execute_command_internal (cmd, asynchronous, prev, pipe_out, fds_to_close);
#if defined (JOB_CONTROL)
if (lstdin > 0)
restore_stdin (lstdin);
#endif
if (prev >= 0)
close (prev);
@@ -2374,9 +2371,7 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
unfreeze_jobs_list ();
}
#if defined (JOB_CONTROL)
discard_unwind_frame ("lastpipe-exec");
#endif
return (exec_result);
}
@@ -2593,11 +2588,7 @@ execute_for_command (for_command)
/* Save this command unless it's a trap command and we're not running
a debug trap. */
#if 0
if (signal_in_progress (DEBUG_TRAP) == 0 && (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0)))
#else
if (signal_in_progress (DEBUG_TRAP) == 0 && running_trap == 0)
#endif
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
+8 -3
View File
@@ -48,6 +48,8 @@
#include "stdc.h"
#include "memalloc.h"
#include <signal.h>
#include "shell.h"
#include "glob.h"
@@ -683,7 +685,11 @@ glob_vector (pat, dir, flags)
lose = 1;
break;
}
run_pending_traps ();
else if (signal_is_pending (SIGINT)) /* XXX - make SIGINT traps responsive */
{
lose = 1;
break;
}
dp = readdir (d);
if (dp == NULL)
@@ -857,8 +863,7 @@ glob_vector (pat, dir, flags)
FREE (tmplink);
}
QUIT;
run_pending_traps ();
/* Don't call QUIT; here; let higher layers deal with it. */
return ((char **)NULL);
}
+9 -5
View File
@@ -119,7 +119,7 @@ ibuffer_space ()
/* Get a key from the buffer of characters to be read.
Return the key in KEY.
Result is KEY if there was a key, or 0 if there wasn't. */
Result is non-zero if there was a key, or 0 if there wasn't. */
static int
rl_get_char (key)
int *key;
@@ -411,7 +411,7 @@ rl_clear_pending_input ()
int
rl_read_key ()
{
int c;
int c, r;
if (rl_pending_input)
{
@@ -429,14 +429,18 @@ rl_read_key ()
{
while (rl_event_hook)
{
if (rl_gather_tyi () < 0) /* XXX - EIO */
if (rl_get_char (&c) != 0)
break;
if ((r = rl_gather_tyi ()) < 0) /* XXX - EIO */
{
rl_done = 1;
return ('\n');
}
else if (r > 0) /* read something */
continue;
RL_CHECK_SIGNALS ();
if (rl_get_char (&c) != 0)
break;
if (rl_done) /* XXX - experimental */
return ('\n');
(*rl_event_hook) ();
+32 -8
View File
@@ -80,6 +80,7 @@ typedef struct { SigHandler *sa_handler; int sa_mask, sa_flags; } sighandler_cxt
static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
static void rl_maybe_restore_sighandler PARAMS((int, sighandler_cxt *));
static RETSIGTYPE rl_signal_handler PARAMS((int));
static RETSIGTYPE _rl_handle_signal PARAMS((int));
@@ -335,6 +336,8 @@ rl_set_sighandler (sig, handler, ohandler)
return (ohandler->sa_handler);
}
/* Set disposition of SIG to HANDLER, returning old state in OHANDLER. Don't
change disposition if OHANDLER indicates the signal was ignored. */
static void
rl_maybe_set_sighandler (sig, handler, ohandler)
int sig;
@@ -350,6 +353,22 @@ rl_maybe_set_sighandler (sig, handler, ohandler)
rl_sigaction (sig, ohandler, &dummy);
}
/* Set the disposition of SIG to HANDLER, if HANDLER->sa_handler indicates the
signal was not being ignored. MUST only be called for signals whose
disposition was changed using rl_maybe_set_sighandler or for which the
SIG_IGN check was performed inline (e.g., SIGALRM below). */
static void
rl_maybe_restore_sighandler (sig, handler)
int sig;
sighandler_cxt *handler;
{
sighandler_cxt dummy;
sigemptyset (&dummy.sa_mask);
if (handler->sa_handler != SIG_IGN)
rl_sigaction (sig, handler, &dummy);
}
int
rl_set_signals ()
{
@@ -454,26 +473,31 @@ rl_clear_signals ()
{
sigemptyset (&dummy.sa_mask);
rl_sigaction (SIGINT, &old_int, &dummy);
rl_sigaction (SIGTERM, &old_term, &dummy);
rl_sigaction (SIGHUP, &old_hup, &dummy);
/* Since rl_maybe_set_sighandler doesn't override a SIG_IGN handler,
we should in theory not have to restore a handler where
old_xxx.sa_handler == SIG_IGN. That's what rl_maybe_restore_sighandler
does. Fewer system calls should reduce readline's per-line
overhead */
rl_maybe_restore_sighandler (SIGINT, &old_int);
rl_maybe_restore_sighandler (SIGTERM, &old_term);
rl_maybe_restore_sighandler (SIGHUP, &old_hup);
#if defined (SIGQUIT)
rl_sigaction (SIGQUIT, &old_quit, &dummy);
rl_maybe_restore_sighandler (SIGQUIT, &old_quit);
#endif
#if defined (SIGALRM)
rl_sigaction (SIGALRM, &old_alrm, &dummy);
rl_maybe_restore_sighandler (SIGALRM, &old_alrm);
#endif
#if defined (SIGTSTP)
rl_sigaction (SIGTSTP, &old_tstp, &dummy);
rl_maybe_restore_sighandler (SIGTSTP, &old_tstp);
#endif /* SIGTSTP */
#if defined (SIGTTOU)
rl_sigaction (SIGTTOU, &old_ttou, &dummy);
rl_maybe_restore_sighandler (SIGTTOU, &old_ttou);
#endif /* SIGTTOU */
#if defined (SIGTTIN)
rl_sigaction (SIGTTIN, &old_ttin, &dummy);
rl_maybe_restore_sighandler (SIGTTIN, &old_ttin);
#endif /* SIGTTIN */
signals_set_flag = 0;
+47 -7
View File
@@ -2824,7 +2824,6 @@ do_assignment_internal (word, expand)
stupidly_hack_special_variables (name);
#if 1
/* Return 1 if the assignment seems to have been performed correctly. */
if (entry == 0 || readonly_p (entry))
retval = 0; /* assignment failure */
@@ -2840,12 +2839,6 @@ do_assignment_internal (word, expand)
VUNSETATTR (entry, att_invisible);
ASSIGN_RETURN (retval);
#else
if (entry)
VUNSETATTR (entry, att_invisible);
ASSIGN_RETURN (entry ? ((readonly_p (entry) == 0) && noassign_p (entry) == 0) : 0);
#endif
}
/* Perform the assignment statement in STRING, and expand the
@@ -5686,6 +5679,7 @@ parameter_brace_expand_word (name, var_is_special, quoted, pflags, indp)
#if defined (ARRAY_VARS)
else if (valid_array_reference (name))
{
expand_arrayref:
/* XXX - does this leak if name[@] or name[*]? */
temp = array_value (name, quoted, 0, &atype, &ind);
if (atype == 0 && temp)
@@ -5724,6 +5718,19 @@ parameter_brace_expand_word (name, var_is_special, quoted, pflags, indp)
else
temp = (char *)NULL;
}
#if defined (ARRAY_VARS)
/* Handle expanding nameref whose value is x[n] */
else if (var = find_variable_last_nameref (name))
{
temp = nameref_cell (var);
if (temp && *temp && valid_array_reference (temp))
{
name = temp;
goto expand_arrayref;
}
temp = (char *)NULL;
}
#endif
else
temp = (char *)NULL;
@@ -5746,6 +5753,23 @@ parameter_brace_expand_indir (name, var_is_special, quoted, quoted_dollar_atp, c
{
char *temp, *t;
WORD_DESC *w;
SHELL_VAR *v;
/* See if it's a nameref first, behave in ksh93-compatible fashion.
There is at least one incompatibility: given ${!foo[0]} where foo=bar,
bash performs an indirect lookup on foo[0] and expands the result;
ksh93 expands bar[0]. We could do that here -- there are enough usable
primitives to do that -- but do not at this point. */
if (var_is_special == 0 && (v = find_variable_last_nameref (name)))
{
if (nameref_p (v) && (t = nameref_cell (v)) && *t)
{
w = alloc_word_desc ();
w->word = savestring (t);
w->flags = 0;
return w;
}
}
w = parameter_brace_expand_word (name, var_is_special, quoted, PF_IGNUNBOUND, 0);
t = w->word;
@@ -7835,6 +7859,22 @@ comsub:
goto return0;
}
#if defined (ARRAY_VARS)
else if (var = find_variable_last_nameref (temp1))
{
temp = nameref_cell (var);
if (temp && *temp && valid_array_reference (temp))
{
tdesc = parameter_brace_expand_word (temp, SPECIAL_VAR (temp, 0), quoted, pflags, (int *)NULL);
if (tdesc == &expand_wdesc_error || tdesc == &expand_wdesc_fatal)
return (tdesc);
ret = tdesc;
goto return0;
}
else
temp = (char *)NULL;
}
#endif
temp = (char *)NULL;
+9488
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
+1 -1
View File
@@ -15,7 +15,7 @@ unset: usage: unset [-f] [-v] [name ...]
./errors.tests: line 52: unset: `/bin/sh': not a valid identifier
./errors.tests: line 55: unset: cannot simultaneously unset a function and a variable
./errors.tests: line 58: declare: -z: invalid option
declare: usage: declare [-aAfFgilrtux] [-p] [name[=value] ...]
declare: usage: declare [-aAfFgilnrtux] [-p] [name[=value] ...]
./errors.tests: line 60: declare: `-z': not a valid identifier
./errors.tests: line 61: declare: `/bin/sh': not a valid identifier
./errors.tests: line 65: declare: cannot use `-f' to make functions
+106
View File
@@ -0,0 +1,106 @@
one
two
three
declare -n fee="flip"
declare -n foo="bar"
turning off nameref attribute on foo
bar
after +n foo bar = other
one
two
one
expect <one>
argv[1] = <one>
expect <two>
argv[1] = <two>
expect <bar>
bar
expect <one>
one
expect <one>
argv[1] = <one>
changevar: expect <two>
argv[1] = <two>
expect <two>
argv[1] = <two>
changevar: expect <three four five>
argv[1] = <three four five>
expect <three four five>
argv[1] = <three four five>
./nameref.tests: line 92: bar: readonly variable
./nameref.tests: line 93: foo: readonly variable
one
one
./nameref.tests: line 105: foo: readonly variable
./nameref.tests: line 102: foo: readonly variable
one
one
bar
./nameref2.sub: line 5: foo: readonly variable
expect <unset>
argv[1] = <unset>
expect <unset>
argv[1] = <unset>
./nameref3.sub: line 15: unset: bar: cannot unset: readonly variable
expect <two>
two
expect <two>
two
three
unset
four
0
expect <a b>
a b
expect <foo>
foo
1 3 5 7 9
9
1 3 42 7 9
1 3 42 7 9
9
1 3 44 7 9
unset
expect <a b c d e>
argv[1] = <a b c d e>
expect <zero> <one> <seven> <three> <four>
argv[1] = <zero>
argv[2] = <one>
argv[3] = <seven>
argv[4] = <three>
argv[5] = <four>
16
expect <4>
4
expect <4>
4
expect <4>
4
expect <one>
one
expect <one>
one
expect <one>
one
expect <four>
four
errors = 0
1
2
v1: 1
v2: 2
ref -> first, value: I am first
ref -> second, value: I am in the middle
ref -> third, value: I am last
final state: ref -> third, value: I am last
ref -> one, value: 1
ref -> two, value: 2
ref -> three, value: 3
final state: ref -> three, value: 3
./nameref5.sub: line 43: unset: three: cannot unset: readonly variable
ref -> one, value: 1
ref -> two, value: 2
ref -> three, value: 3
final state: ref -> three, value: 3
+114
View File
@@ -0,0 +1,114 @@
# basic nameref tests
bar=one
flow=two
flip=three
foo=bar
typeset -n foo
typeset -n fee=flow
echo ${foo}
echo ${fee}
typeset -n fee=flip
echo ${fee}
typeset -n
echo turning off nameref attribute on foo
typeset +n foo=other
echo ${foo}
echo after +n foo bar = $bar
unset foo bar fee
bar=one
foo=bar
typeset -n foo
foo=two printf "%s\n" $foo
foo=two eval 'printf "%s\n" $foo'
foo=two echo $foo
unset foo bar
# other basic assignment tests
bar=one
echo "expect <one>"
recho ${bar}
typeset -n foo=bar
foo=two
echo "expect <two>"
recho ${bar}
# this appears to be a ksh93 bug; it doesn't unset foo here and messes up
# later
unset foo bar
# initial tests of working inside shell functions
echoval()
{
typeset -n ref=$1
printf "%s\n" $ref
}
foo=bar
bar=one
echo "expect <$foo>"
echoval foo
echo "expect <$bar>"
echoval bar
unset foo bar
changevar()
{
typeset -n v=$1
shift
v="$@"
echo "changevar: expect <$@>"
recho "$v"
}
bar=one
echo "expect <one>"
recho ${bar}
changevar bar two
echo "expect <two>"
recho $bar
changevar bar three four five
echo "expect <three four five>"
recho "$bar"
unset foo bar
readonly foo=one
typeset -n bar=foo
bar=4
foo=4
echo $foo
echo $bar
assignvar()
{
typeset -n ref=$1
shift
ref="$@"
}
readonly foo=one
assignvar foo two three four
echo $foo
${THIS_SH} ./nameref1.sub
${THIS_SH} ./nameref2.sub
${THIS_SH} ./nameref3.sub
${THIS_SH} ./nameref4.sub
${THIS_SH} ./nameref5.sub
+108
View File
@@ -0,0 +1,108 @@
# basic nameref tests
bar=one
flow=two
flip=three
foo=bar
typeset -n foo
typeset -n fee=flow
echo ${foo}
echo ${fee}
typeset -n fee=flip
echo ${fee}
typeset -n
echo turning off nameref attribute on foo
typeset +n foo=other
echo ${foo}
echo after +n foo bar = $bar
unset foo bar fee
bar=one
foo=bar
typeset -n foo
foo=two printf "%s\n" $foo
foo=two eval 'printf "%s\n" $foo'
foo=two echo $foo
unset foo bar
# other basic assignment tests
bar=one
echo "expect <one>"
recho ${bar}
typeset -n foo=bar
foo=two
echo "expect <two>"
recho ${bar}
# this appears to be a ksh93 bug; it doesn't unset foo here and messes up
# later
unset foo bar
# initial tests of working inside shell functions
echoval()
{
typeset -n ref=$1
printf "%s\n" $ref
}
foo=bar
bar=one
echo "expect <$foo>"
echoval foo
echo "expect <$bar>"
echoval bar
unset foo bar
changevar()
{
typeset -n v=$1
shift
v="$@"
echo "changevar: expect <$@>"
recho "$v"
}
bar=one
echo "expect <one>"
recho ${bar}
changevar bar two
echo "expect <two>"
recho $bar
changevar bar three four five
echo "expect <three four five>"
recho "$bar"
unset foo bar
readonly foo=one
typeset -n bar=foo
bar=4
foo=4
echo $foo
echo $bar
assignvar()
{
typeset -n ref=$1
shift
ref="$@"
}
readonly foo=one
assignvar foo two three four
echo $foo
+13
View File
@@ -0,0 +1,13 @@
# indirect referencing of a nameref returns the variable name it references
unset foo bar
bar=one
foo=bar
typeset -n foo
echo ${foo}
echo ${!foo}
# this is a current incompatibility
echo ${!foo[0]}
+7
View File
@@ -0,0 +1,7 @@
# test readonly nameref variables
# ksh93 allows this but not typeset -rn ref=foo?
typeset -n ref=foo
readonly ref
foo=4
echo $ref
+31
View File
@@ -0,0 +1,31 @@
# nameref requires changes to unset
bar=one
typeset -n foo=bar
# normal unset unsets both nameref and variable it references
unset foo
echo "expect <unset>"
recho ${bar-unset}
echo "expect <unset>"
recho ${foo-unset}
readonly bar=two
typeset -n foo=bar
unset foo # this should fail because bar is readonly
echo "expect <two>"
echo ${bar-unset}
echo "expect <two>"
echo ${foo-unset}
# one question is what happens when you unset the underlying variable
qux=three
typeset -n ref
ref=qux
echo $ref
unset qux
echo ${ref-unset}
qux=four
echo ${ref-unset}
+211
View File
@@ -0,0 +1,211 @@
# test suite cribbed from ksh93 nameref tests
typeset -i errors=0
ckval()
{
typeset -n one=$1
if [[ $one != $2 ]]; then
echo "one=$one != 2=$2"
(( errors++ ))
fi
}
ckref()
{
typeset -n one=$1 two=$2
if [[ $one != $two ]]; then
echo "one=$one != two=$two"
(( errors++ ))
fi
}
name=first
ckref name name
func1()
{
typeset -n color=$1
func2 color
}
func2()
{
typeset color=$1
set -- ${color[@]}
printf "<%s>" "$@"
echo
}
typeset -A color
color[apple]=red
color[grape]=purple
color[banana]=yellow
# XXX
#func1 color
unset foo bar
export bar=foo
typeset -n foo=bar
ckval foo foo
# XXX - need to see if we can do checks for self-referencing at assignment
# time
command typeset -n xx=yy
command typeset -n yy=xx
echo $?
unset foo bar
set foo
typeset -n bar=$1
foo=hello
ckval bar hello
# XXX -- another self-referencing error?
# ksh93 makes this another invalid self-reference
unset foo bar
bar=123
foobar()
{
typeset -n foo=bar
typeset -n foo=bar
ckval foo 123
}
typeset -n short=long
short=( a b )
echo "expect <a b>"
echo ${long[@]}
unset short long
# assignment to a previously-unset variable
typeset -n short=long
short=foo
echo "expect <foo>"
echo ${long}
unset short long
unset foo bar
# simple array references and assignments
typeset -n foo=bar
bar=( 1 3 5 7 9)
echo ${foo[@]}
echo ${foo[4]}
foo[2]=42
echo ${bar[@]}
barfunc()
{
typeset -n v=$1
echo ${v[@]}
echo ${v[4]}
v[2]=44
echo ${bar[@]}
}
barfunc bar
unset -f foobar
unset foo bar
# should ref at global scope survive call to foobar()?
unset ref x
typeset -n ref
x=42
foobar()
{
local xxx=3
ref=xxx
return 0
}
echo ${ref-unset}
ref=x
foobar
ckval ref xxx
ckval x xxx
# assignment in a function to something possibly out of scope
assignvar()
{
typeset -n v=$1
shift
v="$@"
}
assignvar lex a b c d e
echo "expect <a b c d e>"
recho "${lex}"
unset foo bar short long
typeset -n foo='x[2]'
x=(zero one two three four)
foo=seven
echo "expect <zero> <one> <seven> <three> <four>"
recho "${x[@]}"
unset ref x
typeset -n ref
ref=x
# make sure nameref to a previously-unset variable creates the variable
ref=42
ckval x 42
# make sure they work inside arithmetic expressions
unset foo bar ref x xxx
typeset -i ivar
typeset -n iref=ivar
ivar=4+3
ckval ivar 7
iref+=5
ckval ivar 12
echo $(( iref+4 ))
(( iref=17 ))
ckval ivar 17
typeset +n iref
unset iref ivar
typeset +n foo bar
unset foo bar
# should the reference do immediate evaluation or deferred?
set -- one two three four
bar=4
# XXX - what does foo get set to here?
typeset -n foo='bar[0]'
echo "expect <4>"
echo ${bar[0]}
echo "expect <4>"
echo ${foo}
echo "expect <4>"
echo $foo
ckval foo $bar
# Need to add code and tests for nameref to array subscripts
bar=(one two three four)
typeset -n foo='bar[0]'
typeset -n qux='bar[3]'
echo "expect <one>"
echo ${bar[0]}
echo "expect <one>"
echo ${foo}
echo "expect <one>"
echo $foo
ckval foo $bar
echo "expect <four>"
echo $qux
ckval qux ${bar[3]}
# Need to add code and tests for `for' loop nameref variables
echo errors = $errors
exit $errors
+50
View File
@@ -0,0 +1,50 @@
# nameref variables as for loop index variables are special
v1=1
v2=2
# simple for loop
for v in v1 v2
do
typeset -n ref=$v
echo $ref
done
unset v
set -- first second third fourth fifth
# unless you put a ${!v} in the for loop, ksh93 misbehaves
typeset -n v=v1
for v in v1 v2; do
echo "${!v}: $v"
done
unset v
# example cribbed from ksh93 o'reilly book
first="I am first"
second="I am in the middle"
third="I am last"
typeset -n ref=first
for ref in first second third ; do
echo "ref -> ${!ref}, value: $ref"
done
echo final state: "ref -> ${!ref}, value: $ref"
readonly one=1
readonly two=2
readonly three=3
typeset -n ref=one
for ref in one two three; do
echo "ref -> ${!ref}, value: $ref"
done
echo final state: "ref -> ${!ref}, value: $ref"
unset ref
typeset -n ref=one
readonly ref
for ref in one two three; do
echo "ref -> ${!ref}, value: $ref"
done
echo final state: "ref -> ${!ref}, value: $ref"
+4
View File
@@ -0,0 +1,4 @@
echo "warning: some of these tests will fail if arrays have not" >&2
echo "warning: been compiled into the shell" >&2
${THIS_SH} ./nameref.tests > /tmp/xx 2>&1
diff /tmp/xx nameref.right && rm -f /tmp/xx
+4
View File
@@ -0,0 +1,4 @@
echo "warning: all of these tests will fail if arrays have not" >&2
echo "warning: been compiled into the shell" >&2
${THIS_SH} ./assoc.tests > /tmp/xx 2>&1
diff /tmp/xx assoc.right && rm -f /tmp/xx
+7
View File
@@ -1104,6 +1104,13 @@ signal_is_trapped (sig)
return (sigmodes[sig] & SIG_TRAPPED);
}
int
signal_is_pending (sig)
int sig;
{
return (pending_traps[sig]);
}
int
signal_is_special (sig)
int sig;
+1
View File
@@ -98,6 +98,7 @@ extern void run_interrupt_trap __P((void));
extern int maybe_call_trap_handler __P((int));
extern int signal_is_special __P((int));
extern int signal_is_trapped __P((int));
extern int signal_is_pending __P((int));
extern int signal_is_ignored __P((int));
extern int signal_is_hard_ignored __P((int));
extern void set_signal_ignored __P((int));
+272 -10
View File
@@ -1,6 +1,6 @@
/* variables.c -- Functions for hacking shell variables. */
/* Copyright (C) 1987-2011 Free Software Foundation, Inc.
/* Copyright (C) 1987-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -264,6 +264,10 @@ static int variable_in_context __P((SHELL_VAR *));
static int visible_array_vars __P((SHELL_VAR *));
#endif
static SHELL_VAR *find_nameref_at_context __P((SHELL_VAR *, VAR_CONTEXT *));
static SHELL_VAR *find_variable_nameref_context __P((SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **));
static SHELL_VAR *find_variable_last_nameref_context __P((SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **));
static SHELL_VAR *bind_tempenv_variable __P((const char *, char *));
static void push_temp_var __P((PTR_T));
static void propagate_temp_var __P((PTR_T));
@@ -1803,6 +1807,161 @@ find_variable_internal (name, force_tempenv)
return (var->dynamic_value ? (*(var->dynamic_value)) (var) : var);
}
/* Look up and resolve the chain of nameref variables starting at V all the
way to NULL or non-nameref. */
SHELL_VAR *
find_variable_nameref (v)
SHELL_VAR *v;
{
int level;
char *newname;
level = 0;
while (v && nameref_p (v))
{
level++;
if (level > NAMEREF_MAX)
return ((SHELL_VAR *)0); /* error message here? */
newname = nameref_cell (v);
if (newname == 0 || *newname == '\0')
return ((SHELL_VAR *)0);
v = find_variable_internal (newname, (expanding_redir == 0 && (assigning_in_environment || executing_builtin)));
}
return v;
}
/* Resolve the chain of nameref variables for NAME. XXX - could change later */
SHELL_VAR *
find_variable_last_nameref (name)
const char *name;
{
SHELL_VAR *v, *nv;
char *newname;
int level;
nv = v = find_variable_noref (name);
level = 0;
while (v && nameref_p (v))
{
level++;
if (level > NAMEREF_MAX)
return ((SHELL_VAR *)0); /* error message here? */
newname = nameref_cell (v);
if (newname == 0 || *newname == '\0')
return ((SHELL_VAR *)0);
nv = v;
v = find_variable_internal (newname, (expanding_redir == 0 && (assigning_in_environment || executing_builtin)));
}
return nv;
}
/* Resolve the chain of nameref variables for NAME. XXX - could change later */
SHELL_VAR *
find_global_variable_last_nameref (name)
const char *name;
{
SHELL_VAR *v, *nv;
char *newname;
int level;
nv = v = find_global_variable_noref (name);
level = 0;
while (v && nameref_p (v))
{
level++;
if (level > NAMEREF_MAX)
return ((SHELL_VAR *)0); /* error message here? */
newname = nameref_cell (v);
if (newname == 0 || *newname == '\0')
return ((SHELL_VAR *)0);
nv = v;
v = find_global_variable_noref (newname);
}
return nv;
}
static SHELL_VAR *
find_nameref_at_context (v, vc)
SHELL_VAR *v;
VAR_CONTEXT *vc;
{
SHELL_VAR *nv, *nv2;
VAR_CONTEXT *nvc;
char *newname;
int level;
nv = v;
level = 1;
while (nv && nameref_p (nv))
{
level++;
if (level > NAMEREF_MAX)
return ((SHELL_VAR *)NULL);
newname = nameref_cell (nv);
if (newname == 0 || *newname == '\0')
return ((SHELL_VAR *)NULL);
nv2 = hash_lookup (newname, vc->table);
if (nv2 == 0)
break;
nv = nv2;
}
return nv;
}
/* Do nameref resolution from the VC, which is the local context for some
function or builtin, `up' the chain to the global variables context. If
NVCP is not NULL, return the variable context where we finally ended the
nameref resolution (so the bind_variable_internal can use the correct
variable context and hash table). */
static SHELL_VAR *
find_variable_nameref_context (v, vc, nvcp)
SHELL_VAR *v;
VAR_CONTEXT *vc;
VAR_CONTEXT **nvcp;
{
SHELL_VAR *nv, *nv2;
VAR_CONTEXT *nvc;
/* Look starting at the current context all the way `up' */
for (nv = v, nvc = vc; nvc; nvc = nvc->down)
{
nv2 = find_nameref_at_context (nv, nvc);
if (nv2 == 0)
continue;
nv = nv2;
if (*nvcp)
*nvcp = nvc;
}
return (nameref_p (nv) ? (SHELL_VAR *)NULL : nv);
}
/* Do nameref resolution from the VC, which is the local context for some
function or builtin, `up' the chain to the global variables context. If
NVCP is not NULL, return the variable context where we finally ended the
nameref resolution (so the bind_variable_internal can use the correct
variable context and hash table). */
static SHELL_VAR *
find_variable_last_nameref_context (v, vc, nvcp)
SHELL_VAR *v;
VAR_CONTEXT *vc;
VAR_CONTEXT **nvcp;
{
SHELL_VAR *nv, *nv2;
VAR_CONTEXT *nvc;
/* Look starting at the current context all the way `up' */
for (nv = v, nvc = vc; nvc; nvc = nvc->down)
{
nv2 = find_nameref_at_context (nv, nvc);
if (nv2 == 0)
continue;
nv = nv2;
if (*nvcp)
*nvcp = nvc;
}
return (nameref_p (nv) ? nv : (SHELL_VAR *)NULL);
}
/* Find a variable, forcing a search of the temporary environment first */
SHELL_VAR *
find_variable_tempenv (name)
@@ -1811,6 +1970,8 @@ find_variable_tempenv (name)
SHELL_VAR *var;
var = find_variable_internal (name, 1);
if (var && nameref_p (var))
var = find_variable_nameref (var);
return (var);
}
@@ -1822,6 +1983,8 @@ find_variable_notempenv (name)
SHELL_VAR *var;
var = find_variable_internal (name, 0);
if (var && nameref_p (var))
var = find_variable_nameref (var);
return (var);
}
@@ -1831,6 +1994,22 @@ find_global_variable (name)
{
SHELL_VAR *var;
var = var_lookup (name, global_variables);
if (var && nameref_p (var))
var = find_variable_nameref (var);
if (var == 0)
return ((SHELL_VAR *)NULL);
return (var->dynamic_value ? (*(var->dynamic_value)) (var) : var);
}
SHELL_VAR *
find_global_variable_noref (name)
const char *name;
{
SHELL_VAR *var;
var = var_lookup (name, global_variables);
if (var == 0)
@@ -1846,6 +2025,8 @@ find_shell_variable (name)
SHELL_VAR *var;
var = var_lookup (name, shell_variables);
if (var && nameref_p (var))
var = find_variable_nameref (var);
if (var == 0)
return ((SHELL_VAR *)NULL);
@@ -1858,7 +2039,22 @@ SHELL_VAR *
find_variable (name)
const char *name;
{
return (find_variable_internal (name, (expanding_redir == 0 && (assigning_in_environment || executing_builtin))));
SHELL_VAR *v;
v = find_variable_internal (name, (expanding_redir == 0 && (assigning_in_environment || executing_builtin)));
if (v && nameref_p (v))
v = find_variable_nameref (v);
return v;
}
SHELL_VAR *
find_variable_noref (name)
const char *name;
{
SHELL_VAR *v;
v = find_variable_internal (name, (expanding_redir == 0 && (assigning_in_environment || executing_builtin)));
return v;
}
/* Look up the function entry whose name matches STRING.
@@ -2245,8 +2441,37 @@ bind_variable_internal (name, value, table, hflags, aflags)
SHELL_VAR *entry;
entry = (hflags & HASH_NOSRCH) ? (SHELL_VAR *)NULL : hash_lookup (name, table);
/* Follow the nameref chain here if this is the global variables table */
if (entry && nameref_p (entry) && (invisible_p (entry) == 0) && table == global_variables->table)
{
entry = find_global_variable (entry->name);
/* Let's see if we have a nameref referencing a variable that hasn't yet
been created. */
if (entry == 0)
entry = find_variable_last_nameref (name); /* XXX */
if (entry == 0) /* just in case */
return (entry);
}
if (entry == 0)
/* The first clause handles `declare -n ref; ref=x;' */
if (entry && invisible_p (entry) && nameref_p (entry))
goto assign_value;
else if (entry && nameref_p (entry))
{
newval = nameref_cell (entry);
#if defined (ARRAY_VARS)
/* declare -n foo=x[2] */
if (valid_array_reference (newval))
/* XXX - should it be aflags? */
entry = assign_array_element (newval, make_variable_value (entry, value, 0), aflags);
else
#endif
{
entry = make_new_variable (newval, table);
var_setvalue (entry, make_variable_value (entry, value, 0));
}
}
else if (entry == 0)
{
entry = make_new_variable (name, table);
var_setvalue (entry, make_variable_value (entry, value, 0)); /* XXX */
@@ -2267,6 +2492,7 @@ bind_variable_internal (name, value, table, hflags, aflags)
}
else
{
assign_value:
if (readonly_p (entry) || noassign_p (entry))
{
if (readonly_p (entry))
@@ -2330,8 +2556,9 @@ bind_variable (name, value, flags)
char *value;
int flags;
{
SHELL_VAR *v;
VAR_CONTEXT *vc;
SHELL_VAR *v, *nv;
VAR_CONTEXT *vc, *nvc;
int level;
if (shell_variables == 0)
create_variable_tables ();
@@ -2350,10 +2577,26 @@ bind_variable (name, value, flags)
if (vc_isfuncenv (vc) || vc_isbltnenv (vc))
{
v = hash_lookup (name, vc->table);
nvc = vc;
if (v && nameref_p (v))
{
nv = find_variable_nameref_context (v, vc, &nvc);
if (nv == 0)
{
nv = find_variable_last_nameref_context (v, vc, &nvc);
if (nv && nameref_p (nv))
return (bind_variable_internal (nameref_cell (nv), value, nvc->table, 0, flags));
else
v = nv;
}
else
v = nv;
}
if (v)
return (bind_variable_internal (name, value, vc->table, 0, flags));
return (bind_variable_internal (v->name, value, nvc->table, 0, flags));
}
}
/* bind_variable_internal will handle nameref resolution in this case */
return (bind_variable_internal (name, value, global_variables->table, 0, flags));
}
@@ -2651,7 +2894,9 @@ copy_variable (var)
else if (assoc_p (var))
var_setassoc (copy, assoc_copy (assoc_cell (var)));
#endif
else if (value_cell (var))
else if (nameref_cell (var)) /* XXX - nameref */
var_setref (copy, savestring (nameref_cell (var)));
else if (value_cell (var)) /* XXX - nameref */
var_setvalue (copy, savestring (value_cell (var)));
else
var_setvalue (copy, (char *)NULL);
@@ -2686,6 +2931,8 @@ dispose_variable_value (var)
else if (assoc_p (var))
assoc_dispose (assoc_cell (var));
#endif
else if (nameref_p (var))
FREE (nameref_cell (var));
else
FREE (value_cell (var));
}
@@ -2710,12 +2957,23 @@ dispose_variable (var)
free (var);
}
/* Unset the shell variable referenced by NAME. */
/* Unset the shell variable referenced by NAME. Unsetting a nameref variable
unsets both the variable and the variable it resolves to. */
int
unbind_variable (name)
const char *name;
{
return makunbound (name, shell_variables);
SHELL_VAR *v, *nv;
int r;
v = var_lookup (name, shell_variables);
nv = (v && nameref_p (v)) ? find_variable_nameref (v) : (SHELL_VAR *)NULL;
r = nv ? makunbound (nv->name, shell_variables) : 0;
if (r == 0)
r = makunbound (name, shell_variables);
return r;
}
/* Unset the shell function named NAME. */
@@ -4629,7 +4887,11 @@ sv_histtimefmt (name)
{
SHELL_VAR *v;
v = find_variable (name);
if (v = find_variable (name))
{
if (history_comment_char == 0)
history_comment_char = '#';
}
history_write_timestamps = (v != 0);
}
#endif /* HISTORY */
+5138
View File
File diff suppressed because it is too large Load Diff
+11 -1
View File
@@ -1,6 +1,6 @@
/* variables.h -- data structures for shell variables. */
/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
/* Copyright (C) 1987-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -145,6 +145,7 @@ typedef struct _vlist {
#define uppercase_p(var) ((((var)->attributes) & (att_uppercase)))
#define lowercase_p(var) ((((var)->attributes) & (att_lowercase)))
#define capcase_p(var) ((((var)->attributes) & (att_capcase)))
#define nameref_p(var) ((((var)->attributes) & (att_nameref)))
#define invisible_p(var) ((((var)->attributes) & (att_invisible)))
#define non_unsettable_p(var) ((((var)->attributes) & (att_nounset)))
@@ -160,6 +161,9 @@ typedef struct _vlist {
#define function_cell(var) (COMMAND *)((var)->value)
#define array_cell(var) (ARRAY *)((var)->value)
#define assoc_cell(var) (HASH_TABLE *)((var)->value)
#define nameref_cell(var) ((var)->value) /* so it can change later */
#define NAMEREF_MAX 8 /* only 8 levels of nameref indirection */
#define var_isnull(var) ((var)->value == 0)
#define var_isset(var) ((var)->value != 0)
@@ -169,6 +173,7 @@ typedef struct _vlist {
#define var_setfunc(var, func) ((var)->value = (char *)(func))
#define var_setarray(var, arr) ((var)->value = (char *)(arr))
#define var_setassoc(var, arr) ((var)->value = (char *)(arr))
#define var_setref(var, str) ((var)->value = (str))
/* Make VAR be auto-exported. */
#define set_auto_export(var) \
@@ -234,10 +239,15 @@ extern SHELL_VAR *var_lookup __P((const char *, VAR_CONTEXT *));
extern SHELL_VAR *find_function __P((const char *));
extern FUNCTION_DEF *find_function_def __P((const char *));
extern SHELL_VAR *find_variable __P((const char *));
extern SHELL_VAR *find_variable_noref __P((const char *));
extern SHELL_VAR *find_variable_last_nameref __P((const char *));
extern SHELL_VAR *find_global_variable_last_nameref __P((const char *));
extern SHELL_VAR *find_variable_nameref __P((SHELL_VAR *));
extern SHELL_VAR *find_variable_internal __P((const char *, int));
extern SHELL_VAR *find_variable_tempenv __P((const char *));
extern SHELL_VAR *find_variable_notempenv __P((const char *));
extern SHELL_VAR *find_global_variable __P((const char *));
extern SHELL_VAR *find_global_variable_noref __P((const char *));
extern SHELL_VAR *find_shell_variable __P((const char *));
extern SHELL_VAR *find_tempenv_variable __P((const char *));
extern SHELL_VAR *copy_variable __P((SHELL_VAR *));
+404
View File
@@ -0,0 +1,404 @@
/* variables.h -- data structures for shell variables. */
/* Copyright (C) 1987-2012 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (_VARIABLES_H_)
#define _VARIABLES_H_
#include "stdc.h"
#include "array.h"
#include "assoc.h"
/* Shell variables and functions are stored in hash tables. */
#include "hashlib.h"
#include "conftypes.h"
/* A variable context. */
typedef struct var_context {
char *name; /* empty or NULL means global context */
int scope; /* 0 means global context */
int flags;
struct var_context *up; /* previous function calls */
struct var_context *down; /* down towards global context */
HASH_TABLE *table; /* variables at this scope */
} VAR_CONTEXT;
/* Flags for var_context->flags */
#define VC_HASLOCAL 0x01
#define VC_HASTMPVAR 0x02
#define VC_FUNCENV 0x04 /* also function if name != NULL */
#define VC_BLTNENV 0x08 /* builtin_env */
#define VC_TEMPENV 0x10 /* temporary_env */
#define VC_TEMPFLAGS (VC_FUNCENV|VC_BLTNENV|VC_TEMPENV)
/* Accessing macros */
#define vc_isfuncenv(vc) (((vc)->flags & VC_FUNCENV) != 0)
#define vc_isbltnenv(vc) (((vc)->flags & VC_BLTNENV) != 0)
#define vc_istempenv(vc) (((vc)->flags & (VC_TEMPFLAGS)) == VC_TEMPENV)
#define vc_istempscope(vc) (((vc)->flags & (VC_TEMPENV|VC_BLTNENV)) != 0)
#define vc_haslocals(vc) (((vc)->flags & VC_HASLOCAL) != 0)
#define vc_hastmpvars(vc) (((vc)->flags & VC_HASTMPVAR) != 0)
/* What a shell variable looks like. */
typedef struct variable *sh_var_value_func_t __P((struct variable *));
typedef struct variable *sh_var_assign_func_t __P((struct variable *, char *, arrayind_t, char *));
/* For the future */
union _value {
char *s; /* string value */
intmax_t i; /* int value */
COMMAND *f; /* function */
ARRAY *a; /* array */
HASH_TABLE *h; /* associative array */
double d; /* floating point number */
#if defined (HAVE_LONG_DOUBLE)
long double ld; /* long double */
#endif
struct variable *v; /* possible indirect variable use */
void *opaque; /* opaque data for future use */
};
typedef struct variable {
char *name; /* Symbol that the user types. */
char *value; /* Value that is returned. */
char *exportstr; /* String for the environment. */
sh_var_value_func_t *dynamic_value; /* Function called to return a `dynamic'
value for a variable, like $SECONDS
or $RANDOM. */
sh_var_assign_func_t *assign_func; /* Function called when this `special
variable' is assigned a value in
bind_variable. */
int attributes; /* export, readonly, array, invisible... */
int context; /* Which context this variable belongs to. */
} SHELL_VAR;
typedef struct _vlist {
SHELL_VAR **list;
int list_size; /* allocated size */
int list_len; /* current number of entries */
} VARLIST;
/* The various attributes that a given variable can have. */
/* First, the user-visible attributes */
#define att_exported 0x0000001 /* export to environment */
#define att_readonly 0x0000002 /* cannot change */
#define att_array 0x0000004 /* value is an array */
#define att_function 0x0000008 /* value is a function */
#define att_integer 0x0000010 /* internal representation is int */
#define att_local 0x0000020 /* variable is local to a function */
#define att_assoc 0x0000040 /* variable is an associative array */
#define att_trace 0x0000080 /* function is traced with DEBUG trap */
#define att_uppercase 0x0000100 /* word converted to uppercase on assignment */
#define att_lowercase 0x0000200 /* word converted to lowercase on assignment */
#define att_capcase 0x0000400 /* word capitalized on assignment */
#define att_nameref 0x0000800 /* word is a name reference */
#define user_attrs (att_exported|att_readonly|att_integer|att_local|att_trace|att_uppercase|att_lowercase|att_capcase|att_nameref)
#define attmask_user 0x0000fff
/* Internal attributes used for bookkeeping */
#define att_invisible 0x0001000 /* cannot see */
#define att_nounset 0x0002000 /* cannot unset */
#define att_noassign 0x0004000 /* assignment not allowed */
#define att_imported 0x0008000 /* came from environment */
#define att_special 0x0010000 /* requires special handling */
#define att_nofree 0x0020000 /* do not free value on unset */
#define attmask_int 0x00ff000
/* Internal attributes used for variable scoping. */
#define att_tempvar 0x0100000 /* variable came from the temp environment */
#define att_propagate 0x0200000 /* propagate to previous scope */
#define attmask_scope 0x0f00000
#define exported_p(var) ((((var)->attributes) & (att_exported)))
#define readonly_p(var) ((((var)->attributes) & (att_readonly)))
#define array_p(var) ((((var)->attributes) & (att_array)))
#define function_p(var) ((((var)->attributes) & (att_function)))
#define integer_p(var) ((((var)->attributes) & (att_integer)))
#define local_p(var) ((((var)->attributes) & (att_local)))
#define assoc_p(var) ((((var)->attributes) & (att_assoc)))
#define trace_p(var) ((((var)->attributes) & (att_trace)))
#define uppercase_p(var) ((((var)->attributes) & (att_uppercase)))
#define lowercase_p(var) ((((var)->attributes) & (att_lowercase)))
#define capcase_p(var) ((((var)->attributes) & (att_capcase)))
#define nameref_p(var) ((((var)->attributes) & (att_nameref)))
#define invisible_p(var) ((((var)->attributes) & (att_invisible)))
#define non_unsettable_p(var) ((((var)->attributes) & (att_nounset)))
#define noassign_p(var) ((((var)->attributes) & (att_noassign)))
#define imported_p(var) ((((var)->attributes) & (att_imported)))
#define specialvar_p(var) ((((var)->attributes) & (att_special)))
#define nofree_p(var) ((((var)->attributes) & (att_nofree)))
#define tempvar_p(var) ((((var)->attributes) & (att_tempvar)))
/* Acessing variable values: rvalues */
#define value_cell(var) ((var)->value)
#define function_cell(var) (COMMAND *)((var)->value)
#define array_cell(var) (ARRAY *)((var)->value)
#define assoc_cell(var) (HASH_TABLE *)((var)->value)
#define nameref_cell(var) ((var)->value) /* so it can change later */
#define NAMEREF_MAX 8 /* only 8 levels of nameref indirection */
#define var_isnull(var) ((var)->value == 0)
#define var_isset(var) ((var)->value != 0)
/* Assigning variable values: lvalues */
#define var_setvalue(var, str) ((var)->value = (str))
#define var_setfunc(var, func) ((var)->value = (char *)(func))
#define var_setarray(var, arr) ((var)->value = (char *)(arr))
#define var_setassoc(var, arr) ((var)->value = (char *)(arr))
#define var_setref(var, str) ((var)->value = (str))
/* Make VAR be auto-exported. */
#define set_auto_export(var) \
do { (var)->attributes |= att_exported; array_needs_making = 1; } while (0)
#define SETVARATTR(var, attr, undo) \
((undo == 0) ? ((var)->attributes |= (attr)) \
: ((var)->attributes &= ~(attr)))
#define VSETATTR(var, attr) ((var)->attributes |= (attr))
#define VUNSETATTR(var, attr) ((var)->attributes &= ~(attr))
#define VGETFLAGS(var) ((var)->attributes)
#define VSETFLAGS(var, flags) ((var)->attributes = (flags))
#define VCLRFLAGS(var) ((var)->attributes = 0)
/* Macros to perform various operations on `exportstr' member of a SHELL_VAR. */
#define CLEAR_EXPORTSTR(var) (var)->exportstr = (char *)NULL
#define COPY_EXPORTSTR(var) ((var)->exportstr) ? savestring ((var)->exportstr) : (char *)NULL
#define SET_EXPORTSTR(var, value) (var)->exportstr = (value)
#define SAVE_EXPORTSTR(var, value) (var)->exportstr = (value) ? savestring (value) : (char *)NULL
#define FREE_EXPORTSTR(var) \
do { if ((var)->exportstr) free ((var)->exportstr); } while (0)
#define CACHE_IMPORTSTR(var, value) \
(var)->exportstr = savestring (value)
#define INVALIDATE_EXPORTSTR(var) \
do { \
if ((var)->exportstr) \
{ \
free ((var)->exportstr); \
(var)->exportstr = (char *)NULL; \
} \
} while (0)
/* Stuff for hacking variables. */
typedef int sh_var_map_func_t __P((SHELL_VAR *));
/* Where we keep the variables and functions */
extern VAR_CONTEXT *global_variables;
extern VAR_CONTEXT *shell_variables;
extern HASH_TABLE *shell_functions;
extern HASH_TABLE *temporary_env;
extern int variable_context;
extern char *dollar_vars[];
extern char **export_env;
extern void initialize_shell_variables __P((char **, int));
extern SHELL_VAR *set_if_not __P((char *, char *));
extern void sh_set_lines_and_columns __P((int, int));
extern void set_pwd __P((void));
extern void set_ppid __P((void));
extern void make_funcname_visible __P((int));
extern SHELL_VAR *var_lookup __P((const char *, VAR_CONTEXT *));
extern SHELL_VAR *find_function __P((const char *));
extern FUNCTION_DEF *find_function_def __P((const char *));
extern SHELL_VAR *find_variable __P((const char *));
extern SHELL_VAR *find_variable_noref __P((const char *));
extern SHELL_VAR *find_variable_last_nameref __P((const char *));
extern SHELL_VAR *find_variable_nameref __P((SHELL_VAR *));
extern SHELL_VAR *find_variable_internal __P((const char *, int));
extern SHELL_VAR *find_variable_tempenv __P((const char *));
extern SHELL_VAR *find_variable_notempenv __P((const char *));
extern SHELL_VAR *find_global_variable __P((const char *));
extern SHELL_VAR *find_global_variable_noref __P((const char *));
extern SHELL_VAR *find_shell_variable __P((const char *));
extern SHELL_VAR *find_tempenv_variable __P((const char *));
extern SHELL_VAR *copy_variable __P((SHELL_VAR *));
extern SHELL_VAR *make_local_variable __P((const char *));
extern SHELL_VAR *bind_variable __P((const char *, char *, int));
extern SHELL_VAR *bind_function __P((const char *, COMMAND *));
extern void bind_function_def __P((const char *, FUNCTION_DEF *));
extern SHELL_VAR **map_over __P((sh_var_map_func_t *, VAR_CONTEXT *));
SHELL_VAR **map_over_funcs __P((sh_var_map_func_t *));
extern SHELL_VAR **all_shell_variables __P((void));
extern SHELL_VAR **all_shell_functions __P((void));
extern SHELL_VAR **all_visible_variables __P((void));
extern SHELL_VAR **all_visible_functions __P((void));
extern SHELL_VAR **all_exported_variables __P((void));
extern SHELL_VAR **local_exported_variables __P((void));
extern SHELL_VAR **all_local_variables __P((void));
#if defined (ARRAY_VARS)
extern SHELL_VAR **all_array_variables __P((void));
#endif
extern char **all_variables_matching_prefix __P((const char *));
extern char **make_var_array __P((HASH_TABLE *));
extern char **add_or_supercede_exported_var __P((char *, int));
extern char *get_variable_value __P((SHELL_VAR *));
extern char *get_string_value __P((const char *));
extern char *sh_get_env_value __P((const char *));
extern char *make_variable_value __P((SHELL_VAR *, char *, int));
extern SHELL_VAR *bind_variable_value __P((SHELL_VAR *, char *, int));
extern SHELL_VAR *bind_int_variable __P((char *, char *));
extern SHELL_VAR *bind_var_to_int __P((char *, intmax_t));
extern int assign_in_env __P((WORD_DESC *, int));
extern int unbind_variable __P((const char *));
extern int unbind_func __P((const char *));
extern int unbind_function_def __P((const char *));
extern int makunbound __P((const char *, VAR_CONTEXT *));
extern int kill_local_variable __P((const char *));
extern void delete_all_variables __P((HASH_TABLE *));
extern void delete_all_contexts __P((VAR_CONTEXT *));
extern VAR_CONTEXT *new_var_context __P((char *, int));
extern void dispose_var_context __P((VAR_CONTEXT *));
extern VAR_CONTEXT *push_var_context __P((char *, int, HASH_TABLE *));
extern void pop_var_context __P((void));
extern VAR_CONTEXT *push_scope __P((int, HASH_TABLE *));
extern void pop_scope __P((int));
extern void push_context __P((char *, int, HASH_TABLE *));
extern void pop_context __P((void));
extern void push_dollar_vars __P((void));
extern void pop_dollar_vars __P((void));
extern void dispose_saved_dollar_vars __P((void));
extern void push_args __P((WORD_LIST *));
extern void pop_args __P((void));
extern void adjust_shell_level __P((int));
extern void non_unsettable __P((char *));
extern void dispose_variable __P((SHELL_VAR *));
extern void dispose_used_env_vars __P((void));
extern void dispose_function_env __P((void));
extern void dispose_builtin_env __P((void));
extern void merge_temporary_env __P((void));
extern void merge_builtin_env __P((void));
extern void kill_all_local_variables __P((void));
extern void set_var_read_only __P((char *));
extern void set_func_read_only __P((const char *));
extern void set_var_auto_export __P((char *));
extern void set_func_auto_export __P((const char *));
extern void sort_variables __P((SHELL_VAR **));
extern int chkexport __P((char *));
extern void maybe_make_export_env __P((void));
extern void update_export_env_inplace __P((char *, int, char *));
extern void put_command_name_into_env __P((char *));
extern void put_gnu_argv_flags_into_env __P((intmax_t, char *));
extern void print_var_list __P((SHELL_VAR **));
extern void print_func_list __P((SHELL_VAR **));
extern void print_assignment __P((SHELL_VAR *));
extern void print_var_value __P((SHELL_VAR *, int));
extern void print_var_function __P((SHELL_VAR *));
#if defined (ARRAY_VARS)
extern SHELL_VAR *make_new_array_variable __P((char *));
extern SHELL_VAR *make_local_array_variable __P((char *, int));
extern SHELL_VAR *make_new_assoc_variable __P((char *));
extern SHELL_VAR *make_local_assoc_variable __P((char *));
extern void set_pipestatus_array __P((int *, int));
extern ARRAY *save_pipestatus_array __P((void));
extern void restore_pipestatus_array __P((ARRAY *));
#endif
extern void set_pipestatus_from_exit __P((int));
/* The variable in NAME has just had its state changed. Check to see if it
is one of the special ones where something special happens. */
extern void stupidly_hack_special_variables __P((char *));
/* Reinitialize some special variables that have external effects upon unset
when the shell reinitializes itself. */
extern void reinit_special_variables __P((void));
extern int get_random_number __P((void));
/* The `special variable' functions that get called when a particular
variable is set. */
extern void sv_ifs __P((char *));
extern void sv_path __P((char *));
extern void sv_mail __P((char *));
extern void sv_funcnest __P((char *));
extern void sv_globignore __P((char *));
extern void sv_ignoreeof __P((char *));
extern void sv_strict_posix __P((char *));
extern void sv_optind __P((char *));
extern void sv_opterr __P((char *));
extern void sv_locale __P((char *));
extern void sv_xtracefd __P((char *));
#if defined (READLINE)
extern void sv_comp_wordbreaks __P((char *));
extern void sv_terminal __P((char *));
extern void sv_hostfile __P((char *));
extern void sv_winsize __P((char *));
#endif
#if defined (__CYGWIN__)
extern void sv_home __P((char *));
#endif
#if defined (HISTORY)
extern void sv_histsize __P((char *));
extern void sv_histignore __P((char *));
extern void sv_history_control __P((char *));
# if defined (BANG_HISTORY)
extern void sv_histchars __P((char *));
# endif
extern void sv_histtimefmt __P((char *));
#endif /* HISTORY */
#if defined (HAVE_TZSET)
extern void sv_tz __P((char *));
#endif
#endif /* !_VARIABLES_H_ */