-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_flags.c
99 lines (93 loc) · 2.46 KB
/
get_flags.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_flags.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: moboustt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 14:46:21 by moboustt #+# #+# */
/* Updated: 2019/12/15 21:29:20 by moboustt ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void if_star(const char *fmt, t_struct *list, va_list ap)
{
if (fmt[list->i] == '*')
{
list->width = va_arg(ap, int);
list->asterisk = 1;
if (list->width < 0)
{
list->minus = 1;
list->width = -(list->width);
}
while (fmt[list->i] == '*')
list->i++;
}
}
void flag(const char *fmt, t_struct *list)
{
while (ft_strchr("-0", fmt[list->i]))
{
if (fmt[list->i] == '-')
list->minus = 1;
else if (fmt[list->i] == '0')
list->zero = 1;
list->i++;
}
}
void width(const char *fmt, t_struct *list, va_list ap)
{
if_star(fmt, list, ap);
if (ft_strchr("0123456789", fmt[list->i]))
{
list->width = ft_atoi(&fmt[list->i]);
while (fmt[list->i] >= 48 && fmt[list->i] <= 57)
{
list->i++;
if (fmt[list->i] == '*')
{
list->asterisk = 1;
if (list->width < 0)
{
list->minus = 1;
list->width = -(list->width);
}
while (fmt[list->i] == '*')
list->i++;
}
}
}
}
void precision(const char *fmt, t_struct *list, va_list ap, int p)
{
if (fmt[list->i] == '.')
{
list->i++;
list->dot = 1;
}
if (fmt[list->i] >= 48 && fmt[list->i] <= 57)
{
list->precision = ft_atoi(&fmt[list->i]);
while (fmt[list->i] >= 48 && fmt[list->i] <= 57)
list->i++;
}
else if (fmt[list->i] == '*')
{
p = va_arg(ap, int);
if (p < 0 && fmt[list->i + 1] == 's')
list->precision = -1;
if (p >= 0)
list->precision = p;
else
list->dot = 0;
while (fmt[list->i] == '*')
list->i++;
}
}
void ft__flag(const char *fmt, t_struct *list, va_list ap, int i)
{
flag(fmt, list);
width(fmt, list, ap);
precision(fmt, list, ap, i);
}