-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellie.c
51 lines (47 loc) · 942 Bytes
/
shellie.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
#include "shell.h"
/**
* main - This is the entry point of a custom UNIX command line interpreter
* @argc: Argument count
* @argv: Arguments vector
*
* Return: 0 on success
*/
int main(int argc, char *argv[])
{
int cmd_count = 1;
char *cmd;
cmd_t *cmmds, *args;
copy_env();
cmmds = init_cmd_t();
args = init_cmd_t();
args->var_count = 0;
while (!args->pipe)
{
if (argc == 2)
{
cmd = read_file(argv[1], argv[0], cmmds, args);
cmd = replace_char(cmd, '\n', ';');
cmd = rmv_double(cmd, ';');
args->pipe = 1;
}
else
cmd = userInput(cmmds, args);
if (isatty(STDIN_FILENO) == 0)
{
args->pipe = 1;
}
if (cmd == NULL)
{
cmd_count++;
continue;
}
cmd = rmv_space(cmd);
cmd = replace_char(cmd, '\n', ';');
cmd = rmv_double(cmd, ';');
cmmds->arg_count = tokenize(cmd, cmmds->args, ";");
free(cmd);
looper(cmmds, args, argv[0], &cmd_count);
}
clean(cmmds, args);
return (0);
}