aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libft/Makefile2
-rw-r--r--libft/src/ft_split_redo.c101
-rw-r--r--map/map_one.cub1
-rw-r--r--src/ft_get_res.c13
-rw-r--r--src/ft_parse_map.c5
5 files changed, 115 insertions, 7 deletions
diff --git a/libft/Makefile b/libft/Makefile
index 051fcd7..04035b9 100644
--- a/libft/Makefile
+++ b/libft/Makefile
@@ -58,7 +58,7 @@ SRCS_NAME += ft_strdup.c
SRCS_NAME += ft_substr.c
SRCS_NAME += ft_strjoin.c
SRCS_NAME += ft_strtrim.c
-SRCS_NAME += ft_split.c
+SRCS_NAME += ft_split_redo.c
SRCS_NAME += ft_itoa.c
SRCS_NAME += ft_itoa_base.c
SRCS_NAME += ft_uitoa.c
diff --git a/libft/src/ft_split_redo.c b/libft/src/ft_split_redo.c
new file mode 100644
index 0000000..1d33dda
--- /dev/null
+++ b/libft/src/ft_split_redo.c
@@ -0,0 +1,101 @@
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+static size_t
+ft_count_words(const char *s, char c)
+{
+ size_t i;
+ size_t count;
+ uint8_t ibool;
+
+ i = 0;
+ count = 0;
+ ibool = 1;
+ while (s[i])
+ {
+ while (s[i] == c && s[i])
+ i++;
+ while (s[i] != c && s[i])
+ {
+ if (ibool == 1)
+ count++;
+ ibool = 0;
+ i++;
+ }
+ ibool = 1;
+ }
+ return (count);
+}
+
+static size_t
+ft_splitlen(const char *str, char c)
+{
+ size_t i;
+
+ i = 0;
+ while (str[i] != c && str[i])
+ i++;
+ return (i);
+}
+
+static char
+ *ft_splitdup(const char *str, char c)
+{
+ char *word;
+ size_t i;
+
+ i = 0;
+ if (!(word = (char*)malloc((ft_splitlen(str, c) + 1) * sizeof(char))))
+ return (NULL);
+ while (str[i] != c && str[i])
+ {
+ word[i] = str[i];
+ i++;
+ }
+ word[i] = '\0';
+ return (word);
+}
+
+static void
+ft_splitfree(char **best_split, size_t j)
+{
+ while (j > 0)
+ {
+ free(best_split[j]);
+ j--;
+ }
+ free(best_split);
+}
+
+char
+ **ft_split(const char *s, char c)
+{
+ char **best_split;
+ size_t i;
+ size_t j;
+
+ i = 0;
+ j = 0;
+ if (!(best_split = (char **)malloc((ft_count_words(s, c) + 1)
+ * sizeof(char *))))
+ return (NULL);
+ while (s[i])
+ {
+ while (s[i] == c && s[i])
+ i++;
+ while (s[i] != c && s[i])
+ {
+ if (!(best_split[j] = ft_splitdup(s + i, c)))
+ {
+ ft_splitfree(best_split, j);
+ return (NULL);
+ }
+ i += ft_splitlen(s + i, c);
+ j++;
+ }
+ }
+ best_split[j] = NULL;
+ return (best_split);
+}
diff --git a/map/map_one.cub b/map/map_one.cub
new file mode 100644
index 0000000..db3a096
--- /dev/null
+++ b/map/map_one.cub
@@ -0,0 +1 @@
+R 1920 1080NO ./path_to_the_north_textureSO ./path_to_the_south_textureWE ./path_to_the_west_textureEA ./path_to_the_east_textureS ./path_to_the_sprite_textureF 220,100,0C 225,30,01 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 11 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 11 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 11 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 11 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 11 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 0 0 1 0 0 0 11 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 11 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 11 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 N 0 11 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \ No newline at end of file
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
index c610fc1..ff39280 100644
--- a/src/ft_get_res.c
+++ b/src/ft_get_res.c
@@ -12,11 +12,12 @@ ft_get_res(int fd, t_win *wlist)
get_next_line(fd, &line);
words = ft_split(line, ' ');
i = 0;
- while (words)
- {
- ft_printf("[%s] ", words[i]);
- i++;
- }
- ft_printf("\n");
+ ft_printf("%s\n", line);
+ /* while (words) */
+ /* { */
+ /* ft_printf("[%s] ", words[i]); */
+ /* i++; */
+ /* } */
+ /* ft_printf("\n"); */
return (0);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index d2fbe0d..d3d1f53 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -14,5 +14,10 @@ ft_parse_map(t_win *wlist, t_cub *clist, const char *map_path)
(void)clist;
fd = open(map_path, O_RDONLY);
+ if (fd < 0)
+ {
+ ft_printf("\033[31;1mNo map\033[0m\n");
+ ft_exit(2);
+ }
ft_get_res(fd, wlist);
}