-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_x.c
59 lines (54 loc) · 2.25 KB
/
ft_printf_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_x.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bnidia <bnidia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/04 18:07:41 by bnidia #+# #+# */
/* Updated: 2022/05/21 05:22:06 by bnidia ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_fprintf.h"
int ft_print_out(t_pf *z);
void ft_itoa_base(t_pf *z, t_ull nbr, int base, const char *base_);
int for_zero_put_empty_string(t_pf *z, unsigned int nbr);
void reset_insignificant_values(t_pf *z, int signlen);
int output_of_initial_spaces(t_pf *z, int numlen, int signlen);
int output_of_zeros(t_pf *z, int numlen, int signlen);
int output_of_finite_spaces(t_pf *z, int numlen, int signlen);
static void put_prefix(t_pf *z, unsigned int nbr, char base_charset);
int ft_x(t_pf *z, unsigned int nbr, char base_charset)
{
int numlen;
int signlen;
if (for_zero_put_empty_string(z, nbr) <= 0)
return (z->return_value);
signlen = 0;
if (z->f_hash)
signlen += 2;
numlen = (int)ft_numlen((t_ull)ft_abs_d(nbr), 16);
reset_insignificant_values(z, signlen);
if (output_of_initial_spaces(z, numlen, signlen) == -1)
return (-1);
put_prefix(z, nbr, base_charset);
if (output_of_zeros(z, numlen, signlen) == -1)
return (-1);
if (z->f_space)
z->s[z->s_i++] = ' ';
if (base_charset == 'x')
ft_itoa_base(z, nbr, 16, "0123456789abcdef");
else if (base_charset == 'X')
ft_itoa_base(z, nbr, 16, "0123456789ABCDEF");
if (output_of_finite_spaces(z, numlen, signlen) == -1)
return (-1);
return (0);
}
static void put_prefix(t_pf *z, unsigned int nbr, char base_charset)
{
if (z->f_hash && nbr != 0)
{
z->s[z->s_i++] = '0';
z->s[z->s_i++] = base_charset;
}
}