Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 1 | /* command.h -- The structures used internally to represent commands, and |
| 2 | the extern declarations of the functions used to create them. */ |
| 3 | |
Chet Ramey | 495aee4 | 2011-11-22 19:11:26 -0500 | [diff] [blame] | 4 | /* Copyright (C) 1993-2010 Free Software Foundation, Inc. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 5 | |
| 6 | This file is part of GNU Bash, the Bourne Again SHell. |
| 7 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 8 | Bash is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 12 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 13 | Bash is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 17 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 18 | You should have received a copy of the GNU General Public License |
| 19 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 21 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 22 | #if !defined (_COMMAND_H_) |
| 23 | #define _COMMAND_H_ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 24 | |
| 25 | #include "stdc.h" |
| 26 | |
| 27 | /* Instructions describing what kind of thing to do for a redirection. */ |
| 28 | enum r_instruction { |
| 29 | r_output_direction, r_input_direction, r_inputa_direction, |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 30 | r_appending_to, r_reading_until, r_reading_string, |
| 31 | r_duplicating_input, r_duplicating_output, r_deblank_reading_until, |
| 32 | r_close_this, r_err_and_out, r_input_output, r_output_force, |
| 33 | r_duplicating_input_word, r_duplicating_output_word, |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 34 | r_move_input, r_move_output, r_move_input_word, r_move_output_word, |
| 35 | r_append_err_and_out |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 38 | /* Redirection flags; values for rflags */ |
| 39 | #define REDIR_VARASSIGN 0x01 |
| 40 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 41 | /* Redirection errors. */ |
| 42 | #define AMBIGUOUS_REDIRECT -1 |
| 43 | #define NOCLOBBER_REDIRECT -2 |
| 44 | #define RESTRICTED_REDIRECT -3 /* can only happen in restricted shells. */ |
Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 45 | #define HEREDOC_REDIRECT -4 /* here-doc temp file can't be created */ |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 46 | #define BADVAR_REDIRECT -5 /* something wrong with {varname}redir */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 47 | |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 48 | #define CLOBBERING_REDIRECT(ri) \ |
| 49 | (ri == r_output_direction || ri == r_err_and_out) |
| 50 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 51 | #define OUTPUT_REDIRECT(ri) \ |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 52 | (ri == r_output_direction || ri == r_input_output || ri == r_err_and_out || ri == r_append_err_and_out) |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 53 | |
| 54 | #define INPUT_REDIRECT(ri) \ |
| 55 | (ri == r_input_direction || ri == r_inputa_direction || ri == r_input_output) |
| 56 | |
| 57 | #define WRITE_REDIRECT(ri) \ |
| 58 | (ri == r_output_direction || \ |
| 59 | ri == r_input_output || \ |
| 60 | ri == r_err_and_out || \ |
| 61 | ri == r_appending_to || \ |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 62 | ri == r_append_err_and_out || \ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 63 | ri == r_output_force) |
| 64 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 65 | /* redirection needs translation */ |
| 66 | #define TRANSLATE_REDIRECT(ri) \ |
| 67 | (ri == r_duplicating_input_word || ri == r_duplicating_output_word || \ |
| 68 | ri == r_move_input_word || ri == r_move_output_word) |
| 69 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 70 | /* Command Types: */ |
| 71 | enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select, |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 72 | cm_connection, cm_function_def, cm_until, cm_group, |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 73 | cm_arith, cm_cond, cm_arith_for, cm_subshell, cm_coproc }; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 74 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 75 | /* Possible values for the `flags' field of a WORD_DESC. */ |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 76 | #define W_HASDOLLAR 0x000001 /* Dollar sign present. */ |
| 77 | #define W_QUOTED 0x000002 /* Some form of quote character is present. */ |
| 78 | #define W_ASSIGNMENT 0x000004 /* This word is a variable assignment. */ |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 79 | #define W_SPLITSPACE 0x000008 /* Split this word on " " regardless of IFS */ |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 80 | #define W_NOSPLIT 0x000010 /* Do not perform word splitting on this word because ifs is empty string. */ |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 81 | #define W_NOGLOB 0x000020 /* Do not perform globbing on this word. */ |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 82 | #define W_NOSPLIT2 0x000040 /* Don't split word except for $@ expansion (using spaces) because context does not allow it. */ |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 83 | #define W_TILDEEXP 0x000080 /* Tilde expand this assignment word */ |
| 84 | #define W_DOLLARAT 0x000100 /* $@ and its special handling */ |
| 85 | #define W_DOLLARSTAR 0x000200 /* $* and its special handling */ |
| 86 | #define W_NOCOMSUB 0x000400 /* Don't perform command substitution on this word */ |
| 87 | #define W_ASSIGNRHS 0x000800 /* Word is rhs of an assignment statement */ |
| 88 | #define W_NOTILDE 0x001000 /* Don't perform tilde expansion on this word */ |
| 89 | #define W_ITILDE 0x002000 /* Internal flag for word expansion */ |
| 90 | #define W_NOEXPAND 0x004000 /* Don't expand at all -- do quote removal */ |
| 91 | #define W_COMPASSIGN 0x008000 /* Compound assignment */ |
| 92 | #define W_ASSNBLTIN 0x010000 /* word is a builtin command that takes assignments */ |
| 93 | #define W_ASSIGNARG 0x020000 /* word is assignment argument to command */ |
| 94 | #define W_HASQUOTEDNULL 0x040000 /* word contains a quoted null character */ |
| 95 | #define W_DQUOTE 0x080000 /* word should be treated as if double-quoted */ |
| 96 | #define W_NOPROCSUB 0x100000 /* don't perform process substitution */ |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 97 | #define W_HASCTLESC 0x200000 /* word contains literal CTLESC characters */ |
| 98 | #define W_ASSIGNASSOC 0x400000 /* word looks like associative array assignment */ |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 99 | #define W_ASSIGNARRAY 0x800000 /* word looks like a compound indexed array assignment */ |
| 100 | #define W_ARRAYIND 0x1000000 /* word is an array index being expanded */ |
| 101 | #define W_ASSNGLOBAL 0x2000000 /* word is a global assignment to declare (declare/typeset -g) */ |
| 102 | #define W_NOBRACE 0x4000000 /* Don't perform brace expansion */ |
| 103 | #define W_ASSIGNINT 0x8000000 /* word is an integer assignment to declare */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 104 | |
| 105 | /* Possible values for subshell_environment */ |
| 106 | #define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */ |
| 107 | #define SUBSHELL_PAREN 0x02 /* subshell caused by ( ... ) */ |
| 108 | #define SUBSHELL_COMSUB 0x04 /* subshell caused by `command` or $(command) */ |
| 109 | #define SUBSHELL_FORK 0x08 /* subshell caused by executing a disk command */ |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 110 | #define SUBSHELL_PIPE 0x10 /* subshell from a pipeline element */ |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 111 | #define SUBSHELL_PROCSUB 0x20 /* subshell caused by <(command) or >(command) */ |
| 112 | #define SUBSHELL_COPROC 0x40 /* subshell from a coproc pipeline */ |
Chet Ramey | 495aee4 | 2011-11-22 19:11:26 -0500 | [diff] [blame] | 113 | #define SUBSHELL_RESETTRAP 0x80 /* subshell needs to reset trap strings on first call to trap */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 114 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 115 | /* A structure which represents a word. */ |
| 116 | typedef struct word_desc { |
| 117 | char *word; /* Zero terminated string. */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 118 | int flags; /* Flags associated with this word. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 119 | } WORD_DESC; |
| 120 | |
| 121 | /* A linked list of words. */ |
| 122 | typedef struct word_list { |
| 123 | struct word_list *next; |
| 124 | WORD_DESC *word; |
| 125 | } WORD_LIST; |
| 126 | |
| 127 | |
| 128 | /* **************************************************************** */ |
| 129 | /* */ |
| 130 | /* Shell Command Structs */ |
| 131 | /* */ |
| 132 | /* **************************************************************** */ |
| 133 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 134 | /* What a redirection descriptor looks like. If the redirection instruction |
| 135 | is ri_duplicating_input or ri_duplicating_output, use DEST, otherwise |
| 136 | use the file in FILENAME. Out-of-range descriptors are identified by a |
| 137 | negative DEST. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 138 | |
| 139 | typedef union { |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 140 | int dest; /* Place to redirect REDIRECTOR to, or ... */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 141 | WORD_DESC *filename; /* filename to redirect to. */ |
| 142 | } REDIRECTEE; |
| 143 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 144 | /* Structure describing a redirection. If REDIRECTOR is negative, the parser |
| 145 | (or translator in redir.c) encountered an out-of-range file descriptor. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 146 | typedef struct redirect { |
| 147 | struct redirect *next; /* Next element, or NULL. */ |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 148 | REDIRECTEE redirector; /* Descriptor or varname to be redirected. */ |
| 149 | int rflags; /* Private flags for this redirection */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 150 | int flags; /* Flag value for `open'. */ |
| 151 | enum r_instruction instruction; /* What to do with the information. */ |
| 152 | REDIRECTEE redirectee; /* File descriptor or filename */ |
| 153 | char *here_doc_eof; /* The word that appeared in <<foo. */ |
| 154 | } REDIRECT; |
| 155 | |
| 156 | /* An element used in parsing. A single word or a single redirection. |
| 157 | This is an ephemeral construct. */ |
| 158 | typedef struct element { |
| 159 | WORD_DESC *word; |
| 160 | REDIRECT *redirect; |
| 161 | } ELEMENT; |
| 162 | |
| 163 | /* Possible values for command->flags. */ |
| 164 | #define CMD_WANT_SUBSHELL 0x01 /* User wants a subshell: ( command ) */ |
| 165 | #define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */ |
| 166 | #define CMD_INVERT_RETURN 0x04 /* Invert the exit value. */ |
| 167 | #define CMD_IGNORE_RETURN 0x08 /* Ignore the exit value. For set -e. */ |
| 168 | #define CMD_NO_FUNCTIONS 0x10 /* Ignore functions during command lookup. */ |
| 169 | #define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */ |
| 170 | #define CMD_NO_FORK 0x40 /* Don't fork; just call execve */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 171 | #define CMD_TIME_PIPELINE 0x80 /* Time a pipeline */ |
| 172 | #define CMD_TIME_POSIX 0x100 /* time -p; use POSIX.2 time output spec. */ |
Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 173 | #define CMD_AMPERSAND 0x200 /* command & */ |
| 174 | #define CMD_STDIN_REDIR 0x400 /* async command needs implicit </dev/null */ |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 175 | #define CMD_COMMAND_BUILTIN 0x0800 /* command executed by `command' builtin */ |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 176 | #define CMD_COPROC_SUBSHELL 0x1000 |
Chet Ramey | 495aee4 | 2011-11-22 19:11:26 -0500 | [diff] [blame] | 177 | #define CMD_LASTPIPE 0x2000 |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 178 | |
| 179 | /* What a command looks like. */ |
| 180 | typedef struct command { |
| 181 | enum command_type type; /* FOR CASE WHILE IF CONNECTION or SIMPLE. */ |
| 182 | int flags; /* Flags controlling execution environment. */ |
| 183 | int line; /* line number the command starts on */ |
| 184 | REDIRECT *redirects; /* Special redirects for FOR CASE, etc. */ |
| 185 | union { |
| 186 | struct for_com *For; |
| 187 | struct case_com *Case; |
| 188 | struct while_com *While; |
| 189 | struct if_com *If; |
| 190 | struct connection *Connection; |
| 191 | struct simple_com *Simple; |
| 192 | struct function_def *Function_def; |
| 193 | struct group_com *Group; |
| 194 | #if defined (SELECT_COMMAND) |
| 195 | struct select_com *Select; |
| 196 | #endif |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 197 | #if defined (DPAREN_ARITHMETIC) |
| 198 | struct arith_com *Arith; |
| 199 | #endif |
| 200 | #if defined (COND_COMMAND) |
| 201 | struct cond_com *Cond; |
| 202 | #endif |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 203 | #if defined (ARITH_FOR_COMMAND) |
| 204 | struct arith_for_com *ArithFor; |
| 205 | #endif |
| 206 | struct subshell_com *Subshell; |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 207 | struct coproc_com *Coproc; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 208 | } value; |
| 209 | } COMMAND; |
| 210 | |
| 211 | /* Structure used to represent the CONNECTION type. */ |
| 212 | typedef struct connection { |
| 213 | int ignore; /* Unused; simplifies make_command (). */ |
| 214 | COMMAND *first; /* Pointer to the first command. */ |
| 215 | COMMAND *second; /* Pointer to the second command. */ |
| 216 | int connector; /* What separates this command from others. */ |
| 217 | } CONNECTION; |
| 218 | |
| 219 | /* Structures used to represent the CASE command. */ |
| 220 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 221 | /* Values for FLAGS word in a PATTERN_LIST */ |
| 222 | #define CASEPAT_FALLTHROUGH 0x01 |
| 223 | #define CASEPAT_TESTNEXT 0x02 |
| 224 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 225 | /* Pattern/action structure for CASE_COM. */ |
| 226 | typedef struct pattern_list { |
| 227 | struct pattern_list *next; /* Clause to try in case this one failed. */ |
| 228 | WORD_LIST *patterns; /* Linked list of patterns to test. */ |
| 229 | COMMAND *action; /* Thing to execute if a pattern matches. */ |
Jari Aalto | 95732b4 | 2005-12-07 14:08:12 +0000 | [diff] [blame] | 230 | int flags; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 231 | } PATTERN_LIST; |
| 232 | |
| 233 | /* The CASE command. */ |
| 234 | typedef struct case_com { |
| 235 | int flags; /* See description of CMD flags. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 236 | int line; /* line number the `case' keyword appears on */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 237 | WORD_DESC *word; /* The thing to test. */ |
| 238 | PATTERN_LIST *clauses; /* The clauses to test against, or NULL. */ |
| 239 | } CASE_COM; |
| 240 | |
| 241 | /* FOR command. */ |
| 242 | typedef struct for_com { |
| 243 | int flags; /* See description of CMD flags. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 244 | int line; /* line number the `for' keyword appears on */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 245 | WORD_DESC *name; /* The variable name to get mapped over. */ |
| 246 | WORD_LIST *map_list; /* The things to map over. This is never NULL. */ |
| 247 | COMMAND *action; /* The action to execute. |
| 248 | During execution, NAME is bound to successive |
| 249 | members of MAP_LIST. */ |
| 250 | } FOR_COM; |
| 251 | |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 252 | #if defined (ARITH_FOR_COMMAND) |
| 253 | typedef struct arith_for_com { |
| 254 | int flags; |
| 255 | int line; /* generally used for error messages */ |
| 256 | WORD_LIST *init; |
| 257 | WORD_LIST *test; |
| 258 | WORD_LIST *step; |
| 259 | COMMAND *action; |
| 260 | } ARITH_FOR_COM; |
| 261 | #endif |
| 262 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 263 | #if defined (SELECT_COMMAND) |
| 264 | /* KSH SELECT command. */ |
| 265 | typedef struct select_com { |
| 266 | int flags; /* See description of CMD flags. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 267 | int line; /* line number the `select' keyword appears on */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 268 | WORD_DESC *name; /* The variable name to get mapped over. */ |
| 269 | WORD_LIST *map_list; /* The things to map over. This is never NULL. */ |
| 270 | COMMAND *action; /* The action to execute. |
| 271 | During execution, NAME is bound to the member of |
| 272 | MAP_LIST chosen by the user. */ |
| 273 | } SELECT_COM; |
| 274 | #endif /* SELECT_COMMAND */ |
| 275 | |
| 276 | /* IF command. */ |
| 277 | typedef struct if_com { |
| 278 | int flags; /* See description of CMD flags. */ |
| 279 | COMMAND *test; /* Thing to test. */ |
| 280 | COMMAND *true_case; /* What to do if the test returned non-zero. */ |
| 281 | COMMAND *false_case; /* What to do if the test returned zero. */ |
| 282 | } IF_COM; |
| 283 | |
| 284 | /* WHILE command. */ |
| 285 | typedef struct while_com { |
| 286 | int flags; /* See description of CMD flags. */ |
| 287 | COMMAND *test; /* Thing to test. */ |
| 288 | COMMAND *action; /* Thing to do while test is non-zero. */ |
| 289 | } WHILE_COM; |
| 290 | |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 291 | #if defined (DPAREN_ARITHMETIC) |
| 292 | /* The arithmetic evaluation command, ((...)). Just a set of flags and |
| 293 | a WORD_LIST, of which the first element is the only one used, for the |
| 294 | time being. */ |
| 295 | typedef struct arith_com { |
| 296 | int flags; |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 297 | int line; |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 298 | WORD_LIST *exp; |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 299 | } ARITH_COM; |
| 300 | #endif /* DPAREN_ARITHMETIC */ |
| 301 | |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 302 | /* The conditional command, [[...]]. This is a binary tree -- we slipped |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 303 | a recursive-descent parser into the YACC grammar to parse it. */ |
| 304 | #define COND_AND 1 |
| 305 | #define COND_OR 2 |
| 306 | #define COND_UNARY 3 |
| 307 | #define COND_BINARY 4 |
| 308 | #define COND_TERM 5 |
| 309 | #define COND_EXPR 6 |
| 310 | |
| 311 | typedef struct cond_com { |
| 312 | int flags; |
| 313 | int line; |
| 314 | int type; |
| 315 | WORD_DESC *op; |
| 316 | struct cond_com *left, *right; |
| 317 | } COND_COM; |
| 318 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 319 | /* The "simple" command. Just a collection of words and redirects. */ |
| 320 | typedef struct simple_com { |
| 321 | int flags; /* See description of CMD flags. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 322 | int line; /* line number the command starts on */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 323 | WORD_LIST *words; /* The program name, the arguments, |
| 324 | variable assignments, etc. */ |
| 325 | REDIRECT *redirects; /* Redirections to perform. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 326 | } SIMPLE_COM; |
| 327 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 328 | /* The "function definition" command. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 329 | typedef struct function_def { |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 330 | int flags; /* See description of CMD flags. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 331 | int line; /* Line number the function def starts on. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 332 | WORD_DESC *name; /* The name of the function. */ |
| 333 | COMMAND *command; /* The parsed execution tree. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 334 | char *source_file; /* file in which function was defined, if any */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 335 | } FUNCTION_DEF; |
| 336 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 337 | /* A command that is `grouped' allows pipes and redirections to affect all |
| 338 | commands in the group. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 339 | typedef struct group_com { |
| 340 | int ignore; /* See description of CMD flags. */ |
| 341 | COMMAND *command; |
| 342 | } GROUP_COM; |
| 343 | |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 344 | typedef struct subshell_com { |
| 345 | int flags; |
| 346 | COMMAND *command; |
| 347 | } SUBSHELL_COM; |
| 348 | |
Jari Aalto | 17345e5 | 2009-02-19 22:21:29 +0000 | [diff] [blame] | 349 | #define COPROC_RUNNING 0x01 |
| 350 | #define COPROC_DEAD 0x02 |
| 351 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 352 | typedef struct coproc { |
| 353 | char *c_name; |
| 354 | pid_t c_pid; |
| 355 | int c_rfd; |
| 356 | int c_wfd; |
| 357 | int c_rsave; |
| 358 | int c_wsave; |
| 359 | int c_flags; |
| 360 | int c_status; |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 361 | int c_lock; |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 362 | } Coproc; |
| 363 | |
| 364 | typedef struct coproc_com { |
| 365 | int flags; |
| 366 | char *name; |
| 367 | COMMAND *command; |
| 368 | } COPROC_COM; |
| 369 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 370 | extern COMMAND *global_command; |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 371 | extern Coproc sh_coproc; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 372 | |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 373 | /* Possible command errors */ |
| 374 | #define CMDERR_DEFAULT 0 |
| 375 | #define CMDERR_BADTYPE 1 |
| 376 | #define CMDERR_BADCONN 2 |
| 377 | #define CMDERR_BADJUMP 3 |
| 378 | |
| 379 | #define CMDERR_LAST 3 |
| 380 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 381 | /* Forward declarations of functions declared in copy_cmd.c. */ |
| 382 | |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 383 | extern FUNCTION_DEF *copy_function_def_contents __P((FUNCTION_DEF *, FUNCTION_DEF *)); |
| 384 | extern FUNCTION_DEF *copy_function_def __P((FUNCTION_DEF *)); |
| 385 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 386 | extern WORD_DESC *copy_word __P((WORD_DESC *)); |
| 387 | extern WORD_LIST *copy_word_list __P((WORD_LIST *)); |
| 388 | extern REDIRECT *copy_redirect __P((REDIRECT *)); |
| 389 | extern REDIRECT *copy_redirects __P((REDIRECT *)); |
| 390 | extern COMMAND *copy_command __P((COMMAND *)); |
| 391 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 392 | #endif /* _COMMAND_H_ */ |