-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_putint_signed.c
51 lines (47 loc) · 2.17 KB
/
ft_printf_putint_signed.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_putint_signed.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnakano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/11 08:57:15 by dnakano #+# #+# */
/* Updated: 2020/10/18 14:25:22 by dnakano ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdarg.h>
#include "libftprintf.h"
static t_llong ft_printf_putsignedint_storenbr(va_list *ap,
t_printf_flags *flags)
{
if (flags->flag & FLAG_LONGLONG)
return (va_arg(*ap, t_llong));
else if (flags->flag & FLAG_LONG)
return (va_arg(*ap, long));
else if (flags->flag & FLAG_SHORTSHORT)
return ((char)va_arg(*ap, int));
else if (flags->flag & FLAG_SHORT)
return ((short)va_arg(*ap, int));
return (va_arg(*ap, int));
}
int ft_printf_putsignedint(va_list *ap, t_printf_flags *flags)
{
t_llong nbr;
int nbrwidth;
const t_uint radix = 10;
nbr = ft_printf_putsignedint_storenbr(ap, flags);
nbrwidth = ft_printf_putnbr_width_digit(nbr, radix, flags);
if (flags->precision >= 0)
flags->flag = flags->flag & ~FLAG_ZEROPADDING;
if (flags->flag & FLAG_ZEROPADDING)
ft_printf_putsign(nbr < 0, flags);
if (nbrwidth < flags->width && !(flags->flag & FLAG_LEFTADJUST))
ft_printf_putpadding(flags->width - nbrwidth, flags);
if (!(flags->flag & FLAG_ZEROPADDING))
ft_printf_putsign(nbr < 0, flags);
if (!(nbr == 0 && flags->precision == 0))
ft_printf_putnbr_base_digit(nbr, radix, flags->precision, 0);
if (nbrwidth < flags->width && (flags->flag & FLAG_LEFTADJUST))
ft_printf_putpadding(flags->width - nbrwidth, flags);
return (nbrwidth < flags->width ? flags->width : nbrwidth);
}