-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_di.c
70 lines (67 loc) · 2.48 KB
/
type_di.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_di.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvarodi <vvarodi@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/17 17:22:50 by vvarodi #+# #+# */
/* Updated: 2020/08/19 10:02:39 by vvarodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *type_di2(t_buffer *b, t_flags *f, int num, char *str)
{
if (num < 0 && f->b_zero_padding == 0)
add_to_buffer(b, f, '-');
while (f->zeros-- > 0)
{
if (f->negative == 1 && f->b_zero_padding == 1 && f->b_only_once == 0)
{
add_to_buffer(b, f, '-');
f->b_only_once = 1;
}
add_to_buffer(b, f, '0');
}
if (f->b_preci == 2 && f->precision == 0 && num == 0)
(f->width != 0) ? (b->buffer[b->buff_i] = ' ') :
(b->buffer[b->buff_i] = '\0');
else
{
if (f->negative == 1 && f->b_zero_padding == 1 && f->b_only_once == 0)
add_to_buffer(b, f, '-');
ft_putnbr(b, f, num);
}
if (f->b_left_aligned)
while (f->width > 0)
add_to_buffer(b, f, ' ');
return (str);
}
char *type_di1(t_buffer *b, t_flags *f, int num, char *str)
{
f->negative = (num < 0) ? 1 : 0;
f->b_num_zero = (num == 0) ? 1 : 0;
f->to_write = ft_putnbr_len(b, f, num) + f->negative;
if (f->b_left_aligned == 1 && f->b_zero_padding == 1)
f->b_zero_padding = 0;
if ((f->b_preci == 1 || f->b_preci == 2) && f->precision >= f->to_write)
f->zeros = f->precision - f->to_write + f->negative;
else if (f->b_preci == 2 && f->precision == 0 && num == 0)
f->to_write = 0;
if (!f->b_left_aligned)
f->width = f->width - f->to_write - f->zeros;
if (f->b_zero_padding == 1 && !f->b_left_aligned && f->b_preci == 0)
{
if (f->negative == 1 && f->b_zero_padding == 1 && f->b_only_once == 0)
{
b->buffer[b->buff_i++] = '-';
f->b_only_once = 1;
}
while (f->width > 0)
add_to_buffer(b, f, '0');
}
else if (!f->b_left_aligned)
while (f->width > 0)
add_to_buffer(b, f, ' ');
return (type_di2(b, f, num, str));
}