-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.c
86 lines (78 loc) · 2.41 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flags.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmonereo <mmonereo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/12 16:06:02 by mmonereo #+# #+# */
/* Updated: 2021/01/29 09:49:31 by mmonereo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void flags(char *format, t_flags *fstruct)
{
while (ft_strchr("-0", format[fstruct->pos]))
{
if (format[fstruct->pos] == '-')
fstruct->left = 1;
else if (format[fstruct->pos] == '0')
fstruct->is_zero = 1;
fstruct->pos += 1;
}
}
void widthstar(char *format, t_flags *fstruct, va_list ap)
{
int wstar;
if (format[fstruct->pos] == '*')
{
wstar = va_arg(ap, int);
fstruct->width = wstar;
if (wstar < 0)
{
fstruct->left = 1;
fstruct->width = wstar * -1;
}
while (format[fstruct->pos] == '*')
fstruct->pos++;
}
}
void width(char *format, t_flags *fstruct, va_list ap)
{
widthstar(format, fstruct, ap);
if (format[fstruct->pos] >= '0' && format[fstruct->pos] <= '9')
{
fstruct->width = ft_atoi(&format[fstruct->pos]);
}
while (format[fstruct->pos] >= '0' && format[fstruct->pos] <= '9')
{
fstruct->pos++;
}
}
void precstar(char *format, t_flags *fstruct, va_list ap)
{
int pstar;
pstar = va_arg(ap, int);
if (pstar < 0)
fstruct->is_precision = 0;
else if (pstar >= 0)
fstruct->precision = pstar;
if (format[fstruct->pos] == '*')
fstruct->pos++;
}
void precision(char *format, t_flags *fstruct, va_list ap)
{
if (format[fstruct->pos] == '.')
{
fstruct->is_precision = 1;
fstruct->pos++;
if (format[fstruct->pos] >= '0' && format[fstruct->pos] <= '9')
{
fstruct->precision = ft_atoi(&format[fstruct->pos]);
while (format[fstruct->pos] >= '0' && format[fstruct->pos] <= '9')
fstruct->pos++;
}
else if (format[fstruct->pos] == '*')
precstar(format, fstruct, ap);
}
}