-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorchecks.c
More file actions
79 lines (68 loc) · 1.82 KB
/
errorchecks.c
File metadata and controls
79 lines (68 loc) · 1.82 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* errorchecks.c :+: :+: */
/* +:+ */
/* By: cstaats <cstaats@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/10/31 12:48:08 by cstaats #+# #+# */
/* Updated: 2022/11/01 14:30:55 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
char **errorchecks(int argc, char **argv)
{
int fd;
if (argc != 2)
itsanerror();
isitber(argv[1]);
fd = isitexistant(argv[1]);
return (makeamap(fd));
}
int isitexistant(char *argv)
{
int fd;
fd = open(argv, O_RDONLY);
if (fd <= 2)
itsanerror();
return (fd);
}
void isitones(char *str)
{
int cnt;
cnt = 0;
while (str[cnt] != '\0')
{
if (str[cnt] != '1')
itsanerror();
cnt++;
}
}
void isitgood(char *str)
{
int cnt;
cnt = 0;
if (str[0] != '1')
itsanerror();
while (str[cnt] != '\0')
{
if (!(str[cnt] == '1' || str[cnt] == '0' || str[cnt] == 'P'
|| str[cnt] == 'E' || str[cnt] == 'C'))
itsanerror();
cnt++;
}
if (str[cnt - 1] != '1')
itsanerror();
}
void isitber(char *argv)
{
int cnt;
if (argv == NULL)
itsanerror();
cnt = ft_strlen(argv);
if (cnt < 4)
itsanerror();
if (!(argv[cnt - 1] == 'r' && argv[cnt - 2] == 'e' && argv[cnt - 3] == 'b'
&& argv[cnt - 4] == '.'))
itsanerror();
}