diff --git a/libftx/extra/Makefile b/libftx/extra/Makefile index e90e814..0f4a4a7 100644 --- a/libftx/extra/Makefile +++ b/libftx/extra/Makefile @@ -6,13 +6,13 @@ # By: cchauvet # include "../libft/libft.h" +size_t ft_count(const char *str, char c); unsigned long ft_atoul(const char str[]); int ft_atoul_check(const char str[]); size_t ft_tablen(const void **tab); diff --git a/libftx/extra/ft_count.c b/libftx/extra/ft_count.c new file mode 100644 index 0000000..7c4566e --- /dev/null +++ b/libftx/extra/ft_count.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_count.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/16 18:27:16 by cchauvet #+# #+# */ +/* Updated: 2023/06/16 16:29:22 by cchauvet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "./extra.h" + +size_t ft_count(const char *str, char c) +{ + size_t i; + size_t out; + + i = 0; + out = 0; + while (str[i] != '\0') + { + if (str[i] == c) + out++; + i++; + } + return (out); +} diff --git a/map/parsing_header2.c b/map/parsing_header2.c index abc4e89..68679e7 100644 --- a/map/parsing_header2.c +++ b/map/parsing_header2.c @@ -6,7 +6,7 @@ /* By: cchauvet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/16 17:28:58 by cchauvet #+# #+# */ -/* Updated: 2023/05/16 19:02:08 by cchauvet ### ########.fr */ +/* Updated: 2023/06/16 16:31:06 by cchauvet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,15 +65,14 @@ int set_color(long long *color, const char *key, const char *value) ft_eprintf("map: %s redefinition", key); return (1); } - tab = ft_split(value, ','); - if (tab == NULL) - return (1); - if (ft_tablen((const void **) tab) != 3) + if (ft_count(value, ',') != 2) { - ft_freer_tab_ultimate(1, tab); ft_eprintf("map: invalid format %s %s", key, value); return (1); } + tab = ft_split(value, ','); + if (tab == NULL) + return (1); *color = get_color((const char **) tab); ft_freer_tab_ultimate(1, tab); return (*color == -1);