Print line breaks on appropriate output

This commit is contained in:
Andrei Pago 2023-04-05 19:38:41 +02:00
parent 23a404b106
commit 6ef7b128c3
1 changed files with 14 additions and 7 deletions

View File

@ -6,20 +6,27 @@
/* 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 */
/* Updated: 2023/04/05 19:37:27 by apago ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_bsq.h"
int handle_file(int file)
int handle_file(int file, int extra_newline)
{
t_map map;
if (!parse_file(file, &map))
return (ft_err("map error\n", 1));
{
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);
@ -32,19 +39,19 @@ int main(int argc, char **argv)
int res;
if (argc < 2)
return (handle_file(0));
return (handle_file(0, 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);
if (argc > 2)
ft_err("\n", 1);
continue ;
}
res = handle_file(file);
res = handle_file(file, argc > 2);
close(file);
}
return (0);