-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnutshell.c
More file actions
49 lines (43 loc) · 1018 Bytes
/
nutshell.c
File metadata and controls
49 lines (43 loc) · 1018 Bytes
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
#include "includes.h"
#include "constants.h"
#include "types.h"
#include "prompt.h"
#include "utils.h"
#include "execution.h"
int main()
{
char *input;
size_t input_len;
getcwd(SHELL_HOME_PATH, MAX_PATH_LEN);
while (1)
{
print_prompt();
// read input
input = NULL;
input_len = 0;
if (getline(&input, &input_len, stdin) == -1)
{
if (!feof(stdin))
{
// getline not at EOF, so other error
perror("Error while taking input");
free(input);
exit(EXIT_FAILURE);
}
}
input[strlen(input) - 1] = '\0';
// if non-null input received
if (input)
{
char *command = strtok(input, ";");
while (command)
{
execute(command);
// go to next command
command = strtok(NULL, ";");
}
}
}
free(input);
return 0;
}