-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybash.c
39 lines (31 loc) · 856 Bytes
/
mybash.c
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
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include "internal_commands.h"
#include "command.h"
#include "execute.h"
#include "parsing.h"
#include "prompt.h"
int main(int argc, char *argv[]) {
pipeline pipe = NULL;
Parser input = parser_new(stdin);
quit = false;
while (!quit) {
// WNOHANG is an option to return immediately if no child has exited
while (waitpid(-1, NULL, WNOHANG) > 0) {
};
// Preventing fore and background command collapse
show_prompt();
pipe = parse_pipeline(input);
if (pipe != NULL) {
execute_pipeline(pipe);
pipe = pipeline_destroy(pipe);
}
quit = quit || parser_at_eof(input);
}
printf("\n");
parser_destroy(input);
input = NULL;
return EXIT_SUCCESS;
}