-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_conversions_01.c
123 lines (117 loc) · 3.86 KB
/
ft_printf_conversions_01.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_conversions_01.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmendes- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/18 08:20:06 by tmendes- #+# #+# */
/* Updated: 2020/08/07 08:56:42 by tmendes- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
t_printf format_nbr(t_printf ptf, t_fields fld)
{
if (fld.prec_s)
{
fld.flag[3] += 1;
ptf.txt = pad_str(ptf.txt, fld, fld.prec, 'p');
fld.flag[3] = 0;
}
if (*ptf.end == 'x' || *ptf.end == 'X' || *ptf.end == 'o')
{
if (fld.flag[3])
{
ptf.txt = pad_str(ptf.txt, fld,
(fld.width - ft_strlen(fld.str)), 'w');
fld.str = ft_concat(fld.str, ptf.txt);
}
else
{
fld.str = ft_concat(fld.str, ptf.txt);
fld.str = pad_str(fld.str, fld, fld.width, 'w');
}
free(ptf.txt);
ptf.txt = fld.str;
}
else
ptf.txt = pad_str(ptf.txt, fld, fld.width, 'w');
return (ptf);
}
t_fields fld_process(t_printf ptf, t_fields fld)
{
if (fld.width < 0)
fld.flag[4] += 1;
fld.width = ft_abs(fld.width);
if (fld.prec < 0 || fld.prec_s < 0)
fld.prec_s = 0;
if (*ptf.end == 'd' || *ptf.end == 'i')
if (fld.prec == 0 && (int)fld.llint == 0)
*ptf.txt = 0;
if (*ptf.end == 'x' || *ptf.end == 'X' ||
*ptf.end == 'u' || *ptf.end == 'o')
if (fld.prec == 0 && (int)fld.ullint == 0)
*ptf.txt = 0;
return (fld);
}
t_printf d____type(t_printf ptf, t_fields fld, va_list ap)
{
fld.llint = va_arg(ap, t_llint);
if (fld.len_h == 2)
ptf.txt = ft_llitoa((signed char)fld.llint, 10, 'a');
else if (fld.len_h == 1)
ptf.txt = ft_llitoa((short int)fld.llint, 10, 'a');
else if (fld.len_l == 1)
ptf.txt = ft_llitoa((long int)fld.llint, 10, 'a');
else if (fld.len_l == 2)
ptf.txt = ft_llitoa((long long int)fld.llint, 10, 'a');
else
ptf.txt = ft_llitoa((int)fld.llint, 10, 'a');
fld = fld_process(ptf, fld);
ptf.txt = signal_space(ptf.txt, fld);
ptf = format_nbr(ptf, fld);
return (ptf);
}
t_printf u____type(t_printf ptf, t_fields fld, va_list ap)
{
fld.ullint = va_arg(ap, t_ullint);
if (fld.len_h == 2)
ptf.txt = ft_ullitoa((unsigned char)fld.ullint, 10, 'a');
else if (fld.len_h == 1)
ptf.txt = ft_ullitoa((unsigned short)fld.ullint, 10, 'a');
else if (fld.len_l == 1)
ptf.txt = ft_ullitoa((unsigned long)fld.ullint, 10, 'a');
else if (fld.len_l == 2)
ptf.txt = ft_ullitoa((unsigned long long)fld.ullint, 10, 'a');
else
ptf.txt = ft_ullitoa((unsigned int)fld.ullint, 10, 'a');
fld = fld_process(ptf, fld);
ptf.txt = signal_space(ptf.txt, fld);
ptf = format_nbr(ptf, fld);
return (ptf);
}
t_printf x____type(t_printf ptf, t_fields fld, va_list ap)
{
fld.ullint = va_arg(ap, t_ullint);
if (fld.len_h == 2)
ptf.txt = ft_ullitoa((unsigned char)fld.ullint, 16, *ptf.end);
else if (fld.len_h == 1)
ptf.txt = ft_ullitoa((unsigned short)fld.ullint, 16, *ptf.end);
else if (fld.len_l == 1)
ptf.txt = ft_ullitoa((unsigned long)fld.ullint, 16, *ptf.end);
else if (fld.len_l == 2)
ptf.txt = ft_ullitoa((unsigned long long)fld.ullint, 16, *ptf.end);
else
ptf.txt = ft_ullitoa((unsigned int)fld.ullint, 16, *ptf.end);
if (fld.flag[0] && (int)fld.ullint)
{
fld.str = ft_strdup("0 ");
*(fld.str + 1) = *ptf.end;
}
else
fld.str = ft_strdup("");
fld = fld_process(ptf, fld);
ptf.txt = signal_space(ptf.txt, fld);
ptf = format_nbr(ptf, fld);
return (ptf);
}