fix_parsing
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */
|
/* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/11/06 12:50:01 by adjoly ### ########.fr */
|
/* Updated: 2024/11/11 15:12:35 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -67,7 +67,11 @@ int check_format_rgb(char *sign, char **tab, t_pars *pars);
|
|||||||
//color_utils.c
|
//color_utils.c
|
||||||
int create_argb(int r, int g, int b);
|
int create_argb(int r, int g, int b);
|
||||||
char *ft_strndup_color(char *src, int start, int end);
|
char *ft_strndup_color(char *src, int start, int end);
|
||||||
int check_char_color(char *tab);
|
int check_char_color(char *str);
|
||||||
|
|
||||||
|
//color_utils_two.c
|
||||||
|
int total_len(char **tab);
|
||||||
|
char *multi_join(char **tab, int ct);
|
||||||
|
|
||||||
//find_player.c
|
//find_player.c
|
||||||
int search_letter(char **map, int i, char l);
|
int search_letter(char **map, int i, char l);
|
||||||
@ -102,6 +106,7 @@ int count_tab(char **tab);
|
|||||||
void convert_white_s(char *str);
|
void convert_white_s(char *str);
|
||||||
int longest_line(char **line);
|
int longest_line(char **line);
|
||||||
int count_line_file(int fd);
|
int count_line_file(int fd);
|
||||||
|
char *ft_strcat(char *dest, char *src);
|
||||||
|
|
||||||
//clear_free.c
|
//clear_free.c
|
||||||
void free_tab(char **tab);
|
void free_tab(char **tab);
|
||||||
|
@ -3,7 +3,7 @@ SO ./img/cahuete2.png
|
|||||||
|
|
||||||
WE ./img/cahuete3.png
|
WE ./img/cahuete3.png
|
||||||
EA ./img/cahuete4.png
|
EA ./img/cahuete4.png
|
||||||
C 255,153,102
|
C 255 , 153,102
|
||||||
F 132,132,218
|
F 132,132,218
|
||||||
|
|
||||||
11111111111
|
11111111111
|
||||||
|
@ -6,9 +6,43 @@ EA ./img/suki.png
|
|||||||
C 255,153,102
|
C 255,153,102
|
||||||
F 132,132,218
|
F 132,132,218
|
||||||
|
|
||||||
11111111111
|
11111111111111111111
|
||||||
100000N0001
|
10000000000000000001
|
||||||
11100000111
|
10111111111111111001
|
||||||
10000000101
|
10000000000000000001
|
||||||
10101010101
|
10111111111111111001
|
||||||
11111111111
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
10000000000000000001
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000N01
|
||||||
|
10111111111111111001
|
||||||
|
10000000000000000001
|
||||||
|
11111111111111111111
|
||||||
|
11111111111111111111
|
||||||
|
@ -3,7 +3,7 @@ SO ./img/suki.png
|
|||||||
|
|
||||||
WE ./img/cahuete.png
|
WE ./img/cahuete.png
|
||||||
EA ./img/kanel.png
|
EA ./img/kanel.png
|
||||||
C 75,rere7,9,
|
C 75,rere 7 , 9,
|
||||||
F 50,0,250
|
F 50,0,250
|
||||||
|
|
||||||
11111
|
11111
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
NO ./img/flo.png
|
NO ./img/flo.png
|
||||||
NO ./img/suki.png
|
SO ./img/suki.png
|
||||||
|
|
||||||
WE ./img/cahuete.png
|
WE ./img/cahuete.png
|
||||||
EA ./img/kanel.png
|
EA ./img/kanel.png
|
||||||
C 9,77,56
|
F 9,77,56
|
||||||
F 50,0,250
|
F 50,0,250
|
||||||
|
|
||||||
11111
|
11111
|
||||||
|
@ -3,7 +3,7 @@ SO ./img/suki.png
|
|||||||
|
|
||||||
WE ./img/cahuete.png
|
WE ./img/cahuete.png
|
||||||
EA ./img/kanel.png
|
EA ./img/kanel.png
|
||||||
C 256,1874700,200
|
C 256 ,1874700 ,200
|
||||||
F 50,0,250
|
F 50,0,250
|
||||||
|
|
||||||
11111
|
11111
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */
|
/* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/10/05 15:51:44 by madumerg ### ########.fr */
|
/* Updated: 2024/11/11 13:41:46 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
int detect_info(char **tab, t_pars *pars)
|
int detect_info(char **tab, t_pars *pars)
|
||||||
{
|
{
|
||||||
@ -22,9 +23,9 @@ int detect_info(char **tab, t_pars *pars)
|
|||||||
return (check_texture(tab[0], tab[1], pars));
|
return (check_texture(tab[0], tab[1], pars));
|
||||||
else if (ft_strncmp("EA", tab[0], 2) == 0 && count_tab(tab) == 2)
|
else if (ft_strncmp("EA", tab[0], 2) == 0 && count_tab(tab) == 2)
|
||||||
return (check_texture(tab[0], tab[1], pars));
|
return (check_texture(tab[0], tab[1], pars));
|
||||||
else if (ft_strncmp("F", tab[0], 1) == 0 && count_tab(tab) == 2)
|
else if (ft_strncmp("F", tab[0], 1) == 0)
|
||||||
return (check_format_rgb("F", tab, pars));
|
return (check_format_rgb("F", tab, pars));
|
||||||
else if (ft_strncmp("C", tab[0], 1) == 0 && count_tab(tab) == 2)
|
else if (ft_strncmp("C", tab[0], 1) == 0)
|
||||||
return (check_format_rgb("C", tab, pars));
|
return (check_format_rgb("C", tab, pars));
|
||||||
else
|
else
|
||||||
return (err_mess(NOT_FOUND));
|
return (err_mess(NOT_FOUND));
|
||||||
|
@ -6,10 +6,11 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */
|
/* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/11/10 11:58:40 by madumerg ### ########.fr */
|
/* Updated: 2024/11/11 15:13:02 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
|
||||||
int check_nb_color(char *r, char *g, char *b)
|
int check_nb_color(char *r, char *g, char *b)
|
||||||
@ -20,6 +21,7 @@ int check_nb_color(char *r, char *g, char *b)
|
|||||||
free(r);
|
free(r);
|
||||||
free(g);
|
free(g);
|
||||||
free(b);
|
free(b);
|
||||||
|
err_mess(ERR_COLOR);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -31,9 +33,10 @@ int save_color(char *tab, t_pars *pars, int j, int i)
|
|||||||
char *g;
|
char *g;
|
||||||
char *b;
|
char *b;
|
||||||
|
|
||||||
|
i++;
|
||||||
while (tab[i] != ',')
|
while (tab[i] != ',')
|
||||||
i++;
|
i++;
|
||||||
r = ft_strndup_color(tab, 0, i);
|
r = ft_strndup_color(tab, 1, i);
|
||||||
i += 1;
|
i += 1;
|
||||||
j = i;
|
j = i;
|
||||||
while (tab[i] != ',')
|
while (tab[i] != ',')
|
||||||
@ -53,46 +56,57 @@ int save_color(char *tab, t_pars *pars, int j, int i)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count_precise_char(char *str, char c)
|
int count_precise_char(char *tab, char c)
|
||||||
{
|
{
|
||||||
int ct;
|
int ct;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
ct = 0;
|
ct = 0;
|
||||||
while (str[i])
|
while (tab[i])
|
||||||
{
|
{
|
||||||
if (str[i] == c)
|
if (tab[i] == c)
|
||||||
ct++;
|
ct++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (ct != 2)
|
if (ct != 2)
|
||||||
return (1);
|
return (err_mess(WRONG_F_RGB));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void assign_color(t_pars *pars, char *sign)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(sign, "F") == 0)
|
||||||
|
pars->f_color = pars->color;
|
||||||
|
if (ft_strcmp(sign, "C") == 0)
|
||||||
|
pars->c_color = pars->color;
|
||||||
|
}
|
||||||
|
|
||||||
int check_format_rgb(char *sign, char **tab, t_pars *pars)
|
int check_format_rgb(char *sign, char **tab, t_pars *pars)
|
||||||
{
|
{
|
||||||
static int ct_f;
|
static int ct_f;
|
||||||
static int ct_c;
|
static int ct_c;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = multi_join(tab, count_tab(tab));
|
||||||
|
if (!str)
|
||||||
|
return (err_mess(CRASH));
|
||||||
if (ft_strcmp(sign, "F") == 0)
|
if (ft_strcmp(sign, "F") == 0)
|
||||||
ct_f++;
|
ct_f++;
|
||||||
if (ft_strcmp(sign, "C") == 0)
|
if (ft_strcmp(sign, "C") == 0)
|
||||||
ct_c++;
|
ct_c++;
|
||||||
if (count_tab(tab) > 2)
|
if (check_char_color(str) == 1 || count_precise_char(str, ',') == 1 \
|
||||||
return (err_mess(NOT_FOUND));
|
|| save_color(str, pars, 0, 0) == -1)
|
||||||
if (check_char_color(tab[1]) == 1)
|
{
|
||||||
return (err_mess(INVALID_CHAR));
|
free(str);
|
||||||
if (count_precise_char(tab[1], ',') == 1)
|
return (1);
|
||||||
return (err_mess(WRONG_F_RGB));
|
}
|
||||||
if (save_color(tab[1], pars, 0, 0) == -1)
|
|
||||||
return (err_mess(ERR_COLOR));
|
|
||||||
if (ct_f > 1 || ct_c > 1)
|
if (ct_f > 1 || ct_c > 1)
|
||||||
|
{
|
||||||
|
free(str);
|
||||||
return (err_mess(DUP_ACR));
|
return (err_mess(DUP_ACR));
|
||||||
if (ft_strcmp(sign, "F") == 0)
|
}
|
||||||
pars->f_color = pars->color;
|
assign_color(pars, sign);
|
||||||
if (ft_strcmp(sign, "C") == 0)
|
free(str);
|
||||||
pars->c_color = pars->color;
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/18 19:44:37 by madumerg #+# #+# */
|
/* Created: 2024/09/18 19:44:37 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/10/05 17:52:43 by madumerg ### ########.fr */
|
/* Updated: 2024/11/11 15:09:04 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -40,20 +40,24 @@ char *ft_strndup_color(char *src, int start, int end)
|
|||||||
|
|
||||||
int valid_char_color(char c)
|
int valid_char_color(char c)
|
||||||
{
|
{
|
||||||
if (c == ',' || (c >= '0' && c <= '9'))
|
if (c == ',' || (c >= '0' && c <= '9') || c == '\t' \
|
||||||
|
|| c == ' ' || c == '\0')
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_char_color(char *tab)
|
int check_char_color(char *str)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (str[0] == 'C' || str[0] == 'F')
|
||||||
|
i = 1;
|
||||||
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
while (tab[i])
|
while (str[i])
|
||||||
{
|
{
|
||||||
if (valid_char_color(tab[i]) == 1)
|
if (valid_char_color(str[i]) == 1)
|
||||||
return (1);
|
return (err_mess(INVALID_CHAR));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
48
src/parsing/color_utils_two.c
Normal file
48
src/parsing/color_utils_two.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* color_utils_two.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/11 15:11:11 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/11/11 15:12:20 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "parsing.h"
|
||||||
|
|
||||||
|
int total_len(char **tab)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
len = 0;
|
||||||
|
while (tab[i])
|
||||||
|
{
|
||||||
|
len += ft_strlen(tab[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *multi_join(char **tab, int ct)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int t_len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
t_len = total_len(tab);
|
||||||
|
str = malloc(t_len + 1);
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
str[0] = '\0';
|
||||||
|
while (i < ct)
|
||||||
|
{
|
||||||
|
ft_strcat(str, tab[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/20 09:57:13 by madumerg #+# #+# */
|
/* Created: 2024/09/20 09:57:13 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/10/05 18:33:01 by madumerg ### ########.fr */
|
/* Updated: 2024/11/11 15:09:41 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -77,3 +77,21 @@ int count_line_file(int fd)
|
|||||||
close (fd);
|
close (fd);
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *ft_strcat(char *dest, char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (dest[i] != '\0')
|
||||||
|
i++;
|
||||||
|
j = 0;
|
||||||
|
while (src[j] != '\0')
|
||||||
|
{
|
||||||
|
dest[j + i] = src[j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
dest[i + j] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user