diff options
Diffstat (limited to 'src/parse/parse_resolution.c')
| -rw-r--r-- | src/parse/parse_resolution.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/parse/parse_resolution.c b/src/parse/parse_resolution.c index d6c5759..300b461 100644 --- a/src/parse/parse_resolution.c +++ b/src/parse/parse_resolution.c @@ -6,19 +6,36 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 09:29:27 by cacharle #+# #+# */ -/* Updated: 2020/01/11 09:44:18 by cacharle ### ########.fr */ +/* Updated: 2020/02/04 04:40:35 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" +#define MIN_RES 20 +#define MAX_RES_HEIGHT 2160 +#define MAX_RES_WIDTH 3840 + t_bool parse_resolution(t_state *state, char *line) { - if ((state->window.width = ft_atoi(line)) < 0) + long tmp; + + errno = 0; + if ((tmp = ft_strtol(line, &line, 10)) < MIN_RES) + return (FALSE); + if (tmp > MAX_RES_WIDTH) + return (FALSE); + state->window.width = tmp; + if (*line != ' ') + return (FALSE); + while (*line == ' ') + line++; + if ((tmp = ft_strtol(line, &line, 10)) < MIN_RES) return (FALSE); - if ((line = ft_strrchr(line, ' ') + 1) == NULL) + if (tmp > MAX_RES_HEIGHT) return (FALSE); - if ((state->window.height = ft_atoi(line)) < 0) + state->window.height = tmp; + if (*line != '\0' || errno != 0 || state->window.height > 2160) return (FALSE); return (TRUE); } |
