-
Notifications
You must be signed in to change notification settings - Fork 0
/
argv_check.c
52 lines (48 loc) · 1.6 KB
/
argv_check.c
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
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* argv_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/27 15:36:48 by lbrandy #+# #+# */
/* Updated: 2021/04/02 18:41:53 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int file_check(char *map)
{
char *temp;
if (!map)
return (0);
if (ft_strlen(map) < 5)
return (0);
temp = ft_strrchr(map, '.');
if (!temp)
return (0);
if (ft_strlen(++temp) > 3)
return (0);
if (ft_strncmp("cub", temp, 3) == 0)
return (1);
return (0);
}
int argv_check(int argc, char **argv)
{
if (argc < 2)
error_handler("submit the map\n");
if (argc > 3)
error_handler("too many arguments\n");
if (argc > 1)
{
if (file_check(argv[1]) == 0)
error_handler("argv error\n");
if (argc == 3)
{
if ((ft_strlen(argv[2]) != 6))
error_handler("invalid third argument\n");
if (ft_strncmp("--save", argv[2], 6) != 0)
error_handler("invalid third argument\n");
}
}
return (1);
}