diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-13 17:29:19 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-13 17:29:19 +0100 |
| commit | b71e91e052a2884626c297cb014cbe2b63131c80 (patch) | |
| tree | 1a3c081fa637662553f292b6305390229bc2591e /parse/parse.c | |
| parent | 2007f61ef09c0b538aca2a7f20428f81175f322f (diff) | |
| download | cub3d-b71e91e052a2884626c297cb014cbe2b63131c80.tar.gz cub3d-b71e91e052a2884626c297cb014cbe2b63131c80.tar.bz2 cub3d-b71e91e052a2884626c297cb014cbe2b63131c80.zip | |
Basic parsing structure, Added subject
Diffstat (limited to 'parse/parse.c')
| -rw-r--r-- | parse/parse.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/parse/parse.c b/parse/parse.c new file mode 100644 index 0000000..c882424 --- /dev/null +++ b/parse/parse.c @@ -0,0 +1,54 @@ +#include "cub3d.h" + +t_parsing *parse(char *filename) +{ + int fd; + int ret; + char *line; + t_parsing *parsing; + + if ((parsing = (t_parsing*)malloc(sizeof(t_parsing))) == NULL) + return (NULL); + fd = open(filename, O_RDONLY); + while ((ret = get_next_line(fd, &line)) == 1) + if (!parse_line(parsing, line)) + return (NULL); + if (ret == -1) + return (NULL); + return (parsing); +} + +static t_option_parser option_parsers[] = { + {"R", parse_resolution}, + {"NO", parse_north_texture}, + {"SO", parse_south_texture}, + {"WE", parse_west_texture}, + {"EA", parse_east_texture}, + {"S", parse_sprite_texture}, + {"F", parse_floor_color}, + {"C", parse_ceilling_color}, +}; + +#define OPTIONS_PARSER_SIZE (sizeof(line_parsers) / sizeof(t_line_parser)) + +t_bool parse_option(t_parsing *parsing, char *line) +{ + int i; + + if (!*line) + return (TRUE); + i = -1; + while (++i < LINE_PARSER_SIZE) + if (ft_strchr("012", *line) != NULL) + return (parse_map(parsing, line)); + else if (ft_strncmp(option_parsers[i].id, line, + ft_strlen(option_parsers[i].id)) == 0) + return (option_parsers[i] + .func(parsing, line + ft_strlen(option_parsers[i].id)); + return (FALSE); +} + +t_bool parse_map(t_parsing *parsing, char *line) +{ + return (FALSE); +} |
