-
Notifications
You must be signed in to change notification settings - Fork 0
/
pf_parse_input.c
67 lines (60 loc) · 1.82 KB
/
pf_parse_input.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pf_parse_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gkhodizo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/19 22:12:12 by gkhodizo #+# #+# */
/* Updated: 2020/08/01 18:48:13 by gkhodizo ### ########.fr */
/* */
/* ************************************************************************** */
/*
** The parse_input() parses each char in str.
*/
#include "ft_printf.h"
static int inspect_format(t_fmt *fmt, t_len *pf_len)
{
if (fmt->specifier == '\0')
return (1);
if (fmt->specifier == 'c' && fmt->is_null)
null_char(fmt, pf_len);
else
format_input(fmt, pf_len);
return (0);
}
static int parse_format(char *str, t_fmt *fmt, va_list *ap)
{
int i;
i = 0;
i += parse_flags((str + i), fmt);
i += parse_width((str + i), fmt, ap);
i += parse_precision((str + i), fmt, ap);
i += parse_specifier((str + i), fmt, ap);
return (i);
}
void parse_input(char *str, t_fmt *fmt, t_len *pf_len, va_list *ap)
{
int i;
int j;
i = 0;
while (str[i] != '\0')
{
if (str[i] == '%')
{
++i;
reset_format(fmt);
i += parse_format((str + i), fmt, ap);
if (inspect_format(fmt, pf_len) == 1)
return ;
}
j = 0;
while (str[i] != '%' && str[i] != '\0')
{
++pf_len->print_len;
++j;
++i;
}
ft_putstr_len((str + i - j), j);
}
}