aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_sprite_tex.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-01-24 18:35:49 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-01-24 18:35:49 +0100
commita8444907257b7a46b7b2cb9ee49c20fe82b8789e (patch)
treeff904d583d20e78330b751e3624deb9f0cc4d329 /src/ft_get_sprite_tex.c
parentGot east texture (diff)
download42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.gz
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.bz2
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.xz
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.tar.zst
42-cub3d-a8444907257b7a46b7b2cb9ee49c20fe82b8789e.zip
Correct
Diffstat (limited to '')
-rw-r--r--src/ft_get_sprite_tex.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/ft_get_sprite_tex.c b/src/ft_get_sprite_tex.c
new file mode 100644
index 0000000..5dbe4b4
--- /dev/null
+++ b/src/ft_get_sprite_tex.c
@@ -0,0 +1,44 @@
+#include <libft.h>
+#include <cub3d.h>
+#include <stdlib.h>
+
+static void
+ft_check_empty_line(int fd, unsigned int linum, t_win *wlist)
+{
+ char *line;
+
+ get_next_line(fd, &line);
+ if (*line)
+ {
+ ft_memdel(line);
+ ft_map_error(linum, wlist);
+ }
+ ft_memdel(line);
+}
+
+int
+ft_get_sprite_tex(int fd, t_win *wlist)
+{
+ char *line;
+ char **words;
+ size_t len;
+
+ ft_check_empty_line(fd, 6, wlist);
+ get_next_line(fd, &line);
+ if (!(words = ft_split(line, ' ')))
+ return (ft_exit(5, wlist));
+ if (!(*words) || ft_strcmp(*words, "S")
+ || !(*(words + 1)) || (*(words + 2)))
+ {
+ ft_free_words(words);
+ return (ft_map_error(7, wlist));
+ }
+ ft_memdel(wlist->clist->sprite_path);
+ len = ft_strlen(*(words + 1));
+ if (!(wlist->clist->sprite_path = (char*)malloc((len + 1) * sizeof(char))))
+ return (-1);
+ ft_strlcpy(wlist->clist->sprite_path, *(words + 1), len + 1);
+ ft_free_words(words);
+ ft_memdel(line);
+ return (0);
+}