-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_d.c
92 lines (85 loc) · 2.78 KB
/
print_d.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anel-bou <anel-bou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/22 14:28:08 by anel-bou #+# #+# */
/* Updated: 2019/10/23 23:28:44 by anel-bou ### ########.fr */
/* */
/* ************************************************************************** */
#define LARG_M lst.larg_min
#define PRECS lst.precision
#include "ft_printf.h"
int print(t_arg lst, t_var *v)
{
int r;
int cond;
r = 0;
cond = 1;
if (v->n == 0 && lst.precision == -1 && lst.point)
cond = 0;
if (v->signe && !v->f_spc && ++r)
ft_putchar_fd(v->signe, lst.fd);
if (!ft_strchr(lst.option, '-') && (r += v->f_spc))
ft_putnchar_fd(' ', v->f_spc, lst.fd);
if (v->signe && v->f_spc && ++r)
ft_putchar_fd(v->signe, lst.fd);
if (v->f_zr && (r += v->f_zr))
ft_putnchar_fd('0', v->f_zr, lst.fd);
if (cond && (r += my_decilen(v->n)))
my_putnbr_fd(v->n, lst.fd);
if (v->n == 0 && lst.larg_min && lst.point && lst.precision == -1 &&
!ft_strchr(lst.option, '+') && !ft_strchr(lst.option, ' ') && ++r)
ft_putchar_fd(' ', lst.fd);
if (ft_strchr(lst.option, '-') && (r += v->f_spc))
ft_putnchar_fd(' ', v->f_spc, lst.fd);
return (r);
}
void ft_continue(t_var *v, t_arg lst)
{
if (v->signe && LARG_M > PRECS && v->len != v->decilen)
v->len--;
if (v->len != v->decilen)
{
if (LARG_M > PRECS && PRECS > v->decilen)
{
v->f_spc = v->len - PRECS;
v->f_zr = v->len - v->f_spc - v->decilen;
}
else if (LARG_M > PRECS && PRECS < v->len && (!ft_strchr(lst.option,
'0') || (ft_strchr(lst.option, '0') && lst.point)))
{
v->f_spc = LARG_M - v->decilen;
if (v->signe && v->cond)
v->f_spc--;
}
else
v->f_zr = v->len - v->decilen;
}
}
int print_d(long long int nb, t_arg lst)
{
t_var v;
v.signe = 0;
v.f_zr = 0;
v.f_spc = 0;
v.cond = 1;
if (nb >= 0 && ft_strchr(lst.option, '+'))
v.signe = '+';
if (nb >= 0 && ft_strchr(lst.option, ' '))
v.signe = ' ';
if (nb < 0 && (v.signe = '-'))
v.n = -nb;
else
v.n = nb;
if (v.n == 0 && lst.precision == -1 && lst.point)
v.cond = 0;
v.decilen = my_decilen(v.n);
v.len = biggest_n(LARG_M, PRECS, v.decilen);
if (v.len == v.decilen && ft_strchr(lst.option, ' ') && !v.signe)
v.len++;
ft_continue(&v, lst);
return (print(lst, &v));
}