-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags2.c
71 lines (64 loc) · 2.08 KB
/
flags2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flags2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smbaabu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 13:03:41 by smbaabu #+# #+# */
/* Updated: 2019/07/14 14:26:05 by smbaabu ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static char *select_prefix(char *s, int specifier, int precision, int base)
{
char *prefix;
prefix = NULL;
if (specifier == P && !(precision != -1 && s[0] == '0' && s[1]))
prefix = "0x";
if (precision != 0 && ft_strcmp(s, "0") != 0)
{
if (base == 8)
prefix = "0";
if (base == 16)
{
if (specifier == X)
prefix = "0x";
if (specifier == XX)
prefix = "0X";
}
}
return (prefix);
}
char *apply_hash(char *s, int specifier, int precision, int base)
{
char *prefix;
char *tmp;
if (specifier == F && precision == 0)
{
tmp = s;
s = ft_strjoin(s, ".");
free(tmp);
}
if (precision == 0 && base == 8)
s = join_and_free(ft_strdup("0"), s);
if (specifier == P && (precision != -1 && s[0] == '0' && s[1]))
s = join_prefix(s, "0x");
if ((prefix = select_prefix(s, specifier, precision, base)))
s = apply_prefix(s, prefix, specifier, precision);
return (s);
}
char *apply_plus(char *s, int specifier, int min_width, int base)
{
int i;
i = 0;
if (base == 10 && (specifier == D || specifier == I || specifier == F)
&& check_neg(s) == -1)
{
if (min_width != -1 && s[0] == '0')
s[0] = '+';
else
s = apply_prefix(s, "+", specifier, -1);
}
return (s);
}