-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_flag_set.c
More file actions
64 lines (59 loc) · 2.16 KB
/
ft_flag_set.c
File metadata and controls
64 lines (59 loc) · 2.16 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_flag_set.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sushin <sushin@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/13 00:18:05 by sushin #+# #+# */
/* Updated: 2021/01/15 08:58:07 by ssb ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_type_check(int c, t_flag *flags)
{
if (c == 'c' || c == 's' || c == 'd' || c == 'i'
|| c == 'x' || c == 'X' || c == 'u' || c =='p' || c =='%')
{
flags->type = c;
return (1);
}
return (0);
}
int ft_flag_precision(const char *bowl, int i, t_flag *flags, va_list ap)
{
if (bowl[i] == '*')
flags->precision = va_arg(ap, int);
else
{
flags->precision = 0;
while (ft_isdigit(bowl[i]))
{
flags->precision = (flags->precision * 10) + (bowl[i] - '0');
i++;
}
}
return (i);
}
int ft_flag_set(const char *bowl, int i, va_list ap, t_flag *flags)
{
while (bowl[++i])
{
if (bowl[i] == '0' && flags->minus == 0 && flags->width == 0)
flags->zero = 1;
else if (bowl[i] == '-')
{
flags->minus = 1;
flags->zero = 0;
}
else if (bowl[i] == '*')
ft_flag_width_star(ap, flags);
else if (ft_isdigit(bowl[i]))
flags->width = (flags->width * 10) + (bowl[i] - '0');
else if (bowl[i] == '.')
i = ft_flag_precision(bowl, ++i, flags, ap);
if (ft_type_check(bowl[i], flags))
break ;
}
return (i);
}