-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printp.c
79 lines (72 loc) · 1.89 KB
/
ft_printp.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printp.c :+: :+: */
/* +:+ */
/* By: novan-ve <novan-ve@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/12/27 16:06:59 by novan-ve #+# #+# */
/* Updated: 2019/12/27 16:07:34 by novan-ve ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_printp3(t_print *p)
{
int i;
i = 0;
if (p->just == 'r' || p->padchar == '0')
ft_putstr_fd("0x", 1);
if (p->just == 'r')
ft_putstr_fd(p->hex, 1);
while (i < (p->tmpwidth - p->tmplen))
{
ft_putchar_fd(p->padchar, 1);
i++;
}
i = 0;
if (p->just == 'l' && p->padchar != '0')
ft_putstr_fd("0x", 1);
while (i < (p->prec - p->tmplen + 2))
{
p->len++;
ft_putchar_fd('0', 1);
i++;
}
if (p->just == 'l')
ft_putstr_fd(p->hex, 1);
}
void ft_printp2(t_print *p)
{
int i;
i = 0;
p->tmplen = 3;
if (p->prec == 0)
p->tmplen = 2;
while (i < p->tmpwidth - p->tmplen)
{
ft_putchar_fd(p->padchar, 1);
i++;
}
i = 0;
if (p->tmplen == 2)
ft_putstr_fd("0x", 1);
else if (p->tmplen == 3)
ft_putstr_fd("0x0", 1);
while (i < p->prec - 1)
{
p->len++;
ft_putchar_fd('0', 1);
i++;
}
}
void ft_printp(t_print *p)
{
int i;
i = 0;
ft_dec_to_hex(p, va_arg(p->args, unsigned long), 0, 13);
p->tmplen += 2;
if (p->hex[0] == '\0')
ft_printp2(p);
else
ft_printp3(p);
}