-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_elements.c
More file actions
79 lines (74 loc) · 2.15 KB
/
check_elements.c
File metadata and controls
79 lines (74 loc) · 2.15 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_elements.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wphylici <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/18 01:18:13 by wphylici #+# #+# */
/* Updated: 2020/07/27 13:39:02 by wphylici ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_printf.h"
void check_flags(const char **str, t_printf *elements)
{
if (**str == ' ')
{
elements->length += write(1, " ", 1);
(*str)++;
}
if (**str == '0' || **str == '-')
{
elements->flags = **str;
(*str)++;
if (**str == '-')
elements->flags = '-';
}
while (**str == '0' || **str == '-')
(*str)++;
}
void check_width(const char **str, t_printf *elements, va_list argsptr)
{
if (**str == '*')
{
elements->width = va_arg(argsptr, int);
(*str)++;
}
while (**str >= '0' && **str <= '9')
{
elements->width = elements->width * 10 + **str - '0';
(*str)++;
}
}
void check_precision(const char **str, t_printf *elements, va_list argsptr)
{
if (**str == '.')
{
(*str)++;
if (**str > '9')
elements->indicator_precision = 1;
while (**str >= '0' && **str <= '9')
{
elements->precision = elements->precision * 10 + **str - '0';
(*str)++;
}
if (**str == '*')
{
if ((elements->precision = va_arg(argsptr, int)) == 0)
elements->indicator_precision = 1;
(*str)++;
}
if (elements->precision == 0)
elements->indicator_precision = 1;
}
else
elements->indicator_precision = -1;
}
void check_type(const char **str, t_printf *elements)
{
if (ft_strchr("cspdiuxX%%", **str))
{
elements->type = **str;
(*str)++;
}
}