-
Notifications
You must be signed in to change notification settings - Fork 0
/
command-internals.h
118 lines (95 loc) · 2.3 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
enum command_type
{
AND_COMMAND,
SEQUENCE_COMMAND,
OR_COMMAND, // A || B - B only runs if A exists with nonzero (false)
PIPE_COMMAND, // A | B - pipes the output of A into the input of B
SIMPLE_COMMAND, // a simple command - just a regular command (i.e. ls)
SUBSHELL_COMMAND, // ( A ) - a child shell is spawned to handle these commands
SPACER // for NEWLINES
};
enum token_type
{
BEGIN,
AND,
OR,
WORD,
PIPE,
LEFT_PAREN,
RIGHT_PAREN,
LESS_THAN,
GREATER_THAN,
SEMICOLON,
NEWLINE,
END
};
struct command
{
enum command_type type;
// Exit status
int status;
// I/O redirections. If none, value is 0.
char *input;
char *output;
union //this is a union because a command could only be one of these types.
{
// 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
{
int tokenIndex; //so we can tell which token we are currently reading
char curCh;
int finalIndex;
int (*getbyte) (void *);
void *arg;
token_t tokenArray;
int tokenCount;
int maxTokens;
int maxCommands;
int iterator;
int dontGet; //if set to 1 causes get_next_char to not read the next character immediately
// Line count
int lineNumber;
command_t arrayCommands;
int arrayCommandsIndex;
command_t newHome;
int newHomeIterator;
//this int is to keep track of what command the read_command_stream function is at
int outputCounter;
};
struct token //Need a token because words can have a value
{
enum token_type tType;
// Data associated with a command.
char* wordString;
//for error checking purposes
int lineFound;
int isParenRead;
};
struct word_node
{
char* word;
struct word_node* next;
};
struct dep_node
{
struct parent_node* dependent;
struct dep_node* next;
};
//Nodes describing parent commands and their dependencies
struct parent_node
{
struct command* command;
struct word_node* inputs;
struct word_node* outputs;
int dep_counter;
struct dep_node* dependencies;
int pid;
struct parent_node* next;
};