-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.c
102 lines (91 loc) · 2.24 KB
/
map.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jschotte <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/10 12:54:27 by jschotte #+# #+# */
/* Updated: 2015/12/18 15:23:08 by jschotte ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdlib.h>
int ft_newsize(char *str)
{
int i;
int nb;
int test;
i = 0;
test = 0;
nb = 20;
while (i <= 20)
{
if (str[i] == '.' && str[i + 1] == '.' && str[i + 2] == '.'
&& str[i + 3] == '.')
{
test++;
nb -= 5;
}
i += 5;
}
i = -1;
while (++i < 5)
{
if (str[i] == '.' && str[i + 5] == '.' && str[i + 10] == '.'
&& str[i + 15] == '.')
nb -= 4 - test;
}
return (nb);
}
int ft_lineempty(char *str, int i)
{
int n;
n = i / 5 * 5;
if (str[n] == '.' && str[n + 1] == '.' && str[n + 2] == '.'
&& str[n + 3] == '.')
return (1);
return (0);
}
int ft_colempty(char *str, int i)
{
int n;
while (i > 4)
i -= 5;
n = i;
if (str[n] == '.' && str[n + 5] == '.' && str[n + 10] == '.'
&& str[n + 15] == '.')
return (1);
return (0);
}
char *ft_newchar(char *src, char *dest)
{
int i;
int j;
i = 0;
j = 0;
while (ft_lineempty(src, i) || ft_colempty(src, i))
{
if (ft_lineempty(src, i))
i += 5;
if (ft_colempty(src, i))
i++;
}
while (src[i] && !ft_lineempty(src, i) && !ft_colempty(src, i))
{
dest[j] = src[i];
j++;
i++;
while (src[i] && (ft_lineempty(src, i) || ft_colempty(src, i)))
i++;
}
dest[j] = '\0';
return (dest);
}
char *ft_clear(char *str)
{
char *newstr;
newstr = (char*)malloc(sizeof(newstr) * (ft_newsize(str) + 1));
newstr = ft_newchar(str, newstr);
return (newstr);
}