-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_checker.c
83 lines (78 loc) · 2.57 KB
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bel-bouz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/23 19:16:18 by bel-bouz #+# #+# */
/* Updated: 2019/01/16 11:53:41 by bel-bouz ### ########.fr */
/* */
/* ************************************************************************** */
#include "swap.h"
int test_inst(t_pile **lst_a, t_pile **lst_b, t_var *var, char *line)
{
if (ft_strequ(line, "rra"))
revretation(&*lst_a, var->lena, 0);
else if (ft_strequ(line, "rrb"))
revretation(&*lst_b, var->lenb, 0);
else if (ft_strequ(line, "ra"))
retation(&*lst_a, var->lena, 0);
else if (ft_strequ(line, "rb"))
retation(&*lst_b, var->lenb, 0);
else if (ft_strequ(line, "pa"))
push(&*lst_b, &*lst_a, var->len_b, var->len_a);
else if (ft_strequ(line, "pb"))
push(&*lst_a, &*lst_b, var->len_a, var->len_b);
else if (ft_strequ(line, "sa"))
swap(&*lst_a, var->lena, 0);
else if (ft_strequ(line, "ss"))
swap2(lst_a, lst_b, var);
else if (ft_strequ(line, "rrr"))
rev_retat2(lst_a, lst_b, var);
else if (ft_strequ(line, "sb"))
swap(&*lst_b, var->lenb, 0);
else
return (error());
return (1);
}
int traitement(t_pile **lst_a, t_pile **lst_b, t_var *var, char **line)
{
if (var->lena == 0)
return (-1);
while (get_next_line(0, line) != 0)
if (test_inst(&*lst_a, lst_b, var, *line) == 0)
return (0);
else if (var->i == 2)
affichag_2(&*lst_a, &*lst_b, var);
if (var->i != 0)
{
if (check_decroissant(&*lst_a, var->lena, var->lenb) == 1
|| (var->lena == 1 && var->lenb == 0))
ft_putstr("OK\n");
else
ft_putstr("KO\n");
}
free_lst(&*lst_a, var->lena);
free_lst(&*lst_b, var->lenb);
return (0);
}
int main(int argc, char **argv)
{
t_pile *lst_a;
t_pile *lst_b;
t_var var;
char *line;
inisia(&var);
if (argc < 2)
return (0);
if (ft_strequ(argv[1], "-v") == 1)
var.i = 2;
if (ajout_lst(argc, argv, &lst_a, &var) == 0)
return (0);
if (check(&lst_a, var.lena) == 0)
return (error());
traitement(&lst_a, &lst_b, &var, &line);
free(line);
return (0);
}