aboutsummaryrefslogtreecommitdiff
path: root/bsq/utils.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-24 18:46:39 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-24 18:46:58 +0200
commit83edb77d74bb339f3e1324a51039c78ac503db90 (patch)
tree1e69b9330430438fa499f94e864dcfb4d83ea007 /bsq/utils.c
parent5bab06313e71e9827baa426a02bbaf2a00b4e6a0 (diff)
downloadpiscine-83edb77d74bb339f3e1324a51039c78ac503db90.tar.gz
piscine-83edb77d74bb339f3e1324a51039c78ac503db90.tar.bz2
piscine-83edb77d74bb339f3e1324a51039c78ac503db90.zip
bsq and c13 passed
Diffstat (limited to 'bsq/utils.c')
-rw-r--r--bsq/utils.c87
1 files changed, 87 insertions, 0 deletions
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 <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);
+}