aboutsummaryrefslogtreecommitdiff
path: root/src/parse/parse_resolution.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-04 05:34:27 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-04 05:34:27 +0100
commit3b224458a5d539bbe00318d939c9a099f3f158e1 (patch)
tree1e8533c49647120e2239904e2e0b167b408043cc /src/parse/parse_resolution.c
parentc8de182e9fa0c8a2674bf2f13d2ed9f500607ebd (diff)
downloadcub3d-3b224458a5d539bbe00318d939c9a099f3f158e1.tar.gz
cub3d-3b224458a5d539bbe00318d939c9a099f3f158e1.tar.bz2
cub3d-3b224458a5d539bbe00318d939c9a099f3f158e1.zip
better parsing
Diffstat (limited to 'src/parse/parse_resolution.c')
-rw-r--r--src/parse/parse_resolution.c25
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);
}