-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradix_utils.c
86 lines (79 loc) · 1.93 KB
/
radix_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* radix_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rda-cost <rda-cost@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/06/02 10:10:38 by rda-cost #+# #+# */
/* Updated: 2015/06/03 15:08:31 by rda-cost ### ########.fr */
/* */
/* ************************************************************************** */
#include "radix.h"
#include <sys/stat.h>
#include <fcntl.h>
void print_wrap(t_wrap *start)
{
t_wrap *save;
if (!(save = start))
return ;
if (save->next == save)
return (void)(printf("%s\n", save->str));
while (start)
{
printf("%s\n", start->str);
if (start->next == save)
return ;
start = start->next;
}
}
void radix_print(t_rdx *root, char *cur)
{
char *concat;
(void)cur;
if (!root)
return ;
while (root)
{
concat = NULL;
if (cur)
concat = strjoin(cur, root->str);
if (root->st)
{
if (concat)
printf("%s\n", concat);
else
printf("%s\n", root->str);
}
if (concat)
radix_print(root->down, concat);
else
radix_print(root->down, root->str);
if (concat)
free(concat);
root = root->next;
}
}
void radix_from_file(t_rdx **root, char *file)
{
int fd;
char *line;
size_t ct;
if ((fd = open(file, O_RDONLY)) == -1)
return ;
ct = 0;
while (gnl(fd, &line))
{
radix_insert(root, line);
if (line)
free(line);
ct++;
}
if (line)
{
ct++;
radix_insert(root, line);
free(line);
}
close(fd);
}