-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_utils.c
96 lines (85 loc) · 1.73 KB
/
parser_utils.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
/*
** parser_utils.c for tetris in /home/thibrex/Dropbox/delivery/PSU/PSU_2016_tetris
**
** Made by Thibaut Cornolti
** Login <[email protected]>
**
** Started on Mon Feb 20 16:22:15 2017 Thibaut Cornolti
** Last update Wed Mar 15 13:21:19 2017 Thibaut Cornolti
*/
#include <stdlib.h>
#include "tetris.h"
char ***init_val(t_pre_pars *p)
{
char ***res;
int i;
i = -1;
if ((res = malloc(sizeof(char **) * 10)) == NULL)
exit(my_puterror("Malloc error.\n") + 84);
res[++i] = &p->l;
res[++i] = &p->kl;
res[++i] = &p->kr;
res[++i] = &p->kt;
res[++i] = &p->kd;
res[++i] = &p->kq;
res[++i] = &p->kp;
res[++i] = &p->w;
res[++i] = &p->map_size;
res[++i] = NULL;
return (res);
}
char **init_arg_max()
{
char **res;
int i;
i = -1;
if ((res = malloc(sizeof(char *) * 10)) == NULL)
exit(my_puterror("Malloc error.\n") + 84);
res[++i] = "l";
res[++i] = "key-left";
res[++i] = "key-right";
res[++i] = "key-turn";
res[++i] = "key-drop";
res[++i] = "key-quit";
res[++i] = "key-pause";
res[++i] = "without-next";
res[++i] = "map-size";
res[++i] = NULL;
return (res);
}
char **init_arg_min()
{
char **res;
int i;
i = -1;
if ((res = malloc(sizeof(char *) * 10)) == NULL)
exit(my_puterror("Malloc error.\n") + 84);
res[++i] = "l";
res[++i] = "kl";
res[++i] = "kr";
res[++i] = "kt";
res[++i] = "kd";
res[++i] = "kq";
res[++i] = "kp";
res[++i] = "w";
res[++i] = NULL;
return (res);
}
int contains_tab(char *s, char **tab)
{
int i;
i = -1;
while (tab[++i])
if (!my_strcmp(s, tab[i]))
return (1);
return (0);
}
int contains_char(char *s, char c)
{
int i;
i = -1;
while (s[++i])
if (c == s[i])
return (1);
return (0);
}