piscine-bsq/srcs/main.c

59 lines
1.5 KiB
C

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