From 7e1adfce42a5f20ec31af537bf936d872d14b250 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 25 Jan 2020 19:26:50 +0100 Subject: Colors parsed --- src/ft_get_colors.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file 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 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); } -- cgit v1.2.3