-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_functions.c
103 lines (92 loc) · 2.19 KB
/
list_functions.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpernia- <mpernia-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/16 20:56:51 by mpernia- #+# #+# */
/* Updated: 2020/01/15 21:37:17 by mpernia- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include "libft/libft.h"
int find_specifier(const char *s, int i, t_case *aux)
{
int j;
j = 0;
while (*(s + i + j) && is_specifier(*(s + i + j)) == 0)
++j;
if (is_specifier(*(s + i + j)) == 1)
{
aux->var_type = *(s + i + j);
return (j + 1);
}
return (0);
}
t_case *create_node(void)
{
t_case *aux;
if (!(aux = (t_case*)malloc(sizeof(*aux))))
return (NULL);
aux->next = NULL;
aux->flags = NULL;
aux->var_type = 0;
aux->width = 0;
aux->left_align = 0;
aux->precision = 0;
aux->hex_pref = 0;
aux->plus_sign = 0;
aux->plus_space = 0;
aux->zero_filler = 0;
return (aux);
}
t_case *building_list(const char *s, t_case *head)
{
t_case *aux;
int i;
int j;
i = 0;
aux = head;
while (*(s + i))
{
j = 0;
if (*(s + i) && *(s + i) == '%')
j = find_specifier(s, ++i, aux);
else
{
while (*(s + i + j) && *(s + i + j) != '%')
++j;
}
aux->flags = ft_substr(s, i, j);
i += j;
if (*(s + i))
{
aux->next = create_node();
aux = aux->next;
}
}
return (head);
}
t_case *create_list(const char *s)
{
t_case *head;
if (*s)
{
head = create_node();
return (building_list(s, head));
}
return (0);
}
void free_list(t_case **lst)
{
t_case *next;
while (*lst)
{
next = (*lst)->next;
free((*lst)->flags);
free(*lst);
*lst = NULL;
*lst = next;
}
}