Added memorybook to parsing and cleaned most of the files

This commit is contained in:
Philippe BLAGOJEVIC
2022-05-04 14:38:34 +02:00
parent e564e7c8e9
commit 362668fe35
231 changed files with 11474 additions and 405 deletions

View File

@@ -6,7 +6,7 @@
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 16:03:50 by pblagoje #+# #+# */
/* Updated: 2022/04/23 18:57:37 by pblagoje ### ########.fr */
/* Updated: 2022/05/04 13:14:21 by pblagoje ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,11 +17,12 @@ int size_map(t_map *map, int fd)
char *line;
get_next_line(fd, &line);
mb_add(line);
while (line)
{
if ((*line == '\n' || *line == '\0') && map->size_x)
{
free(line);
mb_free(line);
return (EXIT_FAILURE);
}
else if (*line != '\n' && (int)ft_strlen(line) > map->size_x)
@@ -32,9 +33,10 @@ int size_map(t_map *map, int fd)
}
if (*line != '\n' && *line != '\0')
map->size_y++;
free(line);
mb_free(line);
line = NULL;
get_next_line(fd, &line);
mb_add(line);
}
return (EXIT_SUCCESS);
}
@@ -50,8 +52,8 @@ int find_map(t_map *map, char *file)
return (-1);
while (count < TOTAL_ELEMENTS + 1)
{
free(map->tmp_str);
get_next_line(fd, &map->tmp_str);
mb_add(map->tmp_str);
if (!map->tmp_str)
{
close(fd);
@@ -88,22 +90,25 @@ int fill_map(t_map *map, int fd)
map->content = (char **)mb_alloc((map->size_y + 1) * sizeof(char *));
if (!map->content)
{
free(map->tmp_str);
mb_free(map->tmp_str);
return (EXIT_FAILURE);
}
i = -1;
while (++i < map->size_y)
{
if (i > 0)
{
get_next_line(fd, &map->tmp_str);
mb_add(map->tmp_str);
}
map->content[i] = (char *)mb_alloc((map->size_x + 1) * sizeof(char));
if (!map->content[i])
{
free(map->tmp_str);
mb_free(map->tmp_str);
return (EXIT_FAILURE);
}
fill_row(map->content[i], map->tmp_str, map->size_x);
free(map->tmp_str);
mb_free(map->tmp_str);
map->tmp_str = NULL;
}
map->content[i] = NULL;
@@ -116,20 +121,20 @@ int init_parsing(t_game *game, char *file)
fd = check_elements(game, file);
if (fd == -1)
return (EXIT_FAILURE);
mb_exit("Error\nInvalid .cub file.\n", EXIT_FAILURE);
if (size_map(&(game->map), fd))
{
close(fd);
return (EXIT_FAILURE);
mb_exit("Error\nInvalid map format.\n", EXIT_FAILURE);
}
close(fd);
fd = find_map(&(game->map), file);
if (fd == -1)
return (EXIT_FAILURE);
mb_exit("Error\nCouldn't locate the map.\n", EXIT_FAILURE);
if (fill_map(&(game->map), fd) == EXIT_FAILURE)
{
close(fd);
return (EXIT_FAILURE);
mb_exit("Error\nCouldn't save the map.\n", EXIT_FAILURE);
}
close(fd);
return (EXIT_SUCCESS);