-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_d2.c
106 lines (97 loc) · 3.86 KB
/
ft_printf_d2.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
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_printf_d2.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: bpajot <[email protected]> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/02/09 16:47:41 by bpajot #+# ## ## #+# */
/* Updated: 2018/02/19 11:45:06 by bpajot ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_printf_ld(t_field *cur, va_list *va)
{
long int ld;
ld = va_arg(*va, long int);
cur->l = (cur->preci == 0 && ld == 0) ? 0 : ft_nbr_long_size(ld);
ft_printf_d_flag(cur);
if (((cur->flag & PLUS) || (cur->flag & SPACE)) && ld >= 0)
{
cur->plus = (cur->flag & PLUS) ? 1 : 2;
cur->l++;
}
cur->minus = (ld < 0) ? 1 : 0;
cur->pos_long = (ld < 0 && ld != LONG_MIN) ? -ld : ld;
if (cur->preci > ft_nbr_long_size(ld) - cur->minus)
cur->zero = cur->preci - ft_nbr_long_size(ld) + cur->minus;
ft_printf_d_space(cur);
if (cur->preci != 0 || ld != 0)
cur->ret += (ld == LONG_MIN) ? ft_putstr_size("9223372036854775808") :
ft_putnbr_long_size(cur->pos_long);
cur->ret += ft_putchar_sizel(' ', cur->spc_aft);
}
void ft_printf_lld(t_field *cur, va_list *va)
{
long long int lld;
lld = va_arg(*va, long long int);
cur->l = (cur->preci == 0 && lld == 0) ? 0 : ft_nbr_long_size(lld);
ft_printf_d_flag(cur);
if (((cur->flag & PLUS) || (cur->flag & SPACE)) && lld >= 0)
{
cur->plus = (cur->flag & PLUS) ? 1 : 2;
cur->l++;
}
cur->minus = (lld < 0) ? 1 : 0;
cur->pos_long = (lld < 0 && lld != LLONG_MIN) ? -lld : lld;
if (cur->preci > ft_nbr_long_size(lld) - cur->minus)
cur->zero = cur->preci - ft_nbr_long_size(lld) + cur->minus;
ft_printf_d_space(cur);
if (cur->preci != 0 || lld != 0)
cur->ret += (lld == LLONG_MIN) ? ft_putstr_size("9223372036854775808") :
ft_putnbr_long_size(cur->pos_long);
cur->ret += ft_putchar_sizel(' ', cur->spc_aft);
}
void ft_printf_jd(t_field *cur, va_list *va)
{
intmax_t jd;
jd = va_arg(*va, intmax_t);
cur->l = (cur->preci == 0 && jd == 0) ? 0 : ft_nbr_long_size(jd);
ft_printf_d_flag(cur);
if (((cur->flag & PLUS) || (cur->flag & SPACE)) && jd >= 0)
{
cur->plus = (cur->flag & PLUS) ? 1 : 2;
cur->l++;
}
cur->minus = (jd < 0) ? 1 : 0;
cur->pos_long = (jd < 0 && jd != INTMAX_MIN) ? -jd : jd;
if (cur->preci > ft_nbr_long_size(jd) - cur->minus)
cur->zero = cur->preci - ft_nbr_long_size(jd) + cur->minus;
ft_printf_d_space(cur);
if (cur->preci != 0 || jd != 0)
cur->ret += (jd == INTMAX_MIN) ? ft_putstr_size("9223372036854775808") :
ft_putnbr_long_size(cur->pos_long);
cur->ret += ft_putchar_sizel(' ', cur->spc_aft);
}
void ft_printf_zd(t_field *cur, va_list *va)
{
ssize_t zd;
zd = va_arg(*va, ssize_t);
cur->l = (cur->preci == 0 && zd == 0) ? 0 : ft_nbr_long_size(zd);
ft_printf_d_flag(cur);
if (((cur->flag & PLUS) || (cur->flag & SPACE)) && zd >= 0)
{
cur->plus = (cur->flag & PLUS) ? 1 : 2;
cur->l++;
}
cur->minus = (zd < 0) ? 1 : 0;
if (cur->preci > ft_nbr_long_size(zd) - cur->minus)
cur->zero = cur->preci - ft_nbr_long_size(zd) + cur->minus;
ft_printf_d_space(cur);
cur->pos_long = (zd < 0 && zd != LLONG_MIN) ? -zd : zd;
if (cur->preci != 0 || zd != 0)
cur->ret += (zd == LLONG_MIN) ? ft_putstr_size("9223372036854775808") :
ft_putnbr_long_size(cur->pos_long);
cur->ret += ft_putchar_sizel(' ', cur->spc_aft);
}