-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_2.c
More file actions
97 lines (91 loc) · 2.27 KB
/
Copy pathparser_2.c
File metadata and controls
97 lines (91 loc) · 2.27 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgilwood <bgilwood@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 03:33:29 by medesmon #+# #+# */
/* Updated: 2019/09/26 20:06:59 by bgilwood ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void parse_width(t_params *p)
{
if (p->format[p->i] == '*')
{
p->width = va_arg(p->ap, int);
if (p->width < 0)
{
p->width *= -1;
p->left = 1;
}
p->i++;
}
if (p->format[p->i] >= '0' && p->format[p->i] <= '9')
p->width = 0;
while (p->format[p->i] >= '0' && p->format[p->i] <= '9')
{
p->width *= 10;
p->width += p->format[p->i] - 48;
p->i++;
}
while (p->format[p->i] == ' ')
p->i++;
}
void parse_pres(t_params *p)
{
if (p->format[p->i] == '.')
{
p->dot = 1;
p->i++;
p->zero = 0;
if (p->format[p->i] == '*')
{
p->pres = va_arg(p->ap, int);
if (p->pres < 0)
{
p->dot = 0;
p->pres = 0;
}
p->i++;
if (p->zero == 0)
p->zero = 1;
}
while (p->format[p->i] >= '0' && p->format[p->i] <= '9')
{
p->pres *= 10;
p->pres += p->format[p->i] - 48;
p->i++;
}
}
}
void parse_percent(t_params *p)
{
if (p->format[p->i] == '%')
{
if (p->left == 0 && p->width != 0)
p->len += apply_width(p->width + 1, 1, 0);
ft_putchar('%');
p->len++;
if (p->left == 1 && p->width != 0)
p->len += apply_width(p->width + 1, 1, 0);
}
}
void parse_modifiers(t_params *p)
{
int counter;
counter = 0;
while (p->format[p->i] == 'h' || p->format[p->i] == 'l'
|| p->format[p->i] == 'L')
{
if (p->format[p->i] == 'h')
counter--;
else if (p->format[p->i] == 'l')
counter++;
else
counter = 3;
p->i++;
}
p->mod = counter;
}