-
Notifications
You must be signed in to change notification settings - Fork 0
/
noninteract.c
44 lines (42 loc) · 861 Bytes
/
noninteract.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
#include "main.h"
/**
* noninteract - Non interactive mode of the shell
* @argvo: First argument of main
*
*/
void noninteract(char *argvo)
{
char *input = NULL, *fullcmd, **commands, **currcmd;
size_t n = 0;
int i, status = 0;
if (!(isatty(STDIN_FILENO)))
{
while (getline(&input, &n, stdin) != -1)
{
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, argvo);
if (fullcmd != NULL && fullcmd != currcmd[0])
free(fullcmd);
} else
continue;
freecmd(currcmd);
}
freecmd(commands);
}
free(input);
exit(status);
}
}