From bec06f4323a2cb2c0bc1594df797c529a35d41e2 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 29 Jan 2020 16:09:52 +0100 Subject: Got colors --- src/ft_get_colors.c | 43 +++++-------------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) (limited to 'src/ft_get_colors.c') diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 1b67447..226b427 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -16,11 +16,11 @@ ft_check_digits(const char *word) } int -ft_get_f_color(char *line, char **words, t_cub *clist) +ft_get_f_color(char **words, t_cub *clist) { char **num; - if (!(*words) || ft_strcmp(*words, "F") || !words[1] || words[2]) + if (!(*words) || !words[1] || words[2]) return (-1); if (!(num = ft_split(words[1], ','))) return (-1); @@ -29,7 +29,7 @@ ft_get_f_color(char *line, char **words, t_cub *clist) ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 || ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255) { - ft_free_words(num, NULL); + ft_free_words(num); return (-1); } clist->f_color = ft_atoi(num[0]); @@ -37,13 +37,11 @@ ft_get_f_color(char *line, char **words, t_cub *clist) clist->f_color += ft_atoi(num[1]); clist->f_color *= 1000; clist->f_color += ft_atoi(num[2]); - ft_free_words(num, NULL); - ft_free_words(words, line); return (0); } int -ft_get_c_color(char *line, char **words, t_cub *clist) +ft_get_c_color(char **words, t_cub *clist) { char **num; @@ -56,7 +54,7 @@ ft_get_c_color(char *line, char **words, t_cub *clist) ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 || ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255) { - ft_free_words(num, NULL); + ft_free_words(num); return (-1); } clist->c_color = ft_atoi(num[0]); @@ -64,36 +62,5 @@ ft_get_c_color(char *line, char **words, t_cub *clist) clist->c_color += ft_atoi(num[1]); clist->c_color *= 1000; clist->c_color += ft_atoi(num[2]); - ft_free_words(num, NULL); - ft_free_words(words, line); - return (0); -} - -int -ft_get_colors(int fd, t_cub *clist) -{ - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(8, clist)); - } - if (ft_get_f_color(line, words, clist) < 0) - { - ft_free_words(words, line); - return (ft_map_error(8, clist)); - } - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(9, clist)); - } - if (ft_get_c_color(line, words, clist) < 0) - { - ft_free_words(words, line); - return (ft_map_error(9, clist)); - } return (0); } -- cgit v1.2.3