-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_prints.c
124 lines (113 loc) · 2.85 KB
/
ft_prints.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_prints.c :+: :+: */
/* +:+ */
/* By: novan-ve <novan-ve@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/12/17 16:52:41 by novan-ve #+# #+# */
/* Updated: 2019/12/27 16:14:04 by novan-ve ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_prints5(t_print *p)
{
int i;
char n[7];
i = 0;
n[0] = '(';
n[1] = 'n';
n[2] = 'u';
n[3] = 'l';
n[4] = 'l';
n[5] = ')';
n[6] = '\0';
while (i < p->prec && i < 6)
{
p->len++;
ft_putchar_fd(n[i], 1);
i++;
}
}
void ft_prints4(t_print *p)
{
int i;
i = 0;
if (p->prec == -1 || p->prec > 5)
p->tmplen = 6;
if (p->just == 'r' && (p->prec == -1 || p->prec > 5))
ft_putstr_fd("(null)", 1);
if (p->prec < 6 && p->just == 'r')
ft_prints5(p);
if (p->prec > 0 && p->prec < 6)
i = 1;
while (i < (p->tmpwidth) && i < (p->tmpwidth - p->tmplen))
{
ft_putchar_fd(p->padchar, 1);
i++;
}
if (p->prec < 6 && p->just == 'l')
ft_prints5(p);
if (p->just == 'l' && (p->prec == -1 || p->prec > 5))
ft_putstr_fd("(null)", 1);
}
void ft_prints3(t_print *p)
{
int i;
i = 0;
if (p->prec == p->tmpwidth && p->prec > p->tmplen)
p->prec = p->tmplen;
else if (p->prec == p->tmpwidth)
p->tmplen = p->prec;
if (p->prec > p->tmplen)
p->prec = p->tmplen;
if (p->just == 'r')
ft_putprec_fd(p->strtmp, 1, p->prec);
while (i < (p->tmpwidth - p->prec))
{
ft_putchar_fd(p->padchar, 1);
i++;
}
if (p->just == 'l')
ft_putprec_fd(p->strtmp, 1, p->prec);
if (p->prec < p->tmplen)
p->tmplen = p->prec;
if (p->tmplen < p->tmpwidth)
p->tmplen = p->tmpwidth;
}
void ft_prints2(t_print *p)
{
int i;
i = 0;
if (p->just == 'r')
ft_putstr_fd(p->strtmp, 1);
while (i < (p->tmpwidth - p->tmplen))
{
ft_putchar_fd(p->padchar, 1);
i++;
}
if (p->just == 'l')
ft_putstr_fd(p->strtmp, 1);
if (p->tmplen < p->tmpwidth)
p->tmplen = p->tmpwidth;
}
void ft_prints(t_print *p)
{
int i;
int j;
i = 0;
j = 6;
p->strtmp = va_arg(p->args, char*);
if (p->strtmp == NULL)
i = -1;
else
p->tmplen = ft_strlen(p->strtmp);
if (p->tmplen < p->tmpwidth && p->prec == -1 && i == 0)
ft_prints2(p);
else if (p->prec >= 0 && i == 0)
ft_prints3(p);
else if (p->prec == -1 && i == 0)
ft_putstr_fd(p->strtmp, 1);
else if (i == -1)
ft_prints4(p);
}