-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.c
105 lines (99 loc) · 2.52 KB
/
parse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbelov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/13 16:36:53 by kbelov #+# #+# */
/* Updated: 2019/10/13 16:37:01 by kbelov ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void parse_flags(t_format *f, const char *restrict format, size_t *i)
{
while (FLAGS(format[*i]))
{
if (format[*i] == '-')
f->minus = 1;
else if (format[*i] == '+')
f->plus = 1;
else if (format[*i] == ' ')
f->space = 1;
else if (format[*i] == '#')
f->hash = 1;
else if (format[*i] == '0')
f->null = 1;
(*i)++;
}
}
void parse_wid(t_format *f, const char *ft, size_t *i, va_list *ap)
{
if (ft[*i] == '*')
{
f->width = va_arg(*ap, int);
i++;
}
else if (ft_isdigit(ft[*i]))
f->width = ft_atoi(&(ft[*i]));
while (ft_isdigit(ft[*i]))
(*i)++;
}
void parse_prec(t_format *f, const char *ft, size_t *i, va_list *ap)
{
if (ft[*i] == '.')
{
(*i)++;
if (ft[*i] == '*')
{
f->precision = va_arg(*ap, int);
(*i)++;
}
else if (ft_isdigit(ft[*i]))
f->precision = ft_atoi(&(ft[*i]));
else
f->precision = 0;
while (ft_isdigit(ft[*i]))
(*i)++;
}
}
void parse_length(t_format *f, const char *format, size_t *i)
{
if (format[*i] == 'h')
{
if (format[*i + 1] == 'h')
f->length = 2;
else
f->length = 1;
}
else if (format[*i] == 'l')
{
if (format[*i + 1] == 'l')
f->length = 4;
else
f->length = 3;
}
else if (format[*i] == 'L')
f->length = 5;
else if (format[*i] == 'j')
f->length = 7;
else if (format[*i] == 'z')
f->length = 9;
if ((f->length % 2 == 1) && f->length)
(*i)++;
if ((f->length % 2 == 0) && f->length)
(*i) += 2;
}
void parse_type(t_format *f, const char *format, size_t *i)
{
if (TYPE1(format[*i]) || TYPE2(format[*i]) || TYPE3(format[*i]))
{
f->specifier = format[*i];
(*i)++;
}
else if (format[*i] == 'U')
{
f->specifier = 'u';
(*i)++;
}
}