-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_error.c
109 lines (98 loc) Β· 2.49 KB
/
check_error.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_eroor.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/13 14:57:29 by ahajji #+# #+# */
/* Updated: 2023/02/01 23:20:25 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void check_if_sorted(t_list **lst, t_data *data)
{
t_list *node;
int i;
int count;
node = *lst;
count = 0;
i = 1;
while (node)
{
if ((node)->index == i)
count++;
i++;
node = (node)->next;
}
if (count == data->num_arg)
free_all(data, lst);
}
void check_max_min(t_data *data)
{
int i;
i = 0;
while (i < data->num_arg)
{
if (data->integers[i] > 2147483647)
print_error_free(data);
else if (data->integers[i] < -2147483648)
print_error_free(data);
i++;
}
}
void check_arg_3(char *arg)
{
int i;
i = 0;
if ((arg[i] == '+' && arg[i + 1] == '+') || (arg[i] == '+'
&& arg[i + 1] == '-') || (arg[i] == '-' && arg[i + 1] == '+')
|| (arg[i] == '-' && arg[i + 1] == '-'))
print_error();
if ((arg[i] != '-' && arg[i] != '+') && (arg[i] != ' ') && !(arg[i] >= '0'
&& arg[i] <= '9'))
print_error();
if ((arg[i] == '-' || arg[i] == '+') && !(arg[i + 1] >= '0'
&& arg[i + 1] <= '9'))
print_error();
if ((arg[i] == '-' || arg[i] == '+') && (arg[i - 1] >= '0'
&& arg[i - 1] <= '9') && (arg[i + 1] >= '0' && arg[i + 1] <= '9'))
print_error();
}
void check_arg_2(char *arg)
{
int i;
int count;
count = 0;
i = 0;
while (arg[i])
{
check_arg_3(&arg[i]);
if (arg[i] == ' ')
count++;
i++;
}
if (count == i)
print_error();
}
void check_arg(int argc, char **argv, t_data *data)
{
int i;
i = 1;
while (i < argc)
{
check_arg_2(argv[i]);
i++;
}
i = 1;
data->ptr = 0;
while (i < argc)
{
data->ptr = ft_strjoin(data->ptr, argv[i]);
i++;
}
data->ret_split = ft_split(data->ptr, ' ');
free(data->ptr);
check_duplicate(data);
check_max_min(data);
}