-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_attr.c
104 lines (95 loc) · 2.37 KB
/
set_attr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_attr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anttran <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/13 10:29:56 by anttran #+# #+# */
/* Updated: 2019/02/27 19:30:37 by anttran ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static t_attr l(const char *f, t_attr attr, int i, int conv)
{
int s;
int e;
if ((s = hidden_c(f, "hlLzj", i, conv)))
{
e = hidden_c2(f, "hlLzj", i, conv);
attr.lms[0] = f[s];
attr.lms[1] = (e == s + 1) ? f[s] : '\0';
if (e == s + 1)
attr.lms[2] = '\0';
}
if (!s)
attr.lms[0] = '\0';
return (attr);
}
static t_attr p(const char *f, t_attr attr, int i, int conv)
{
if (f[i] == '.')
{
i++;
if (ft_isdigit(f[i]))
attr.prec = ft_atoull(f + i);
else
attr.prec = 0;
while (ft_isdigit(f[i]))
i++;
attr.sp = 1;
}
else
{
attr.prec = 0;
attr.sp = 0;
}
return (l(f, attr, i, conv));
}
static t_attr w(const char *f, t_attr attr, int i, int conv)
{
while (find_c("0#+- ", f[i]))
i++;
if (ft_isdigit(f[i]))
attr.width = ft_atoull(f + i);
else
attr.width = 0;
while (ft_isdigit(f[i]))
i++;
return (p(f, attr, i, conv));
}
static t_attr fl(const char *f, t_attr attr, int i, int conv)
{
int e;
int c;
int tmp;
c = i;
e = i;
while (find_c(" 0-+#", f[c]))
c++;
if (c != i)
{
e = c;
c = 0;
tmp = i - 1;
while (tmp++ < e)
if (f[tmp] != '0')
attr.flags[c++] = f[tmp];
if (hidden_c(f, "0", i, e + 1))
attr.flags[c++] = '0';
}
if (e == i)
attr.flags[0] = '\0';
else
attr.flags[c] = '\0';
return (w(f, attr, i, conv));
}
t_attr set_attr(const char *f, int i)
{
int conv;
t_attr attr;
conv = hidden_c(f, "cspfFdDioOuUxX%", i, ft_strlen(f));
attr.conv[0] = f[conv];
attr.conv[1] = '\0';
return (fl(f, attr, i, conv));
}