-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_links.c
83 lines (74 loc) · 1.99 KB
/
get_links.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_links.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vcombey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/19 19:51:38 by vcombey #+# #+# */
/* Updated: 2017/03/08 14:42:56 by vcombey ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
#include "libft/libft.h"
void init_mat(t_anthill *a)
{
int n;
int i;
i = 0;
n = a->nb_room;
if (!(a->mat = (int **)malloc(sizeof(int *) * (n + 1))))
ft_exit_err("malloc error", NULL);
a->mat[n] = NULL;
while (i < n)
{
if (!(a->mat[i] = (int *)ft_memalloc(sizeof(int) * (n + 1))))
ft_exit_err("malloc error", NULL);
i++;
}
}
int name_to_number(char *name, t_room *r)
{
t_room *tmp;
tmp = r;
while (tmp)
{
if (ft_strequ(tmp->name, name))
return (tmp->n);
tmp = tmp->next;
}
return (-1);
}
char *number_to_name(int n, t_room *r)
{
t_room *tmp;
tmp = r;
while (tmp)
{
if (n == tmp->n)
return (tmp->name);
tmp = tmp->next;
}
return ("lol");
}
int get_links(char *line, t_anthill *a)
{
int i;
int k;
int l;
if (line[0] == '#' && line[1] == '#')
return (0);
else if (line[0] == '#')
return (1);
if ((i = ft_strchri(line, '-')) == -1)
return (0);
line[i] = '\0';
if ((k = name_to_number(line, a->room)) == -1)
return (0);
if ((l = name_to_number(line + i + 1, a->room)) == -1)
return (0);
line[i] = '-';
a->mat[k][l] = 1;
a->mat[l][k] = 1;
return (1);
}