blob: b863c94240776d3c4953e197a03d325e356c3cf5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_resolution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/15 09:29:27 by cacharle #+# #+# */
/* Updated: 2020/02/05 00:04:03 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)
{
long tmp;
if (state->pflags & PFLAGS_R)
return (FALSE);
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 (tmp > MAX_RES_HEIGHT)
return (FALSE);
state->window.height = tmp;
if (*line != '\0' || errno != 0 || state->window.height > 2160)
return (FALSE);
state->pflags |= PFLAGS_R;
return (TRUE);
}
|