You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if !defined (_COMMAND_H_)
#define _COMMAND_H_
#define AMBIGUOUS_REDIRECT -1
#define NOCLOBBER_REDIRECT -2
#define RESTRICTED_REDIRECT -3 /* can only happen in restricted shells. */
+#define HEREDOC_REDIRECT -4 /* here-doc temp file can't be created */
+
+#define CLOBBERING_REDIRECT(ri) \
+ (ri == r_output_direction || ri == r_err_and_out)
#define OUTPUT_REDIRECT(ri) \
(ri == r_output_direction || ri == r_input_output || ri == r_err_and_out)
/* Command Types: */
enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
- cm_connection, cm_function_def, cm_until, cm_group };
+ cm_connection, cm_function_def, cm_until, cm_group,
+ cm_arith, cm_cond, cm_arith_for, cm_subshell };
/* Possible values for the `flags' field of a WORD_DESC. */
#define W_HASDOLLAR 0x01 /* Dollar sign present. */
#define W_ASSIGNMENT 0x04 /* This word is a variable assignment. */
#define W_GLOBEXP 0x08 /* This word is the result of a glob expansion. */
#define W_NOSPLIT 0x10 /* Do not perform word splitting on this word. */
+#define W_NOGLOB 0x20 /* Do not perform globbing on this word. */
+#define W_NOSPLIT2 0x40 /* Don't split word except for $@ expansion. */
/* Possible values for subshell_environment */
#define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */
#define SUBSHELL_PAREN 0x02 /* subshell caused by ( ... ) */
#define SUBSHELL_COMSUB 0x04 /* subshell caused by `command` or $(command) */
#define SUBSHELL_FORK 0x08 /* subshell caused by executing a disk command */
+#define SUBSHELL_PIPE 0x10 /* subshell from a pipeline element */
/* A structure which represents a word. */
typedef struct word_desc {
#define CMD_NO_FORK 0x40 /* Don't fork; just call execve */
#define CMD_TIME_PIPELINE 0x80 /* Time a pipeline */
#define CMD_TIME_POSIX 0x100 /* time -p; use POSIX.2 time output spec. */
+#define CMD_AMPERSAND 0x200 /* command & */
+#define CMD_STDIN_REDIR 0x400 /* async command needs implicit </dev/null */
/* What a command looks like. */
typedef struct command {
#if defined (SELECT_COMMAND)
struct select_com *Select;
#endif
+#if defined (DPAREN_ARITHMETIC)
+ struct arith_com *Arith;
+#endif
+#if defined (COND_COMMAND)
+ struct cond_com *Cond;
+#endif
+#if defined (ARITH_FOR_COMMAND)
+ struct arith_for_com *ArithFor;
+#endif
+ struct subshell_com *Subshell;
} value;
} COMMAND;
members of MAP_LIST. */
} FOR_COM;
+#if defined (ARITH_FOR_COMMAND)
+typedef struct arith_for_com {
+ int flags;
+ int line; /* generally used for error messages */
+ WORD_LIST *init;
+ WORD_LIST *test;
+ WORD_LIST *step;
+ COMMAND *action;
+} ARITH_FOR_COM;
+#endif
+
#if defined (SELECT_COMMAND)
/* KSH SELECT command. */
typedef struct select_com {
COMMAND *action; /* Thing to do while test is non-zero. */
} WHILE_COM;
+#if defined (DPAREN_ARITHMETIC)
+/* The arithmetic evaluation command, ((...)). Just a set of flags and
+ a WORD_LIST, of which the first element is the only one used, for the
+ time being. */
+typedef struct arith_com {
+ int flags;
+ WORD_LIST *exp;
+ int line;
+} ARITH_COM;
+#endif /* DPAREN_ARITHMETIC */
+
+/* The conditional command, [[...]]. This is a binary tree -- we slippped
+ a recursive-descent parser into the YACC grammar to parse it. */
+#define COND_AND 1
+#define COND_OR 2
+#define COND_UNARY 3
+#define COND_BINARY 4
+#define COND_TERM 5
+#define COND_EXPR 6
+
+typedef struct cond_com {
+ int flags;
+ int line;
+ int type;
+ WORD_DESC *op;
+ struct cond_com *left, *right;
+} COND_COM;
+
/* The "simple" command. Just a collection of words and redirects. */
typedef struct simple_com {
int flags; /* See description of CMD flags. */
/* The "function definition" command. */
typedef struct function_def {
- int ignore; /* See description of CMD flags. */
+ int flags; /* See description of CMD flags. */
WORD_DESC *name; /* The name of the function. */
COMMAND *command; /* The parsed execution tree. */
int line; /* Line number the function def starts on. */
COMMAND *command;
} GROUP_COM;
+typedef struct subshell_com {
+ int flags;
+ COMMAND *command;
+} SUBSHELL_COM;
+
extern COMMAND *global_command;
+/* Possible command errors */
+#define CMDERR_DEFAULT 0
+#define CMDERR_BADTYPE 1
+#define CMDERR_BADCONN 2
+#define CMDERR_BADJUMP 3
+
+#define CMDERR_LAST 3
+
/* Forward declarations of functions declared in copy_cmd.c. */
extern WORD_DESC *copy_word __P((WORD_DESC *));