You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.2 KiB
93 lines
2.2 KiB
3 years ago
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* fdf_parsing.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2022/02/22 09:16:28 by narnaud #+# #+# */
|
||
|
/* Updated: 2022/02/24 13:47:26 by narnaud ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "fdf.h"
|
||
|
|
||
|
/* Function : parse_line
|
||
|
* ---------------------
|
||
|
* map :
|
||
|
* p :
|
||
|
* splitted
|
||
|
*/
|
||
|
|
||
|
void parse_line(t_map *map, t_2di p, char ***splited)
|
||
|
{
|
||
|
p.x = 0;
|
||
|
map->altitude[p.y] = ft_calloc(p.len, sizeof(int));
|
||
|
while ((*splited)[p.x])
|
||
|
{
|
||
|
map->altitude[p.y][p.x] = ft_atoi((*splited)[p.x]);
|
||
|
if (abs(map->altitude[p.y][p.x]) > abs(map->hightest))
|
||
|
map->hightest = abs(map->altitude[p.y][p.x]);
|
||
|
free((*splited)[p.x]);
|
||
|
p.x++;
|
||
|
}
|
||
|
if (map->hightest == 0)
|
||
|
map->hightest = 1;
|
||
|
free((*splited));
|
||
|
}
|
||
|
|
||
|
/* Function : parse_file
|
||
|
* ---------------------
|
||
|
* fd :
|
||
|
* line :
|
||
|
* splited :
|
||
|
*/
|
||
|
|
||
|
t_map *parse_file(int fd, t_map *map)
|
||
|
{
|
||
|
t_2di p;
|
||
|
char *line;
|
||
|
char **splited;
|
||
|
|
||
|
map->hightest = 0;
|
||
|
p.x = 0;
|
||
|
line = get_next_line(fd);
|
||
|
splited = ft_split(line, ' ');
|
||
|
free(line);
|
||
|
while (splited[p.x])
|
||
|
p.x++;
|
||
|
p.len = p.x;
|
||
|
p.y = 0;
|
||
|
while (splited)
|
||
|
{
|
||
|
parse_line(map, p, &(splited));
|
||
|
line = get_next_line(fd);
|
||
|
splited = ft_split(line, ' ');
|
||
|
free(line);
|
||
|
p.y++;
|
||
|
}
|
||
|
map->width = p.x;
|
||
|
map->depth = p.y;
|
||
|
close(fd);
|
||
|
return (map);
|
||
|
}
|
||
|
|
||
|
/* Function : get_file_ext
|
||
|
* --------------------------
|
||
|
* fd : file_descriptor
|
||
|
* return file extension
|
||
|
*/
|
||
|
|
||
|
const char *get_file_ext(const char *filename)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = 0;
|
||
|
while (filename[i])
|
||
|
i++;
|
||
|
while (filename[--i])
|
||
|
if (filename[i] == '.')
|
||
|
return (filename + i + 1);
|
||
|
return (NULL);
|
||
|
}
|