-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.c
91 lines (83 loc) · 1.91 KB
/
checker.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
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: admansar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 00:21:14 by admansar #+# #+# */
/* Updated: 2023/03/31 16:05:39 by admansar ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
unsigned long counter_space(char *c)
{
int i;
i = 0;
while (c[i] == ' ')
i++;
return (i);
}
void init_errors(int ac, char **av)
{
int i;
i = ac;
while (i--)
{
if (!ft_strlen(av[i]))
{
write(2, "Error\n", ft_strlen("Error\n"));
exit(1);
}
}
while (++i < ac)
{
if (ft_strlen(av[i]) == counter_space(av[i]))
{
write(2, "Error\n", ft_strlen("Error\n"));
exit(1);
}
}
}
void freeing_machine(char **a, char **b, int i)
{
i = 0;
if (ft_strcount(a) && !ft_strcount(b))
{
while (a[i])
free(a[i++]);
free(a);
free(b);
}
else if (ft_strcount(b) && !ft_strcount(a))
{
while (b[i])
free(b[i++]);
free(b);
free(a);
}
else if (ft_strcount(a) && ft_strcount(b))
{
while (a[i])
free(a[i++]);
free(a);
i = 0;
while (b[i])
free(b[i++]);
free(b);
}
}
int main(int ac, char **av)
{
char **a;
char **b;
if (ac == 1)
exit(0);
init_errors(ac, av);
av = split_args(av);
a = words(av);
ft_error(a);
b = ft_calloc(1, sizeof(char *));
checker(a, b);
return (0);
}