-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_common_functions.c
104 lines (94 loc) · 2.69 KB
/
ft_printf_common_functions.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_common_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bnidia <bnidia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/04 08:42:42 by bnidia #+# #+# */
/* Updated: 2022/05/21 05:20:52 by bnidia ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_fprintf.h"
int ft_print_out(t_pf *z);
void reset_insignificant_values(t_pf *z, int signlen)
{
if (z->f_zero && z->width > 0 && z->precision <= 0)
{
z->f_zero = false;
z->precision = z->width - signlen;
z->width = 0;
}
if (z->width <= z->precision)
z->width = 0;
}
int output_of_initial_spaces(t_pf *z, int numlen, int signlen)
{
int spaces;
spaces = 0;
if (z->width > numlen || z->precision < numlen)
spaces = z->width - numlen - signlen;
if (z->width > z->precision && z->precision > numlen)
spaces = z->width - z->precision - signlen;
while (spaces > 0 && !z->f_minus)
{
z->s[z->s_i++] = ' ';
if (ft_print_out(z) == -1)
return (-1);
spaces--;
}
return (0);
}
int output_of_zeros(t_pf *z, int numlen, int signlen)
{
int zero;
zero = 0;
if (z->precision > numlen)
zero = z->precision - numlen;
else if (z->f_zero && z->width > numlen)
zero = z->width - numlen - signlen;
if (z->f_zero && z->precision < numlen \
&& z->width > z->precision && z->precision > 0)
zero = 0;
while (zero--)
{
z->s[z->s_i++] = '0';
if (ft_print_out(z) == -1)
return (-1);
}
return (0);
}
int output_of_finite_spaces(t_pf *z, int numlen, int signlen)
{
int spaces;
spaces = z->width - numlen - signlen;
if (z->width >= z->precision && z->precision > numlen)
spaces = z->width - z->precision - signlen;
if (z->width < z->precision)
spaces = 0;
while (z->f_minus && spaces > 0)
{
z->s[z->s_i++] = ' ';
if (ft_print_out(z) == -1)
return (-1);
spaces--;
}
return (0);
}
int for_zero_put_empty_string(t_pf *z, unsigned int nbr)
{
if (z->precision == 0 && nbr == 0)
{
while (z->width-- > 0)
{
z->s[z->s_i++] = ' ';
z->return_value = ft_print_out(z);
if (z->return_value == -1)
return (-1);
}
z->return_value = 0;
return (0);
}
z->return_value = 1;
return (1);
}