-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_and_check_map_2.c
67 lines (61 loc) · 2.08 KB
/
make_and_check_map_2.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* make_and_check_map_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mkorpela <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/14 15:54:52 by mkorpela #+# #+# */
/* Updated: 2024/03/14 15:56:37 by mkorpela ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
static void check_number_of_arguments(int argc)
{
if (argc != 2)
{
ft_putstr_fd("Error\n", 2);
ft_putstr_fd("You should pass in only ONE argument - ", 2);
ft_putstr_fd("and that would be the map. ;) ", 2);
ft_putstr_fd("You have passed ", 2);
ft_putnbr_fd(argc - 1, 2);
ft_putstr_fd(" argument(s).\n", 2);
exit (1);
}
}
static void check_directory_of_map_file(char **argv)
{
if (ft_strncmp(argv[1], "maps/", 5) != 0
|| ft_strchr(&argv[1][5], '/') != NULL)
{
ft_putstr_fd("Error\n", 2);
ft_putendl_fd("Invalid file path. Try 'maps/<map_file_name>'", 2);
exit (1);
}
}
static void check_name_of_map(char **argv)
{
size_t i;
i = f_strlen(argv[1]);
if (i < 9)
{
ft_putstr_fd("Error\n", 2);
ft_putstr_fd("Map name is too short. ", 2);
ft_putstr_fd("The name should end with \".ber\".\n", 2);
exit (1);
}
i = i - 4;
if (ft_strncmp(&argv[1][i], ".ber", 4) != 0)
{
ft_putstr_fd("Error\n", 2);
ft_putstr_fd("Incorrect map name. ", 2);
ft_putstr_fd("The name should end with \".ber\".\n", 2);
exit (1);
}
}
void check_map_name_path_and_argument_count(int argc, char **argv)
{
check_number_of_arguments(argc);
check_directory_of_map_file(argv);
check_name_of_map(argv);
}