-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_checker.c
87 lines (81 loc) · 2.43 KB
/
run_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* run_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhlim <zhlim@student.42kl.edu.my> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/04 16:01:16 by zhlim #+# #+# */
/* Updated: 2023/08/10 23:38:47 by zhlim ### ########.fr */
/* */
/* ************************************************************************** */
#include "checker.h"
void check_command2(char *line, t_list **stack_a, t_list **stack_b)
{
if (*line == 'r')
{
line++;
if (*line == 'a')
single_rotate(stack_a, "ra\n");
else if (*line == 'b')
single_rotate(stack_b, "rb\n");
else if (*line == 'r')
{
line++;
if (*line == 'a')
single_reverse_rotate(stack_a, "rra\n");
else if (*line == 'b')
single_reverse_rotate(stack_b, "rrb\n");
else if (*line == 'r')
double_reverse_rotate(stack_a, stack_b, "rrr\n");
else
double_rotate(stack_a, stack_b, "rr\n");
}
}
}
void check_command(char *line, t_list **stack_a, t_list **stack_b)
{
if (*line == 's')
{
line++;
if (*line == 'a')
single_swap(stack_a, "sa\n");
else if (*line == 'b')
single_swap(stack_b, "sb\n");
else if (*line == 's')
double_swap(stack_a, stack_b, "ss\n");
}
else if (*line == 'p')
{
line++;
if (*line == 'a')
push(stack_b, stack_a, "pa\n");
else if (*line == 'b')
push(stack_a, stack_b, "pb\n");
}
else
check_command2(line, stack_a, stack_b);
}
void invalidate(char *line)
{
if (*line != 's' && *line != 'p' && *line != 'r')
print_error_exit("Error\n");
line++;
if (*line != 'a' && *line != 'b' && *line != 'r' && *line != 's')
print_error_exit("Error\n");
line++;
if (*line != '\n' && *line != 'a' && *line != 'b' && *line != 'r')
print_error_exit("Error\n");
}
void run_checker(t_list **stack_a, t_list **stack_b)
{
char *line;
line = get_next_line(0);
while (line)
{
invalidate(line);
check_command(line, stack_a, stack_b);
free(line);
line = get_next_line(0);
}
}