| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | This file is shopt.def, from which is created shopt.c. | 
					
						
							|  |  |  | It implements the Bash `shopt' builtin. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  | Copyright (C) 1994-2010 Free Software Foundation, Inc. | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | This file is part of GNU Bash, the Bourne Again SHell. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 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. | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 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. | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | along with Bash.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $PRODUCES shopt.c | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN shopt | 
					
						
							|  |  |  | $FUNCTION shopt_builtin | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | $SHORT_DOC shopt [-pqsu] [-o] [optname ...] | 
					
						
							|  |  |  | Set and unset shell options. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Change the setting of each shell option OPTNAME.  Without any option | 
					
						
							|  |  |  | arguments, list all shell options with an indication of whether or not each | 
					
						
							|  |  |  | is set.  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  |   -o	restrict OPTNAMEs to those defined for use with `set -o' | 
					
						
							|  |  |  |   -p	print each shell option with an indication of its status | 
					
						
							|  |  |  |   -q	suppress output | 
					
						
							|  |  |  |   -s	enable (set) each OPTNAME | 
					
						
							|  |  |  |   -u	disable (unset) each OPTNAME | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Exit Status: | 
					
						
							|  |  |  | Returns success if OPTNAME is enabled; fails if an invalid option is | 
					
						
							|  |  |  | given or OPTNAME is disabled. | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <config.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HAVE_UNISTD_H) | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #  ifdef _MINIX | 
					
						
							|  |  |  | #    include <sys/types.h> | 
					
						
							|  |  |  | #  endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  include <unistd.h> | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #include "version.h" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #include "../bashintl.h" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include "../shell.h" | 
					
						
							|  |  |  | #include "../flags.h" | 
					
						
							|  |  |  | #include "common.h" | 
					
						
							|  |  |  | #include "bashgetopt.h" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							|  |  |  | #  include "../bashhist.h" | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #define UNSETOPT	0 | 
					
						
							|  |  |  | #define SETOPT		1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define OPTFMT		"%-15s\t%s\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | extern int allow_null_glob_expansion, fail_glob_expansion, glob_dot_filenames; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | extern int cdable_vars, mail_warning, source_uses_path; | 
					
						
							|  |  |  | extern int no_exit_on_failed_exec, print_shift_error; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | extern int check_hashed_filenames, promptvars; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | extern int cdspelling, expand_aliases; | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | extern int extended_quote; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | extern int check_window_size; | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | extern int glob_ignore_case, match_ignore_case; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | extern int hup_on_exit; | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | extern int xpg_echo; | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | extern int gnu_error_format; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | extern int check_jobs_at_exit; | 
					
						
							|  |  |  | extern int autocd; | 
					
						
							|  |  |  | extern int glob_star; | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  | extern int lastpipe_opt; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined (EXTENDED_GLOB) | 
					
						
							|  |  |  | extern int extended_glob; | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | extern int hist_verify, history_reediting, perform_hostname_completion; | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | extern int no_empty_command_completion; | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | extern int force_fignore; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | extern int dircomplete_spelling; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | extern int enable_hostname_completion __P((int)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | #if defined (PROGRAMMABLE_COMPLETION) | 
					
						
							|  |  |  | extern int prog_completion_enabled; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #if defined (RESTRICTED_SHELL) | 
					
						
							|  |  |  | extern char *shell_name; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #if defined (DEBUGGER) | 
					
						
							|  |  |  | extern int debugging_mode; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | static void shopt_error __P((char *)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | static int set_shellopts_after_change __P((char *, int)); | 
					
						
							|  |  |  | static int shopt_enable_hostname_completion __P((char *, int)); | 
					
						
							|  |  |  | static int set_compatibility_level __P((char *, int)); | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #if defined (RESTRICTED_SHELL) | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | static int set_restricted_shell __P((char *, int)); | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static int shopt_login_shell; | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  | static int shopt_compat31; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | static int shopt_compat32; | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | static int shopt_compat40; | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  | static int shopt_compat41; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | typedef int shopt_set_func_t __P((char *, int)); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static struct { | 
					
						
							|  |  |  |   char *name; | 
					
						
							|  |  |  |   int  *value; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   shopt_set_func_t *set_func; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } shopt_vars[] = { | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   { "autocd", &autocd, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "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 }, | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #if defined (JOB_CONTROL) | 
					
						
							|  |  |  |   { "checkjobs", &check_jobs_at_exit, (shopt_set_func_t *)NULL }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "checkwinsize", &check_window_size, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |   { "compat31", &shopt_compat31, set_compatibility_level }, | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   { "compat32", &shopt_compat32, set_compatibility_level }, | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  |   { "compat40", &shopt_compat40, set_compatibility_level }, | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  |   { "compat41", &shopt_compat41, set_compatibility_level }, | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							|  |  |  |   { "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "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 }, | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #if defined (DEBUGGER) | 
					
						
							|  |  |  |   { "extdebug", &debugging_mode, (shopt_set_func_t *)NULL }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #if defined (EXTENDED_GLOB) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "extglob", &extended_glob, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   { "extquote", &extended_quote, (shopt_set_func_t *)NULL }, | 
					
						
							|  |  |  |   { "failglob", &fail_glob_expansion, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   { "force_fignore", &force_fignore, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   { "globstar", &glob_star, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |   { "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "histappend", &force_append_history, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |   { "histreedit", &history_reediting, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "histverify", &hist_verify, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  |   { "hostcomplete", &perform_hostname_completion, shopt_enable_hostname_completion }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   { "interactive_comments", &interactive_comments, set_shellopts_after_change }, | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  |   { "lastpipe", &lastpipe_opt, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "lithist", &literal_history, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "login_shell", &shopt_login_shell, set_login_shell }, | 
					
						
							|  |  |  |   { "mailwarn", &mail_warning, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | #if defined (READLINE) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "no_empty_cmd_completion", &no_empty_command_completion, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "nocaseglob", &glob_ignore_case, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |   { "nocasematch", &match_ignore_case, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "nullglob",	&allow_null_glob_expansion, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | #if defined (PROGRAMMABLE_COMPLETION) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "progcomp", &prog_completion_enabled, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "promptvars", &promptvars, (shopt_set_func_t *)NULL }, | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #if defined (RESTRICTED_SHELL) | 
					
						
							|  |  |  |   { "restricted_shell", &restricted_shell, set_restricted_shell }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { "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 } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | #define N_SHOPT_OPTIONS		(sizeof (shopt_vars) / sizeof (shopt_vars[0])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GET_SHOPT_OPTION_VALUE(i)	(*shopt_vars[i].value) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | static const char * const on = "on"; | 
					
						
							|  |  |  | static const char * const off = "off"; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 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)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define SFLAG	0x01 | 
					
						
							|  |  |  | #define UFLAG	0x02 | 
					
						
							|  |  |  | #define QFLAG	0x04 | 
					
						
							|  |  |  | #define OFLAG	0x08 | 
					
						
							|  |  |  | #define PFLAG	0x10 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | shopt_builtin (list) | 
					
						
							|  |  |  |      WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int opt, flags, rval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   flags = 0; | 
					
						
							|  |  |  |   reset_internal_getopt (); | 
					
						
							|  |  |  |   while ((opt = internal_getopt (list, "psuoq")) != -1) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       switch (opt) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case 's': | 
					
						
							|  |  |  | 	  flags |= SFLAG; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case 'u': | 
					
						
							|  |  |  | 	  flags |= UFLAG; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case 'q': | 
					
						
							|  |  |  | 	  flags |= QFLAG; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case 'o': | 
					
						
							|  |  |  | 	  flags |= OFLAG; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case 'p': | 
					
						
							|  |  |  | 	  flags |= PFLAG; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	  builtin_usage (); | 
					
						
							|  |  |  | 	  return (EX_USAGE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   list = loptend; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ((flags & (SFLAG|UFLAG)) == (SFLAG|UFLAG)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |       builtin_error (_("cannot set and unset shell options simultaneously")); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rval = EXECUTION_SUCCESS; | 
					
						
							|  |  |  |   if ((flags & OFLAG) && ((flags & (SFLAG|UFLAG)) == 0))	/* shopt -o */ | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |     rval = list_shopt_o_options (list, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else if (list && (flags & OFLAG))		/* shopt -so args */ | 
					
						
							|  |  |  |     rval = set_shopt_o_options ((flags & SFLAG) ? FLAG_ON : FLAG_OFF, list, flags & QFLAG); | 
					
						
							|  |  |  |   else if (flags & OFLAG)	/* shopt -so */ | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |     rval = list_some_o_options ((flags & SFLAG) ? 1 : 0, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else if (list && (flags & (SFLAG|UFLAG)))	/* shopt -su args */ | 
					
						
							|  |  |  |     rval = toggle_shopts ((flags & SFLAG) ? SETOPT : UNSETOPT, list, flags & QFLAG); | 
					
						
							|  |  |  |   else if ((flags & (SFLAG|UFLAG)) == 0)	/* shopt [args] */ | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |     rval = list_shopts (list, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else						/* shopt -su */ | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |     rval = list_some_shopts ((flags & SFLAG) ? SETOPT : UNSETOPT, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (rval); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | /* Reset the options managed by `shopt' to the values they would have at | 
					
						
							|  |  |  |    shell startup. */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | reset_shopt_options () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   allow_null_glob_expansion = glob_dot_filenames = 0; | 
					
						
							|  |  |  |   cdable_vars = mail_warning = 0; | 
					
						
							|  |  |  |   no_exit_on_failed_exec = print_shift_error = 0; | 
					
						
							|  |  |  |   check_hashed_filenames = cdspelling = expand_aliases = check_window_size = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   source_uses_path = promptvars = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #if defined (EXTENDED_GLOB) | 
					
						
							|  |  |  |   extended_glob = 0; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #if defined (HISTORY) | 
					
						
							|  |  |  |   literal_history = force_append_history = 0; | 
					
						
							|  |  |  |   command_oriented_history = 1; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (READLINE) | 
					
						
							|  |  |  |   hist_verify = history_reediting = 0; | 
					
						
							|  |  |  |   perform_hostname_completion = 1; | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   shopt_login_shell = login_shell; | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | find_shopt (name) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; shopt_vars[i].name; i++) | 
					
						
							|  |  |  |     if (STREQ (name, shopt_vars[i].name)) | 
					
						
							|  |  |  |       return i; | 
					
						
							|  |  |  |   return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | shopt_error (s) | 
					
						
							|  |  |  |      char *s; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   builtin_error (_("%s: invalid shell option name"), s); | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | toggle_shopts (mode, list, quiet) | 
					
						
							|  |  |  |      int mode; | 
					
						
							|  |  |  |      WORD_LIST *list; | 
					
						
							|  |  |  |      int quiet; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   WORD_LIST *l; | 
					
						
							|  |  |  |   int ind, rval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       ind = find_shopt (l->word->word); | 
					
						
							|  |  |  |       if (ind < 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  shopt_error (l->word->word); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  rval = EXECUTION_FAILURE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  *shopt_vars[ind].value = mode;	/* 1 for set, 0 for unset */ | 
					
						
							|  |  |  | 	  if (shopt_vars[ind].set_func) | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | 	    (*shopt_vars[ind].set_func) (shopt_vars[ind].name, mode); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   set_bashopts (); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (rval); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | print_shopt (name, val, flags) | 
					
						
							|  |  |  |      char *name; | 
					
						
							|  |  |  |      int val, flags; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (flags & PFLAG) | 
					
						
							|  |  |  |     printf ("shopt %s %s\n", val ? "-s" : "-u", name); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     printf (OPTFMT, name, val ? on : off); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* List the values of all or any of the `shopt' options.  Returns 0 if | 
					
						
							|  |  |  |    all were listed or all variables queried were on; 1 otherwise. */ | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | list_shopts (list, flags) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |      WORD_LIST *list; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |      int flags; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   WORD_LIST *l; | 
					
						
							|  |  |  |   int i, val, rval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (list == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       for (i = 0; shopt_vars[i].name; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  val = *shopt_vars[i].value; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | 	  if ((flags & QFLAG) == 0) | 
					
						
							|  |  |  | 	    print_shopt (shopt_vars[i].name, val, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       i = find_shopt (l->word->word); | 
					
						
							|  |  |  |       if (i < 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  shopt_error (l->word->word); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  rval = EXECUTION_FAILURE; | 
					
						
							|  |  |  | 	  continue; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       val = *shopt_vars[i].value; | 
					
						
							|  |  |  |       if (val == 0) | 
					
						
							|  |  |  | 	rval = EXECUTION_FAILURE; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       if ((flags & QFLAG) == 0) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	print_shopt (l->word->word, val, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (sh_chkwrite (rval)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | list_some_shopts (mode, flags) | 
					
						
							|  |  |  |      int mode, flags; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   int val, i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; shopt_vars[i].name; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       val = *shopt_vars[i].value; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       if (((flags & QFLAG) == 0) && mode == val) | 
					
						
							|  |  |  | 	print_shopt (shopt_vars[i].name, val, flags); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | list_shopt_o_options (list, flags) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |      WORD_LIST *list; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |      int flags; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   WORD_LIST *l; | 
					
						
							|  |  |  |   int val, rval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (list == 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       if ((flags & QFLAG) == 0) | 
					
						
							|  |  |  | 	list_minus_o_opts (-1, (flags & PFLAG)); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       val = minus_o_option_value (l->word->word); | 
					
						
							|  |  |  |       if (val == -1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	  sh_invalidoptname (l->word->word); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  rval = EXECUTION_FAILURE; | 
					
						
							|  |  |  | 	  continue; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       if (val == 0) | 
					
						
							|  |  |  | 	rval = EXECUTION_FAILURE; | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |       if ((flags & QFLAG) == 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  if (flags & PFLAG) | 
					
						
							|  |  |  | 	    printf ("set %co %s\n", val ? '-' : '+', l->word->word); | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    printf (OPTFMT, l->word->word, val ? on : off); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (sh_chkwrite (rval)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | list_some_o_options (mode, flags) | 
					
						
							|  |  |  |      int mode, flags; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  |   if ((flags & QFLAG) == 0) | 
					
						
							|  |  |  |     list_minus_o_opts (mode, (flags & PFLAG)); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | set_shopt_o_options (mode, list, quiet) | 
					
						
							|  |  |  |      int mode; | 
					
						
							|  |  |  |      WORD_LIST *list; | 
					
						
							|  |  |  |      int quiet; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   WORD_LIST *l; | 
					
						
							|  |  |  |   int rval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (set_minus_o_option (mode, l->word->word) == EXECUTION_FAILURE) | 
					
						
							|  |  |  | 	rval = EXECUTION_FAILURE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   set_shellopts (); | 
					
						
							|  |  |  |   return rval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* If we set or unset interactive_comments with shopt, make sure the | 
					
						
							|  |  |  |    change is reflected in $SHELLOPTS. */ | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | set_shellopts_after_change (option_name, mode) | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |      int mode; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   set_shellopts (); | 
					
						
							|  |  |  |   return (0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | shopt_enable_hostname_completion (option_name, mode) | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							|  |  |  |      int mode; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (enable_hostname_completion (mode)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | set_compatibility_level (option_name, mode) | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |      int mode; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Need to change logic here as we add more compatibility levels */ | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* First, check option_name so we can turn off other compat options when | 
					
						
							|  |  |  |      one is set. */ | 
					
						
							|  |  |  |   if (mode && option_name[6] == '3' && option_name[7] == '1') | 
					
						
							|  |  |  |     shopt_compat32 = shopt_compat40 = 0; | 
					
						
							|  |  |  |   else if (mode && option_name[6] == '3' && option_name[7] == '2') | 
					
						
							|  |  |  |     shopt_compat31 = shopt_compat40 = 0; | 
					
						
							|  |  |  |   else if (mode && option_name[6] == '4' && option_name[7] == '0') | 
					
						
							|  |  |  |     shopt_compat31 = shopt_compat32 = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Then set shell_compatibility_level based on what remains */ | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |   if (shopt_compat31) | 
					
						
							|  |  |  |     shell_compatibility_level = 31; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   else if (shopt_compat32) | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |     shell_compatibility_level = 32; | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  |   else if (shopt_compat40) | 
					
						
							|  |  |  |     shell_compatibility_level = 40; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     shell_compatibility_level = DEFAULT_COMPAT_LEVEL; | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #if defined (RESTRICTED_SHELL) | 
					
						
							|  |  |  | /* Don't allow the value of restricted_shell to be modified. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | set_restricted_shell (option_name, mode) | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |      int mode; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   static int save_restricted = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (save_restricted == -1) | 
					
						
							|  |  |  |     save_restricted = shell_is_restricted (shell_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   restricted_shell = save_restricted; | 
					
						
							|  |  |  |   return (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* RESTRICTED_SHELL */ | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | /* Not static so shell.c can call it to initialize shopt_login_shell */ | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | set_login_shell (option_name, mode) | 
					
						
							|  |  |  |      char *option_name; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |      int mode; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   shopt_login_shell = login_shell != 0; | 
					
						
							|  |  |  |   return (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  | char ** | 
					
						
							|  |  |  | get_shopt_options () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char **ret; | 
					
						
							|  |  |  |   int n, i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   n = sizeof (shopt_vars) / sizeof (shopt_vars[0]); | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |   ret = strvec_create (n + 1); | 
					
						
							| 
									
										
										
										
											2000-03-17 21:46:59 +00:00
										 |  |  |   for (i = 0; shopt_vars[i].name; i++) | 
					
						
							|  |  |  |     ret[i] = savestring (shopt_vars[i].name); | 
					
						
							|  |  |  |   ret[i] = (char *)NULL; | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * 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) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       shopt_error (name); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   print_shopt (name, *shopt_vars[i].value, reusable ? PFLAG : 0); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | set_bashopts () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char *value; | 
					
						
							|  |  |  |   char tflag[N_SHOPT_OPTIONS]; | 
					
						
							|  |  |  |   int vsize, i, vptr, *ip, exported; | 
					
						
							|  |  |  |   SHELL_VAR *v; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (vsize = i = 0; shopt_vars[i].name; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       tflag[i] = 0; | 
					
						
							|  |  |  |       if (GET_SHOPT_OPTION_VALUE (i)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  vsize += strlen (shopt_vars[i].name) + 1; | 
					
						
							|  |  |  | 	  tflag[i] = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   value = (char *)xmalloc (vsize + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = vptr = 0; shopt_vars[i].name; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (tflag[i]) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  strcpy (value + vptr, shopt_vars[i].name); | 
					
						
							|  |  |  | 	  vptr += strlen (shopt_vars[i].name); | 
					
						
							|  |  |  | 	  value[vptr++] = ':'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (vptr) | 
					
						
							|  |  |  |     vptr--;			/* cut off trailing colon */ | 
					
						
							|  |  |  |   value[vptr] = '\0'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   v = find_variable ("BASHOPTS"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Turn off the read-only attribute so we can bind the new value, and | 
					
						
							|  |  |  |      note whether or not the variable was exported. */ | 
					
						
							|  |  |  |   if (v) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       VUNSETATTR (v, att_readonly); | 
					
						
							|  |  |  |       exported = exported_p (v); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     exported = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   v = bind_variable ("BASHOPTS", value, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* 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. */ | 
					
						
							|  |  |  |   VSETATTR (v, att_readonly); | 
					
						
							|  |  |  |   if (mark_modified_vars && exported == 0 && exported_p (v)) | 
					
						
							|  |  |  |     VUNSETATTR (v, att_exported); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   free (value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | parse_bashopts (value) | 
					
						
							|  |  |  |      char *value; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char *vname; | 
					
						
							|  |  |  |   int vptr, ind; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   vptr = 0; | 
					
						
							|  |  |  |   while (vname = extract_colon_unit (value, &vptr)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       ind = find_shopt (vname); | 
					
						
							|  |  |  |       if (ind >= 0) | 
					
						
							|  |  |  |         *shopt_vars[ind].value = 1; | 
					
						
							|  |  |  |       free (vname); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | initialize_bashopts (no_bashopts) | 
					
						
							|  |  |  |      int no_bashopts; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char *temp; | 
					
						
							|  |  |  |   SHELL_VAR *var; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (no_bashopts == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       var = find_variable ("BASHOPTS"); | 
					
						
							|  |  |  |       /* set up any shell options we may have inherited. */ | 
					
						
							|  |  |  |       if (var && imported_p (var)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var)); | 
					
						
							|  |  |  | 	  if (temp) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      parse_bashopts (temp); | 
					
						
							|  |  |  | 	      free (temp); | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Set up the $BASHOPTS variable. */ | 
					
						
							|  |  |  |   set_bashopts (); | 
					
						
							|  |  |  | } |