-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_conversion.c
85 lines (81 loc) · 2.21 KB
/
ft_printf_conversion.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_conversion.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfrisby <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/11 13:11:30 by mfrisby #+# #+# */
/* Updated: 2017/07/12 14:10:01 by mfrisby ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
static void ft_printf_conversion3(t_env *e, char c)
{
e->field_width--;
if (e->flag_moins == 1)
{
ft_printf_buffer_flush(e);
if (e->family == 0)
ft_putchar(c);
else if (e->family == 1)
ft_putchar_fd(c, e->fd);
else if (e->family == 2)
fwrite(&c, sizeof(char), 1, e->file);
e->size++;
ft_printf_putflags(e, ft_strdup(""));
e->i++;
}
else
ft_printf_putflags(e, ft_strdup(""));
}
static int ft_printf_conversion2(t_env *e, char c)
{
if (c == 'o')
ft_printf_o(e);
else if (c == 'O')
ft_printf_omaj(e);
else if (c == 'x')
ft_printf_x(e);
else if (c == 'X')
ft_printf_xmaj(e);
else if (c == 'c')
ft_printf_c(e);
else if (c == 'C')
ft_printf_cmaj(e);
else if (c == 'd' || c == 'i')
ft_printf_di(e);
else if (c == 'D')
ft_printf_dmaj(e);
else if (c == 'b')
ft_printf_b(e);
else
return (-1);
e->type = c;
return (1);
}
int ft_printf_conversion(t_env *e, char c)
{
if (e->flag_moins == 1 && e->flag_zero == 1)
e->flag_zero = 0;
if (ft_printf_conversion2(e, c) == 1)
return (0);
if (c == 'u')
ft_printf_u(e);
else if (c == 'U')
ft_printf_umaj(e);
else if (c == 's')
ft_printf_s(e);
else if (c == 'S')
ft_printf_smaj(e);
else if (c == 'p')
ft_printf_p(e);
else if (c == '%')
ft_printf_modulo(e);
else
{
ft_printf_conversion3(e, c);
return (-1);
}
return (0);
}