-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_parse.c
More file actions
88 lines (82 loc) · 2.45 KB
/
ft_parse.c
File metadata and controls
88 lines (82 loc) · 2.45 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fdi-cecc <fdi-cecc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/16 16:48:05 by fdi-cecc #+# #+# */
/* Updated: 2024/05/20 16:15:32 by fdi-cecc ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_processflags(t_flags *flag, const char *str, int *i)
{
if (str[1] == '#')
flag->hash = 1;
else if (str[1] == ' ')
flag->space = 1;
else if (str[1] == '+')
flag->plus = 1;
else if (str[1] == '0')
{
flag->zerofill = ft_atoiptr(str + 2, i);
flag->zero = 1;
}
else if (str[1] == '-')
{
flag->left = ft_atoiptr(str + 2, i);
flag->minus = 1;
}
else if (str[1] == '.')
{
flag->precision = ft_atoiptr(str + 2, i);
flag->dot = 1;
}
}
int ft_processfmt(const char *str, va_list *args, t_flags flag)
{
int len;
len = 0;
if (str[1] == 'c')
len += ft_printchar(va_arg (*args, int), flag);
else if (str[1] == 's')
len += ft_printstr(va_arg (*args, char *), flag);
else if (str[1] == 'p')
len += ft_printptr(va_arg(*args, void *), flag);
else if (str[1] == 'd' || str[1] == 'i')
len += ft_printnum(va_arg(*args, int), flag);
else if (str[1] == 'u')
len += ft_printuns(va_arg(*args, unsigned int), flag);
else if (str[1] == 'x')
len += ft_printhex(va_arg(*args, int), 0, flag);
else if (str[1] == 'X')
len += ft_printhex(va_arg(*args, int), 1, flag);
else if (str[1] == '%')
{
ft_putchar('%');
len++;
}
return (len);
}
int ft_parse(const char *str, va_list *args, int *i)
{
int len;
t_flags flag;
len = 0;
ft_initflags(&flag);
while (ft_checkflags(str[*i + 1], "01234567890# +-."))
{
if (ft_checkflags(str[*i + 1], "# +0-."))
ft_processflags(&flag, str + (*i), i);
else
{
flag.width = ft_atoiptr(str + (*i) + 1, i);
(*i)--;
}
(*i)++;
}
len += ft_processfmt(str + (*i), args, flag);
(*i)++;
return (len);
}