-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_o.c
80 lines (73 loc) · 2.34 KB
/
type_o.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_o.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdegraev <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 12:12:03 by qdegraev #+# #+# */
/* Updated: 2016/02/18 13:41:55 by qdegraev ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *type_o_std(unsigned long long d, t_arg *a)
{
char *s;
s = a->p == 0 && d == 0 ? ft_strnew(0) : ft_utoa_base(d, 8);
a->ret = ft_strlen(s);
while (a->ret < a->p)
{
s = ft_cjoin(ft_strdup("0"), s);
a->ret++;
}
a->ret += a->f_h && s[0] != 0 ? 1 : 0;
a->f_h && s[0] != '0' ? s = ft_cjoin(ft_strdup("0"), s) : 0;
while (a->ret < a->l)
{
s = a->f_m ? ft_cjoin(s, ft_strdup(" ")) : ft_cjoin(ft_strdup(" "), s);
a->ret++;
}
return (s);
}
char *type_o_zero(unsigned long long d, t_arg *a)
{
char *s;
s = a->p == 0 && d == 0 ? ft_strnew(0) : ft_utoa_base(d, 8);
a->ret = ft_strlen(s);
if (a->p != 1)
while (a->ret++ < a->p)
s = ft_cjoin(ft_strdup("0"), s);
else
while (a->ret++ < a->l)
s = ft_cjoin(ft_strdup("0"), s);
a->ret += a->f_h && s[0] != '0' ? 1 : 0;
a->f_h && s[0] != '0' ? s = ft_cjoin(ft_strdup("0"), s) : 0;
while (a->ret <= a->l)
{
s = a->f_m ? ft_cjoin(s, ft_strdup(" ")) : ft_cjoin(ft_strdup(" "), s);
a->ret++;
}
return (s);
}
void type_o(char type, t_arg *a)
{
unsigned long long d;
char *s;
d = va_arg(a->ap, unsigned long long);
if (a->m_l || type == 'O')
d = (unsigned long)d;
else if (a->m_h)
d = (unsigned short int)d;
else if (a->m_hh)
d = (unsigned char)d;
else if (a->m_j)
d = (uintmax_t)d;
else if (a->m_z)
d = (size_t)d;
else if (!a->m_ll)
d = (unsigned int)d;
s = a->f_zero && !a->f_m ? type_o_zero(d, a) : type_o_std(d, a);
a->ret = ft_strlen(s);
ft_putstr(s);
ft_strdel(&s);
}