-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_parsing.c
103 lines (97 loc) · 2.74 KB
/
ft_parsing.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rledrin <rledrin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/13 10:15:57 by rledrin #+# #+# */
/* Updated: 2019/11/13 10:15:59 by rledrin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_reset(t_tab *t)
{
t->min_len = 0;
t->minus = 0;
t->zero = 0;
t->precision = -1;
t->type = 0;
t->sign = 0;
t->space = 0;
}
t_tab *ft_flags(t_tab *t, int *i, int *check)
{
char *str;
str = ft_strchr("-0", t->format[*i]);
if (str)
{
if (*str == '-')
t->minus = 1;
else if (*str == '0' && t->format[*i - 1] != '.')
t->zero = 1;
}
if (t->format[*i] == '.')
*check = 1;
if (t->format[*i] > '0' && t->format[*i] <= '9' && t->min_len == 0)
{
while (ft_isdigit(t->format[*i]) && *check == 0)
t->min_len = t->min_len * 10 + t->format[(*i)++] - '0';
*check = 1;
}
if (t->format[*i] == '*' && t->format[(*i) - 1] != '.')
{
t->min_len = va_arg(t->ap, int);
ft_too_much_line(t);
}
return (t);
}
t_tab *ft_prec(t_tab *t, int *i, int *check)
{
if (t->format[*i] > '0' && t->format[*i] <= '9')
{
t->precision = 0;
while (ft_isdigit(t->format[*i]))
{
t->precision = t->precision * 10 + t->format[*i] - '0';
(*i)++;
}
(*i)--;
}
if (*check == 1 && !ft_isdigit(t->format[*i]) && t->format[(*i) - 1] == '.')
t->precision = 0;
if (t->format[*i] == '0' && t->format[(*i) - 1] == '.')
t->precision = 0;
if (t->precision == -1 && t->format[*i])
{
if (t->format[*i] == '.' && t->format[(*i) + 1] == '*')
{
t->precision = va_arg(t->ap, int);
(*i)++;
if (t->precision < -1)
t->precision = -1;
}
}
return (t);
}
void ft_type(t_tab *t, int *i)
{
if (t->format[*i] == 'c')
t->type = 'c';
else if (t->format[*i] == 's')
t->type = 's';
else if (t->format[*i] == 'd' || t->format[*i] == 'i')
t->type = 'd';
else if (t->format[*i] == 'p')
t->type = 'p';
else if (t->format[*i] == 'u')
t->type = 'u';
else if (t->format[*i] == 'x')
t->type = 'x';
else if (t->format[*i] == 'X')
t->type = 'X';
else if (t->format[*i] == '%' && !t->type)
t->type = '%';
else if (t->format[*i] == ' ')
t->space = 1;
}