-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.c
More file actions
65 lines (60 loc) · 1.76 KB
/
error.c
File metadata and controls
65 lines (60 loc) · 1.76 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhedeon <mhedeon@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/02 21:00:23 by mhedeon #+# #+# */
/* Updated: 2018/07/03 16:07:31 by mhedeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int valid_name(char *filename)
{
int i;
char **tmp;
i = 0;
tmp = ft_strsplit(filename, '.');
while (tmp[i])
i++;
if (i != 2)
{
ft_matrixdel((void *)tmp, i);
return (FALSE);
}
else if (!ft_strcmp(tmp[1], ".fdf"))
{
ft_matrixdel((void *)tmp, i);
return (FALSE);
}
ft_matrixdel((void *)tmp, i);
return (TRUE);
}
int valid_file(int ac, char **av, t_map *map)
{
int fd;
if (ac != 2)
ft_putstr("usage: ./fdf [filename]\n");
else if ((fd = open(av[ac - 1], O_RDONLY)) == -1)
{
ft_putstr("The file \"");
ft_putstr(av[ac - 1]);
ft_putstr("\" does not exist.\n");
}
else if (!valid_name(av[ac - 1]))
ft_putstr("Invalid filename: \"filename.fdf\"\n");
else if (!valid_map(av[ac - 1], map))
{
ft_putstr("Invalid map in file \"");
ft_putstr(av[ac - 1]);
ft_putstr("\"\n");
}
else
{
close(fd);
return (TRUE);
}
close(fd);
return (FALSE);
}