-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
138 lines (121 loc) · 3.19 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "get_next_line.h"
#include "debug.h"
char* readline(fd)
{
char *tmp = malloc(10000 * sizeof(char));
char *tmpCur;
tmpCur = tmp;
while (read(fd, tmpCur, 1) && *tmpCur != '\n')
tmpCur++;
*tmpCur = '\0';
return (tmp);
}
int ft_strcomp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && s1[i] && s2[i])
i++;
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
return (0);
}
int main(void)
{
//char *testfile = "tests/test";
int fd = open("tests/bar.txt", O_RDONLY);
int fdcheck = open("tests/bar.txt", O_RDONLY);
char *line ;
line = NULL;
int i = 0;
int res = 1;
char *exp1;
/*int fd2 = open("tests/test2", O_RDONLY);
int fd2check = open("tests/test2", O_RDONLY);
char *line2;
line2 = NULL;
char *exp2;
int res2;
int fd3 = open("tests/test3", O_RDONLY);
int fd3check = open("tests/test3", O_RDONLY);
char *line3;
line3 = NULL;
int res3 = 1;
char *exp3;
int fd4 = open("tests/test4", O_RDONLY);
int fd4check = open("tests/test4", O_RDONLY);
char *line4;
line4 = NULL;
int res4 = 1;
char *exp4;
int fd5 = 0;
char *line5;
line5 = NULL;
int res5 = 1;*/
//printf("\n\033[1;33m--------------- GNL START ----------- BUFF: %d-------\033[0m\n", BUFFER_SIZE);
while (res > 0)
{
//printf("\n\033[1;34m--------------- GNL CALL - %d -------- BUFF: %d --------\033[0m\n", i, BUFFER_SIZE);
if (res > 0)
{
exp1 = readline(fdcheck);
res = get_next_line(fd, &line);
printf(GRN"fd: %d - RES %d -> %s"PINK"[end]"RST" - "YELO"RETURN %d\n", fd, i, line, res);
/* if (exp1 && line && ft_strcomp(exp1, line) != 0)
{
//printf(URED"DIFF\nEXP:%s"BGPINK"{END}"RST"\n\nRET:%s"PINK"{END}"RST"\n", exp1, line);
// free(exp1);
//s free(line);
return (0);
}*/
free(exp1);
free(line);
}
/*
if (res2 > 0)
{
exp2 = readline(fd2check);
res2 = get_next_line(fd2, &line2);
printf("\033[0;32mfd: %d - RES %d -> %s\033[0;35m[end]\033[0m - RETURN %d\n", fd2, i, line2, res2);
if (exp2 && line2 && ft_strcomp(exp2, line2) != 0)
{
printf("DIFF\n");
return (0);
}
}
if(res3 > 0)
{
exp3 = readline(fd3check);
res3 = get_next_line(fd3, &line3);
printf("\033[0;32mfd: %d - RES %d -> %s\033[0;35m[end]\033[0m - RETURN %d\n", fd3, i, line3, res3);
if (exp3 && line3 && ft_strcomp(exp3, line3) != 0)
{
printf("DIFF\n");
return (0);
}
}
if(res4 > 0)
{
exp4 = readline(fd4check);
res4 = get_next_line(fd4, &line4);
printf("\033[0;32mfd: %d - RES %d -> %s\033[0;35m[end]\033[0m - RETURN %d\n", fd4, i, line4, res4);
if (exp4 && line4 && ft_strcomp(exp4, line4) != 0)
{
printf("DIFF\n");
return (0);
}
}
if(res5 > 0)
{
res5 = get_next_line(fd5, &line5);
printf("\033[0;32mfd: %d - RES %d -> %s\033[0;35m[end]\033[0m - RETURN %d\n", fd5, i, line5, res5);
}*/
i++;
}
close(fd);
// printf("\n\033[1;32m--------------- GNL END ------------------\033[0m\n");
// printf("\n\033[1;32m--------------- GNL END ------------------\033[0m\n");
// printf("\n\033[1;32m--------------- GNL END ------------------\033[0m\n");
// printf("\n\033[1;32m--------------- GNL END ------------------\033[0m\n");
// printf("\n\033[1;32m--------------- GNL END ------------------\033[0m\n");
}