a la norme et sans leaks

This commit is contained in:
hugogogo
2021-07-25 14:56:05 +02:00
parent e4b4f5e751
commit 463ce19ce3
5 changed files with 40 additions and 26 deletions

View File

@@ -14,8 +14,6 @@ int **split_to_map(t_fdf *fdf, char *raw)
int j;
int **map;
if (fdf->map_height == 0)
shut_down(fdf);
map = ft_calloc(fdf->map_height, sizeof(map));
if (!map)
shut_down(fdf);
@@ -50,11 +48,13 @@ int is_color(char *color)
return (i);
}
int size_width(char *raw)
void size_map(t_fdf *fdf, char *raw, int height)
{
int i;
int j;
if (height == 0)
shut_down(fdf);
i = 0;
while (raw[i] && raw[i] != '!')
{
@@ -67,7 +67,10 @@ int size_width(char *raw)
i += is_color(raw + i);
j++;
}
return (j);
fdf->map_width = j;
fdf->map_height = height;
fdf->min_z = 0;
fdf->max_z = 0;
}
int **parse_map(t_fdf *fdf, int fd)
@@ -76,6 +79,7 @@ int **parse_map(t_fdf *fdf, int fd)
int ret;
char *line;
char *raw;
int **map;
height = 0;
ret = 1;
@@ -91,9 +95,9 @@ int **parse_map(t_fdf *fdf, int fd)
raw = ft_strjoinfree(raw, ft_strdup("!"));
}
}
fdf->map_height = height;
fdf->map_width = size_width(raw);
fdf->min_z = 0;
fdf->max_z = 0;
return (split_to_map(fdf, raw));
size_map(fdf, raw, height);
map = split_to_map(fdf, raw);
free(line);
free(raw);
return (map);
}