-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_util_gen.c
75 lines (69 loc) · 2.29 KB
/
ft_util_gen.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_util_gen.c :+: :+: */
/* +:+ */
/* By: averheij <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/14 12:57:42 by averheij #+# #+# */
/* Updated: 2019/11/22 11:35:40 by averheij ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include "libft.h"
void ft_do_conv(const char **format, va_list a_list, t_conv *conv, int *n)
{
ft_init_conv_vars(conv);
ft_set_conv_vars(format, conv);
if (conv->type)
{
if (conv->width == -1)
conv->width = va_arg(a_list, int);
if (conv->precision == -1)
conv->precision = va_arg(a_list, int);
ft_call_converter(conv, a_list, n);
}
}
void ft_init_conv_vars(t_conv *conv)
{
conv->hash = 0;
conv->leftj = 0;
conv->padzero = 0;
conv->precision = -2;
conv->width = 0;
conv->sign = 0;
conv->hassign = 0;
conv->size = 0;
conv->length = 0;
}
int ft_spotter(const char **format, t_conv *conv)
{
if (!*(*format + 1))
{
conv->type = 0;
return (1);
}
return (0);
}
void ft_identify_size_flag(const char **format, t_conv *conv)
{
if (**format == 'l' && *(*format + 1) == 'l')
conv->size = 'L';
else if (**format == 'h' && *(*format + 1) == 'h')
conv->size = 'H';
else if (**format == 'l' || **format == 'h')
conv->size = **format;
}
void ft_find_flag_end(const char **format, t_conv *conv)
{
if (**format == 'l' && *(*format + 1) == 'l')
*format = *format + 1;
else if (**format == 'h' && *(*format + 1) == 'h')
*format = *format + 1;
else if (**format == '.' &&
(*(*format + 1) == '*' || ft_isdigit(*(*format + 1))))
*format = *format + 1;
if (conv->precision != -2 || conv->width != 0)
while (ft_isdigit(*(*format)) && ft_isdigit(*(*format + 1)))
*format = *format + 1;
}