1 /* shell.h -- The data structures used by the shell */
3 /* Copyright (C) 1993-2020 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne Again SHell.
7 Bush 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 Bush 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 Bush. If not, see <http://www.gnu.org/licenses/>.
27 #include "lxrgmr/command.h"
31 #include "var/variables.h"
32 #include "var/arrayfunc.h"
35 #include "runner/unwind_prot.h"
36 #include "lxrgmr/dispose_cmd.h"
37 #include "lxrgmr/make_cmd.h"
39 #include "lxrgmr/subst.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 */
75 #define EX_DISKFALLBACK 262 /* fall back to disk command from builtin */
77 /* Flag values that control parameter pattern substitution. */
78 #define MATCH_ANY 0x000
79 #define MATCH_BEG 0x001
80 #define MATCH_END 0x002
82 #define MATCH_TYPEMASK 0x003
84 #define MATCH_GLOBREP 0x010
85 #define MATCH_QUOTED 0x020
86 #define MATCH_ASSIGNRHS 0x040
87 #define MATCH_STARSUB 0x080
89 /* Some needed external declarations. */
90 extern char **shell_environment
;
91 extern WORD_LIST
*rest_of_args
;
93 /* Generalized global variables. */
94 extern char *command_execution_string
;
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 bush_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
;
109 extern int posixly_correct
;
110 extern int no_line_editing
;
112 extern char *shell_name
;
113 extern char *current_host_name
;
115 extern int subshell_argc
;
116 extern char **subshell_argv
;
117 extern char **subshell_envp
;
119 /* variables managed using shopt */
120 extern int hup_on_exit
;
121 extern int check_jobs_at_exit
;
123 extern int check_window_size
;
126 extern int build_version
, patch_level
;
127 extern char *dist_version
, *release_status
;
129 extern int locale_mb_cur_max
;
130 extern int locale_utf8locale
;
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. */
139 #define FD_BITMAP_SIZE 32
141 #define CTLESC '\001'
142 #define CTLNUL '\177'
144 /* Information about the current user. */
149 char *shell
; /* shell from the password file */
153 extern struct user_info current_user
;
155 /* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle
157 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
158 # define USE_VAR(x) ((void) &(x))
163 #define HEREDOC_MAX 16
165 /* Structure in which to save partial parsing state when doing things like
166 PROMPT_COMMAND and bush_execute_unix_command execution. */
168 typedef struct _sh_parser_state_t
{
175 int token_buffer_size
;
177 /* input line state -- line number saved elsewhere */
178 int input_line_terminator
;
181 #if defined (HANDLE_MULTIBYTE)
182 /* Nothing right now for multibyte state, but might want something later. */
185 char **prompt_string_pointer
;
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
;
194 /* execution state possibly modified by the parser */
195 int last_command_exit_value
;
196 #if defined (ARRAY_VARS)
199 sh_builtin_func_t
*last_shell_builtin
, *this_shell_builtin
;
201 /* flags state affecting the parser */
203 int echo_input_at_read
;
205 int here_doc_first_line
;
207 /* structures affecting the parser */
208 REDIRECT
*redir_stack
[HEREDOC_MAX
];
211 typedef struct _sh_input_line_state_t
{
213 size_t input_line_index
;
214 size_t input_line_size
;
215 size_t input_line_len
;
216 #if defined (HANDLE_MULTIBYTE)
217 char *input_property
;
218 size_t input_propsize
;
220 } sh_input_line_state_t
;
222 /* Let's try declaring these here. */
223 extern char *parser_remaining_input
PARAMS((void));
225 extern sh_parser_state_t
*save_parser_state
PARAMS((sh_parser_state_t
*));
226 extern void restore_parser_state
PARAMS((sh_parser_state_t
*));
228 extern sh_input_line_state_t
*save_input_line_state
PARAMS((sh_input_line_state_t
*));
229 extern void restore_input_line_state
PARAMS((sh_input_line_state_t
*));