]>
Commit | Line | Data |
---|---|---|
726f6388 JA |
1 | /* shell.h -- The data structures used by the shell */ |
2 | ||
b8c60bc9 | 3 | /* Copyright (C) 1993-2024 Free Software Foundation, Inc. |
726f6388 JA |
4 | |
5 | This file is part of GNU Bash, the Bourne Again SHell. | |
6 | ||
3185942a JA |
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. | |
726f6388 | 11 | |
3185942a JA |
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. | |
726f6388 | 16 | |
3185942a JA |
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 | */ | |
726f6388 | 20 | |
f73dda09 | 21 | #ifdef HAVE_CONFIG_H |
726f6388 | 22 | #include "config.h" |
f73dda09 | 23 | #endif |
ccc6cda3 JA |
24 | |
25 | #include "bashjmp.h" | |
26 | ||
726f6388 | 27 | #include "command.h" |
28ef6c31 | 28 | #include "syntax.h" |
726f6388 JA |
29 | #include "general.h" |
30 | #include "error.h" | |
31 | #include "variables.h" | |
32 | #include "quit.h" | |
33 | #include "maxpath.h" | |
34 | #include "unwind_prot.h" | |
35 | #include "dispose_cmd.h" | |
36 | #include "make_cmd.h" | |
7117c2d2 | 37 | #include "ocache.h" |
726f6388 | 38 | #include "subst.h" |
b8c60bc9 | 39 | #include "arrayfunc.h" |
ccc6cda3 JA |
40 | #include "sig.h" |
41 | #include "pathnames.h" | |
726f6388 JA |
42 | #include "externs.h" |
43 | ||
44 | extern int EOF_Reached; | |
45 | ||
46 | #define NO_PIPE -1 | |
47 | #define REDIRECT_BOTH -2 | |
726f6388 JA |
48 | |
49 | #define NO_VARIABLE -1 | |
50 | ||
726f6388 JA |
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. */ | |
ccc6cda3 JA |
56 | #define EX_BADUSAGE 2 |
57 | ||
495aee44 CR |
58 | #define EX_MISCERROR 2 |
59 | ||
ccc6cda3 | 60 | /* Special exit statuses used by the shell, internally and externally. */ |
0001803f CR |
61 | #define EX_RETRYFAIL 124 |
62 | #define EX_WEXPCOMSUB 125 | |
ccc6cda3 JA |
63 | #define EX_BINARY_FILE 126 |
64 | #define EX_NOEXEC 126 | |
65 | #define EX_NOINPUT 126 | |
66 | #define EX_NOTFOUND 127 | |
726f6388 | 67 | |
ccc6cda3 JA |
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 */ | |
d233b485 | 75 | #define EX_DISKFALLBACK 262 /* fall back to disk command from builtin */ |
b8c60bc9 | 76 | #define EX_UTILERROR 263 /* Posix special builtin utility error */ |
726f6388 | 77 | |
ccc6cda3 | 78 | /* Flag values that control parameter pattern substitution. */ |
b80f6443 JA |
79 | #define MATCH_ANY 0x000 |
80 | #define MATCH_BEG 0x001 | |
81 | #define MATCH_END 0x002 | |
ccc6cda3 | 82 | |
b80f6443 | 83 | #define MATCH_TYPEMASK 0x003 |
ccc6cda3 | 84 | |
b80f6443 JA |
85 | #define MATCH_GLOBREP 0x010 |
86 | #define MATCH_QUOTED 0x020 | |
a0c0a00f CR |
87 | #define MATCH_ASSIGNRHS 0x040 |
88 | #define MATCH_STARSUB 0x080 | |
74091dd4 | 89 | #define MATCH_EXPREP 0x100 /* for pattern substitution, expand replacement */ |
726f6388 | 90 | |
ccc6cda3 | 91 | /* Some needed external declarations. */ |
726f6388 JA |
92 | extern char **shell_environment; |
93 | extern WORD_LIST *rest_of_args; | |
94 | ||
95 | /* Generalized global variables. */ | |
d233b485 CR |
96 | extern char *command_execution_string; |
97 | ||
b80f6443 | 98 | extern int debugging_mode; |
b8c60bc9 CR |
99 | extern int executing; |
100 | extern int login_shell; | |
101 | extern int su_shell; | |
102 | extern int parsing_command; | |
f73dda09 | 103 | extern int interactive, interactive_shell; |
7117c2d2 | 104 | extern int startup_state; |
d233b485 | 105 | extern int reading_shell_script; |
b8c60bc9 | 106 | extern int ssh_reading_startup_files; |
d233b485 CR |
107 | extern int shell_initialized; |
108 | extern int bash_argv_initialized; | |
0001803f | 109 | extern int subshell_environment; |
d233b485 CR |
110 | extern int current_command_number; |
111 | extern int indirection_level; | |
f1be666c | 112 | extern int shell_compatibility_level; |
b8c60bc9 | 113 | extern const int default_compatibility_level; |
d233b485 CR |
114 | extern int running_under_emacs; |
115 | ||
b8c60bc9 CR |
116 | extern int pretty_print_mode; |
117 | ||
d233b485 CR |
118 | extern int posixly_correct; |
119 | extern int no_line_editing; | |
120 | ||
121 | extern char *shell_name; | |
122 | extern char *current_host_name; | |
123 | ||
124 | extern int subshell_argc; | |
125 | extern char **subshell_argv; | |
126 | extern char **subshell_envp; | |
127 | ||
128 | /* variables managed using shopt */ | |
129 | extern int hup_on_exit; | |
130 | extern int check_jobs_at_exit; | |
131 | extern int autocd; | |
132 | extern int check_window_size; | |
133 | ||
134 | /* from version.c */ | |
135 | extern int build_version, patch_level; | |
136 | extern char *dist_version, *release_status; | |
726f6388 | 137 | |
ac50fbac | 138 | extern int locale_mb_cur_max; |
d233b485 | 139 | extern int locale_utf8locale; |
ac50fbac | 140 | |
726f6388 JA |
141 | /* Structure to pass around that holds a bitmap of file descriptors |
142 | to close, and the size of that structure. Used in execute_cmd.c. */ | |
143 | struct fd_bitmap { | |
f73dda09 | 144 | int size; |
726f6388 JA |
145 | char *bitmap; |
146 | }; | |
147 | ||
148 | #define FD_BITMAP_SIZE 32 | |
149 | ||
150 | #define CTLESC '\001' | |
151 | #define CTLNUL '\177' | |
152 | ||
153 | /* Information about the current user. */ | |
154 | struct user_info { | |
b8c60bc9 CR |
155 | uid_t uid, euid, saveuid; |
156 | gid_t gid, egid, savegid; | |
726f6388 JA |
157 | char *user_name; |
158 | char *shell; /* shell from the password file */ | |
159 | char *home_dir; | |
160 | }; | |
161 | ||
162 | extern struct user_info current_user; | |
f73dda09 JA |
163 | |
164 | /* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle | |
165 | this badly. */ | |
7117c2d2 | 166 | #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8) |
f73dda09 JA |
167 | # define USE_VAR(x) ((void) &(x)) |
168 | #else | |
169 | # define USE_VAR(x) | |
170 | #endif | |
b80f6443 | 171 | |
a0c0a00f CR |
172 | #define HEREDOC_MAX 16 |
173 | ||
b80f6443 JA |
174 | /* Structure in which to save partial parsing state when doing things like |
175 | PROMPT_COMMAND and bash_execute_unix_command execution. */ | |
176 | ||
74091dd4 CR |
177 | typedef struct _sh_parser_state_t |
178 | { | |
b80f6443 JA |
179 | /* parsing state */ |
180 | int parser_state; | |
181 | int *token_state; | |
b8c60bc9 | 182 | int parsing_command; |
b80f6443 | 183 | |
b4839c27 | 184 | char *token; |
74091dd4 CR |
185 | size_t token_buffer_size; |
186 | int eof_token; | |
b4839c27 | 187 | |
b80f6443 JA |
188 | /* input line state -- line number saved elsewhere */ |
189 | int input_line_terminator; | |
190 | int eof_encountered; | |
74091dd4 | 191 | int eol_lookahead; |
b80f6443 JA |
192 | |
193 | #if defined (HANDLE_MULTIBYTE) | |
194 | /* Nothing right now for multibyte state, but might want something later. */ | |
195 | #endif | |
196 | ||
495aee44 CR |
197 | char **prompt_string_pointer; |
198 | ||
b80f6443 JA |
199 | /* history state affecting or modified by the parser */ |
200 | int current_command_line_count; | |
201 | #if defined (HISTORY) | |
202 | int remember_on_history; | |
203 | int history_expansion_inhibited; | |
204 | #endif | |
205 | ||
206 | /* execution state possibly modified by the parser */ | |
207 | int last_command_exit_value; | |
208 | #if defined (ARRAY_VARS) | |
209 | ARRAY *pipestatus; | |
210 | #endif | |
211 | sh_builtin_func_t *last_shell_builtin, *this_shell_builtin; | |
212 | ||
213 | /* flags state affecting the parser */ | |
214 | int expand_aliases; | |
215 | int echo_input_at_read; | |
daefb2c5 | 216 | int need_here_doc; |
a0c0a00f | 217 | int here_doc_first_line; |
daefb2c5 | 218 | |
74091dd4 CR |
219 | int esacs_needed; |
220 | int expecting_in; | |
b8c60bc9 | 221 | int incmd; |
74091dd4 | 222 | |
a0c0a00f | 223 | /* structures affecting the parser */ |
74091dd4 | 224 | void *pushed_strings; |
a0c0a00f | 225 | REDIRECT *redir_stack[HEREDOC_MAX]; |
b80f6443 JA |
226 | } sh_parser_state_t; |
227 | ||
74091dd4 CR |
228 | typedef struct _sh_input_line_state_t |
229 | { | |
b4839c27 | 230 | char *input_line; |
ac50fbac CR |
231 | size_t input_line_index; |
232 | size_t input_line_size; | |
233 | size_t input_line_len; | |
8868edaf CR |
234 | #if defined (HANDLE_MULTIBYTE) |
235 | char *input_property; | |
236 | size_t input_propsize; | |
237 | #endif | |
b4839c27 CR |
238 | } sh_input_line_state_t; |
239 | ||
b80f6443 | 240 | /* Let's try declaring these here. */ |
b8c60bc9 CR |
241 | extern void shell_ungets (char *); |
242 | extern void rewind_input_string (void); | |
74091dd4 | 243 | |
b8c60bc9 | 244 | extern char *parser_remaining_input (void); |
ca6a2ba4 | 245 | |
b8c60bc9 CR |
246 | extern sh_parser_state_t *save_parser_state (sh_parser_state_t *); |
247 | extern void restore_parser_state (sh_parser_state_t *); | |
248 | extern void flush_parser_state (sh_parser_state_t *); | |
249 | extern void uw_restore_parser_state (void *); | |
b4839c27 | 250 | |
b8c60bc9 CR |
251 | extern sh_input_line_state_t *save_input_line_state (sh_input_line_state_t *); |
252 | extern void restore_input_line_state (sh_input_line_state_t *); |