-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (64 loc) · 1.13 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
74
75
76
77
#include "mymain.h"
/**
* free_data - frees data structure,..
*
* @datash: data structure,..
*
*/
void free_data(data_shell *datash)
{
unsigned int i;
for (i = 0; datash->_environ[i]; i++)
{
free(datash->_environ[i]);
}
free(datash->_environ);
free(datash->pid);
}
/**
* set_data - Initialize data structure
*
* @datash: data structure,..
*
* @av: argument vector,..
*
*/
void set_data(data_shell *datash, char **av)
{
unsigned int i;
datash->av = av;
datash->input = NULL;
datash->args = NULL;
datash->status = 0;
datash->counter = 1;
for (i = 0; environ[i]; i++)
;
datash->_environ = malloc(sizeof(char *) * (i + 1));
for (i = 0; environ[i]; i++)
{
datash->_environ[i] = _strdup(environ[i]);
}
datash->_environ[i] = NULL;
datash->pid = aux_itoa(getpid());
}
/**
* main - Entry point.,,.
*
* @ac: argument count,..
*
* @av: argument vector,..
*
* Return: 0 on success.,..
*/
int main(int ac, char **av)
{
data_shell datash;
(void) ac;
signal(SIGINT, get_sigint);
set_data(&datash, av);
shell_loop(&datash);
free_data(&datash);
if (datash.status < 0)
return (255);
return (datash.status);
}