-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
73 lines (62 loc) · 1.21 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "main.h"
/**
* free_data - frees data structure
*
* @data_shell: data structure
* Return: no return
*/
void free_data(d_sh *data_shell)
{
unsigned int i;
for (i = 0; data_shell->_environ[i]; i++)
{
free(data_shell->_environ[i]);
}
free(data_shell->_environ);
free(data_shell->pid);
}
/**
* set_data - Initialize data structure
*
* @data_shell: data structure
* @av: argument vector
* Return: no return
*/
void set_data(d_sh *data_shell, char **av)
{
unsigned int i;
data_shell->av = av;
data_shell->reg_inpute = NULL;
data_shell->args = NULL;
data_shell->status = 0;
data_shell->counter = 1;
for (i = 0; environ[i]; i++)
;
data_shell->_environ = malloc(sizeof(char *) * (i + 1));
for (i = 0; environ[i]; i++)
{
data_shell->_environ[i] = string_dup(environ[i]);
}
data_shell->_environ[i] = NULL;
data_shell->pid = aid_func(getpid());
}
/**
* main - Entry point
*
* @ac: argument count
* @av: argument vector
*
* Return: 0 on success.
*/
int main(int ac, char **av)
{
d_sh data_shell;
(void) ac;
signal(SIGINT, get_signt);
set_data(&data_shell, av);
shell_loop(&data_shell);
free_data(&data_shell);
if (data_shell.status < 0)
return (255);
return (data_shell.status);
}