diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-24 00:09:11 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-24 00:09:11 +0100 |
commit | fbd69257b509d3374573282ee08f5d9fc9ed4095 (patch) | |
tree | 28b9ab225e910a8ae279623b08152e310431242c /src/ft_get_res.c | |
parent | Nice and working (diff) | |
download | 42-cub3d-fbd69257b509d3374573282ee08f5d9fc9ed4095.tar.gz 42-cub3d-fbd69257b509d3374573282ee08f5d9fc9ed4095.tar.bz2 42-cub3d-fbd69257b509d3374573282ee08f5d9fc9ed4095.tar.xz 42-cub3d-fbd69257b509d3374573282ee08f5d9fc9ed4095.tar.zst 42-cub3d-fbd69257b509d3374573282ee08f5d9fc9ed4095.zip |
It ain't much but it's honest work
Diffstat (limited to '')
-rw-r--r-- | src/ft_get_res.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/ft_get_res.c b/src/ft_get_res.c index c610fc1..92e0890 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -1,22 +1,50 @@ #include <libft.h> #include <cub3d.h> +static void +ft_free_words(char **words) +{ + size_t i; + + i = 0; + while (words[i]) + { + ft_memdel(words[i]); + i++; + } + ft_memdel(words); +} + +static void +ft_checkdigit(const char *word) +{ + size_t i; + + i = 0; + while (ft_isdigit(word[i])) + i++; + if (i != ft_strlen(word)) + ft_map_error(1); +} + int ft_get_res(int fd, t_win *wlist) { char *line; char **words; - int i; (void)wlist; get_next_line(fd, &line); - words = ft_split(line, ' '); - i = 0; - while (words) - { - ft_printf("[%s] ", words[i]); - i++; - } - ft_printf("\n"); + if (!(words = ft_split(line, ' '))) + return (ft_exit(5)); + if (!(*words) || ft_strcmp(*words, "R") || !(*(words + 1)) + || !(*(words + 2)) || (*(words + 3))) + ft_map_error(1); + ft_checkdigit(words[1]); + ft_checkdigit(words[2]); + wlist->x_size = ft_atoi(words[1]); + wlist->y_size = ft_atoi(words[2]); + ft_free_words(words); + ft_memdel(line); return (0); } |