From 83edb77d74bb339f3e1324a51039c78ac503db90 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 24 Jul 2019 18:46:39 +0200 Subject: bsq and c13 passed --- bsq/utils.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 bsq/utils.c (limited to 'bsq/utils.c') diff --git a/bsq/utils.c b/bsq/utils.c new file mode 100644 index 0000000..2fa9d29 --- /dev/null +++ b/bsq/utils.c @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/23 19:19:56 by cacharle #+# #+# */ +/* Updated: 2019/07/24 14:50:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#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); +} -- cgit