-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_u.c
96 lines (88 loc) · 2.97 KB
/
type_u.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_u.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/25 11:33:25 by nahmed-m #+# #+# */
/* Updated: 2016/02/01 14:11:13 by nahmed-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void ft_putnbr_u(unsigned long value)
{
if (value >= 10)
ft_putnbr_u(value / 10);
ft_putchar(value % 10 + '0');
}
static void ft_putstr_left(t_var *e, unsigned long value)
{
if (e->f_precis != 1 && e->f_width < e->f_precis)
ft_put_zero(e->f_precis - e->t_size, e);
else if (e->f_precis != 1 && e->f_width > e->f_precis)
ft_put_zero(e->f_precis - e->t_size, e);
ft_putnbr_u(value);
if (e->f_left == 1 && e->f_width != 0 && e->f_width > e->t_size && \
e->f_precis == 1)
ft_put_space(e->f_width - e->t_size, e);
else if (e->f_left == 1 && e->f_width != 0 && e->f_width > e->t_size && \
e->f_precis != 1)
ft_put_space(e->f_width - e->f_precis, e);
}
static void ft_putstr_right(t_var *e, unsigned long value)
{
if (e->f_zero == 0 && e->f_precis == 1)
ft_put_space(e->f_width - e->t_size, e);
else if (e->f_precis != 1 && e->f_width > e->f_precis && e->f_precis >\
e->t_size)
ft_put_space(e->f_width - e->f_precis, e);
else if (e->f_precis != 1 && e->f_width > e->f_precis && e->f_precis <\
e->t_size)
ft_put_space(e->f_width - e->t_size, e);
if (e->f_zero == 1 && e->f_precis == 1)
ft_put_zero(e->f_width - e->t_size, e);
else if (e->f_precis != 1 && e->f_precis > e->t_size)
ft_put_zero(e->f_precis - e->t_size, e);
ft_putnbr_u(value);
}
static int len_d(unsigned long value, t_var *e)
{
int i;
i = 0;
if (value == 0)
{
e->ret++;
return (1);
}
while (value != 0)
{
i++;
value /= 10;
}
e->ret += i;
return (i);
}
void type_u(t_var *e)
{
unsigned long value;
if (e->f_hh == 1 && e->u_exep == 0)
value = (unsigned char)va_arg(e->ap, unsigned int);
else if (e->f_h == 0 && e->f_hh == 0 && e->f_ll == 0 && e->f_l == 0 && \
e->f_j == 0 && e->f_z == 0 && e->u_exep == 0)
value = va_arg(e->ap, unsigned int);
else
value = va_arg(e->ap, unsigned long);
if (e->f_precis == 0 && value == 0)
{
ft_put_space(e->f_width, e);
return ;
}
e->t_size = len_d(value, e);
if (e->error == 1)
return ;
if (e->f_left == 0 && e->f_width != 0 && e->f_width > e->t_size)
ft_putstr_right(e, value);
else
ft_putstr_left(e, value);
}