diff options
author | Chet Ramey <chet.ramey@case.edu> | 2019-01-07 09:27:52 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2019-01-07 09:27:52 -0500 |
commit | d233b485e83c3a784b803fb894280773f16f2deb (patch) | |
tree | 16d51f3ccca2d4ad2d8f2da564d68ca848de595b /builtins/set.def | |
parent | 64447609994bfddeef1061948022c074093e9a9f (diff) | |
download | bash-d233b485e83c3a784b803fb894280773f16f2deb.tar.gz |
bash-5.0 distribution sources and documentationbash-5.0
Diffstat (limited to 'builtins/set.def')
-rw-r--r-- | builtins/set.def | 120 |
1 files changed, 68 insertions, 52 deletions
diff --git a/builtins/set.def b/builtins/set.def index 8122361e..d2bba434 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -1,7 +1,7 @@ This file is set.def, from which is created set.c. It implements the "set" and "unset" builtins in Bash. -Copyright (C) 1987-2015 Free Software Foundation, Inc. +Copyright (C) 1987-2018 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -35,6 +35,7 @@ $PRODUCES set.c #include "../bashintl.h" #include "../shell.h" +#include "../parser.h" #include "../flags.h" #include "common.h" #include "bashgetopt.h" @@ -49,14 +50,6 @@ $PRODUCES set.c # 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 ...] @@ -161,6 +154,8 @@ $END typedef int setopt_set_func_t __P((int, char *)); typedef int setopt_get_func_t __P((char *)); +static int find_minus_o_option __P((char *)); + static void print_minus_o_option __P((char *, int, int)); static void print_all_shell_variables __P((void)); @@ -249,6 +244,18 @@ const struct { ((o_options[i].set_func) ? (*o_options[i].set_func) (onoff, name) \ : (*o_options[i].variable = (onoff == FLAG_ON))) +static int +find_minus_o_option (name) + char *name; +{ + register int i; + + for (i = 0; o_options[i].name; i++) + if (STREQ (name, o_options[i].name)) + return i; + return -1; +} + int minus_o_option_value (name) char *name; @@ -256,21 +263,17 @@ minus_o_option_value (name) register int i; int *on_or_off; - for (i = 0; o_options[i].name; i++) + i = find_minus_o_option (name); + if (i < 0) + return (-1); + + if (o_options[i].letter) { - 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)); - } + on_or_off = find_flag (o_options[i].letter); + return ((on_or_off == FLAG_UNKNOWN) ? -1 : *on_or_off); } - - return (-1); + else + return (GET_BINARY_O_OPTION_VALUE (i, name)); } #define MINUS_O_FORMAT "%-15s\t%s\n" @@ -330,9 +333,12 @@ char * get_current_options () { char *temp; - int i; + int i, posixopts; - temp = (char *)xmalloc (1 + N_O_OPTIONS); + posixopts = num_posix_options (); /* shopts modified by posix mode */ + /* Make the buffer big enough to hold the set -o options and the shopt + options modified by posix mode. */ + temp = (char *)xmalloc (1 + N_O_OPTIONS + posixopts); for (i = 0; o_options[i].name; i++) { if (o_options[i].letter) @@ -340,7 +346,11 @@ get_current_options () else temp[i] = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name); } - temp[i] = '\0'; + + /* Add the shell options that are modified by posix mode to the end of the + bitmap. They will be handled in set_current_options() */ + get_posix_options (temp+i); + temp[i+posixopts] = '\0'; return (temp); } @@ -352,6 +362,7 @@ set_current_options (bitmap) if (bitmap == 0) return; + for (i = 0; o_options[i].name; i++) { if (o_options[i].letter) @@ -359,6 +370,9 @@ set_current_options (bitmap) else SET_BINARY_O_OPTION_VALUE (i, bitmap[i] ? FLAG_ON : FLAG_OFF, o_options[i].name); } + + /* Now reset the variables changed by posix mode */ + set_posix_options (bitmap+i); } static int @@ -458,32 +472,29 @@ set_minus_o_option (on_or_off, option_name) { register int i; - for (i = 0; o_options[i].name; i++) + i = find_minus_o_option (option_name); + if (i < 0) { - if (STREQ (option_name, o_options[i].name)) - { - if (o_options[i].letter == 0) - { - previous_option_value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name); - SET_BINARY_O_OPTION_VALUE (i, on_or_off, option_name); - return (EXECUTION_SUCCESS); - } - else - { - if ((previous_option_value = 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); + } + if (o_options[i].letter == 0) + { + previous_option_value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name); + SET_BINARY_O_OPTION_VALUE (i, on_or_off, option_name); + return (EXECUTION_SUCCESS); + } + else + { + if ((previous_option_value = 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 @@ -807,7 +818,7 @@ unset_builtin (list) WORD_LIST *list; { int unset_function, unset_variable, unset_array, opt, nameref, any_failed; - int global_unset_func, global_unset_var; + int global_unset_func, global_unset_var, vflags; char *name, *tname; unset_function = unset_variable = unset_array = nameref = any_failed = 0; @@ -844,6 +855,10 @@ unset_builtin (list) else if (unset_function && nameref) nameref = 0; +#if defined (ARRAY_VARS) + vflags = assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0; +#endif + while (list) { SHELL_VAR *var; @@ -859,7 +874,8 @@ unset_builtin (list) #if defined (ARRAY_VARS) unset_array = 0; - if (!unset_function && nameref == 0 && valid_array_reference (name, 0)) + /* XXX valid array reference second arg was 0 */ + if (!unset_function && nameref == 0 && valid_array_reference (name, vflags)) { t = strchr (name, '['); *t++ = '\0'; @@ -916,7 +932,7 @@ unset_builtin (list) if (var && unset_array) { /* Let unbind_array_element decide what to do with non-array vars */ - tem = unbind_array_element (var, t); + tem = unbind_array_element (var, t, vflags); /* XXX new third arg */ if (tem == -2 && array_p (var) == 0 && assoc_p (var) == 0) { builtin_error (_("%s: not an array variable"), var->name); @@ -938,8 +954,8 @@ unset_builtin (list) 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); + if (var = array_variable_part (tname, 0, &t, (int *)0)) + tem = unbind_array_element (var, t, vflags); /* XXX new third arg */ free (tname); } else |