-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_num_flag.c
78 lines (71 loc) · 2.21 KB
/
ft_printf_num_flag.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_num_flag.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaraval <tmaraval@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/15 07:52:49 by tmaraval #+# #+# */
/* Updated: 2018/01/23 10:54:18 by tmaraval ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_printf_num_sharp_dohexa(t_parsed_opt *opt)
{
char *temp;
temp = opt->str_arg;
ft_printf_precision(opt);
if (ft_printf_flag_strarg_isnega(opt) != 0
|| opt->ch_convert == 'p')
{
temp = opt->str_arg;
opt->str_arg = ft_strjoin("0x", opt->str_arg);
free(temp);
}
}
void ft_printf_num_sharp(t_parsed_opt *opt)
{
char *temp;
if (opt->bin_flag & FLG_SHARP || opt->ch_convert == 'p')
{
if (opt->ch_convert == 'o' || opt->ch_convert == 'O')
{
temp = opt->str_arg;
if (ft_printf_flag_strarg_isnega(opt) != 0)
{
temp = opt->str_arg;
opt->str_arg = ft_strjoin("0", opt->str_arg);
free(temp);
}
ft_printf_precision(opt);
}
if (opt->ch_convert == 'x' || opt->ch_convert == 'X'
|| opt->ch_convert == 'p')
ft_printf_num_sharp_dohexa(opt);
}
}
void ft_printf_num_manage_flag(t_parsed_opt *opt)
{
char *temp;
ft_printf_num_sharp(opt);
if (opt->bin_flag & FLG_SP && ft_strchr("di", opt->ch_convert))
{
if (opt->str_arg[0] != '-')
{
ft_printf_precision(opt);
temp = opt->str_arg;
opt->str_arg = ft_strjoin(" ", opt->str_arg);
free(temp);
}
}
if (opt->bin_flag & FLG_PLUS && ft_strchr("di", opt->ch_convert))
{
if (opt->str_arg[0] != '-')
{
ft_printf_precision(opt);
temp = opt->str_arg;
opt->str_arg = ft_strjoin("+", opt->str_arg);
free(temp);
}
}
}