mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-12 05:00:50 +02:00
commit bash-20160603 snapshot
This commit is contained in:
+67
-36
@@ -286,8 +286,8 @@ declare_internal (list, local_var)
|
||||
/* There are arguments left, so we are making variables. */
|
||||
while (list) /* declare [-aAfFirx] name [name ...] */
|
||||
{
|
||||
char *value, *name;
|
||||
int offset, aflags, wflags;
|
||||
char *value, *name, *oldname;
|
||||
int offset, aflags, wflags, created_var, namelen;
|
||||
#if defined (ARRAY_VARS)
|
||||
int making_array_special, compound_array_assign, simple_array_assign;
|
||||
int var_exists, array_exists, creating_array, array_subscript_assignment;
|
||||
@@ -297,6 +297,7 @@ declare_internal (list, local_var)
|
||||
wflags = list->word->flags;
|
||||
offset = assignment (name, 0);
|
||||
aflags = 0;
|
||||
created_var = 0;
|
||||
|
||||
if (local_var && variable_context && STREQ (name, "-"))
|
||||
{
|
||||
@@ -332,27 +333,10 @@ declare_internal (list, local_var)
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
else if (valid_array_reference (value, 0))
|
||||
{
|
||||
t = array_variable_name (value, (int *)NULL, (int *)NULL);
|
||||
if (t && STREQ (name, t))
|
||||
{
|
||||
if (variable_context == 0)
|
||||
{
|
||||
free (t);
|
||||
builtin_error (_("%s: nameref variable self references not allowed"), name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
else
|
||||
builtin_warning (_("%s: circular name reference"), name);
|
||||
}
|
||||
free (t);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
/* disallow self references at global scope, warn at function scope */
|
||||
if (STREQ (name, value))
|
||||
if (check_selfref (name, value, 0))
|
||||
{
|
||||
if (variable_context == 0)
|
||||
{
|
||||
@@ -364,7 +348,7 @@ declare_internal (list, local_var)
|
||||
builtin_warning (_("%s: circular name reference"), name);
|
||||
}
|
||||
#if 1
|
||||
if (value && *value && (aflags & ASS_APPEND) == 0 && valid_nameref_value (value, 0) == 0)
|
||||
if (value && *value && (aflags & ASS_APPEND) == 0 && valid_nameref_value (value, 1) == 0)
|
||||
{
|
||||
builtin_error (_("`%s': invalid variable name for name reference"), value);
|
||||
assign_error++;
|
||||
@@ -374,13 +358,15 @@ declare_internal (list, local_var)
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
restart_new_var_name:
|
||||
var_exists = array_exists = creating_array = 0;
|
||||
compound_array_assign = simple_array_assign = 0;
|
||||
array_subscript_assignment = 0;
|
||||
subscript_start = (char *)NULL;
|
||||
if (t = strchr (name, '[')) /* ] */
|
||||
{
|
||||
/* If offset != 0 we have already validated any array reference */
|
||||
/* If offset != 0 we have already validated any array reference
|
||||
because assignment() calls skipsubscript() */
|
||||
if (offset == 0 && valid_array_reference (name, 0) == 0)
|
||||
{
|
||||
sh_invalidid (name);
|
||||
@@ -417,6 +403,7 @@ declare_internal (list, local_var)
|
||||
refvar = (SHELL_VAR *)NULL;
|
||||
if (variable_context && mkglobal == 0 && ((flags_on & att_function) == 0))
|
||||
{
|
||||
/* check name for validity here? */
|
||||
#if defined (ARRAY_VARS)
|
||||
if (flags_on & att_assoc)
|
||||
var = make_local_assoc_variable (name);
|
||||
@@ -446,6 +433,7 @@ declare_internal (list, local_var)
|
||||
/* otherwise we have a var at the right context */
|
||||
}
|
||||
else
|
||||
/* XXX - check name for validity here with valid_nameref_value */
|
||||
var = make_local_variable (name); /* sets att_invisible for new vars */
|
||||
if (var == 0)
|
||||
{
|
||||
@@ -592,8 +580,50 @@ declare_internal (list, local_var)
|
||||
var = mkglobal ? find_global_variable (nameref_cell (refvar)) : find_variable (nameref_cell (refvar));
|
||||
if (refvar && var == 0)
|
||||
{
|
||||
free (name);
|
||||
name = savestring (nameref_cell (refvar));
|
||||
oldname = name; /* need to free this */
|
||||
|
||||
namelen = strlen (nameref_cell (refvar));
|
||||
#if defined (ARRAY_VARS)
|
||||
if (subscript_start)
|
||||
{
|
||||
*subscript_start = '['; /*]*/
|
||||
namelen += strlen (subscript_start);
|
||||
}
|
||||
#endif
|
||||
name = xmalloc (namelen + 2 + strlen (value) + 1);
|
||||
strcpy (name, nameref_cell (refvar));
|
||||
#if defined (ARRAY_VARS)
|
||||
if (subscript_start)
|
||||
strcpy (name + strlen (nameref_cell (refvar)), subscript_start);
|
||||
#endif
|
||||
/* We are committed to using the new name, so reset */
|
||||
if (offset)
|
||||
{
|
||||
/* Rebuild assignment and restore offset and value */
|
||||
if (aflags & ASS_APPEND)
|
||||
name[namelen++] = '+';
|
||||
name[namelen++] = '=';
|
||||
if (value && *value)
|
||||
strcpy (name + namelen, value);
|
||||
else
|
||||
name[namelen] = '\0';
|
||||
offset = assignment (name, 0);
|
||||
/* if offset was valid previously, but the substituting
|
||||
of the nameref value results in an invalid assignment,
|
||||
throw an invalid identifier error */
|
||||
if (offset == 0)
|
||||
{
|
||||
free (oldname);
|
||||
sh_invalidid (name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
name[offset] = '\0';
|
||||
value = name + namelen;
|
||||
}
|
||||
free (oldname);
|
||||
goto restart_new_var_name;
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
if (var == 0)
|
||||
@@ -622,13 +652,9 @@ declare_internal (list, local_var)
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (offset)
|
||||
/* We're just setting a temporary value here, so force assignment */
|
||||
var = mkglobal ? bind_global_variable (name, (char *)NULL, ASS_FORCE) : bind_variable (name, (char *)NULL, ASS_FORCE);
|
||||
else
|
||||
{
|
||||
var = mkglobal ? bind_global_variable (name, (char *)NULL, ASS_FORCE) : bind_variable (name, (char *)NULL, ASS_FORCE);
|
||||
if (var && no_invisible_vars == 0)
|
||||
if (var && offset == 0 && no_invisible_vars == 0)
|
||||
VSETATTR (var, att_invisible);
|
||||
}
|
||||
if (var == 0)
|
||||
@@ -636,6 +662,7 @@ declare_internal (list, local_var)
|
||||
/* Has to appear in brackets */
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
created_var = 1;
|
||||
}
|
||||
/* Can't take an existing array variable and make it a nameref */
|
||||
else if ((array_p (var) || assoc_p (var)) && (flags_on & att_nameref))
|
||||
@@ -775,14 +802,14 @@ declare_internal (list, local_var)
|
||||
VUNSETATTR (var, flags_off);
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
aflags |= ASS_FORCE;
|
||||
if (offset && compound_array_assign)
|
||||
assign_array_var_from_string (var, value, aflags);
|
||||
assign_array_var_from_string (var, value, aflags|ASS_FORCE);
|
||||
else if (simple_array_assign && subscript_start)
|
||||
{
|
||||
/* declare [-aA] name[N]=value */
|
||||
*subscript_start = '['; /* ] */
|
||||
var = assign_array_element (name, value, 0); /* XXX - not aflags */
|
||||
/* XXX - problem here with appending */
|
||||
var = assign_array_element (name, value, aflags&ASS_APPEND); /* XXX - not aflags */
|
||||
*subscript_start = '\0';
|
||||
if (var == 0) /* some kind of assignment error */
|
||||
{
|
||||
@@ -796,12 +823,13 @@ declare_internal (list, local_var)
|
||||
{
|
||||
/* let bind_{array,assoc}_variable take care of this. */
|
||||
if (assoc_p (var))
|
||||
bind_assoc_variable (var, name, savestring ("0"), value, aflags);
|
||||
bind_assoc_variable (var, name, savestring ("0"), value, aflags|ASS_FORCE);
|
||||
else
|
||||
bind_array_variable (name, 0, value, aflags);
|
||||
bind_array_variable (name, 0, value, aflags|ASS_FORCE);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
/* XXX - no ASS_FORCE here */
|
||||
/* bind_variable_value duplicates the essential internals of
|
||||
bind_variable() */
|
||||
if (offset)
|
||||
@@ -811,11 +839,14 @@ declare_internal (list, local_var)
|
||||
v = bind_variable_value (var, value, aflags);
|
||||
if (v == 0 && (onref || nameref_p (var)))
|
||||
{
|
||||
if (valid_nameref_value (value, 0) == 0)
|
||||
if (valid_nameref_value (value, 1) == 0)
|
||||
sh_invalidid (value);
|
||||
assign_error++;
|
||||
/* XXX - unset this variable? or leave it as normal var? */
|
||||
delete_var (var->name, mkglobal ? global_variables : shell_variables);
|
||||
if (created_var)
|
||||
delete_var (var->name, mkglobal ? global_variables : shell_variables);
|
||||
flags_on |= onref; /* undo change from above */
|
||||
flags_off |= offref;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ parse_and_execute (string, from_file, flags)
|
||||
current_token = '\n'; /* reset_parser() ? */
|
||||
|
||||
with_input_from_string (string, from_file);
|
||||
clear_shell_input_line ();
|
||||
while (*(bash_input.location.string))
|
||||
{
|
||||
command = (COMMAND *)NULL;
|
||||
@@ -497,7 +498,7 @@ parse_string (string, from_file, flags, endp)
|
||||
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &ps_sigmask);
|
||||
#endif
|
||||
|
||||
/* itrace("parse_string: `%s'", string); */
|
||||
/*itrace("parse_string: `%s'", string);*/
|
||||
/* Reset the line number if the caller wants us to. If we don't reset the
|
||||
line number, we have to subtract one, because we will add one just
|
||||
before executing the next command (resetting the line number sets it to
|
||||
|
||||
+20
-5
@@ -808,7 +808,7 @@ unset_builtin (list)
|
||||
{
|
||||
int unset_function, unset_variable, unset_array, opt, nameref, any_failed;
|
||||
int global_unset_func, global_unset_var;
|
||||
char *name;
|
||||
char *name, *tname;
|
||||
|
||||
unset_function = unset_variable = unset_array = nameref = any_failed = 0;
|
||||
global_unset_func = global_unset_var = 0;
|
||||
@@ -859,7 +859,7 @@ unset_builtin (list)
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
unset_array = 0;
|
||||
if (!unset_function && valid_array_reference (name, 0))
|
||||
if (!unset_function && nameref == 0 && valid_array_reference (name, 0))
|
||||
{
|
||||
t = strchr (name, '[');
|
||||
*t++ = '\0';
|
||||
@@ -897,7 +897,7 @@ unset_builtin (list)
|
||||
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 == 0 && nameref == 0 && unset_variable == 0 && unset_function == 0)
|
||||
{
|
||||
if (var = find_function (name))
|
||||
unset_function = 1;
|
||||
@@ -932,7 +932,22 @@ unset_builtin (list)
|
||||
if (var == 0 && nameref == 0 && unset_function == 0)
|
||||
{
|
||||
var = find_variable_last_nameref (name, 0);
|
||||
tem = (var && nameref_p (var)) ? unbind_variable (nameref_cell (var)) : unbind_variable (name);
|
||||
if (var && nameref_p (var))
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (valid_array_reference (nameref_cell (var), 0))
|
||||
{
|
||||
tname = savestring (nameref_cell (var));
|
||||
if (var = array_variable_part (tname, &t, 0))
|
||||
tem = unbind_array_element (var, t);
|
||||
free (tname);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
tem = unbind_variable (nameref_cell (var));
|
||||
}
|
||||
else
|
||||
tem = unbind_variable (name);
|
||||
}
|
||||
else
|
||||
tem = unset_function ? unbind_func (name) : (nameref ? unbind_nameref (name) : unbind_variable (name));
|
||||
@@ -941,7 +956,7 @@ unset_builtin (list)
|
||||
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)
|
||||
if (tem == -1 && nameref == 0 && unset_function == 0 && unset_variable == 0)
|
||||
tem = unbind_func (name);
|
||||
|
||||
name = list->word->word; /* reset above for namerefs */
|
||||
|
||||
Reference in New Issue
Block a user