-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utils9.c
90 lines (82 loc) · 1.36 KB
/
ft_utils9.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
87
88
89
90
#include "minishell.h"
void pushfront(t_list *l, char *val)
{
t_elem *nouv;
nouv = malloc(sizeof(t_elem));
if (!nouv)
exit(0);
nouv->data = val;
nouv->next = l->first;
nouv->prec = NULL;
if (l->first)
l->first->prec = nouv;
else
l->last = nouv;
l->first = nouv;
}
void free_str(char *str)
{
if (str)
{
free(str);
str = NULL;
}
}
void free_char_tab(char **str)
{
int i;
i = 0;
while (str && str[i] != NULL)
{
free(str[i]);
str[i] = NULL;
i++;
}
if (str)
{
free(str);
str = NULL;
}
}
int exit_arg(t_struct *d)
{
if (d->l.arg[1] != NULL && ft_strlen_twochar(d->l.arg) == 2
&& is_char(d->l.arg[1]) == 0 && check_char(d->l.arg[1]) == 0
&& ft_strlen_minus(d->l.arg[1]) <= 1)
{
g_global.g_build_error_exec = ft_atoi(d->l.arg[1]);
printf("exit\n");
}
else if ((d->l.arg[1] && check_char(d->l.arg[1]) == 1)
|| (is_char(d->l.arg[1])))
{
printf("exit\nbash: exit: %s: numeric argument required\n", d->l.arg[1]);
exit (255);
}
else if (ft_strlen_minus(d->l.arg[1]) > 1)
{
printf("exit\nbash: exit: %s: numeric argument required\n", d->l.arg[1]);
exit (255);
}
else
{
printf("exit\nbash: exit: too many arguments\n");
g_global.g_build_error_exec = 1;
return (1);
}
return (2);
}
int ft_strlen_minus(char *str)
{
int i;
int j;
i = 0;
j = 0;
while (str[i])
{
if (str[i] == '-')
j++;
i++;
}
return (j);
}