-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicroshell.c
86 lines (77 loc) · 1.81 KB
/
microshell.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
78
79
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* microshell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbiodies <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/02 09:35:27 by rbiodies #+# #+# */
/* Updated: 2022/03/03 17:28:07 by rbiodies ### ########.fr */
/* */
/* ************************************************************************** */
#include "microshell.h"
int ft_strlen(char *str)
{
int i;
i = 0;
if (str == NULL)
return (0);
while (str[i] != '\0')
i++;
return (i);
}
int ft_putstr_error(char *str)
{
if (str != NULL)
write(STDERR, str, ft_strlen(str));
return (1);
}
void ft_error_fatal(void)
{
ft_putstr_error("error: fatal\n");
exit(EXIT_FAILURE);
}
static void ft_lstclear(t_list *list)
{
t_list *temp;
int i;
while (list != NULL)
{
temp = list->next;
i = 0;
while (list->tokens[i] != NULL)
{
free(list->tokens[i]);
i++;
}
free(list->tokens);
free(list);
list = temp;
}
}
int main(int argc, char **argv, char **envp)
{
int i;
t_list *list;
int ret;
ret = 0;
i = 1;
list = NULL;
if (argc > 1)
{
while (i < argc)
{
if (strcmp(argv[i], ";") == 0)
{
i++;
continue ;
}
i += ft_parser(&list, &argv[i]);
i++;
}
if (list != NULL)
ret = ft_executor(list, envp);
ft_lstclear(list);
}
return (ret);
}