blob: 3cf25df0bd64155ce45f698d15fd696644c23e5c [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* shell.h -- The data structures used by the shell */
2
Jari Aalto31859422009-01-12 13:36:28 +00003/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00004
5 This file is part of GNU Bash, the Bourne Again SHell.
6
Jari Aalto31859422009-01-12 13:36:28 +00007 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.
Jari Aalto726f6381996-08-26 18:22:31 +000011
Jari Aalto31859422009-01-12 13:36:28 +000012 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.
Jari Aalto726f6381996-08-26 18:22:31 +000016
Jari Aalto31859422009-01-12 13:36:28 +000017 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*/
Jari Aalto726f6381996-08-26 18:22:31 +000020
Jari Aaltof73dda02001-11-13 17:56:06 +000021#ifdef HAVE_CONFIG_H
Jari Aalto726f6381996-08-26 18:22:31 +000022#include "config.h"
Jari Aaltof73dda02001-11-13 17:56:06 +000023#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +000024
25#include "bashjmp.h"
26
Jari Aalto726f6381996-08-26 18:22:31 +000027#include "command.h"
Jari Aalto28ef6c32001-04-06 19:14:31 +000028#include "syntax.h"
Jari Aalto726f6381996-08-26 18:22:31 +000029#include "general.h"
30#include "error.h"
31#include "variables.h"
Jari Aaltof73dda02001-11-13 17:56:06 +000032#include "arrayfunc.h"
Jari Aalto726f6381996-08-26 18:22:31 +000033#include "quit.h"
34#include "maxpath.h"
35#include "unwind_prot.h"
36#include "dispose_cmd.h"
37#include "make_cmd.h"
Jari Aalto7117c2d2002-07-17 14:10:11 +000038#include "ocache.h"
Jari Aalto726f6381996-08-26 18:22:31 +000039#include "subst.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +000040#include "sig.h"
41#include "pathnames.h"
Jari Aalto726f6381996-08-26 18:22:31 +000042#include "externs.h"
43
44extern int EOF_Reached;
45
46#define NO_PIPE -1
47#define REDIRECT_BOTH -2
Jari Aalto726f6381996-08-26 18:22:31 +000048
49#define NO_VARIABLE -1
50
Jari Aalto726f6381996-08-26 18:22:31 +000051/* 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. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +000056#define EX_BADUSAGE 2
Jari Aalto726f6381996-08-26 18:22:31 +000057
Chet Ramey495aee42011-11-22 19:11:26 -050058#define EX_MISCERROR 2
59
Jari Aaltoccc6cda1996-12-23 17:02:34 +000060/* Special exit statuses used by the shell, internally and externally. */
Chet Ramey00018032011-11-21 20:51:19 -050061#define EX_RETRYFAIL 124
62#define EX_WEXPCOMSUB 125
Jari Aaltoccc6cda1996-12-23 17:02:34 +000063#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 */
Jari Aalto726f6381996-08-26 18:22:31 +000075
Jari Aaltoccc6cda1996-12-23 17:02:34 +000076/* Flag values that control parameter pattern substitution. */
Jari Aaltob80f6442004-07-27 13:29:18 +000077#define MATCH_ANY 0x000
78#define MATCH_BEG 0x001
79#define MATCH_END 0x002
Jari Aaltoccc6cda1996-12-23 17:02:34 +000080
Jari Aaltob80f6442004-07-27 13:29:18 +000081#define MATCH_TYPEMASK 0x003
Jari Aaltoccc6cda1996-12-23 17:02:34 +000082
Jari Aaltob80f6442004-07-27 13:29:18 +000083#define MATCH_GLOBREP 0x010
84#define MATCH_QUOTED 0x020
85#define MATCH_STARSUB 0x040
Jari Aaltoccc6cda1996-12-23 17:02:34 +000086
87/* Some needed external declarations. */
Jari Aalto726f6381996-08-26 18:22:31 +000088extern char **shell_environment;
89extern WORD_LIST *rest_of_args;
90
91/* Generalized global variables. */
Jari Aaltob80f6442004-07-27 13:29:18 +000092extern int debugging_mode;
Jari Aalto726f6381996-08-26 18:22:31 +000093extern int executing, login_shell;
Jari Aaltof73dda02001-11-13 17:56:06 +000094extern int interactive, interactive_shell;
Jari Aalto7117c2d2002-07-17 14:10:11 +000095extern int startup_state;
Chet Ramey00018032011-11-21 20:51:19 -050096extern int subshell_environment;
Jari Aaltof1be6662008-11-18 13:15:12 +000097extern int shell_compatibility_level;
Jari Aalto726f6381996-08-26 18:22:31 +000098
Chet Rameyac50fba2014-02-26 09:36:43 -050099extern int locale_mb_cur_max;
100
Jari Aalto726f6381996-08-26 18:22:31 +0000101/* Structure to pass around that holds a bitmap of file descriptors
102 to close, and the size of that structure. Used in execute_cmd.c. */
103struct fd_bitmap {
Jari Aaltof73dda02001-11-13 17:56:06 +0000104 int size;
Jari Aalto726f6381996-08-26 18:22:31 +0000105 char *bitmap;
106};
107
108#define FD_BITMAP_SIZE 32
109
110#define CTLESC '\001'
111#define CTLNUL '\177'
112
113/* Information about the current user. */
114struct user_info {
Jari Aaltod166f041997-06-05 14:59:13 +0000115 uid_t uid, euid;
116 gid_t gid, egid;
Jari Aalto726f6381996-08-26 18:22:31 +0000117 char *user_name;
118 char *shell; /* shell from the password file */
119 char *home_dir;
120};
121
122extern struct user_info current_user;
Jari Aaltof73dda02001-11-13 17:56:06 +0000123
124/* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle
125 this badly. */
Jari Aalto7117c2d2002-07-17 14:10:11 +0000126#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
Jari Aaltof73dda02001-11-13 17:56:06 +0000127# define USE_VAR(x) ((void) &(x))
128#else
129# define USE_VAR(x)
130#endif
Jari Aaltob80f6442004-07-27 13:29:18 +0000131
132/* Structure in which to save partial parsing state when doing things like
133 PROMPT_COMMAND and bash_execute_unix_command execution. */
134
135typedef struct _sh_parser_state_t {
136
137 /* parsing state */
138 int parser_state;
139 int *token_state;
140
Chet Rameyb4839c22011-11-22 20:02:35 -0500141 char *token;
142 int token_buffer_size;
143
Jari Aaltob80f6442004-07-27 13:29:18 +0000144 /* input line state -- line number saved elsewhere */
145 int input_line_terminator;
146 int eof_encountered;
147
148#if defined (HANDLE_MULTIBYTE)
149 /* Nothing right now for multibyte state, but might want something later. */
150#endif
151
Chet Ramey495aee42011-11-22 19:11:26 -0500152 char **prompt_string_pointer;
153
Jari Aaltob80f6442004-07-27 13:29:18 +0000154 /* history state affecting or modified by the parser */
155 int current_command_line_count;
156#if defined (HISTORY)
157 int remember_on_history;
158 int history_expansion_inhibited;
159#endif
160
161 /* execution state possibly modified by the parser */
162 int last_command_exit_value;
163#if defined (ARRAY_VARS)
164 ARRAY *pipestatus;
165#endif
166 sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
167
168 /* flags state affecting the parser */
169 int expand_aliases;
170 int echo_input_at_read;
Chet Rameydaefb2c2014-08-01 15:30:48 -0400171 int need_here_doc;
172
Jari Aaltob80f6442004-07-27 13:29:18 +0000173} sh_parser_state_t;
174
Chet Rameyb4839c22011-11-22 20:02:35 -0500175typedef struct _sh_input_line_state_t {
176 char *input_line;
Chet Rameyac50fba2014-02-26 09:36:43 -0500177 size_t input_line_index;
178 size_t input_line_size;
179 size_t input_line_len;
Chet Rameyb4839c22011-11-22 20:02:35 -0500180} sh_input_line_state_t;
181
Jari Aaltob80f6442004-07-27 13:29:18 +0000182/* Let's try declaring these here. */
Chet Ramey80b4d712014-10-05 19:12:20 -0400183extern char *parser_remaining_input __P((void));
184
Jari Aaltob80f6442004-07-27 13:29:18 +0000185extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
186extern void restore_parser_state __P((sh_parser_state_t *));
Chet Rameyb4839c22011-11-22 20:02:35 -0500187
188extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
189extern void restore_input_line_state __P((sh_input_line_state_t *));