#include "fdf.h" int **split_to_map(t_fdf *fdf, char *raw) { int i; int j; int z; int **map; map = ft_calloc(fdf->map_height, sizeof(map)); i = -1; z = 0; while (++i < fdf->map_height) { map[i] = ft_calloc(fdf->map_width, sizeof(*map)); j = -1; while (++j < fdf->map_width) { while (!ft_isdigit(*raw)) raw++; map[i][j] = ft_atoi(raw); while (ft_isdigit(*raw)) raw++; if (map[i][j] > z) z = map[i][j]; } } fdf->max_z = z; return (map); } int size_width(char *raw) { int i; int j; i = 0; while (raw[i] && raw[i] != '!') { while (raw[i] == ' ') i++; while (ft_isdigit(raw[i])) i++; j++; } return (j); } int **parse_map(t_fdf *fdf, int fd) { int height; int ret; char *line; char *raw; height = 0; ret = 1; line = NULL; raw = ft_strdup(""); while (ret > 0) { ret = ft_gnl(fd, &line); if (ret > 0) { height++; raw = ft_strjoinfree(raw, line); raw = ft_strjoinfree(raw, ft_strdup("!")); } } fdf->map_height = height; fdf->map_width = size_width(raw); return (split_to_map(fdf, raw)); }