Handle arguments
This commit is contained in:
parent
d76384446b
commit
e13c1fec1f
|
@ -6,7 +6,7 @@
|
|||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/04 18:22:11 by apago #+# #+# */
|
||||
/* Updated: 2023/04/05 17:39:31 by apago ### ########.fr */
|
||||
/* Updated: 2023/04/05 18:08:33 by apago ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -40,7 +40,7 @@ int parse_valid_uint(char *str, size_t len);
|
|||
int read_char(char *str, char *dst);
|
||||
int printable(char c);
|
||||
size_t count_first_line(char *line);
|
||||
int read_fname(char *name, t_map *map);
|
||||
int parse_file(int file, t_map *map);
|
||||
void copy_bytes(char *dst, char *src, size_t bytes);
|
||||
void ft_memset_int(int *dst, int set, size_t bytes);
|
||||
|
||||
|
|
33
srcs/main.c
33
srcs/main.c
|
@ -6,7 +6,7 @@
|
|||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/05 18:00:14 by apago ### ########.fr */
|
||||
/* Updated: 2023/04/05 18:16:13 by apago ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
|||
#include "solution.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
int handle_file(int file)
|
||||
{
|
||||
t_map map;
|
||||
|
||||
if (!read_fname("./assets/map20x40.map", &map))
|
||||
if (!parse_file(file, &map))
|
||||
return (ft_err("map error\n", 1));
|
||||
solve(&map);
|
||||
print_map(&map, 0);
|
||||
|
@ -27,3 +27,30 @@ int main(void)
|
|||
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);
|
||||
if (res)
|
||||
return (res);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/04 16:19:27 by apago #+# #+# */
|
||||
/* Updated: 2023/04/05 17:59:32 by apago ### ########.fr */
|
||||
/* Updated: 2023/04/05 18:07:43 by apago ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -111,17 +111,12 @@ int parse_input(char *str, t_map *map)
|
|||
return (1);
|
||||
}
|
||||
|
||||
int read_fname(char *name, t_map *map)
|
||||
int parse_file(int file, t_map *map)
|
||||
{
|
||||
int file;
|
||||
char *text;
|
||||
int res;
|
||||
|
||||
file = open(name, O_RDONLY);
|
||||
if (file == -1)
|
||||
return (0);
|
||||
text = read_file(file);
|
||||
close(file);
|
||||
if (!text)
|
||||
return (0);
|
||||
res = parse_input(text, map);
|
||||
|
|
Loading…
Reference in New Issue