-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
63 lines (52 loc) · 1.13 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
#include "shell.h"
char **commands = NULL;
char *line = NULL;
char *shell_name = NULL;
int status = 0;
/**
* main - the main shell code
* @argc: number of arguments passed
* @argv: program arguments to be parsed
*
* applies the functions in utils and helpers
* implements EOF
* Prints error on Failure
* Return: 0 on success
*/
int main(int argc __attribute__((unused)), char **argv)
{
char **current_command = NULL;
int i, type_command = 0;
size_t n = 0;
signal(SIGINT, ctrl_c_handler);
shell_name = argv[0];
while (1)
{
non_interactive();
print(" ($) ", STDOUT_FILENO);
if (getline(&line, &n, stdin) == -1)
{
free(line);
exit(status);
}
remove_newline(line);
remove_comment(line);
commands = tokenizer(line, ";");
for (i = 0; commands[i] != NULL; i++)
{
current_command = tokenizer(commands[i], " ");
if (current_command[0] == NULL)
{
free(current_command);
break;
}
type_command = parse_command(current_command[0]);
/* initializer - */
initializer(current_command, type_command);
free(current_command);
}
free(commands);
}
free(line);
return (status);
}