Cub3D
Loading...
Searching...
No Matches
check_last_map.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* check_last_map.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/12/17 19:20:57 by kamitsui #+# #+# */
9/* Updated: 2024/12/18 02:12:23 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15static bool is_map_line(const char *str)
16{
17 const char *identifier = " 10NWES";
18 size_t i;
19 size_t len;
20
21 if (*str == '\n')
22 return (false);
23 len = ft_strlen(identifier);
24 while (*str != '\n' && *str != '\0')
25 {
26 i = 0;
27 while (i < len)
28 {
29 if (ft_strncmp(str, identifier + i, (size_t)1) == 0)
30 break ;
31 i++;
32 }
33 if (i == len)
34 return (false);
35 str++;
36 }
37 return (true);
38}
39
40static int check_continue_of_map(bool is_map_line, const char *line)
41{
42 if (is_map_line == true && *line != '\n')
43 {
44 ft_eprintf("%s%s\nNG line: [", ERR_PROMPT, EMSG_MAP_CHAR);
45 print_until_ch(STDOUT_FILENO, line, '\n');
46 ft_eprintf("]\n");
47 return (EXIT_FAILURE);
48 }
49 if (is_map_line == false && *line != '\n')
50 {
51 ft_eprintf("%s%s\n", ERR_PROMPT, EMSG_MAP_NOT_LAST);
52 return (EXIT_FAILURE);
53 }
54 return (EXIT_SUCCESS);
55}
56
57int check_last_map(const char *line, t_parse *parse)
58{
59 bool is_find_map;
60
61 while (line != NULL)
62 {
63 is_find_map = false;
64 while (is_map_line(line) == true)
65 {
66 is_find_map = true;
67 line = find_next_line(line);
68 if (line == NULL)
69 return (EXIT_SUCCESS);
70 }
71 if (check_continue_of_map(is_find_map, line) != EXIT_SUCCESS)
72 return (EXIT_FAILURE);
73 line = find_next_line(line);
74 }
75 (void)parse;
76 return (EXIT_SUCCESS);
77}