aboutsummaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
Diffstat (limited to 'parse')
-rw-r--r--parse/parse.c54
-rw-r--r--parse/parse_ceilling_color.c12
-rw-r--r--parse/parse_east_texture.c8
-rw-r--r--parse/parse_floor_color.c12
-rw-r--r--parse/parse_north_texture.c8
-rw-r--r--parse/parse_resolution.c9
-rw-r--r--parse/parse_south_texture.c8
-rw-r--r--parse/parse_sprite_texture.c8
-rw-r--r--parse/parse_west_texture.c8
9 files changed, 127 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);
+}
diff --git a/parse/parse_ceilling_color.c b/parse/parse_ceilling_color.c
new file mode 100644
index 0000000..0f93ed1
--- /dev/null
+++ b/parse/parse_ceilling_color.c
@@ -0,0 +1,12 @@
+#include "cub3d.h"
+
+t_bool parse_ceilling_color(t_parsing *parsing, char *line)
+{
+ line++;
+ parsing->ceilling_color.r = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->ceilling_color.g = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->ceilling_color.b = ft_atoi(line);
+ return (TRUE);
+}
diff --git a/parse/parse_east_texture.c b/parse/parse_east_texture.c
new file mode 100644
index 0000000..e8d356a
--- /dev/null
+++ b/parse/parse_east_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_east_texture(t_parsing *parsing, char *line)
+{
+ parsing->east_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_floor_color.c b/parse/parse_floor_color.c
new file mode 100644
index 0000000..62d0a06
--- /dev/null
+++ b/parse/parse_floor_color.c
@@ -0,0 +1,12 @@
+#include "cub3d.h"
+
+t_bool parse_floor_color(t_parsing *parsing, char *line)
+{
+ line++;
+ parsing->floor_color.r = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->floor_color.g = ft_atoi(line);
+ line = ft_strchr(line, ',');
+ parsing->floor_color.b = ft_atoi(line);
+ return (TRUE);
+}
diff --git a/parse/parse_north_texture.c b/parse/parse_north_texture.c
new file mode 100644
index 0000000..0d1af87
--- /dev/null
+++ b/parse/parse_north_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_north_texture(t_parsing *parsing, char *line)
+{
+ parsing->north_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_resolution.c b/parse/parse_resolution.c
new file mode 100644
index 0000000..c8e0c7f
--- /dev/null
+++ b/parse/parse_resolution.c
@@ -0,0 +1,9 @@
+#include "cub3d.h"
+
+t_bool parse_resolution(t_parsing *parsing, char *line)
+{
+ parsing->resolution_width = ft_atoi(line);
+ line = ft_strchr(line, ' ');
+ parsing->resolution_height = ft_atoi(line);
+ return (TRUE);
+}
diff --git a/parse/parse_south_texture.c b/parse/parse_south_texture.c
new file mode 100644
index 0000000..9ec89d0
--- /dev/null
+++ b/parse/parse_south_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_south_texture(t_parsing *parsing, char *line)
+{
+ parsing->south_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_sprite_texture.c b/parse/parse_sprite_texture.c
new file mode 100644
index 0000000..039a827
--- /dev/null
+++ b/parse/parse_sprite_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_sprite_texture(t_parsing *parsing, char *line)
+{
+ parsing->sprite_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+
diff --git a/parse/parse_west_texture.c b/parse/parse_west_texture.c
new file mode 100644
index 0000000..5252ab4
--- /dev/null
+++ b/parse/parse_west_texture.c
@@ -0,0 +1,8 @@
+#include "cub3d.h"
+
+t_bool parse_west_texture(t_parsing *parsing, char *line)
+{
+ parsing->west_texture_path = ft_strdup(line + 1);
+ return (TRUE);
+}
+