-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_map_4.c
More file actions
101 lines (93 loc) · 2.44 KB
/
Copy pathparse_map_4.c
File metadata and controls
101 lines (93 loc) · 2.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_map_4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: devoma <devoma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 12:17:56 by devoma #+# #+# */
/* Updated: 2023/05/18 12:17:57 by devoma ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
char *create_line(char *map_line, int j)
{
int malloc_count;
int new_i;
char *new_line;
malloc_count = malloc_counting(map_line);
new_i = 0;
new_line = malloc(sizeof(char) * malloc_count);
if (!new_line)
return (NULL);
while (map_line[j] && (map_line[j] == ' ' || map_line[j] == '\t'))
j++;
while (map_line[j])
{
if (!map_line[j])
{
new_line[new_i] = '\0';
return (new_line);
}
new_line[new_i] = map_line[j];
j++;
new_i++;
new_line[new_i] = '\0';
}
return (new_line);
}
int check_line_f_c(char *line)
{
int i;
int index;
i = 1;
index = 0;
if (check_full_num(line, &i, &index) == 0)
return (0);
if (check_semi(line, &i) == 0)
return (0);
if (check_full_num(line, &i, &index) == 0)
return (0);
if (check_semi(line, &i) == 0)
return (0);
if (check_full_num(line, &i, &index) == 0)
return (0);
while (line[i])
{
if (line[i] != ' ' && line[i] != '\t' && line[i] != '\n')
return (0);
i++;
}
return (1);
}
int check_semi(char *line, int *i)
{
while (line[*i] && (line[*i] == ' ' || line[*i] == '\t'))
(*i)++;
if (line[*i] && line[*i] != ',')
return (0);
(*i)++;
return (1);
}
int check_full_num(char *line, int *i, int *index)
{
char *temp;
while (line[*i] && (line[*i] == ' ' || line[*i] == '\t'))
(*i)++;
(*index) = (*i);
while (line[*i] && ft_isdigit(line[*i]))
(*i)++;
if ((*i) - (*index) > 0)
{
temp = ft_substr(line, *index, (*i) - (*index));
if (!temp || ft_atoi(temp) > 255 || ft_atoi(temp) < 0)
{
free(temp);
return (0);
}
free(temp);
}
else
return (0);
return (1);
}