23 while (lines[rows] != NULL)
25 tmp_len = ft_strlen(lines[rows]);
30 return ((
t_map_size){.rows = rows, .cols = cols});
42 array = (
char **)malloc((rows + 1) *
sizeof(
char *));
48 array[i] = (
char *)malloc((cols + 1) *
sizeof(char));
51 free_double_pointer_n(array, i);
59static void copy_and_pad_lines(
char **src,
char **dst,
size_t max_len)
65 while (src[i] != NULL)
67 len = ft_strlen(src[i]);
68 ft_memset(dst[i],
' ', max_len);
69 ft_memcpy(dst[i], src[i], len);
70 dst[i][max_len] =
'\0';
76static char **convert_str2array(
const char *str_map)
82 lines = split_lines(str_map);
85 map_size = get_map_size(lines);
86 array = allocate_map(map_size);
89 free_double_pointer(lines);
92 copy_and_pad_lines(lines, array, map_size.cols);
93 free_double_pointer(lines);
97int get_map_data(
const char *line,
t_parse *parse)
102 map = &parse->game->map;
103 map->data = convert_str2array(line);
104 if (map->data == NULL)
106 ft_eprintf(
"Error: convert_str2array() fail\n");
107 return (EXIT_FAILURE);
109 map->width = ft_strlen(map->data[0]);
111 while (map->data[count] != NULL)
114 parse->flag |= BIT_INIT_MAP;
115 return (EXIT_SUCCESS);