-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstructs.h
219 lines (201 loc) · 4.63 KB
/
structs.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#ifndef STRUCT
#define STRUCT
/**
* struct token - categorizes a token
* @id: id of token from TOKEN_ macros
* @str: token
* @prec: the prec
*/
typedef struct token
{
int id;
char *str;
int prec;
} token_t;
/**
* struct tokens - struct for tokenizing string
* @tokens: array of token_t structs with tokenized strings and ids
* @tokensN: amount of tokens parsed
*
* NOTE: do not deallocate everthing from here until the full parse tree
* deallocation, because AST will use tokens from this structure!
*/
typedef struct tokens
{
token_t *tokens;
unsigned int tokensN;
} tokens_t;
/**
* struct token_id - baby token
* @token_id: numerical id
* @token_str: the exact token string to be compared with
* @token_descr: for debugging
* @precedence: the precedence
*/
typedef struct token_id
{
int token_id;
const char *token_str;
const char *token_descr;
int precedence;
} token_types;
/**
* struct ptree - base parse tree struct
* @left: left child node
* @right: right child node
* @parent: parent node
* @token_id: id from macros
* @strings: corresponding strings, NULL if not TOKEN_STRING
* @stringsN: amount of strings in strings +1 (for NULL), 0 if not TOKEN_STRING
*/
typedef struct ptree
{
struct ptree *left;
struct ptree *right;
struct ptree *parent;
int token_id;
char **strings;
unsigned int stringsN;
} ptree_t;
/**
* struct parser - struct to parse
* @tree: resulting parse tree
*/
typedef struct parser
{
ptree_t *tree;
} parser_t;
/**
* struct process - this attributes a parse tree with TOKEN_STRING id with a
* process id
* @ptree: ptree to process
* @pid: pid
* @io_redir: io_redir
* @filename: filename
*/
typedef struct process
{
ptree_t *ptree;
pid_t pid;
/* 0 for no redirection, 3 for >, 4 >>, 5 < */
int io_redir;
char *filename;
} process_t;
/**
* struct pipeline - struct containing multiple processes
* @processes: array of processes
* @processesN: number of processes
* @background: for background tasks
* @background_pid: background of pid
*/
typedef struct pipeline
{
process_t *processes;
unsigned int processesN;
unsigned int background;
pid_t background_pid;
} pipeline_t;
/**
* struct env - struct for holding custom environmental variables list
* @var: environmental variable and value separated by '=' char
* @val: value of env var
* @next: pointer to the next env variable node
*/
typedef struct env
{
char *var;
char *val;
struct env *next;
} env_t;
/**
* struct history - builds linked list of history of input commands
* @number: command number
* @command: the input command
* @next: pointer to next command
*/
typedef struct history
{
unsigned int number;
char *command;
struct history *next;
} history_t;
/**
* struct alias - matches command with appropriate help text output
* @alias: the alias
* @command: the actual command
* @next: address of next node of alias if present
*/
typedef struct alias
{
char *alias;
char *command;
struct alias *next;
} alias_t;
/**
* struct arg_inventory - inventory of support arguments for immediate access
* @input_commands: string of input commands
* @envlist: custom davinci environ linked list
* @buflimit: buflimit max of 1024 chars
* @commands: double pointer to commands list
* @st_mode: st_mode either FIFO or terminal
* @history: linked list of history
* @history_file: the history file to store command history
* @alias_file: the aliases file to store aliases
* @alias: linked list of aliases
* @tokens: tokens list
* @parser: a parse
* @pipeline: pipline list
* @n_bg_jobs: pipeline
* @pipein: pipein variable
* @pipeout: pipeout variable
* @io_redir: io redirection
* @filename: the filename
* @last_bg_pid: last pid
* @exit: indicator to exit or not
* @exit_status: the exit status
*/
typedef struct arg_inventory
{
char *input_commands;
env_t *envlist;
char **commands;
size_t buflimit;
int st_mode;
history_t *history;
char *history_file;
alias_t *alias;
char *alias_file;
tokens_t tokens;
parser_t parser;
pipeline_t pipeline;
int n_bg_jobs;
int pipein;
int pipeout;
/* 0 for no redirection, 3 for >, 4 >>, 5 < */
int io_redir;
char *filename;
pid_t last_bg_pid;
int exit;
int exit_status;
} arg_inventory_t;
/**
* struct _builtins - matches command to appropriate builtin function
* @command: string command for builtin
* @builtin_func: function to handle builtin command
*/
typedef struct _builtins
{
char *command;
int (*builtin_func)(arg_inventory_t *arginv);
} builtins_t;
/**
* struct bins - matches command to appropriate builtin function
* @function: string of function name
* @help: string of name of file
*/
typedef struct bins
{
char *function;
void (*help)(void);
} bins_t;
#endif