]> git.ipfire.org Git - thirdparty/bash.git/blame - command.h
Imported from ../bash-1.14.7.tar.gz.
[thirdparty/bash.git] / command.h
CommitLineData
726f6388
JA
1/* command.h -- The structures used internally to represent commands, and
2 the extern declarations of the functions used to create them. */
3
4/* Copyright (C) 1993 Free Software Foundation, Inc.
5
6 This file is part of GNU Bash, the Bourne Again SHell.
7
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#if !defined (_COMMAND_H)
23#define _COMMAND_H
24
25#include "stdc.h"
26
27/* Instructions describing what kind of thing to do for a redirection. */
28enum r_instruction {
29 r_output_direction, r_input_direction, r_inputa_direction,
30 r_appending_to, r_reading_until, r_duplicating_input,
31 r_duplicating_output, r_deblank_reading_until, r_close_this,
32 r_err_and_out, r_input_output, r_output_force,
33 r_duplicating_input_word, r_duplicating_output_word
34};
35
36/* Command Types: */
37enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
38 cm_connection, cm_function_def, cm_until, cm_group };
39
40/* A structure which represents a word. */
41typedef struct word_desc {
42 char *word; /* Zero terminated string. */
43 int dollar_present; /* Non-zero means dollar sign present. */
44 int quoted; /* Non-zero means single, double, or back quote
45 or backslash is present. */
46 int assignment; /* Non-zero means that this word contains an
47 assignment. */
48} WORD_DESC;
49
50/* A linked list of words. */
51typedef struct word_list {
52 struct word_list *next;
53 WORD_DESC *word;
54} WORD_LIST;
55
56
57/* **************************************************************** */
58/* */
59/* Shell Command Structs */
60/* */
61/* **************************************************************** */
62
63/* What a redirection descriptor looks like. If FLAGS is IS_DESCRIPTOR,
64 then we use REDIRECTEE.DEST, else we use the file specified. */
65
66typedef union {
67 long dest; /* Place to redirect REDIRECTOR to, or ... */
68 WORD_DESC *filename; /* filename to redirect to. */
69} REDIRECTEE;
70
71typedef struct redirect {
72 struct redirect *next; /* Next element, or NULL. */
73 int redirector; /* Descriptor to be redirected. */
74 int flags; /* Flag value for `open'. */
75 enum r_instruction instruction; /* What to do with the information. */
76 REDIRECTEE redirectee; /* File descriptor or filename */
77 char *here_doc_eof; /* The word that appeared in <<foo. */
78} REDIRECT;
79
80/* An element used in parsing. A single word or a single redirection.
81 This is an ephemeral construct. */
82typedef struct element {
83 WORD_DESC *word;
84 REDIRECT *redirect;
85} ELEMENT;
86
87/* Possible values for command->flags. */
88#define CMD_WANT_SUBSHELL 0x01 /* User wants a subshell: ( command ) */
89#define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */
90#define CMD_INVERT_RETURN 0x04 /* Invert the exit value. */
91#define CMD_IGNORE_RETURN 0x08 /* Ignore the exit value. For set -e. */
92#define CMD_NO_FUNCTIONS 0x10 /* Ignore functions during command lookup. */
93#define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */
94#define CMD_NO_FORK 0x40 /* Don't fork; just call execve */
95
96/* What a command looks like. */
97typedef struct command {
98 enum command_type type; /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
99 int flags; /* Flags controlling execution environment. */
100 int line; /* line number the command starts on */
101 REDIRECT *redirects; /* Special redirects for FOR CASE, etc. */
102 union {
103 struct for_com *For;
104 struct case_com *Case;
105 struct while_com *While;
106 struct if_com *If;
107 struct connection *Connection;
108 struct simple_com *Simple;
109 struct function_def *Function_def;
110 struct group_com *Group;
111#if defined (SELECT_COMMAND)
112 struct select_com *Select;
113#endif
114 } value;
115} COMMAND;
116
117/* Structure used to represent the CONNECTION type. */
118typedef struct connection {
119 int ignore; /* Unused; simplifies make_command (). */
120 COMMAND *first; /* Pointer to the first command. */
121 COMMAND *second; /* Pointer to the second command. */
122 int connector; /* What separates this command from others. */
123} CONNECTION;
124
125/* Structures used to represent the CASE command. */
126
127/* Pattern/action structure for CASE_COM. */
128typedef struct pattern_list {
129 struct pattern_list *next; /* Clause to try in case this one failed. */
130 WORD_LIST *patterns; /* Linked list of patterns to test. */
131 COMMAND *action; /* Thing to execute if a pattern matches. */
132} PATTERN_LIST;
133
134/* The CASE command. */
135typedef struct case_com {
136 int flags; /* See description of CMD flags. */
137 WORD_DESC *word; /* The thing to test. */
138 PATTERN_LIST *clauses; /* The clauses to test against, or NULL. */
139} CASE_COM;
140
141/* FOR command. */
142typedef struct for_com {
143 int flags; /* See description of CMD flags. */
144 WORD_DESC *name; /* The variable name to get mapped over. */
145 WORD_LIST *map_list; /* The things to map over. This is never NULL. */
146 COMMAND *action; /* The action to execute.
147 During execution, NAME is bound to successive
148 members of MAP_LIST. */
149} FOR_COM;
150
151#if defined (SELECT_COMMAND)
152/* KSH SELECT command. */
153typedef struct select_com {
154 int flags; /* See description of CMD flags. */
155 WORD_DESC *name; /* The variable name to get mapped over. */
156 WORD_LIST *map_list; /* The things to map over. This is never NULL. */
157 COMMAND *action; /* The action to execute.
158 During execution, NAME is bound to the member of
159 MAP_LIST chosen by the user. */
160} SELECT_COM;
161#endif /* SELECT_COMMAND */
162
163/* IF command. */
164typedef struct if_com {
165 int flags; /* See description of CMD flags. */
166 COMMAND *test; /* Thing to test. */
167 COMMAND *true_case; /* What to do if the test returned non-zero. */
168 COMMAND *false_case; /* What to do if the test returned zero. */
169} IF_COM;
170
171/* WHILE command. */
172typedef struct while_com {
173 int flags; /* See description of CMD flags. */
174 COMMAND *test; /* Thing to test. */
175 COMMAND *action; /* Thing to do while test is non-zero. */
176} WHILE_COM;
177
178/* The "simple" command. Just a collection of words and redirects. */
179typedef struct simple_com {
180 int flags; /* See description of CMD flags. */
181 WORD_LIST *words; /* The program name, the arguments,
182 variable assignments, etc. */
183 REDIRECT *redirects; /* Redirections to perform. */
184 int line; /* line number the command starts on */
185} SIMPLE_COM;
186
187/* The "function_def" command. This isn't really a command, but it is
188 represented as such for now. If the function def appears within
189 `(' `)' the parser tries to set the SUBSHELL bit of the command. That
190 means that FUNCTION_DEF has to be run through the executor. Maybe this
191 command should be defined in a subshell. Who knows or cares. */
192typedef struct function_def {
193 int ignore; /* See description of CMD flags. */
194 WORD_DESC *name; /* The name of the function. */
195 COMMAND *command; /* The parsed execution tree. */
196} FUNCTION_DEF;
197
198/* A command that is `grouped' allows pipes to take effect over
199 the entire command structure. */
200typedef struct group_com {
201 int ignore; /* See description of CMD flags. */
202 COMMAND *command;
203} GROUP_COM;
204
205extern COMMAND *global_command;
206
207/* Forward declarations of functions declared in copy_cmd.c. */
208
209extern WORD_DESC *copy_word __P((WORD_DESC *));
210extern WORD_LIST *copy_word_list __P((WORD_LIST *));
211extern REDIRECT *copy_redirect __P((REDIRECT *));
212extern REDIRECT *copy_redirects __P((REDIRECT *));
213extern COMMAND *copy_command __P((COMMAND *));
214
215#endif /* _COMMAND_H */