-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_shell.c
52 lines (50 loc) · 1.04 KB
/
simple_shell.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
#include "main.h"
/**
* main - simple shell.
* @argc: argument count
* @argv: argument vector
*
* Return: Always 0 (Success)
*/
int main(int argc, char *argv[])
{
char *line, **paths;
ssize_t nread;
FILE *fp = stdin;
Alias *l_alias = NULL;
char **o_env_adrs = NULL, **o_env_elms = NULL;
if (argc == 2)
return (run_frm_file(argv));
o_env_adrs = environ;
o_env_elms = malloc(sizeof(char *) * (_get_null_index() + 1));
o_env_elms = memcpy(o_env_elms, environ,
(sizeof(char *) * (_get_null_index() + 1)));
signal(SIGINT, handleSigInt);
prompt();
while ((nread = _get_line(&line, fp)) != -1)
{
if ((nread == 1 && *line == 10) || nread == 0)
{
free(line);
prompt();
continue;
}
if (line[nread - 1] == 10)
line[nread - 1] = 0;
trim_in(line);
paths = get_path(environ);
multi_comms(0, argv[0], line, &l_alias, paths, o_env_adrs,
o_env_elms);
free(line);
if (paths)
{
free(*paths);
free(paths);
}
prompt();
}
free(line);
free_alias(l_alias);
free_environ(-1, o_env_adrs, o_env_elms);
return (0);
}