-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.c
More file actions
130 lines (119 loc) · 2.75 KB
/
Copy patherrors.c
File metadata and controls
130 lines (119 loc) · 2.75 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: devoma <devoma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 12:16:23 by devoma #+# #+# */
/* Updated: 2023/05/18 18:22:32 by devoma ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
char **check_arguments(int ac, char **av)
{
int fd;
int malloc_count;
char **map;
if (ac != 2)
{
printf("Nombre de parametre insufisant...\n");
return (NULL);
}
if (check_extension(av[1]) == 0)
{
printf("Fichier non valide...\n");
return (NULL);
}
fd = open(av[1], O_RDONLY);
if (fd == -1)
{
printf("Fichier non valide...\n");
return (NULL);
}
malloc_count = reading_lines(fd) + 1;
close(fd);
map = check_arguments_2(av, malloc_count);
return (map);
}
char **check_arguments_2(char **av, int count)
{
int fd;
char **map;
fd = open(av[1], O_RDONLY);
if (fd == -1)
{
printf("Fichier non valide...\n");
return (NULL);
}
map = reading_file(fd, count);
if (map == NULL)
{
printf("Map non valide...\n");
return (NULL);
}
if (check_new_lines(map) == 0 || check_full_map(map) == 0)
{
free_map(map);
printf("Map non valide...\n");
return (NULL);
}
return (map);
}
int check_new_lines(char **map)
{
int i;
int id_count;
i = 0;
id_count = 0;
while (map[++i])
{
if (is_id(map[i], 0))
id_count++;
if (map[i] && id_count == 6)
{
i++;
while (map[i] && is_empty_str(map[i]) == 1)
i++;
while (map[i])
{
if (is_empty_str(map[i]) == 1)
return (0);
i++;
}
i--;
}
}
return (1);
}
int check_all_chars(char **map, int first_i)
{
int i;
int j;
i = first_i - 1;
while (map[++i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] != '0' && map[i][j] != '1'
&& map[i][j] != 'N' && map[i][j] != 'S'
&& map[i][j] != 'E' && map[i][j] != 'W'
&& map[i][j] != ' ' && map[i][j] != '\t' && map[i][j] != '\n')
return (0);
j++;
}
}
return (1);
}
int check_extension(char *str)
{
int index;
index = ft_strlen(str) - 1;
if (ft_strlen(str) < 5)
return (0);
if (str[index] != 'b' || str[index - 1] != 'u'
|| str[index - 2] != 'c' || str[index - 3] != '.')
return (0);
return (1);
}