-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
120 lines (109 loc) · 2.41 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
118
119
120
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hyoon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/22 18:03:29 by hyoon #+# #+# */
/* Updated: 2020/04/29 01:06:59 by hyoon ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void ft_lstclear(t_list **lst)
{
t_list *l;
t_list *front;
l = *lst;
if (!l)
return ;
while (l)
{
front = l;
l = l->next;
if (front->content)
free(front->content);
free(front);
}
*lst = NULL;
}
t_list *ft_lstnew(void)
{
int i;
t_list *lst;
lst = (t_list *)malloc(sizeof(t_list));
lst->content = (char *)malloc(sizeof(char) * BUFFER_SIZE);
if (lst->content == NULL || lst == NULL)
return (0);
i = 0;
while (i < BUFFER_SIZE)
{
*((unsigned char *)(lst->content) + i) = 0;
i++;
}
lst->next = NULL;
return (lst);
}
void ft_lstadd_back(t_list **lst, t_list *n)
{
t_list *l;
l = *lst;
if (!n)
return ;
else if (!l)
{
*lst = n;
return ;
}
while (l->next)
l = l->next;
l->next = n;
n->next = NULL;
}
int ft_start_check(t_list *start)
{
int i;
int j;
i = 0;
while (start)
{
j = 0;
while (j < BUFFER_SIZE)
{
if (*((char *)(start->content) + j) == 0)
{
j = BUFFER_SIZE;
continue ;
}
else if (*((char *)(start->content) + j) == -1 ||
*((char *)(start->content) + j) == '\n')
return (i);
i++;
j++;
}
start = start->next;
}
return (-1);
}
void ft_cpy_line(char *line, t_list *start, int i)
{
int count;
int s_count;
t_list *lst;
count = 0;
s_count = 0;
lst = start;
while (count < i)
{
if (s_count >= BUFFER_SIZE
|| *((char *)lst->content + s_count) == 0)
{
lst = lst->next;
s_count = 0;
}
*(line + count) = *((char *)(lst->content) + s_count);
count++;
s_count++;
}
*(line + count) = 0;
}