This file is shopt.def, from which is created shopt.c.
It implements the Bash `shopt' builtin.
-Copyright (C) 1994 Free Software Foundation, Inc.
+Copyright (C) 1994-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
$PRODUCES shopt.c
$BUILTIN shopt
-$DOCNAME shopt_builtin
$FUNCTION shopt_builtin
$SHORT_DOC shopt [-pqsu] [-o long-option] optname [optname...]
Toggle the values of variables controlling optional behavior.
#include <stdio.h>
+#include "../bashintl.h"
+
#include "../shell.h"
#include "../flags.h"
#include "common.h"
#define OPTFMT "%-15s\t%s\n"
-extern int allow_null_glob_expansion, glob_dot_filenames;
+extern int allow_null_glob_expansion, fail_glob_expansion, glob_dot_filenames;
extern int cdable_vars, mail_warning, source_uses_path;
extern int no_exit_on_failed_exec, print_shift_error;
-extern int check_hashed_filenames, promptvars, interactive_comments;
+extern int check_hashed_filenames, promptvars;
extern int cdspelling, expand_aliases;
+extern int extended_quote;
extern int check_window_size;
-extern int glob_ignore_case;
+extern int glob_ignore_case, match_ignore_case;
extern int hup_on_exit;
extern int xpg_echo;
+extern int gnu_error_format;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
#if defined (READLINE)
extern int hist_verify, history_reediting, perform_hostname_completion;
extern int no_empty_command_completion;
-extern void enable_hostname_completion ();
+extern int force_fignore;
+extern int enable_hostname_completion __P((int));
#endif
#if defined (PROGRAMMABLE_COMPLETION)
#endif
#if defined (RESTRICTED_SHELL)
-extern int restricted_shell;
extern char *shell_name;
#endif
-extern void set_shellopts ();
+#if defined (DEBUGGER)
+extern int debugging_mode;
+#endif
+
+static void shopt_error __P((char *));
-static int set_interactive_comments ();
+static int set_shellopts_after_change __P((int));
+
+static int set_compatibility_level __P((int));
#if defined (RESTRICTED_SHELL)
-static int set_restricted_shell ();
+static int set_restricted_shell __P((int));
#endif
+static int shopt_login_shell;
+static int shopt_compat31;
+
+typedef int shopt_set_func_t __P((int));
+
static struct {
char *name;
int *value;
- Function *set_func;
+ shopt_set_func_t *set_func;
} shopt_vars[] = {
- { "cdable_vars", &cdable_vars, (Function *)NULL },
- { "cdspell", &cdspelling, (Function *)NULL },
- { "checkhash", &check_hashed_filenames, (Function *)NULL },
- { "checkwinsize", &check_window_size, (Function *)NULL },
+ { "cdable_vars", &cdable_vars, (shopt_set_func_t *)NULL },
+ { "cdspell", &cdspelling, (shopt_set_func_t *)NULL },
+ { "checkhash", &check_hashed_filenames, (shopt_set_func_t *)NULL },
+ { "checkwinsize", &check_window_size, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
- { "cmdhist", &command_oriented_history, (Function *)NULL },
+ { "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL },
+#endif
+ { "compat31", &shopt_compat31, set_compatibility_level },
+ { "dotglob", &glob_dot_filenames, (shopt_set_func_t *)NULL },
+ { "execfail", &no_exit_on_failed_exec, (shopt_set_func_t *)NULL },
+ { "expand_aliases", &expand_aliases, (shopt_set_func_t *)NULL },
+#if defined (DEBUGGER)
+ { "extdebug", &debugging_mode, (shopt_set_func_t *)NULL },
#endif
- { "dotglob", &glob_dot_filenames, (Function *)NULL },
- { "execfail", &no_exit_on_failed_exec, (Function *)NULL },
- { "expand_aliases", &expand_aliases, (Function *)NULL },
#if defined (EXTENDED_GLOB)
- { "extglob", &extended_glob, (Function *)NULL },
+ { "extglob", &extended_glob, (shopt_set_func_t *)NULL },
#endif
+ { "extquote", &extended_quote, (shopt_set_func_t *)NULL },
+ { "failglob", &fail_glob_expansion, (shopt_set_func_t *)NULL },
#if defined (READLINE)
- { "histreedit", &history_reediting, (Function *)NULL },
+ { "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
#endif
+ { "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
- { "histappend", &force_append_history, (Function *)NULL },
+ { "histappend", &force_append_history, (shopt_set_func_t *)NULL },
#endif
#if defined (READLINE)
- { "histverify", &hist_verify, (Function *)NULL },
- { "hostcomplete", &perform_hostname_completion, (Function *)enable_hostname_completion },
+ { "histreedit", &history_reediting, (shopt_set_func_t *)NULL },
+ { "histverify", &hist_verify, (shopt_set_func_t *)NULL },
+ { "hostcomplete", &perform_hostname_completion, enable_hostname_completion },
#endif
- { "huponexit", &hup_on_exit, (Function *)NULL },
- { "interactive_comments", &interactive_comments, set_interactive_comments },
+ { "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL },
+ { "interactive_comments", &interactive_comments, set_shellopts_after_change },
#if defined (HISTORY)
- { "lithist", &literal_history, (Function *)NULL },
+ { "lithist", &literal_history, (shopt_set_func_t *)NULL },
#endif
- { "mailwarn", &mail_warning, (Function *)NULL },
+ { "login_shell", &shopt_login_shell, set_login_shell },
+ { "mailwarn", &mail_warning, (shopt_set_func_t *)NULL },
#if defined (READLINE)
- { "no_empty_cmd_completion", &no_empty_command_completion, (Function *)NULL },
+ { "no_empty_cmd_completion", &no_empty_command_completion, (shopt_set_func_t *)NULL },
#endif
- { "nocaseglob", &glob_ignore_case, (Function *)NULL },
- { "nullglob", &allow_null_glob_expansion, (Function *)NULL },
+ { "nocaseglob", &glob_ignore_case, (shopt_set_func_t *)NULL },
+ { "nocasematch", &match_ignore_case, (shopt_set_func_t *)NULL },
+ { "nullglob", &allow_null_glob_expansion, (shopt_set_func_t *)NULL },
#if defined (PROGRAMMABLE_COMPLETION)
- { "progcomp", &prog_completion_enabled, (Function *)NULL },
+ { "progcomp", &prog_completion_enabled, (shopt_set_func_t *)NULL },
#endif
- { "promptvars", &promptvars, (Function *)NULL },
+ { "promptvars", &promptvars, (shopt_set_func_t *)NULL },
#if defined (RESTRICTED_SHELL)
{ "restricted_shell", &restricted_shell, set_restricted_shell },
#endif
- { "shift_verbose", &print_shift_error, (Function *)NULL },
- { "sourcepath", &source_uses_path, (Function *)NULL },
- { "xpg_echo", &xpg_echo, (Function *)NULL },
- { (char *)0, (int *)0, (Function *)NULL }
+ { "shift_verbose", &print_shift_error, (shopt_set_func_t *)NULL },
+ { "sourcepath", &source_uses_path, (shopt_set_func_t *)NULL },
+ { "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL },
+ { (char *)0, (int *)0, (shopt_set_func_t *)NULL }
};
static char *on = "on";
static char *off = "off";
-static int list_shopt_o_options ();
-static int list_some_o_options (), list_some_shopts ();
-static int toggle_shopts (), list_shopts (), set_shopt_o_options ();
+static int find_shopt __P((char *));
+static int toggle_shopts __P((int, WORD_LIST *, int));
+static void print_shopt __P((char *, int, int));
+static int list_shopts __P((WORD_LIST *, int));
+static int list_some_shopts __P((int, int));
+static int list_shopt_o_options __P((WORD_LIST *, int));
+static int list_some_o_options __P((int, int));
+static int set_shopt_o_options __P((int, WORD_LIST *, int));
#define SFLAG 0x01
#define UFLAG 0x02
if ((flags & (SFLAG|UFLAG)) == (SFLAG|UFLAG))
{
- builtin_error ("cannot set and unset shell options simultaneously");
+ builtin_error (_("cannot set and unset shell options simultaneously"));
return (EXECUTION_FAILURE);
}
hist_verify = history_reediting = 0;
perform_hostname_completion = 1;
#endif
+
+ shopt_login_shell = login_shell;
}
static int
return -1;
}
-#define SHOPT_ERROR(str) builtin_error ("%s: unknown shell option name", str)
+static void
+shopt_error (s)
+ char *s;
+{
+ builtin_error (_("%s: invalid shell option name"), s);
+}
static int
toggle_shopts (mode, list, quiet)
ind = find_shopt (l->word->word);
if (ind < 0)
{
- SHOPT_ERROR (l->word->word);
+ shopt_error (l->word->word);
rval = EXECUTION_FAILURE;
}
else
i = find_shopt (l->word->word);
if (i < 0)
{
- SHOPT_ERROR (l->word->word);
+ shopt_error (l->word->word);
rval = EXECUTION_FAILURE;
continue;
}
if (val == 0)
rval = EXECUTION_FAILURE;
if ((flags & QFLAG) == 0)
- print_shopt (l->word->word, val, flags);
+ print_shopt (l->word->word, val, flags);
}
+
return (rval);
}
val = minus_o_option_value (l->word->word);
if (val == -1)
{
- builtin_error ("%s: unknown option name", l->word->word);
+ sh_invalidoptname (l->word->word);
rval = EXECUTION_FAILURE;
continue;
}
/* If we set or unset interactive_comments with shopt, make sure the
change is reflected in $SHELLOPTS. */
static int
-set_interactive_comments (mode)
+set_shellopts_after_change (mode)
int mode;
{
set_shellopts ();
return (0);
}
+static int
+set_compatibility_level (mode)
+ int mode;
+{
+ /* Need to change logic here as we add more compatibility levels */
+ if (shopt_compat31)
+ shell_compatibility_level = 31;
+ else
+ shell_compatibility_level = 32;
+ return 0;
+}
+
#if defined (RESTRICTED_SHELL)
/* Don't allow the value of restricted_shell to be modified. */
}
#endif /* RESTRICTED_SHELL */
+/* Not static so shell.c can call it to initialize shopt_login_shell */
+int
+set_login_shell (mode)
+ int mode;
+{
+ shopt_login_shell = login_shell != 0;
+ return (0);
+}
+
char **
get_shopt_options ()
{
int n, i;
n = sizeof (shopt_vars) / sizeof (shopt_vars[0]);
- ret = alloc_array (n + 1);
+ ret = strvec_create (n + 1);
for (i = 0; shopt_vars[i].name; i++)
ret[i] = savestring (shopt_vars[i].name);
ret[i] = (char *)NULL;
return ret;
}
+
+/*
+ * External interface for other parts of the shell. NAME is a string option;
+ * MODE is 0 if we want to unset an option; 1 if we want to set an option.
+ * REUSABLE is 1 if we want to print output in a form that may be reused.
+ */
+int
+shopt_setopt (name, mode)
+ char *name;
+ int mode;
+{
+ WORD_LIST *wl;
+ int r;
+
+ wl = add_string_to_list (name, (WORD_LIST *)NULL);
+ r = toggle_shopts (mode, wl, 0);
+ dispose_words (wl);
+ return r;
+}
+
+int
+shopt_listopt (name, reusable)
+ char *name;
+ int reusable;
+{
+ int i;
+
+ if (name == 0)
+ return (list_shopts ((WORD_LIST *)NULL, reusable ? PFLAG : 0));
+
+ i = find_shopt (name);
+ if (i < 0)
+ {
+ shopt_error (name);
+ return (EXECUTION_FAILURE);
+ }
+
+ print_shopt (name, *shopt_vars[i].value, reusable ? PFLAG : 0);
+ return (EXECUTION_SUCCESS);
+}