forked from luismvargasg/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsh_main.c
56 lines (52 loc) · 1.08 KB
/
sh_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
#include "header.h"
/**
* main - Entry point / run the shell!
* @ac: - Number of arguments passed to the program.
* @av: - One-dimensional array of strings - "arguments".
* @env: - Null terminated array of strings - "environment".
*
* Return: 0 on success.
*/
int main(int ac, char *av[], char **env)
{
char *string = NULL, **token;
int flagsc = 0;
(void)ac;
signal(SIGINT, handle_sigint);
while (1)
{
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "$ ", 2);
string = read_line();
if (*string == '\n')
{
free(string);
continue;
}
flagsc = built_in(string, env);
if (flagsc == 1)
continue;
token = NULL;
token = toktok(string);
if (token[0] == NULL)
{
freezer(token, string);
continue;
}
childhood(token, av, env, string);
wait(NULL);
}
return (0);
}
/**
* freezer - Function that frees the memory allocated by the program.
* @token: Array of pointers that stores the tokens.
* @string: Pointer that stores the input from the keyboard.
*
* Return: Nothing.
*/
void freezer(char **token, char *string)
{
free(string);
free(token);
}