blob: 2fa9d29356dd7d4e74ab71503f7668666c385f20 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/23 19:19:56 by cacharle #+# #+# */
/* Updated: 2019/07/24 14:50:31 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdlib.h>
#include "include.h"
/*
** Solve terrain (from Stdin), print and free it when it's done
*/
void parse_stdin_print(void)
{
t_parsed_terrain *pterrain;
pterrain = malloc(sizeof(t_parsed_terrain));
if (parse_fildes(STDIN_FILENO, pterrain) < 0)
write(STDOUT_FILENO, "map error\n", 10);
else
{
solve_and_complete(pterrain->terrain);
print_terrain(pterrain);
destroy_terrain(pterrain->terrain);
}
free(pterrain);
}
/*
** Solve terrain (from a file), print and free it when it's done
*/
void parse_file_print(char *filename)
{
t_parsed_terrain *pterrain;
pterrain = malloc(sizeof(t_parsed_terrain));
if (parse_file(filename, pterrain) < 0)
write(STDOUT_FILENO, "map error\n", 10);
else
{
solve_and_complete(pterrain->terrain);
print_terrain(pterrain);
destroy_terrain(pterrain->terrain);
}
free(pterrain);
}
/*
** count the number of line of a file
*/
int count_lines(char *file)
{
int counter;
counter = 0;
while (*file)
{
if (*file == '\n')
counter++;
file++;
}
return (counter);
}
/*
** strlen until '\n' or '\0'
*/
int ft_line_len(char *str)
{
int counter;
counter = 0;
while (str[counter] && str[counter] != '\n')
counter++;
return (counter);
}
|