-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpf_print.c
83 lines (78 loc) · 2.37 KB
/
pf_print.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pf_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mg <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/26 13:32:51 by mg #+# #+# */
/* Updated: 2020/06/21 12:44:01 by mg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void pf_print(va_list *ap, t_fmt *flag)
{
if (flag->spec)
{
pf_convert_specifier(ap, flag);
pf_format_precision(flag);
pf_format_numeric(flag);
pf_format_case(flag);
pf_format_padding_width(flag);
if (flag->spec == 'c' && flag->is_null)
pf_print_null(flag);
else
flag->print_len += ft_putstr(flag->print);
free(flag->print);
if (0)
pf_print_flags_1(flag);
}
else
flag->print_len += ft_putchar('%');
}
void pf_print_null(t_fmt *flag)
{
if (flag->spec == 'c' && flag->is_null)
{
if (flag->left)
{
flag->print_len += ft_putchar(0);
flag->print_len += ft_putstr(flag->print);
}
else
{
flag->print_len += ft_putstr(flag->print);
flag->print_len += ft_putchar(0);
}
}
}
void pf_convert_specifier(va_list *ap, t_fmt *flag)
{
if (flag->spec == '%')
pf_convert_pct(flag);
else if (pf_is_signed_spec(flag->spec, flag))
pf_convert_signed(ap, flag);
else if (pf_is_unsigned_spec(flag->spec, flag))
pf_convert_unsigned(ap, flag);
else if (pf_is_float_spec(flag->spec, flag))
pf_convert_float(ap, flag);
else if (flag->spec == 'c')
pf_convert_char(ap, flag);
else if (flag->spec == 's')
pf_convert_str(ap, flag);
else if (flag->spec == 'p')
pf_convert_pointer(ap, flag);
else if (flag->spec == 'n')
pf_convert_n_count(ap, flag);
}
void pf_format_numeric(t_fmt *flag)
{
if (flag->is_numeric)
{
pf_format_alternate(flag);
pf_format_exponent(flag);
pf_format_padding_zero(flag);
pf_format_space(flag);
pf_format_showsign(flag);
}
}