-
Notifications
You must be signed in to change notification settings - Fork 0
/
command-internals.h
49 lines (40 loc) · 948 Bytes
/
command-internals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// UCLA CS 111 Lab 1 command internals
#ifndef COMMAND_INTERNALS_H
#define COMMAND_INTERNALS_H
enum command_type
{
AND_COMMAND, // A && B
SEQUENCE_COMMAND, // A ; B
OR_COMMAND, // A || B
PIPE_COMMAND, // A | B
SIMPLE_COMMAND, // a simple command
SUBSHELL_COMMAND, // ( A )
};
// Data associated with a command.
struct command
{
enum command_type type;
// Exit status, or -1 if not known (e.g., because it has not exited yet).
int status;
// I/O redirections, or null if none.
char *input;
char *output;
int *read_pipe;
int *write_pipe;
union
{
// for AND_COMMAND, SEQUENCE_COMMAND, OR_COMMAND, PIPE_COMMAND:
struct command *command[2];
// for SIMPLE_COMMAND:
char **word;
// for SUBSHELL_COMMAND:
struct command *subshell_command;
} u;
};
struct command_stream
{
command_t* commands;
int num_commands;
int index;
};
#endif