diff options
| -rw-r--r-- | cub3d.h | 6 | ||||
| -rw-r--r-- | error.c | 24 | ||||
| -rw-r--r-- | main.c | 9 | ||||
| -rw-r--r-- | parse/parse.c | 26 | ||||
| -rw-r--r-- | parse/parse_check.c | 12 | ||||
| -rw-r--r-- | state.c | 4 |
6 files changed, 50 insertions, 31 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 06:40:37 by cacharle #+# #+# */ -/* Updated: 2020/01/11 10:59:58 by cacharle ### ########.fr */ +/* Updated: 2020/01/11 12:54:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdio.h> @@ -203,6 +203,10 @@ double vector_norm(t_vector v); */ void error_put_usage_exit(char *name); +void error_put(char *message); +void *error_put_return(char *message); +void *error_put_return_state_destroy(char *message, t_state *state); +void *error_put_return_lines_state_destroy(char *message, t_state *state, char **lines); /* ** helper.c @@ -9,3 +9,27 @@ void error_put_usage_exit(char *name) ft_putendl_fd(" [.cub file] [--save]", STDERR_FILENO); exit(EXIT_FAILURE); } + +void error_put(char *message) +{ + ft_putstr("Error\nCouldnt "); + ft_putendl(message); +} + +void *error_put_return(char *message) +{ + error_put(message); + return (NULL); +} + +void *error_put_return_state_destroy(char *message, t_state *state) +{ + state_destroy(state); + return error_put_return(message); +} + +void *error_put_return_lines_state_destroy(char *message, t_state *state, char **lines) +{ + helper_free_splited(lines); + return (error_put_return_state_destroy(message, state)); +} @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 06:39:39 by cacharle #+# #+# */ -/* Updated: 2020/01/11 12:33:37 by cacharle ### ########.fr */ +/* Updated: 2020/01/11 13:04:38 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,14 +36,9 @@ int main(int argc, char **argv) int main(int argc, char **argv) { (void)argc; - t_state *s = parse(argv[1]); + t_state *s = parse_check(parse(argv[1])); if (s == NULL) return (1); - if (parse_check(s) == NULL) - { - printf("wrong .cub format"); - return (1); - } printf("R %d %d\n", s->window.width, s->window.height); printf("NO %s\n", s->textures_path[TEX_NORTH]); printf("SO %s\n", s->textures_path[TEX_SOUTH]); diff --git a/parse/parse.c b/parse/parse.c index 84a8957..3eb8846 100644 --- a/parse/parse.c +++ b/parse/parse.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 09:29:21 by cacharle #+# #+# */ -/* Updated: 2020/01/11 11:29:45 by cacharle ### ########.fr */ +/* Updated: 2020/01/11 12:59:58 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,32 +19,26 @@ t_state *parse(char *filename) t_state *state; if ((state = state_new_empty()) == NULL) - return (NULL); + return (error_put_return("create empty state")); if ((lines = get_file_lines(filename)) == NULL) - return (state_destroy(state)); - /* for (int i = 0; lines[i]; i++) */ - /* printf("%d [%s]\n", i, lines[i]); */ + return (error_put_return_state_destroy("read .cub file", state)); i = -1; while (lines[++i] != NULL) { if (*lines[i] == '1') break ; if (!parse_line(state, lines[i])) - { - helper_free_splited(lines); - return (state_destroy(state)); - } + return (error_put_return_lines_state_destroy( + "parse configuration", state, lines)); } if ((state = parse_map(state, lines + i)) == NULL) - { - helper_free_splited(lines); - return (state_destroy(state)); - } + return (error_put_return_lines_state_destroy( + "parse map", state, lines)); helper_free_splited(lines); return (state); } -char **get_file_lines(char *filename) +char **get_file_lines(char *filename) { int fd; int ret; @@ -81,7 +75,7 @@ static t_option_parser g_option_parsers[] = #define OPTIONS_PARSERS_SIZE (sizeof(g_option_parsers) / sizeof(t_option_parser)) -t_bool parse_line(t_state *state, char *line) +t_bool parse_line(t_state *state, char *line) { int i; @@ -115,7 +109,7 @@ t_state *parse_map(t_state *state, char **lines) return (state); } -t_cell *create_map_row(char *line) +t_cell *create_map_row(char *line) { int i; t_cell *row; diff --git a/parse/parse_check.c b/parse/parse_check.c index 7bcfc8b..a65d74a 100644 --- a/parse/parse_check.c +++ b/parse/parse_check.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/11 10:59:15 by cacharle #+# #+# */ -/* Updated: 2020/01/11 11:15:04 by cacharle ### ########.fr */ +/* Updated: 2020/01/11 13:03:33 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,19 +15,21 @@ t_state *parse_check(t_state *state) { int i; - int j; - int player_count; + /* int j; */ + /* int player_count; */ i = -1; while (++i < state->map_width) if (state->map[0][i] != CELL_WALL || state->map[state->map_height - 1][i] != CELL_WALL) - return (state_destroy(state)); + return (error_put_return_state_destroy( + "validate map without borders", state)); i = -1; while (++i < state->map_height) if (state->map[i][0] != CELL_WALL || state->map[i][state->map_width - 1] != CELL_WALL) - return (state_destroy(state)); + return (error_put_return_state_destroy( + "validate map without borders", state)); // maybe not necessary /* player_count = 0; */ /* i = -1; */ @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/19 16:39:57 by cacharle #+# #+# */ -/* Updated: 2020/01/11 12:32:13 by cacharle ### ########.fr */ +/* Updated: 2020/01/11 13:10:45 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ t_state *state_new(t_state *state) { load_texture(state->mlx_ptr, &state->textures[i], state->textures_path[i]); if (state->textures[i].id == NULL) - return (state_destroy(state)); + return (error_put_return_state_destroy("load texture", state)); } if ((state->window.id = mlx_new_image(state->mlx_ptr, state->window.width, state->window.height)) == NULL) |
