-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
117 lines (107 loc) · 2.2 KB
/
get_next_line_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fdi-cecc <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/26 23:22:14 by fdi-cecc #+# #+# */
/* Updated: 2024/06/03 15:35:53 by fdi-cecc ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void ft_freelist(t_list **list, t_list *cleannode, char *buffer)
{
t_list *temp;
if (NULL == *list)
return ;
while (*list)
{
temp = (*list)->next;
free((*list)->content);
free(*list);
*list = temp;
}
*list = NULL;
if (cleannode->content[0])
*list = cleannode;
else
{
free(buffer);
free(cleannode);
}
}
void ft_copyline(t_list *list, char *str)
{
int i;
int k;
if (NULL == list)
return ;
k = 0;
while (list)
{
i = 0;
while (list->content[i])
{
if (list->content[i] == '\n')
{
str[k++] = '\n';
str[k] = '\0';
return ;
}
str[k++] = list->content[i++];
}
list = list->next;
}
str[k] = '\0';
}
int ft_linelength(t_list *list)
{
int i;
int len;
if (NULL == list)
return (0);
len = 0;
while (list)
{
i = 0;
while (list->content[i])
{
if (list->content[i] == '\n')
{
len++;
return (len);
}
i++;
len++;
}
list = list->next;
}
return (len);
}
t_list *ft_lastnode(t_list *list)
{
if (NULL == list)
return (NULL);
while (list->next)
list = list->next;
return (list);
}
int ft_newline(t_list *list)
{
int i;
if (NULL == list)
return (0);
while (list)
{
i = 0;
while (list->content[i] && i < BUFFER_SIZE)
{
if (list->content[i] == '\n')
return (1);
i++;
}
list = list->next;
}
return (0);
}