-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_flagparsers.c
84 lines (78 loc) · 2.1 KB
/
ft_flagparsers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_flagparsers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hgoncalv <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/27 02:43:13 by hugogoncalv #+# #+# */
/* Updated: 2021/03/20 02:26:40 by hgoncalv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "libftprintf.h"
int ft_is_flag(char c)
{
if (c == '-' || c == '+' || c == '#' || c == '0' || c == ' '
|| c >= '0' || c <= '9')
return (1);
else
return (0);
}
int ft_is_spec(char c)
{
if (c == 'c' || c == 'd' || c == 'i' || c == 'e' || c == 'E'
|| c == 'f' || c == 'g' || c == 'G' || c == 'o'
|| c == 's' || c == 'u' || c == 'x' || c == 'X'
|| c == 'p' || c == 'n' || c == '%')
return (1);
else
return (0);
}
void ft_flag_parser(char fmt, t_strk *strk)
{
if (fmt == '-')
{
strk->minus = 1;
strk->zero = 0;
}
else if (fmt == '+')
strk->plus = 1;
else if (fmt == ' ')
strk->space = 1;
else if (fmt == '#')
strk->hash = 1;
else if (ft_isdigit(fmt))
{
if (strk->star == 1)
strk->width = 0;
strk->width = (strk->width * 10) + (fmt - '0');
}
}
void ft_flag_width(va_list *args, t_strk *strk)
{
strk->star = 1;
strk->width = va_arg(*args, int);
if (strk->width < 0)
{
strk->minus = 1;
strk->width *= -1;
}
}
char *ft_flag_dot(char *fmt,
t_strk *strk, va_list *args)
{
fmt++;
if (*fmt == '*')
{
strk->dot = va_arg(*args, int);
fmt++;
}
else
{
strk->dot = 0;
while (ft_isdigit(*fmt))
strk->dot = (strk->dot * 10) + (*(fmt++) - '0');
}
return (fmt);
}