summaryrefslogtreecommitdiff
path: root/builtins/setattr.def
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 14:49:26 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 15:19:40 -0700
commit011c1d1c0766c65517ebd495465c99e86edb63ec (patch)
tree30d8f6a13235af90897c3223554871ef52225462 /builtins/setattr.def
parent40cfaccf7b178b6239b5cd0013ef80b7ff8e503e (diff)
downloadvyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.tar.gz
vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.zip
Update to bash-4.1
Diffstat (limited to 'builtins/setattr.def')
-rw-r--r--builtins/setattr.def151
1 files changed, 112 insertions, 39 deletions
diff --git a/builtins/setattr.def b/builtins/setattr.def
index 28102bc..8b4cdf7 100644
--- a/builtins/setattr.def
+++ b/builtins/setattr.def
@@ -1,23 +1,22 @@
This file is setattr.def, from which is created setattr.c.
It implements the builtins "export" and "readonly", in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+Bash is 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.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+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
@@ -52,14 +51,21 @@ extern int declare_builtin __P((WORD_LIST *));
$BUILTIN export
$FUNCTION export_builtin
-$SHORT_DOC export [-nf] [name[=value] ...] or export -p
-NAMEs are marked for automatic export to the environment of
-subsequently executed commands. If the -f option is given,
-the NAMEs refer to functions. If no NAMEs are given, or if `-p'
-is given, a list of all names that are exported in this shell is
-printed. An argument of `-n' says to remove the export property
-from subsequent NAMEs. An argument of `--' disables further option
-processing.
+$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
@@ -77,13 +83,22 @@ export_builtin (list)
$BUILTIN readonly
$FUNCTION readonly_builtin
$SHORT_DOC readonly [-af] [name[=value] ...] or readonly -p
-The given NAMEs are marked readonly and the values of these NAMEs may
-not be changed by subsequent assignment. If the -f option is given,
-then functions corresponding to the NAMEs are so marked. If no
-arguments are given, or if `-p' is given, a list of all readonly names
-is printed. The `-a' option means to treat each NAME as
-an array variable. An argument of `--' disables further option
-processing.
+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
@@ -96,7 +111,7 @@ readonly_builtin (list)
}
#if defined (ARRAY_VARS)
-# define ATTROPTS "afnp"
+# define ATTROPTS "aAfnp"
#else
# define ATTROPTS "fnp"
#endif
@@ -110,7 +125,8 @@ set_or_show_attributes (list, attribute, nodefs)
int attribute, nodefs;
{
register SHELL_VAR *var;
- int assign, undo, functions_only, arrays_only, any_failed, assign_error, opt;
+ int assign, undo, any_failed, assign_error, opt;
+ int functions_only, arrays_only, assoc_only;
int aflags;
char *name;
#if defined (ARRAY_VARS)
@@ -118,7 +134,8 @@ set_or_show_attributes (list, attribute, nodefs)
WORD_DESC *w;
#endif
- undo = functions_only = arrays_only = any_failed = assign_error = 0;
+ 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)
@@ -133,8 +150,11 @@ set_or_show_attributes (list, attribute, nodefs)
break;
#if defined (ARRAY_VARS)
case 'a':
- arrays_only = 1;
- break;
+ arrays_only = 1;
+ break;
+ case 'A':
+ assoc_only = 1;
+ break;
#endif
case 'p':
break;
@@ -206,11 +226,11 @@ set_or_show_attributes (list, attribute, nodefs)
#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)
+ if (arrays_only || assoc_only)
{
tlist = list->next;
list->next = (WORD_LIST *)NULL;
- w = make_word ("-ra");
+ w = arrays_only ? make_word ("-ra") : make_word ("-rA");
nlist = make_word_list (w, list);
opt = declare_builtin (nlist);
if (opt != EXECUTION_SUCCESS)
@@ -257,6 +277,12 @@ set_or_show_attributes (list, attribute, nodefs)
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)
@@ -266,9 +292,15 @@ set_or_show_attributes (list, attribute, nodefs)
#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);
+ {
+ show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
+ if (any_failed = sh_chkwrite (any_failed))
+ break;
+ }
}
free (variable_list);
}
@@ -279,6 +311,30 @@ set_or_show_attributes (list, attribute, nodefs)
: 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'.
@@ -290,7 +346,7 @@ show_var_attributes (var, pattr, nodefs)
SHELL_VAR *var;
int pattr, nodefs;
{
- char flags[8], *x;
+ char flags[16], *x;
int i;
i = 0;
@@ -301,6 +357,9 @@ show_var_attributes (var, pattr, nodefs)
#if defined (ARRAY_VARS)
if (array_p (var))
flags[i++] = 'a';
+
+ if (assoc_p (var))
+ flags[i++] = 'A';
#endif
if (function_p (var))
@@ -317,12 +376,24 @@ show_var_attributes (var, pattr, nodefs)
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))
@@ -336,7 +407,7 @@ show_var_attributes (var, pattr, nodefs)
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), 1));
+ 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' */
@@ -350,8 +421,10 @@ show_var_attributes (var, pattr, nodefs)
printf ("%s ", this_command_name);
#if defined (ARRAY_VARS)
- if (array_p (var))
+ 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
@@ -359,7 +432,7 @@ show_var_attributes (var, pattr, nodefs)
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), 1));
+ printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
else if (invisible_p (var))
printf ("%s\n", var->name);
else