-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhsh.c
More file actions
53 lines (46 loc) · 1.14 KB
/
hsh.c
File metadata and controls
53 lines (46 loc) · 1.14 KB
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
#include "main.h"
/**
* main - Main function to run the simple shell.
*
* @argc: Arguments counter.
*
* @argv: Arguments vector.
*
* Return: 0.
*/
int main(int argc __attribute__((unused)), char **argv)
{
size_t n = 0;
int bytes_read = 0, errors = 1, while_st = 1, exit_status = 0;
int validate = 0;
char *command = NULL, *no_line = NULL;
response *req = NULL;
signal(SIGINT, c_handler);
while (while_st)
{
while_st = isatty(STDIN_FILENO), n = 0;
if (while_st == 1)
write(1, "$ ", 2);
bytes_read = getline(&command, &n, stdin);
validate = first_validations(command, bytes_read, &while_st);
if (validate == -1)
break;
else if (validate == 1)
continue;
no_line = strndup(command, bytes_read - 1), free(command);
req = tokenize(no_line);
if (match_built_in(req, &errors, argv[0], &exit_status))
{
free_all(req, &while_st);
continue;
}
if (route_works(req, &while_st, &exit_status))
continue;
if (fail_route(req, argv[0], &errors, &exit_status))
continue;
req->hold = which(req->hold);
validate_last_access(req, argv[0], &errors, &exit_status);
free_all(req, &while_st);
}
return (exit_status);
}