summaryrefslogtreecommitdiff
path: root/builtins/declare.def~
diff options
context:
space:
mode:
Diffstat (limited to 'builtins/declare.def~')
-rw-r--r--builtins/declare.def~131
1 files changed, 97 insertions, 34 deletions
diff --git a/builtins/declare.def~ b/builtins/declare.def~
index e129ae52..52fa829c 100644
--- a/builtins/declare.def~
+++ b/builtins/declare.def~
@@ -5,25 +5,24 @@ Copyright (C) 1987-2008 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 declare.c
$BUILTIN declare
$FUNCTION declare_builtin
-$SHORT_DOC declare [-afFirtx] [-p] [name[=value] ...]
+$SHORT_DOC declare [-aAfFilrtux] [-p] [name[=value] ...]
Set variable values and attributes.
Declare variables and give them attributes. If no NAMEs are given,
@@ -36,10 +35,13 @@ Options:
-p display the attributes and value of each NAME
Options which set attributes:
- -a to make NAMEs arrays (if supported)
+ -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
-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.
@@ -56,7 +58,7 @@ $END
$BUILTIN typeset
$FUNCTION declare_builtin
-$SHORT_DOC typeset [-afFirtx] [-p] name[=value] ...
+$SHORT_DOC typeset [-aAfFilrtux] [-p] name[=value] ...
Set variable values and attributes.
Obsolete. See `help declare'.
@@ -123,9 +125,9 @@ local_builtin (list)
}
#if defined (ARRAY_VARS)
-# define DECLARE_OPTS "+afiprtxF"
+# define DECLARE_OPTS "+acfilprtuxAF"
#else
-# define DECLARE_OPTS "+fiprtxF"
+# define DECLARE_OPTS "+cfilprtuxF"
#endif
/* The workhorse function. */
@@ -134,7 +136,8 @@ declare_internal (list, local_var)
register WORD_LIST *list;
int local_var;
{
- int flags_on, flags_off, *flags, any_failed, assign_error, pflag, nodefs, opt;
+ int flags_on, flags_off, *flags;
+ int any_failed, assign_error, pflag, nodefs, opt;
char *t, *subscript_start;
SHELL_VAR *var;
FUNCTION_DEF *shell_fn;
@@ -150,8 +153,19 @@ declare_internal (list, local_var)
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++;
@@ -176,6 +190,25 @@ declare_internal (list, local_var)
*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);
@@ -186,7 +219,7 @@ declare_internal (list, local_var)
/* If there are no more arguments left, then we just want to show
some variables. */
- if (list == 0) /* declare -[afFirtx] */
+ if (list == 0) /* declare -[aAfFirtx] */
{
/* Show local variables defined at this context level if this is
the `local' builtin. */
@@ -215,7 +248,7 @@ declare_internal (list, local_var)
return (sh_chkwrite (EXECUTION_SUCCESS));
}
- if (pflag) /* declare -p [-afFirtx] name [name...] */
+ if (pflag) /* declare -p [-aAfFirtx] name [name...] */
{
for (any_failed = 0; list; list = list->next)
{
@@ -232,7 +265,7 @@ declare_internal (list, local_var)
#define NEXT_VARIABLE() free (name); list = list->next; continue
/* There are arguments left, so we are making variables. */
- while (list) /* declare [-afFirx] name [name ...] */
+ while (list) /* declare [-aAfFirx] name [name ...] */
{
char *value, *name;
int offset, aflags;
@@ -244,7 +277,7 @@ declare_internal (list, local_var)
offset = assignment (name, 0);
aflags = 0;
- if (offset) /* declare [-afFirx] name=value */
+ if (offset) /* declare [-aAfFirx] name=value */
{
name[offset] = '\0';
value = name + offset + 1;
@@ -291,7 +324,9 @@ declare_internal (list, local_var)
if (variable_context && ((flags_on & att_function) == 0))
{
#if defined (ARRAY_VARS)
- if ((flags_on & att_array) || making_array_special)
+ 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);
else
#endif
@@ -364,7 +399,7 @@ declare_internal (list, local_var)
NEXT_VARIABLE ();
}
}
- else /* declare -[airx] name [name...] */
+ else /* declare -[aAirx] name [name...] */
{
/* Non-null if we just created or fetched a local variable. */
if (var == 0)
@@ -373,11 +408,21 @@ declare_internal (list, local_var)
if (var == 0)
{
#if defined (ARRAY_VARS)
- if ((flags_on & att_array) || making_array_special)
+ 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
- var = bind_variable (name, "", 0);
+
+ if (offset)
+ var = bind_variable (name, "", 0);
+ else
+ {
+ var = bind_variable (name, (char *)NULL, 0);
+ VSETATTR (var, att_invisible);
+ }
+#endif
}
/* Cannot use declare +r to turn off readonly attribute. */
@@ -399,30 +444,48 @@ declare_internal (list, local_var)
}
#if defined (ARRAY_VARS)
- if ((making_array_special || (flags_on & att_array) || array_p (var)) && offset)
+ if ((making_array_special || (flags_on & (att_array|att_assoc)) || array_p (var) || assoc_p (var)) && offset)
{
int vlen;
vlen = STRLEN (value);
-#if 0
- if (value[0] == '(' && strchr (value, ')'))
-#else
+
if (value[0] == '(' && value[vlen-1] == ')')
-#endif
compound_array_assign = 1;
else
simple_array_assign = 1;
}
- /* Cannot use declare +a name to remove an array variable. */
- if ((flags_off & att_array) && array_p (var))
+ /* 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 ();
}
- /* declare -a name makes name an array variable. */
- if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
+ 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)
var = convert_var_to_array (var);
#endif /* ARRAY_VARS */