-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanthill_printing.c
54 lines (49 loc) · 1.57 KB
/
anthill_printing.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* anthill_printing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: obenazzo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/06 10:54:33 by obenazzo #+# #+# */
/* Updated: 2017/11/06 10:54:40 by obenazzo ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
void remove_invalid_last_line(char **t)
{
char *s;
if (valid_last_line(-1))
return ;
s = ft_strchr(*t, '\n') + 1;
while (ft_strchr(s, '\n')[1])
s = ft_strchr(s, '\n') + 1;
*s = 0;
}
int anthill_printing(int fd, char **t, int print)
{
static char *buffer = 0;
int g;
char *temp;
char *tf;
pr_free(t ? *t : 0);
if (print && buffer)
{
remove_invalid_last_line(&buffer);
write(1, buffer, ft_strlen(buffer));
pr_free(buffer);
buffer = 0;
return (1);
}
if ((g = get_next_line(fd, t)) == 1)
{
tf = buffer;
buffer = ft_strjoin(buffer ? buffer : "",
temp = ft_strjoin(*t, "\n"));
pr_free(tf);
pr_free(temp);
}
else if (g == -1)
error();
return (g);
}