-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
51 lines (49 loc) · 999 Bytes
/
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
#include "main.h"
/**
* main - A simple shell
* @ac: Number of arguments
* @argv: Array of arguments
*
* Return: Always 0
*/
int main(int __attribute__((unused)) ac, char *argv[])
{
char *input = NULL, *fullcmd, **commands, **currcmd;
size_t n;
int status = 0, i;
signal(SIGINT, ctrlc);
while (1)
{
noninteract(argv[0]);
print(" ($) ", STDOUT_FILENO);
if (getline(&input, &n, stdin) == -1)
{
free(input);
exit(status);
}
rm_newline(input);
rm_comment(input);
commands = strtostrs(input, ";");
for (i = 0; commands[i] != NULL; i++)
{
currcmd = strtostrs(commands[i], " \t\n");
if (currcmd[0] == NULL)
{
free(currcmd);
break;
}
if (execute_builtin(currcmd, commands, input) == 1)
{
fullcmd = _which(currcmd[0]);
ownexecve(fullcmd, currcmd, argv[0]);
if (fullcmd != NULL && fullcmd != currcmd[0])
free(fullcmd);
} else
continue;
freecmd(currcmd);
}
freecmd(commands);
}
free(input);
return (status);
}