-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybash.c
51 lines (46 loc) · 1023 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
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include "command.h"
#include "execute.h"
#include "parser.h"
#include "parsing.h"
#include "builtin.h"
static void show_prompt(void)
{
char current_directory[1000];
current_directory[999] = '\0';
getcwd(current_directory, 1000);
if (current_directory == NULL)
{
printf("You are currently in an inexistent directory");
exit(EXIT_FAILURE);
}
printf("mybash: %s> ", current_directory);
fflush(stdout);
}
int main(int argc, char *argv[])
{
pipeline pipe;
Parser input;
bool quit = false;
input = parser_new(stdin);
while (!quit)
{
quit = parser_at_eof(input);
if (!quit)
{
show_prompt();
pipe = parse_pipeline(input);
if (pipe != NULL)
{
execute_pipeline(pipe);
}
}
}
printf("\n");
parser_destroy(input);
input = NULL;
return EXIT_SUCCESS;
}