-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_setformat.c
67 lines (62 loc) · 1.97 KB
/
ft_setformat.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_setformat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abello-r <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/21 11:36:35 by abello-r #+# #+# */
/* Updated: 2020/02/21 11:36:39 by abello-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_pick2(int nb, t_printf *format)
{
if (*format->str == '.')
{
format->dot = '.';
format->str++;
if (*format->str == '*')
{
format->precision = va_arg(format->argptr, int);
if (format->precision == 0)
format->precision = -1;
}
if (ft_isdigit(*format->str))
format->precision = ft_atoi(format->str);
}
}
void ft_pick(int nb, t_printf *format)
{
if (*format->str == '-')
format->tab = '-';
if (*format->str == '0' && format->width == 0)
format->zero_space = '0';
if (*format->str == '*')
{
nb = va_arg(format->argptr, int);
format->width = (nb < 0) ? (nb * -1) : nb;
if (nb < 0)
format->tab = '-';
}
if (ft_isdigit(*format->str) && *format->str != '0' &&
format->width == 0 && format->dot != '.')
format->width = ft_atoi(format->str);
ft_pick2(nb, format);
}
void ft_setformat(t_printf *format)
{
int nb;
format->width = 0;
format->precision = 0;
format->tab = ' ';
format->zero_space = ' ';
format->dot = ' ';
while (!ft_isalpha(*format->str))
{
++format->str;
ft_pick(nb, format);
if (*format->str == '%')
break ;
}
}