-
Notifications
You must be signed in to change notification settings - Fork 0
/
auxiliary.c
101 lines (94 loc) · 2.14 KB
/
auxiliary.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
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* auxiliary.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nrepak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/24 17:17:55 by nrepak #+# #+# */
/* Updated: 2018/02/07 15:17:04 by nrepak ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_conversions(char c)
{
if (c == '%')
return (1);
if (c == 'D' || c == 'd' || c == 'i')
return (2);
if (c == 'C' || c == 'c')
return (3);
if (c == 'S' || c == 's')
return (4);
if (c == 'X' || c == 'x')
return (5);
if (c == 'O' || c == 'o')
return (6);
if (c == 'U' || c == 'u')
return (7);
if (c == 'p')
return (8);
return (0);
}
int ft_plus_space(intmax_t i, t_flags *f)
{
if (f->plus)
{
if (i >= 0)
return (1);
else
return (2);
}
if (f->space)
{
if (i >= 0)
return (3);
else
return (2);
}
if (i < 0)
return (2);
return (0);
}
int ft_is_conversions(const char *str)
{
int i;
i = 0;
while (str[i])
{
while (str[i] == 'h' || str[i] == 'l' || str[i] == 'j' || str[i] == 'z')
i++;
if ((ft_isalpha(str[i]) || str[i] == '%'))
{
if (ft_conversions(str[i]))
return (1);
else
break ;
}
i++;
}
return (0);
}
int ft_is_flags(char c)
{
if (c == '#' || c == '0' || c == '-' || c == ' ' || c == '+')
return (1);
else if (c == 'h' || c == 'l' || c == 'j' || c == 'z')
return (1);
else
return (0);
}
void ft_zero_to_all(t_flags *f)
{
f->slash = 0;
f->minus = 0;
f->plus = 0;
f->space = 0;
f->zero = 0;
f->hh = 0;
f->h = 0;
f->l = 0;
f->ll = 0;
f->j = 0;
f->z = 0;
}