Added memorybook to parsing and cleaned most of the files
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/16 20:54:37 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/02 15:45:01 by simplonco ### ########.fr */
|
||||
/* Updated: 2022/05/04 13:01:16 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,21 +17,25 @@ int set_path(t_txt *txt, char *path, char identifier)
|
||||
if (identifier == 'N' && txt->txt_north == NULL)
|
||||
{
|
||||
txt->txt_north = ft_strdup(path);
|
||||
mb_add(txt->txt_north);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
else if (identifier == 'S' && txt->txt_south == NULL)
|
||||
{
|
||||
txt->txt_south = ft_strdup(path);
|
||||
mb_add(txt->txt_south);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
else if (identifier == 'W' && txt->txt_west == NULL)
|
||||
{
|
||||
txt->txt_west = ft_strdup(path);
|
||||
mb_add(txt->txt_west);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
else if (identifier == 'E' && txt->txt_east == NULL)
|
||||
{
|
||||
txt->txt_east = ft_strdup(path);
|
||||
mb_add(txt->txt_east);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
return (EXIT_FAILURE);
|
||||
@@ -45,21 +49,21 @@ static int check_path(t_txt *txt, char *element, char identifier)
|
||||
while (element && *element && ft_strchr(" \t\r", *element))
|
||||
element++;
|
||||
path = ft_substr(element, 0, ft_strlen(element));
|
||||
mb_add(path);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1 || check_extension(path, ".xpm"))
|
||||
{
|
||||
ft_putstr_fd("Error\nInvalid texture file.\n", 2);
|
||||
free(path);
|
||||
mb_free(path);
|
||||
close(fd);
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nInvalid texture file.\n", EXIT_FAILURE);
|
||||
}
|
||||
if (set_path(txt, path, identifier) == EXIT_FAILURE)
|
||||
{
|
||||
free(path);
|
||||
mb_free(path);
|
||||
close(fd);
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nCouldn't save texture paths.\n", EXIT_FAILURE);
|
||||
}
|
||||
free(path);
|
||||
mb_free(path);
|
||||
close(fd);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -81,6 +85,7 @@ static int check_element(t_game *game, char *element)
|
||||
if (ft_strnstr("F C ", identifier, 5) && \
|
||||
!check_rgb(&(game->txt), element, identifier[0]))
|
||||
return (EXIT_SUCCESS);
|
||||
mb_exit("Error\nInvalid textures and/or RGB elements.\n", EXIT_FAILURE);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -98,15 +103,16 @@ int check_elements(t_game *game, char *file)
|
||||
while (count < TOTAL_ELEMENTS)
|
||||
{
|
||||
get_next_line(fd, &line);
|
||||
mb_add(line);
|
||||
if (line && *line != '\n' && !check_element(game, line))
|
||||
count++;
|
||||
else if (!line || (*line != '\n' && *line != '\0'))
|
||||
{
|
||||
free(line);
|
||||
mb_free(line);
|
||||
close(fd);
|
||||
return (-1);
|
||||
}
|
||||
free(line);
|
||||
mb_free(line);
|
||||
line = NULL;
|
||||
}
|
||||
return (fd);
|
||||
|
||||
Reference in New Issue
Block a user