diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-25 19:26:50 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-25 19:26:50 +0100 |
commit | 7e1adfce42a5f20ec31af537bf936d872d14b250 (patch) | |
tree | 84efb92f879cbbc66c0a9c06f0a7690f99ef1a22 | |
parent | not too bad (diff) | |
download | 42-cub3d-7e1adfce42a5f20ec31af537bf936d872d14b250.tar.gz 42-cub3d-7e1adfce42a5f20ec31af537bf936d872d14b250.tar.bz2 42-cub3d-7e1adfce42a5f20ec31af537bf936d872d14b250.tar.xz 42-cub3d-7e1adfce42a5f20ec31af537bf936d872d14b250.tar.zst 42-cub3d-7e1adfce42a5f20ec31af537bf936d872d14b250.zip |
Colors parsed
-rw-r--r-- | src/ft_get_colors.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 8ef0678..c2e8b31 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -3,7 +3,7 @@ #include <stddef.h> static int -ft_get_f_color(char **words, t_win *wlist) +ft_get_f_color(char *line, char **words, t_win *wlist) { char **num; @@ -22,6 +22,31 @@ ft_get_f_color(char **words, t_win *wlist) wlist->clist->f_color *= 1000; wlist->clist->f_color += ft_atoi(num[2]); ft_free_words(num, NULL); + ft_free_words(words, line); + return (0); +} + +static int +ft_get_c_color(char *line, char **words, t_win *wlist) +{ + char **num; + + if (!(*words) || ft_strcmp(*words, "C") || !words[1] || words[2]) + return (-1); + if (!(num = ft_split(words[1], ','))) + return (-1); + if (!num[0] || !num[1] || !num[2] || num[3]) + { + ft_free_words(num, NULL); + return (-1); + } + wlist->clist->c_color = ft_atoi(num[0]); + wlist->clist->c_color *= 1000; + wlist->clist->c_color += ft_atoi(num[1]); + wlist->clist->c_color *= 1000; + wlist->clist->c_color += ft_atoi(num[2]); + ft_free_words(num, NULL); + ft_free_words(words, line); return (0); } @@ -36,13 +61,20 @@ ft_get_colors(int fd, t_win *wlist) ft_memdel(line); return (ft_map_error(8, wlist)); } - if (ft_get_f_color(words, wlist) < 0) + if (ft_get_f_color(line, words, wlist) < 0) { ft_free_words(words, line); return (ft_map_error(8, wlist)); } - ft_free_words(words, line); - /* if (ft_get_c_color(words, wlist) < 0) */ - /* return (-1); */ + if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) + { + ft_memdel(line); + return (ft_map_error(9, wlist)); + } + if (ft_get_c_color(line, words, wlist) < 0) + { + ft_free_words(words, line); + return (-1); + } return (0); } |