Fix parsing
This commit is contained in:
parent
c90731e654
commit
23a404b106
1
Makefile
1
Makefile
|
@ -7,6 +7,7 @@ SRC = \
|
|||
printing.c \
|
||||
map_helpers.c \
|
||||
ft_string.c \
|
||||
validation.c \
|
||||
|
||||
HEADERS = ft_bsq.h
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
97ox
|
||||
777777777777777777777777777
|
||||
7777o7777777777777777777777
|
||||
777777777777o77777777777777
|
||||
777777777777777777777777777
|
||||
7777o7777777777777777777777
|
||||
777777777777777o77777777777
|
||||
777777777777777777777777777
|
||||
777777o77777777777777o77777
|
||||
77o7777777o7777777777777777
|
|
@ -6,7 +6,7 @@
|
|||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 09:56:45 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/05 19:08:07 by apago ### ########.fr */
|
||||
/* Updated: 2023/04/05 19:27:20 by apago ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -56,5 +56,6 @@ void solve(t_map *map);
|
|||
int itoc(int idx, int width);
|
||||
int itor(int idx, int width);
|
||||
int get_index(t_map *map, int idx, int top, int left);
|
||||
int validate_meta(t_meta *meta);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/04 16:19:27 by apago #+# #+# */
|
||||
/* Updated: 2023/04/05 19:12:00 by apago ### ########.fr */
|
||||
/* Updated: 2023/04/05 19:28:14 by apago ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -14,23 +14,24 @@
|
|||
|
||||
int parse_meta(char *str, t_meta *meta)
|
||||
{
|
||||
int read_bytes;
|
||||
size_t read_bytes;
|
||||
|
||||
read_bytes = read_uint(str);
|
||||
meta->height = parse_valid_uint(str, read_bytes);
|
||||
read_bytes = 0;
|
||||
while (str[read_bytes] && str[read_bytes] != '\n')
|
||||
read_bytes++;
|
||||
if (read_bytes < 4)
|
||||
return (0);
|
||||
if (!read_char(&str[read_bytes - 3], &meta->empty))
|
||||
return (0);
|
||||
if (!read_char(&str[read_bytes - 2], &meta->obstacle))
|
||||
return (0);
|
||||
if (!read_char(&str[read_bytes - 1], &meta->full))
|
||||
return (0);
|
||||
if (read_uint(str) < read_bytes - 3)
|
||||
return (0);
|
||||
meta->height = parse_valid_uint(str, read_bytes - 3);
|
||||
if (meta->height < 1)
|
||||
return (0);
|
||||
if (!read_char(&str[read_bytes++], &meta->empty))
|
||||
return (0);
|
||||
if (!read_char(&str[read_bytes++], &meta->obstacle))
|
||||
return (0);
|
||||
if (!read_char(&str[read_bytes++], &meta->full))
|
||||
return (0);
|
||||
if (!printable(meta->empty) || !printable(meta->obstacle)
|
||||
|| !printable(meta->full))
|
||||
return (0);
|
||||
if ((meta->empty == meta->obstacle) || (meta->obstacle == meta->full))
|
||||
return (0);
|
||||
if (str[read_bytes++] != '\n')
|
||||
return (0);
|
||||
return (read_bytes);
|
||||
|
@ -91,7 +92,7 @@ int parse_input(char *str, t_map *map)
|
|||
size_t read_bytes;
|
||||
|
||||
read_bytes = parse_meta(str, &map->meta);
|
||||
if (!read_bytes)
|
||||
if (!read_bytes || !validate_meta(&map->meta))
|
||||
return (0);
|
||||
offset = read_bytes;
|
||||
map->meta.width = count_first_line(&str[offset]);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* validation.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 19:27:00 by apago #+# #+# */
|
||||
/* Updated: 2023/04/05 19:28:47 by apago ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_bsq.h"
|
||||
|
||||
int validate_meta(t_meta *meta)
|
||||
{
|
||||
if (!printable(meta->empty) || !printable(meta->obstacle)
|
||||
|| !printable(meta->full))
|
||||
return (0);
|
||||
if ((meta->empty == meta->obstacle) || (meta->obstacle == meta->full))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
Loading…
Reference in New Issue