-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_make_instructions.c
87 lines (80 loc) · 2.61 KB
/
ft_make_instructions.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_make_instructions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlana <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/30 20:30:38 by dlana #+# #+# */
/* Updated: 2021/10/01 18:32:15 by dlana ### ########.fr */
/* */
/* ************************************************************************** */
#include "checker.h"
static void ft_make_swap(t_point *points, char *line, int i)
{
if (line[i + 1] == 'a' && line[i + 2] == '\n')
ft_swap_a(points);
else if (line[i + 1] == 'b' && line[i + 2] == '\n')
ft_swap_b(points);
else if (line[i + 1] == 's' && line[i + 2] == '\n')
ft_swap_a_and_b(points);
else
ft_error();
}
static void ft_make_push(t_point *points, char *line, int i)
{
if (line[i + 1] == 'a' && line[i + 2] == '\n')
ft_push_a(points);
else if (line[i + 1] == 'b' && line[i + 2] == '\n')
ft_push_b(points);
else
ft_error();
}
static void ft_make_rotate(t_point *points, char *line, int i)
{
if (line[i + 1] == 'a' && line[i + 2] == '\n')
ft_rotate_a(points);
else if (line[i + 1] == 'b' && line[i + 2] == '\n')
ft_rotate_b(points);
else if (line[i + 1] == 'r' && line[i + 2] == '\n')
ft_rotate_a_and_b(points);
else
ft_error();
}
static void ft_make_reverse_rotate(t_point *points, char *line, int i)
{
if (line[i + 1] == 'a' && line[i + 2] == '\n')
ft_reverse_rotate_a(points);
else if (line[i + 1] == 'b' && line[i + 2] == '\n')
ft_reverse_rotate_b(points);
else if (line[i + 1] == 'r' && line[i + 2] == '\n')
ft_reverse_rotate_a_and_b(points);
else
ft_error();
}
int ft_make_instructions(t_point *points, char *line)
{
int i;
int count_instructions;
i = 0;
count_instructions = 0;
while (line[i] != '\0')
{
if (line[i] == 's')
ft_make_swap(points, line, i);
else if (line[i] == 'p')
ft_make_push(points, line, i);
else if (line[i] == 'r' && line[i + 2] == '\n')
ft_make_rotate(points, line, i);
else if (line[i] == 'r' && line[i + 1] == 'r')
{
i++;
ft_make_reverse_rotate(points, line, i);
}
else
ft_error();
count_instructions++;
i = i + 3;
}
return (count_instructions);
}