-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
90 lines (81 loc) · 2.06 KB
/
utils.c
File metadata and controls
90 lines (81 loc) · 2.06 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamir <mamir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/05 21:51:23 by mamir #+# #+# */
/* Updated: 2024/05/20 11:17:46 by mamir ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void check_xpm(void *img)
{
if (!img)
ft_error("Invalid XPM\n");
}
void while_check(t_data *data, char *str, char *path)
{
int j;
int i;
int fd;
fd = open(path, O_RDONLY);
str = get_next_line(fd);
i = 0;
while (str != NULL)
{
j = 0;
if (i == data->map_dim[0] - 1)
{
while (str[j] != '\0')
{
if (str[j] != '1')
ft_error("in lines\n");
j++;
}
}
free(str);
str = get_next_line(fd);
i++;
}
}
char *ft_strrchr(const char *str, int c)
{
int i;
i = ft_strlen((char *)str);
while (i >= 0)
{
if (str[i] == (char)c)
return ((char *)str + i);
i--;
}
return (NULL);
}
int ft_strcmp(const char *s1, const char *s2)
{
if (s1 == NULL || s2 == NULL)
return (-1);
while (*s1 || *s2)
{
if (*s1 != *s2)
return ((unsigned char)*s1 - (unsigned char)*s2);
s1++;
s2++;
}
return (0);
}
void check_extension(char *path)
{
char *filename;
char *file_extension;
filename = ft_strrchr(path, '/');
if (filename == NULL)
filename = path;
else
filename++;
file_extension = ft_strrchr(filename, '.');
if (file_extension == NULL || ft_strcmp(file_extension, ".ber") != 0
|| ft_strlen(filename) <= 4)
ft_error("Bad Extension!\n");
}