-
Notifications
You must be signed in to change notification settings - Fork 0
/
printers.c
127 lines (121 loc) · 3.46 KB
/
printers.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asfaihi <asfaihi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/23 16:38:37 by asfaihi #+# #+# */
/* Updated: 2021/01/14 10:57:53 by asfaihi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void pre_space_print(int width, char c, long arg, t_set *group)
{
if ((c == 'x' || c == 'X') && arg)
{
if (group->precision < ft_intsize_hexa(arg))
width -= ft_intsize_hexa(arg);
else
width -= group->precision;
}
else if (c == 'u' && arg < 0 && (group->precision <= ft_intsize(arg + M_UI)))
width -= ft_intsize(arg + M_UI);
else
{
if (group->precision < ft_intsize(arg) && arg)
width -= ft_intsize(arg);
else
width -= group->precision;
}
if ((c == 'd' || c == 'i') && arg < 0 && group->precision >= ft_intsize(arg))
width--;
while (width-- > 0)
ft_putchar_g(' ', group);
}
void zeroes_printer(int i, char c, long arg, t_set *group)
{
if (c == 'c' || c == '%')
i--;
else if (c == 'd' || c == 'i')
i -= ft_intsize(arg);
else if (c == 'x' || c == 'X')
i -= ft_intsize_hexa(arg);
else if (c == 'p')
{
ft_putstr_g("0x", group);
if (i > ft_intsize_hexa_p(arg) && group->pre_toggle)
i -= ft_intsize_hexa_p(arg);
else
i -= ft_intsize_hexa_p(arg) + 2;
}
else if (c == 'u')
{
if (arg >= 0)
i -= ft_intsize(arg);
else
i -= ft_intsize(arg + M_UI);
}
while (i-- > 0)
ft_putchar_g('0', group);
}
void space_printer(int i, char c, long arg, t_set *group)
{
if (c == 'c' || c == '%')
i--;
else if (c == 'd' || c == 'i')
i -= ft_intsize(arg);
else if (c == 'x' || c == 'X')
i -= ft_intsize_hexa(arg);
else if (c == 'p')
i -= ft_intsize_hexa_p(arg) + 2;
else if (c == 'u')
{
if (arg >= 0)
i -= ft_intsize(arg);
else
i -= ft_intsize(arg + M_UI);
}
while (i-- > 0)
ft_putchar_g(' ', group);
}
void specifier_printer(char c, long arg, t_set *group)
{
if (c != '%' && c != 'c' && group->pre_toggle && !group->precision && !arg)
return ;
if (c == 'c')
ft_putchar_g(arg, group);
else if (c == 'd' || c == 'i')
ft_putnbr_g(arg, group);
else if (c == 'u')
{
if (arg > 0 || arg == 0)
ft_putnbr_g(arg, group);
else
ft_putnbr_g(arg + M_UI, group);
}
else if (c == 'p')
{
deci_to_hexa_lower_p(arg, group);
}
else if (c == '%')
ft_putchar_g('%', group);
else if (c == 'x')
deci_to_hexa_lower(arg, group);
else if (c == 'X')
deci_to_hexa_upper(arg, group);
}
void executer(t_set *group, va_list list)
{
if (group->specifier == 'c' || group->specifier == '%')
percent_c(group, list);
else if (group->specifier == 's')
percent_s(group, list);
else if (group->specifier == 'p')
percent_p(group, list);
else if (group->specifier == 'd' || group->specifier == 'i')
percent_d(group, list);
else if (group->specifier == 'X' || group->specifier == 'x' ||
group->specifier == 'u')
percent_u_x(group, list);
}