Imported from ../bash-2.05.tar.gz.
[platform/upstream/bash.git] / flags.c
diff --git a/flags.c b/flags.c
index 856698d..8d2f7f5 100644 (file)
--- a/flags.c
+++ b/flags.c
@@ -7,7 +7,7 @@ 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 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
 version.
 
 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -17,7 +17,7 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
 
 /* Flags hacking. */
 #include "config.h"
@@ -32,6 +32,13 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
 extern int set_job_control ();
 #endif
 
+#if defined (RESTRICTED_SHELL)
+extern char *shell_name;
+#endif
+
+/* -c, -s invocation options -- not really flags, but they show up in $- */
+extern int want_pending_command, read_from_stdin;
+
 /* **************************************************************** */
 /*                                                                 */
 /*                     The Standard Sh Flags.                      */
@@ -125,12 +132,14 @@ int interactive_comments = 1;
    disallows: changing directories, command or path names containing `/',
    unsetting or resetting the values of $PATH and $SHELL, and any type of
    output redirection. */
-int restricted = 0;
+int restricted = 0;            /* currently restricted */
+int restricted_shell = 0;      /* shell was started in restricted mode. */
 #endif /* RESTRICTED_SHELL */
 
 /* Non-zero means that this shell is running in `privileged' mode.  This
-   mode is entered on startup if the real and effective uids or gids
-   differ. */
+   is required if the shell is to run setuid.  If the `-p' option is
+   not supplied at startup, and the real and effective uids or gids
+   differ, disable_priv_mode is called to relinquish setuid status. */
 int privileged_mode = 0;
 
 #if defined (BRACE_EXPANSION)
@@ -204,8 +213,8 @@ find_flag (name)
 }
 
 /* Change the state of a flag, and return it's original value, or return
-   FLAG_ERROR if there is no flag called NAME.  ON_OR_OFF should be one
-   of FLAG_ON or FLAG_OFF. */
+   FLAG_ERROR if there is no flag FLAG.  ON_OR_OFF must be either
+   FLAG_ON or FLAG_OFF. */
 int
 change_flag (flag, on_or_off)
   int flag;
@@ -213,37 +222,46 @@ change_flag (flag, on_or_off)
 {
   int *value, old_value;
 
-  value = find_flag (flag);
-
 #if defined (RESTRICTED_SHELL)
   /* Don't allow "set +r" in a shell which is `restricted'. */
   if (restricted && flag == 'r' && on_or_off == FLAG_OFF)
     return (FLAG_ERROR);
 #endif /* RESTRICTED_SHELL */
 
-  if (value == (int *)FLAG_UNKNOWN)
+  value = find_flag (flag);
+
+  if ((value == (int *)FLAG_UNKNOWN) || (on_or_off != FLAG_ON && on_or_off != FLAG_OFF))
     return (FLAG_ERROR);
 
   old_value = *value;
 
-  if (on_or_off == FLAG_ON)
-    *value = 1;
-  else if (on_or_off == FLAG_OFF)
-    *value = 0;
-  else
-    return (FLAG_ERROR);
+  *value = (on_or_off == FLAG_ON) ? 1 : 0;
 
   /* Special cases for a few flags. */
   switch (flag)
     {
 #if defined (JOB_CONTROL)
     case 'm':
-      set_job_control (on_or_off == '-');
+      set_job_control (on_or_off == FLAG_ON);
       break;
 #endif /* JOB_CONTROL */
 
+#if defined (RESTRICTED_SHELL)
+    case 'r':
+      if (on_or_off == FLAG_ON)
+       maybe_make_restricted (shell_name);
+      break;
+#endif
+
+#if defined (BANG_HISTORY)
+    case 'H':
+      if (on_or_off == FLAG_ON)
+       bash_initialize_history ();
+      break;
+#endif
+
     case 'p':
-      if (on_or_off == '+')
+      if (on_or_off == FLAG_OFF)
        disable_priv_mode ();
 
       break;
@@ -260,11 +278,44 @@ which_set_flags ()
   char *temp;
   int i, string_index;
 
-  temp = xmalloc (1 + NUM_SHELL_FLAGS);
+  temp = xmalloc (1 + NUM_SHELL_FLAGS + read_from_stdin + want_pending_command);
   for (i = string_index = 0; shell_flags[i].name; i++)
     if (*(shell_flags[i].value))
       temp[string_index++] = shell_flags[i].name;
 
+  if (want_pending_command)
+    temp[string_index++] = 'c';
+  if (read_from_stdin)
+    temp[string_index++] = 's';
+
   temp[string_index] = '\0';
   return (temp);
 }
+
+void
+reset_shell_flags ()
+{
+  mark_modified_vars = exit_immediately_on_error = disallow_filename_globbing = 0;
+  place_keywords_in_env = read_but_dont_execute = just_one_command = 0;
+  noclobber = unbound_vars_is_error = echo_input_at_read = 0;
+  echo_command_at_execute = jobs_m_flag = forced_interactive = 0;
+  no_symbolic_links = no_invisible_vars = privileged_mode = 0;
+
+  hashing_enabled = interactive_comments = 1;
+
+#if defined (JOB_CONTROL)
+  asynchronous_notification = 0;
+#endif
+
+#if defined (BANG_HISTORY)
+  history_expansion = 1;
+#endif
+
+#if defined (BRACE_EXPANSION)
+  brace_expansion = 1;
+#endif
+
+#if defined (RESTRICTED_SHELL)
+  restricted = 0;
+#endif
+}