-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_padding_numbnull.c
76 lines (69 loc) · 2.33 KB
/
ft_padding_numbnull.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_padding_numbnull.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/02 16:12:57 by jraymond #+# #+# */
/* Updated: 2018/02/14 17:43:48 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_padding_numbnull(t_printf *elem, t_nbcaddpw *nbca)
{
char sp;
char more;
sp = ' ';
more = '+';
if (elem->flags & PRECI && !(elem->precision) && elem->width)
nbca->width++;
if (elem->flags & MINUS)
{
ft_handle_overflow(elem, &sp, nbca->width, 1);
if (elem->flags & MORE)
ft_handle_overflow(elem, &more, 1, 1);
}
else
{
if (elem->flags & MORE)
ft_handle_overflow(elem, &more, 1, 1);
ft_handle_overflow(elem, &sp, nbca->width, 1);
}
}
void nb_c_addoctnull_pw(t_nbcaddpw *nbca, t_printf *elem)
{
int i;
ft_bzero(nbca, sizeof(t_nbcaddpw));
if (elem->flags & PRECI && elem->flags & SHARP)
nbca->preci = (0 >= elem->precision) ? 1 : elem->precision;
else if (elem->flags & PRECI && !(elem->flags & SHARP))
nbca->preci = (0 >= elem->precision) ? 0 : elem->precision;
else if (!(elem->flags & PRECI))
nbca->preci = 1;
i = nbca->preci;
if (elem->width)
nbca->width = elem->width <= i ? 0 : (elem->width - i);
}
int ft_paddoct_null(t_printf *elem, t_nbcaddpw *nbca)
{
char sp;
char zero;
sp = ' ';
zero = '0';
nb_c_addoctnull_pw(nbca, elem);
if (elem->flags & ZERO || !(elem->flags & MINUS))
{
if (!(elem->flags & ZERO))
ft_handle_overflow(elem, &sp, nbca->width, 1);
else
ft_handle_overflow(elem, &zero, nbca->width, 1);
ft_handle_overflow(elem, &zero, nbca->preci, 1);
}
else
{
ft_handle_overflow(elem, &zero, nbca->preci, 1);
ft_handle_overflow(elem, &sp, nbca->width, 1);
}
return (0);
}