piscine-bsq/srcs/main.c

52 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */
/* Updated: 2023/04/05 19:14:11 by apago ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_bsq.h"
int handle_file(int file)
{
t_map map;
if (!parse_file(file, &map))
return (ft_err("map error\n", 1));
solve(&map);
print_map(&map, 0);
free(map.data);
free(map.index);
return (0);
}
int main(int argc, char **argv)
{
int i;
int file;
int res;
if (argc < 2)
return (handle_file(0));
i = 0;
while (++i < argc)
{
if (i > 1)
ft_putchar('\n', 1);
file = open(argv[i], O_RDONLY);
if (file < 0)
{
ft_err("map error\n", 1);
continue ;
}
res = handle_file(file);
close(file);
}
return (0);
}