-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.c
108 lines (100 loc) · 2.42 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
106
107
108
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asyed <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/14 00:55:06 by asyed #+# #+# */
/* Updated: 2017/11/27 15:52:08 by asyed ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void parse_options(char **str, t_options *info, va_list ap)
{
int i;
while (IS_FLAG(**str))
{
i = 0;
while (flags[i].command)
{
if (**str == flags[i].command)
{
flags[i].func(info);
break ;
}
i++;
}
(*str)++;
}
min_width(str, info, ap);
precision(str, info, ap);
l_modifier(str, info, ap);
}
void min_width(char **str, t_options *info, va_list ap)
{
if (**str == '*')
{
info->min_width += va_arg(ap, int);
(*str)++;
}
else if (**str >= '0' && **str <= '9')
{
info->min_width += ft_atoi(*str);
(*str) += s_n_length(info->min_width);
}
}
void precision(char **str, t_options *info, va_list ap)
{
if (**str == '.')
{
(*str)++;
if (**str == '*')
{
info->precision = va_arg(ap, int);
(*str)++;
}
else if (**str >= '0' && **str <= '9')
{
info->precision = ft_atoi(*str);
(*str) += s_n_length(info->precision);
}
info->altform = 0;
}
}
/*
** The length modifier - This is a straight copy from my old code
** Shorten/Norm this bullshit
*/
void setitter(char **str, t_options *info, int num)
{
info->length = num;
(*str)++;
}
void l_modifier(char **str, t_options *info, va_list ap)
{
while (IS_LMOD(**str))
{
if (**str == 'h')
{
(*str)++;
if (**str == 'h')
setitter(str, info, 2);
else
info->length = 1;
}
else if (**str == 'l')
{
(*str)++;
if (**str == 'l')
setitter(str, info, 4);
else
info->length = 3;
}
else if (**str == 'j')
setitter(str, info, 5);
else if (**str == 'z')
setitter(str, info, 6);
}
(void)ap;
}