-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_action_dp.c
118 lines (107 loc) · 3.51 KB
/
ft_action_dp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_action_dp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edelangh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/12/29 15:45:06 by edelangh #+# #+# */
/* Updated: 2015/01/23 11:00:50 by edelangh ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_get_value_ou(va_list ap, t_printf *info)
{
size_t i;
size_t j;
j = 0;
i = 0;
if (info->l == 2 && ((i = va_arg(ap, unsigned long long)) || 1))
info->value = ft_zutoa(i);
else if (info->l == 1 && ((i = va_arg(ap, unsigned long int)) || 1))
info->value = ft_zutoa(i);
else if (info->h == 2 && ((i = (unsigned char)va_arg(ap, int)) || 1))
info->value = ft_itoa(i);
else if (info->h == 1 && ((i = (unsigned short)va_arg(ap, int)) || 1))
info->value = ft_itoa(i);
else if (info->j == 1 && ((i = va_arg(ap, uintmax_t)) || 1))
info->value = ft_zutoa(i);
else if (info->z == 1 && ((i = va_arg(ap, size_t)) || 1))
info->value = ft_zutoa(i);
else
return (2);
return ((i != 0 || j != 0 ? 1 : 0));
}
int ft_get_value_d(va_list ap, t_printf *info)
{
long long i;
size_t j;
j = 0;
i = 0;
if (info->l == 2 && ((i = va_arg(ap, long long int)) || 1))
info->value = ft_lltoa(i);
else if (info->l == 1 && ((i = va_arg(ap, long int)) || 1))
info->value = ft_lltoa(i);
else if (info->h == 2 && ((i = (signed char)va_arg(ap, int)) || 1))
info->value = ft_itoa(i);
else if (info->h == 1 && ((i = (short)va_arg(ap, int)) || 1))
info->value = ft_itoa(i);
else if (info->j == 1 && ((i = va_arg(ap, intmax_t)) || 1))
info->value = ft_lltoa(i);
else if (info->z == 1 && ((i = va_arg(ap, long long)) || 1))
info->value = ft_lltoa(i);
else if ((i = va_arg(ap, int)) || 1)
info->value = ft_itoa(i);
return ((i != 0 || j != 0 ? 1 : 0));
}
int ft_action_p(char *f, int lenud, va_list ap)
{
t_printf info;
int len;
size_t nbr;
char *tmp;
info.type = 'p';
init_info(&info, f, lenud, ap);
nbr = va_arg(ap, size_t);
tmp = ft_zutoa(nbr);
info.value = ft_convert_base(tmp, "0123456789", "0123456789abcdef");
free(tmp);
len = ft_strlen(info.value);
info.add = '\0';
ft_print_d(info, len, nbr, "0x");
free(info.value);
return (len);
}
int ft_action_d(char *f, int lenud, va_list ap, char type)
{
t_printf info;
int len;
int nbr;
info.type = type;
init_info(&info, f, lenud, ap);
nbr = ft_get_value_d(ap, &info);
len = ft_strlen(info.value);
ft_print_d(info, len, nbr != 0,
(info.spad = ft_strjoinnchar(NULL, 1, info.add)));
free(info.value);
free(info.spad);
return (len);
}
int ft_action_zu(char *f, int lenud, va_list ap, char type)
{
t_printf info;
int len;
size_t nbr;
info.type = type;
init_info(&info, f, lenud, ap);
nbr = va_arg(ap, size_t);
info.value = ft_zutoa((size_t)nbr);
len = ft_strlen(info.value);
if (type == 'U')
info.add = '\0';
ft_print_d(info, len, nbr != 0,
(info.spad = ft_strjoinnchar(NULL, 1, info.add)));
free(info.value);
free(info.spad);
return (len);
}