-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags_func.c
54 lines (50 loc) · 1.57 KB
/
flags_func.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flags_func.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achane-l <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/14 12:04:24 by achane-l #+# #+# */
/* Updated: 2021/07/14 12:04:28 by achane-l ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void initialize_flags(t_flags *flags)
{
flags->zero = 0;
flags->minus = 0;
flags->width = 0;
flags->precision = -1;
flags->space = 0;
flags->sharp = 0;
flags->number_sign = 0;
}
void append_flags(t_flags *flags, char c)
{
if (c == '0' && flags->minus == 0)
flags->zero++;
else if (c == '-')
{
flags->minus++;
if (flags->zero > 0)
flags->zero = 0;
}
else if (c == '+')
flags->number_sign++;
else if (c == ' ')
flags->space++;
else if (c == '#')
flags->sharp++;
}
void change_state_flags(t_flags *flags)
{
if (flags->precision >= 0)
flags->zero = 0;
if (flags->width < 0)
{
flags->zero = 0;
flags->minus += 1;
flags->width = -(flags->width);
}
}