-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
56 lines (51 loc) · 1.54 KB
/
main.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jwebber <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/21 12:32:11 by jwebber #+# #+# */
/* Updated: 2019/07/24 15:54:58 by jraelene ### ########.fr */
/* */
/* ************************************************************************** */
#include "io_support.h"
#include "ft/func_prot.h"
#include "list/ft_list.h"
#include "main.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
void read_file(int argc, char **argv)
{
char *buff;
int i;
int fd;
i = 1;
while (i < argc)
{
fd = open(argv[i], O_RDONLY);
buff = NULL;
if (fd == -1 || !(buff = io_read(fd)) || !solve(buff))
write(2, "map error\n", 10);
i++;
if (i < argc)
ft_putchar('\n');
if (buff)
free(buff);
}
}
int main(int argc, char **argv)
{
char *buff;
if (argc == 1)
{
if (!(buff = io_read(0)) || !solve(buff))
write(2, "map error\n", 10);
if (buff)
free(buff);
}
else
read_file(argc, argv);
return (0);
}