]> git.ipfire.org Git - thirdparty/bash.git/blob - shell.h
Bash-5.0 patch 1: fix pathname expansion of directory names containing backslashes
[thirdparty/bash.git] / shell.h
1 /* shell.h -- The data structures used by the shell */
2
3 /* Copyright (C) 1993-2009 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
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.
11
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.
16
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/>.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "bashjmp.h"
26
27 #include "command.h"
28 #include "syntax.h"
29 #include "general.h"
30 #include "error.h"
31 #include "variables.h"
32 #include "arrayfunc.h"
33 #include "quit.h"
34 #include "maxpath.h"
35 #include "unwind_prot.h"
36 #include "dispose_cmd.h"
37 #include "make_cmd.h"
38 #include "ocache.h"
39 #include "subst.h"
40 #include "sig.h"
41 #include "pathnames.h"
42 #include "externs.h"
43
44 extern int EOF_Reached;
45
46 #define NO_PIPE -1
47 #define REDIRECT_BOTH -2
48
49 #define NO_VARIABLE -1
50
51 /* Values that can be returned by execute_command (). */
52 #define EXECUTION_FAILURE 1
53 #define EXECUTION_SUCCESS 0
54
55 /* Usage messages by builtins result in a return status of 2. */
56 #define EX_BADUSAGE 2
57
58 #define EX_MISCERROR 2
59
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
64 #define EX_NOEXEC 126
65 #define EX_NOINPUT 126
66 #define EX_NOTFOUND 127
67
68 #define EX_SHERRBASE 256 /* all special error values are > this. */
69
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 */
75 #define EX_DISKFALLBACK 262 /* fall back to disk command from builtin */
76
77 /* Flag values that control parameter pattern substitution. */
78 #define MATCH_ANY 0x000
79 #define MATCH_BEG 0x001
80 #define MATCH_END 0x002
81
82 #define MATCH_TYPEMASK 0x003
83
84 #define MATCH_GLOBREP 0x010
85 #define MATCH_QUOTED 0x020
86 #define MATCH_ASSIGNRHS 0x040
87 #define MATCH_STARSUB 0x080
88
89 /* Some needed external declarations. */
90 extern char **shell_environment;
91 extern WORD_LIST *rest_of_args;
92
93 /* Generalized global variables. */
94 extern char *command_execution_string;
95
96 extern int debugging_mode;
97 extern int executing, login_shell;
98 extern int interactive, interactive_shell;
99 extern int startup_state;
100 extern int reading_shell_script;
101 extern int shell_initialized;
102 extern int bash_argv_initialized;
103 extern int subshell_environment;
104 extern int current_command_number;
105 extern int indirection_level;
106 extern int shell_compatibility_level;
107 extern int running_under_emacs;
108
109 extern int posixly_correct;
110 extern int no_line_editing;
111
112 extern char *shell_name;
113 extern char *current_host_name;
114
115 extern int subshell_argc;
116 extern char **subshell_argv;
117 extern char **subshell_envp;
118
119 /* variables managed using shopt */
120 extern int hup_on_exit;
121 extern int check_jobs_at_exit;
122 extern int autocd;
123 extern int check_window_size;
124
125 /* from version.c */
126 extern int build_version, patch_level;
127 extern char *dist_version, *release_status;
128
129 extern int locale_mb_cur_max;
130 extern int locale_utf8locale;
131
132 /* Structure to pass around that holds a bitmap of file descriptors
133 to close, and the size of that structure. Used in execute_cmd.c. */
134 struct fd_bitmap {
135 int size;
136 char *bitmap;
137 };
138
139 #define FD_BITMAP_SIZE 32
140
141 #define CTLESC '\001'
142 #define CTLNUL '\177'
143
144 /* Information about the current user. */
145 struct user_info {
146 uid_t uid, euid;
147 gid_t gid, egid;
148 char *user_name;
149 char *shell; /* shell from the password file */
150 char *home_dir;
151 };
152
153 extern struct user_info current_user;
154
155 /* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle
156 this badly. */
157 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
158 # define USE_VAR(x) ((void) &(x))
159 #else
160 # define USE_VAR(x)
161 #endif
162
163 #define HEREDOC_MAX 16
164
165 /* Structure in which to save partial parsing state when doing things like
166 PROMPT_COMMAND and bash_execute_unix_command execution. */
167
168 typedef struct _sh_parser_state_t {
169
170 /* parsing state */
171 int parser_state;
172 int *token_state;
173
174 char *token;
175 int token_buffer_size;
176
177 /* input line state -- line number saved elsewhere */
178 int input_line_terminator;
179 int eof_encountered;
180
181 #if defined (HANDLE_MULTIBYTE)
182 /* Nothing right now for multibyte state, but might want something later. */
183 #endif
184
185 char **prompt_string_pointer;
186
187 /* history state affecting or modified by the parser */
188 int current_command_line_count;
189 #if defined (HISTORY)
190 int remember_on_history;
191 int history_expansion_inhibited;
192 #endif
193
194 /* execution state possibly modified by the parser */
195 int last_command_exit_value;
196 #if defined (ARRAY_VARS)
197 ARRAY *pipestatus;
198 #endif
199 sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
200
201 /* flags state affecting the parser */
202 int expand_aliases;
203 int echo_input_at_read;
204 int need_here_doc;
205 int here_doc_first_line;
206
207 /* structures affecting the parser */
208 REDIRECT *redir_stack[HEREDOC_MAX];
209 } sh_parser_state_t;
210
211 typedef struct _sh_input_line_state_t {
212 char *input_line;
213 size_t input_line_index;
214 size_t input_line_size;
215 size_t input_line_len;
216 } sh_input_line_state_t;
217
218 /* Let's try declaring these here. */
219 extern char *parser_remaining_input __P((void));
220
221 extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
222 extern void restore_parser_state __P((sh_parser_state_t *));
223
224 extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
225 extern void restore_input_line_state __P((sh_input_line_state_t *));