-
Notifications
You must be signed in to change notification settings - Fork 0
/
pf_convert_alpha.c
62 lines (56 loc) · 1.7 KB
/
pf_convert_alpha.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pf_convert_alpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mg <mg@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/02 16:15:04 by mg #+# #+# */
/* Updated: 2020/06/28 00:40:46 by mg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void pf_convert_char(va_list *ap, t_fmt *flag)
{
char chr;
if (flag->spec == 'c')
{
flag->print = ft_strnew(1);
chr = (char)va_arg(*ap, int);
if (chr == 0)
{
flag->is_null = 1;
if (flag->width > 0)
--flag->width;
}
else
*flag->print = chr;
}
}
void pf_convert_str(va_list *ap, t_fmt *flag)
{
char *ptr;
if (flag->spec == 's')
{
flag->print = ft_strnew(0);
ptr = va_arg(*ap, char *);
if (!ptr)
{
ft_strappend_xo(&flag->print, "(null)");
if (!IS_MACOS && flag->precision != -1)
flag->precision = flag->precision > 5 ? flag->precision : 0;
}
else
ft_strappend_xo(&flag->print, ptr);
}
}
void pf_convert_pct(t_fmt *flag)
{
if (flag->spec == '%')
{
flag->print = ft_strnew(0);
ft_strappend_xo_chr(&flag->print, '%');
if (IS_MACOS)
flag->is_numeric = 1;
}
}