1 /* shell.h -- The data structures used by the shell */
3 /* Copyright (C) 1993-2009 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
31 #include "variables.h"
32 #include "arrayfunc.h"
35 #include "unwind_prot.h"
36 #include "dispose_cmd.h"
41 #include "pathnames.h"
44 extern int EOF_Reached
;
47 #define REDIRECT_BOTH -2
49 #define NO_VARIABLE -1
51 /* Values that can be returned by execute_command (). */
52 #define EXECUTION_FAILURE 1
53 #define EXECUTION_SUCCESS 0
55 /* Usage messages by builtins result in a return status of 2. */
58 #define EX_MISCERROR 2
60 /* Special exit statuses used by the shell, internally and externally. */
61 #define EX_RETRYFAIL 124
62 #define EX_WEXPCOMSUB 125
63 #define EX_BINARY_FILE 126
65 #define EX_NOINPUT 126
66 #define EX_NOTFOUND 127
68 #define EX_SHERRBASE 256 /* all special error values are > this. */
70 #define EX_BADSYNTAX 257 /* shell syntax error */
71 #define EX_USAGE 258 /* syntax error in usage */
72 #define EX_REDIRFAIL 259 /* redirection failed */
73 #define EX_BADASSIGN 260 /* variable assignment error */
74 #define EX_EXPFAIL 261 /* word expansion failed */
76 /* Flag values that control parameter pattern substitution. */
77 #define MATCH_ANY 0x000
78 #define MATCH_BEG 0x001
79 #define MATCH_END 0x002
81 #define MATCH_TYPEMASK 0x003
83 #define MATCH_GLOBREP 0x010
84 #define MATCH_QUOTED 0x020
85 #define MATCH_ASSIGNRHS 0x040
86 #define MATCH_STARSUB 0x080
88 /* Some needed external declarations. */
89 extern char **shell_environment
;
90 extern WORD_LIST
*rest_of_args
;
92 /* Generalized global variables. */
93 extern int debugging_mode
;
94 extern int executing
, login_shell
;
95 extern int interactive
, interactive_shell
;
96 extern int startup_state
;
97 extern int subshell_environment
;
98 extern int shell_compatibility_level
;
100 extern int locale_mb_cur_max
;
102 /* Structure to pass around that holds a bitmap of file descriptors
103 to close, and the size of that structure. Used in execute_cmd.c. */
109 #define FD_BITMAP_SIZE 32
111 #define CTLESC '\001'
112 #define CTLNUL '\177'
114 /* Information about the current user. */
119 char *shell
; /* shell from the password file */
123 extern struct user_info current_user
;
125 /* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle
127 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
128 # define USE_VAR(x) ((void) &(x))
133 #define HEREDOC_MAX 16
135 /* Structure in which to save partial parsing state when doing things like
136 PROMPT_COMMAND and bash_execute_unix_command execution. */
138 typedef struct _sh_parser_state_t
{
145 int token_buffer_size
;
147 /* input line state -- line number saved elsewhere */
148 int input_line_terminator
;
151 #if defined (HANDLE_MULTIBYTE)
152 /* Nothing right now for multibyte state, but might want something later. */
155 char **prompt_string_pointer
;
157 /* history state affecting or modified by the parser */
158 int current_command_line_count
;
159 #if defined (HISTORY)
160 int remember_on_history
;
161 int history_expansion_inhibited
;
164 /* execution state possibly modified by the parser */
165 int last_command_exit_value
;
166 #if defined (ARRAY_VARS)
169 sh_builtin_func_t
*last_shell_builtin
, *this_shell_builtin
;
171 /* flags state affecting the parser */
173 int echo_input_at_read
;
175 int here_doc_first_line
;
177 /* structures affecting the parser */
178 REDIRECT
*redir_stack
[HEREDOC_MAX
];
181 typedef struct _sh_input_line_state_t
{
183 size_t input_line_index
;
184 size_t input_line_size
;
185 size_t input_line_len
;
186 } sh_input_line_state_t
;
188 /* Let's try declaring these here. */
189 extern char *parser_remaining_input
__P((void));
191 extern sh_parser_state_t
*save_parser_state
__P((sh_parser_state_t
*));
192 extern void restore_parser_state
__P((sh_parser_state_t
*));
194 extern sh_input_line_state_t
*save_input_line_state
__P((sh_input_line_state_t
*));
195 extern void restore_input_line_state
__P((sh_input_line_state_t
*));