| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | /* shell.h -- The data structures used by the shell */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | /* Copyright (C) 1993-2009 Free Software Foundation, Inc.
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +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-08-26 18:22:31 +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-08-26 18:22:31 +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-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "bashjmp.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "command.h"
 | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | #include "syntax.h"
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "general.h"
 | 
					
						
							|  |  |  | #include "error.h"
 | 
					
						
							|  |  |  | #include "variables.h"
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #include "arrayfunc.h"
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "quit.h"
 | 
					
						
							|  |  |  | #include "maxpath.h"
 | 
					
						
							|  |  |  | #include "unwind_prot.h"
 | 
					
						
							|  |  |  | #include "dispose_cmd.h"
 | 
					
						
							|  |  |  | #include "make_cmd.h"
 | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #include "ocache.h"
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "subst.h"
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include "sig.h"
 | 
					
						
							|  |  |  | #include "pathnames.h"
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "externs.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern int EOF_Reached; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NO_PIPE -1
 | 
					
						
							|  |  |  | #define REDIRECT_BOTH -2
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NO_VARIABLE -1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Values that can be returned by execute_command (). */ | 
					
						
							|  |  |  | #define EXECUTION_FAILURE 1
 | 
					
						
							|  |  |  | #define EXECUTION_SUCCESS 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Usage messages by builtins result in a return status of 2. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #define EX_BADUSAGE	2
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  | #define EX_MISCERROR	2
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Special exit statuses used by the shell, internally and externally. */ | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | #define EX_RETRYFAIL	124
 | 
					
						
							|  |  |  | #define EX_WEXPCOMSUB	125
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #define EX_BINARY_FILE	126
 | 
					
						
							|  |  |  | #define EX_NOEXEC	126
 | 
					
						
							|  |  |  | #define EX_NOINPUT	126
 | 
					
						
							|  |  |  | #define EX_NOTFOUND	127
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #define EX_SHERRBASE	256	/* all special error values are > this. */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define EX_BADSYNTAX	257	/* shell syntax error */
 | 
					
						
							|  |  |  | #define EX_USAGE	258	/* syntax error in usage */
 | 
					
						
							|  |  |  | #define EX_REDIRFAIL	259	/* redirection failed */
 | 
					
						
							|  |  |  | #define EX_BADASSIGN	260	/* variable assignment error */
 | 
					
						
							|  |  |  | #define EX_EXPFAIL	261	/* word expansion failed */
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Flag values that control parameter pattern substitution. */ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #define MATCH_ANY	0x000
 | 
					
						
							|  |  |  | #define MATCH_BEG	0x001
 | 
					
						
							|  |  |  | #define MATCH_END	0x002
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #define MATCH_TYPEMASK	0x003
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #define MATCH_GLOBREP	0x010
 | 
					
						
							|  |  |  | #define MATCH_QUOTED	0x020
 | 
					
						
							|  |  |  | #define MATCH_STARSUB	0x040
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Some needed external declarations. */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | extern char **shell_environment; | 
					
						
							|  |  |  | extern WORD_LIST *rest_of_args; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Generalized global variables. */ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | extern int debugging_mode; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | extern int executing, login_shell; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | extern int interactive, interactive_shell; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | extern int startup_state; | 
					
						
							| 
									
										
										
										
											2011-11-21 20:51:19 -05:00
										 |  |  | extern int subshell_environment; | 
					
						
							| 
									
										
										
										
											2008-11-18 13:15:12 +00:00
										 |  |  | extern int shell_compatibility_level; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Structure to pass around that holds a bitmap of file descriptors
 | 
					
						
							|  |  |  |    to close, and the size of that structure.  Used in execute_cmd.c. */ | 
					
						
							|  |  |  | struct fd_bitmap { | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   int size; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   char *bitmap; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FD_BITMAP_SIZE 32
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define CTLESC '\001'
 | 
					
						
							|  |  |  | #define CTLNUL '\177'
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Information about the current user. */ | 
					
						
							|  |  |  | struct user_info { | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |   uid_t uid, euid; | 
					
						
							|  |  |  |   gid_t gid, egid; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   char *user_name; | 
					
						
							|  |  |  |   char *shell;		/* shell from the password file */ | 
					
						
							|  |  |  |   char *home_dir; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern struct user_info current_user; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Force gcc to not clobber X on a longjmp().  Old versions of gcc mangle
 | 
					
						
							|  |  |  |    this badly. */ | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #  define USE_VAR(x)	((void) &(x))
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #  define USE_VAR(x)
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Structure in which to save partial parsing state when doing things like
 | 
					
						
							|  |  |  |    PROMPT_COMMAND and bash_execute_unix_command execution. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct _sh_parser_state_t { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* parsing state */ | 
					
						
							|  |  |  |   int parser_state; | 
					
						
							|  |  |  |   int *token_state; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* input line state -- line number saved elsewhere */ | 
					
						
							|  |  |  |   int input_line_terminator; | 
					
						
							|  |  |  |   int eof_encountered; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HANDLE_MULTIBYTE)
 | 
					
						
							|  |  |  |   /* Nothing right now for multibyte state, but might want something later. */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-22 19:11:26 -05:00
										 |  |  |   char **prompt_string_pointer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |   /* history state affecting or modified by the parser */ | 
					
						
							|  |  |  |   int current_command_line_count; | 
					
						
							|  |  |  | #if defined (HISTORY)
 | 
					
						
							|  |  |  |   int remember_on_history; | 
					
						
							|  |  |  |   int history_expansion_inhibited; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* execution state possibly modified by the parser */ | 
					
						
							|  |  |  |   int last_command_exit_value; | 
					
						
							|  |  |  | #if defined (ARRAY_VARS)
 | 
					
						
							|  |  |  |   ARRAY *pipestatus; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   sh_builtin_func_t *last_shell_builtin, *this_shell_builtin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* flags state affecting the parser */ | 
					
						
							|  |  |  |   int expand_aliases; | 
					
						
							|  |  |  |   int echo_input_at_read; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  | } sh_parser_state_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Let's try declaring these here. */ | 
					
						
							|  |  |  | extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *)); | 
					
						
							|  |  |  | extern void restore_parser_state __P((sh_parser_state_t *)); |