-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_sizes_x.c
132 lines (122 loc) · 3.55 KB
/
ft_sizes_x.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
128
129
130
131
132
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_sizes_xx.c :+: :+: */
/* +:+ */
/* By: greed <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/18 11:41:55 by greed #+# #+# */
/* Updated: 2019/11/21 13:20:28 by greed ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "libftprintf.h"
void ft_print_ll_x(t_conv *conv, va_list a_list, int *lv)
{
unsigned long long num;
num = va_arg(a_list, unsigned long long);
ft_conv_ll_x(conv, &num);
if (conv->hash && num != 0 && (conv->left || conv->padzero))
ft_putstr_c_fd("0x", 1, 2, lv);
if (conv->left)
{
ft_pad_width(conv->precision, conv->numlen, '0', lv);
if (conv->precision)
ft_x_res_ll_c_fd(num, lv);
}
if (!conv->left && conv->padzero)
ft_pad_width(conv->width, conv->precision + (conv->hash * 2), '0', lv);
else
ft_pad_width(conv->width, conv->precision + (conv->hash * 2), ' ', lv);
if (!conv->left)
{
if (conv->hash && num != 0 && !conv->padzero)
ft_putstr_c_fd("0x", 1, 2, lv);
ft_pad_width(conv->precision, conv->numlen, '0', lv);
if (conv->precision)
ft_x_res_ll_c_fd(num, lv);
}
}
void ft_conv_ll_x(t_conv *conv, unsigned long long *num)
{
if (conv->size == 3)
*num = ((unsigned short)*num);
if (conv->size == 4)
*num = ((unsigned char)*num);
conv->numlen = ft_x_ll_size(*num);
if (conv->precision != -2)
conv->padzero = 0;
if (*num == 0)
conv->hash = 0;
if (conv->precision == -2 ||
(conv->precision < conv->numlen && conv->precision != 0))
conv->precision = conv->numlen;
}
void ft_x_res_ll_c_fd(unsigned long long num, int *lv)
{
unsigned long long res;
unsigned long long power;
char *hex;
hex = "0123456789abcdef";
res = num;
power = 1;
while (res / 16)
{
res /= 16;
power *= 16;
}
res = num;
while (power)
{
ft_putchar_c_fd(hex[num / power], 1, lv);
num %= power;
power /= 16;
}
}
void ft_upx_res_ll_c_fd(unsigned long long num, int *lv)
{
unsigned long long res;
unsigned long long power;
char *hex;
hex = "0123456789ABCDEF";
res = num;
power = 1;
while (res / 16)
{
res /= 16;
power *= 16;
}
res = num;
while (power)
{
ft_putchar_c_fd(hex[num / power], 1, lv);
num %= power;
power /= 16;
}
}
void ft_print_ll_up_x(t_conv *conv, va_list a_list, int *lv)
{
unsigned long long num;
num = va_arg(a_list, unsigned long long);
ft_conv_ll_x(conv, &num);
if (conv->hash && num != 0 && (conv->left || conv->padzero))
ft_putstr_c_fd("0X", 1, 2, lv);
if (conv->left)
{
ft_pad_width(conv->precision, conv->numlen, '0', lv);
if (conv->precision)
ft_upx_res_ll_c_fd(num, lv);
}
if (!conv->left && conv->padzero)
ft_pad_width(conv->width, conv->precision + (conv->hash * 2), '0', lv);
else
ft_pad_width(conv->width, conv->precision + (conv->hash * 2), ' ', lv);
if (!conv->left)
{
if (conv->hash && num != 0 && !conv->padzero)
ft_putstr_c_fd("0X", 1, 2, lv);
ft_pad_width(conv->precision, conv->numlen, '0', lv);
if (conv->precision)
ft_upx_res_ll_c_fd(num, lv);
}
}