-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_flag.c
71 lines (67 loc) · 2.11 KB
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_flag.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fulloa-s <fulloa-s@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/09 12:09:14 by fulloa-s #+# #+# */
/* Updated: 2021/02/09 14:00:33 by fulloa-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_checkflagfin(t_list *list, int i)
{
if (list->flag_zero == 1 && list->flag_minus == 1)
list->flag_zero = 0;
if (list->width < 0)
{
list->flag_minus = 1;
list->width *= -1;
}
return (i);
}
int ft_checkflag1(const char *input, int i, t_list *list, va_list args)
{
if (input[i] == '-')
list->flag_minus = 1;
else if (input[i] == '0')
list->flag_zero = 1;
else if (input[i] > '0' && input[i] <= '9')
{
list->width = ft_atoi((char *)input + i);
while (input[i + 1] >= '0' && input[i + 1] <= '9')
i++;
}
else if (input[i] == '*')
list->width = va_arg(args, int);
return (i);
}
int ft_checkflag(const char *input, int i, t_list *list, va_list args)
{
while (input[i] == '-' || input[i] == '0' || input[i] == '*' ||
(input[i] > '0' && input[i] <= '9') || input[i] == '.')
{
i = ft_checkflag1(input, i, list, args);
if (input[i] == '.')
{
list->dot = 1;
i++;
if (input[i] == '*')
list->precision = va_arg(args, int);
else if (input[i] >= '0' && input[i] <= '9')
{
list->precision = ft_atoi((char *)input + i);
while (input[i + 1] >= '0' && input[i + 1] <= '9')
i++;
}
else
{
list->dot = 2;
break ;
}
}
i++;
}
return (ft_checkflagfin(list, i));
}