-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
72 lines (68 loc) · 1.2 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
64
65
66
67
68
69
70
71
72
#include "shell.h"
/**
* run - This function executes the program
* @str: command and arguments
*/
void run(char *str)
{
char **argv = NULL;
int w_len = 0, execFlag = 0;
w_len = count_input(str);
if (str[0] != '\n' && w_len > 0)
{
argv = tokenize(str, " \t", w_len);
execFlag = builtin_functions(argv, str);
if (!execFlag)
{
argv[0] = find(argv[0]);
if (argv[0] && access(argv[0], X_OK) == 0)
execute(argv[0], argv);
else
{
exit_status = 127;
fprintf(stderr, "./hsh: 1: %s: not found\n", argv[0]);
}
}
frees_tokens(argv);
}
}
/**
* main - Entry point
* @ac: Number of argumenents
* @av: Arguments
*
* Description: Simple shell project
*
* Return: Always 0
*/
int main(int ac, char **av)
{
char *str = NULL;
int res = 0, execFlag = 0;
size_t num = 0;
if (ac == 2)
simple_shell(av[1]);
cpyEnviron();
while (1)
{
signal(SIGINT, signal_handler);
if (isatty(STDIN_FILENO))
_printf("$ ");
res = getline(&str, &num, stdin);
if (res == -1)
{
if (isatty(STDIN_FILENO))
_printf("\n");
break;
}
execFlag = special_circ(str);
if (execFlag == -1)
{
run(str);
}
}
free(str);
free_env();
frees_tokens(aliase);
return (exit_status);
}