-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_checker.c
104 lines (98 loc) · 2.51 KB
/
parser_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
92
93
94
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dfurneau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/10 13:04:46 by dfurneau #+# #+# */
/* Updated: 2021/12/11 06:29:54 by dfurneau ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/push_swap.h"
/**
* Checker
* All Sx functions such as sa, sb, and sss
**/
static void sx(char *line, t_stack *a, t_stack *b)
{
if (!ft_strncmp("sa\n", line, ft_strlen(line)))
sa(a);
else if (!ft_strncmp("sb\n", line, ft_strlen(line)))
sb(b);
else if (!ft_strncmp("ss\n", line, ft_strlen(line)))
sss(a, b);
else
{
free(line);
error(a, b);
}
}
/**
* Checker
* All Px functions such as pa and pb
**/
static void px(char *line, t_stack *a, t_stack *b)
{
if (!ft_strncmp("pa\n", line, ft_strlen(line)))
pa(a, b);
else if (!ft_strncmp("pb\n", line, ft_strlen(line)))
pb(a, b);
else
{
free(line);
error(a, b);
}
}
/**
* Checker
* All RRx functions such as rra, rrb, rrr
**/
static void rrx(char *line, t_stack *a, t_stack *b)
{
if (!ft_strncmp("rra\n", line, ft_strlen(line)))
rra(a);
else if (!ft_strncmp("rrb\n", line, ft_strlen(line)))
rrb(b);
else if (!ft_strncmp("rrr\n", line, ft_strlen(line)))
rrr(a, b);
else
{
free(line);
error(a, b);
}
}
/**
* Checker
* All Rx functions such as ra, rb, rr & rrx
**/
static void rx(char *line, t_stack *a, t_stack *b)
{
if (!ft_strncmp("ra\n", line, ft_strlen(line)))
ra(a);
else if (!ft_strncmp("rb\n", line, ft_strlen(line)))
rb(b);
else if (!ft_strncmp("rr\n", line, ft_strlen(line)))
rr(a, b);
else
rrx(line, a, b);
}
/**
* Main Checker
* Parses each line and calls the respective
* operations
**/
void checker(t_stack *a, t_stack *b, char *line)
{
if (ft_strchr(line, 's'))
sx(line, a, b);
else if (ft_strchr(line, 'p'))
px(line, a, b);
else if (ft_strchr(line, 'r'))
rx(line, a, b);
else
{
free(line);
error(a, b);
}
}