diff options
Diffstat (limited to 'builtins/set.def')
-rw-r--r-- | builtins/set.def | 96 |
1 files changed, 53 insertions, 43 deletions
diff --git a/builtins/set.def b/builtins/set.def index 74f2e5c..b5ac83b 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -24,6 +24,9 @@ $PRODUCES set.c #include <config.h> #if defined (HAVE_UNISTD_H) +# ifdef _MINIX +# include <sys/types.h> +# endif # include <unistd.h> #endif @@ -229,31 +232,20 @@ minus_o_option_value (name) #define MINUS_O_FORMAT "%-15s\t%s\n" -void -list_minus_o_opts (mode) - int mode; +static void +print_minus_o_option (name, value, pflag) + char *name; + int value, pflag; { - register int i; - int *on_or_off, value; - - for (value = i = 0; o_options[i].name; i++) - { - 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) - printf (MINUS_O_FORMAT, o_options[i].name, *on_or_off ? on : off); - } - for (i = 0; binary_o_options[i].name; i++) - { - value = GET_BINARY_O_OPTION_VALUE (i, binary_o_options[i].name); - if (mode == -1 || mode == value) - printf (MINUS_O_FORMAT, binary_o_options[i].name, value ? on : off); - } + if (pflag == 0) + printf (MINUS_O_FORMAT, name, value ? on : off); + else + printf ("set %co %s\n", value ? '-' : '+', name); } -static void -minus_o_option_commands () +void +list_minus_o_opts (mode, reusable) + int mode, reusable; { register int i; int *on_or_off, value; @@ -263,12 +255,14 @@ minus_o_option_commands () on_or_off = find_flag (o_options[i].letter); if (on_or_off == FLAG_UNKNOWN) on_or_off = &value; - printf ("set %co %s\n", *on_or_off ? '-' : '+', o_options[i].name); + if (mode == -1 || mode == *on_or_off) + print_minus_o_option (o_options[i].name, *on_or_off, reusable); } for (i = 0; binary_o_options[i].name; i++) { value = GET_BINARY_O_OPTION_VALUE (i, binary_o_options[i].name); - printf ("set %co %s\n", value ? '-' : '+', binary_o_options[i].name); + if (mode == -1 || mode == value) + print_minus_o_option (binary_o_options[i].name, value, reusable); } } @@ -421,7 +415,7 @@ void set_shellopts () { char *value; - int vsize, i, vptr, *ip; + int vsize, i, vptr, *ip, exported; SHELL_VAR *v; for (vsize = i = 0; o_options[i].name; i++) @@ -458,10 +452,25 @@ set_shellopts () 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) - v->attributes &= ~att_readonly; + { + v->attributes &= ~att_readonly; + exported = exported_p (v); + } + else + exported = 0; + v = bind_variable ("SHELLOPTS", value); + + /* 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. */ v->attributes |= att_readonly; + if (mark_modified_vars && exported == 0 && exported_p (v)) + v->attributes &= ~att_exported; free (value); } @@ -482,20 +491,24 @@ parse_shellopts (value) } void -initialize_shell_options () +initialize_shell_options (no_shellopts) + int no_shellopts; { char *temp; SHELL_VAR *var; - var = find_variable ("SHELLOPTS"); - /* set up any shell options we may have inherited. */ - if (var && imported_p (var)) + if (no_shellopts == 0) { - temp = (array_p (var)) ? (char *)NULL : savestring (value_cell (var)); - if (temp) + var = find_variable ("SHELLOPTS"); + /* set up any shell options we may have inherited. */ + if (var && imported_p (var)) { - parse_shellopts (temp); - free (temp); + temp = (array_p (var)) ? (char *)NULL : savestring (value_cell (var)); + if (temp) + { + parse_shellopts (temp); + free (temp); + } } } @@ -607,10 +620,7 @@ set_builtin (list) if (opt == 0) { - if (on_or_off == '-') - list_minus_o_opts (-1); - else - minus_o_option_commands (); + list_minus_o_opts (-1, (on_or_off == '+')); continue; } @@ -619,10 +629,7 @@ set_builtin (list) if (option_name == 0 || *option_name == '\0' || *option_name == '-' || *option_name == '+') { - if (on_or_off == '-') - list_minus_o_opts (-1); - else - minus_o_option_commands (); + list_minus_o_opts (-1, (on_or_off == '+')); continue; } list = list->next; /* Skip over option name. */ @@ -730,7 +737,10 @@ unset_builtin (list) } #endif - if (legal_identifier (name) == 0) + /* 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) { builtin_error ("`%s': not a valid identifier", name); NEXT_VARIABLE (); |