-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_2.c
More file actions
68 lines (61 loc) · 2.36 KB
/
format_2.c
File metadata and controls
68 lines (61 loc) · 2.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vportell <vportell@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/23 22:55:11 by vportell #+# #+# */
/* Updated: 2016/12/24 06:01:20 by vportell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void format_setup_1(char **s, t_format *format, unsigned long arg, char **k)
{
int len;
len = ft_strlen(*s);
if (format->period && format->precision < len && !arg)
{
len = format->precision < 0 ? 0 : format->precision;
*k = ft_strsub(*s, ft_strlen(*s) - len, len);
ft_strdel(s);
*s = ft_strdup(*k);
ft_strdel(k);
}
}
void format_setup_2(char *s, t_format *format, char **p, char **k)
{
format_precision(s, format, p, k);
!(*p) ? *p = ft_strdup("") : 0;
format_width(s, format, p, k);
!(*k) ? *k = ft_strdup("") : 0;
}
void format_chr(char **s, t_format *format, void *arg)
{
if (format->length == 3 || format->length == 4 || format->type == 14)
print_ch2(s, format, arg);
else
print_chr(s, format, arg);
}
void format_str(char **s, t_format *format, void *arg)
{
if (format->length == 3 || format->length == 4 || format->type == 4)
print_st2(s, format, arg);
else
print_str(s, format, arg);
}
void format_bin(char **s, t_format *format, void *arg)
{
if (format->length == 1 && format->type != 16)
print_bin(s, format, (unsigned char)arg);
else if (format->length == 2 && format->type != 16)
print_bin(s, format, (unsigned short)arg);
else if (format->length == 3 || format->length == 4 || format->type != 16)
print_bin(s, format, (unsigned long)arg);
else if (format->length == 5)
print_bin(s, format, (unsigned long)arg);
else if (format->length == 6)
print_bin(s, format, (unsigned long)arg);
else
print_bin(s, format, (unsigned int)arg);
}