-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_aux2.c
executable file
·121 lines (111 loc) · 2.72 KB
/
ft_printf_aux2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_aux2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngouy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/02/12 19:56:23 by ngouy #+# #+# */
/* Updated: 2015/02/17 17:23:56 by ngouy ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
void switch_space(const char **str)
{
while (**str == ' ')
{
(*str)++;
}
}
static int ft_aux1(t_opt *opt)
{
char *str1;
int ret;
ret = 0;
if (opt->prec == 0)
{
write (1, "(null)", 6);
return (6);
}
(opt->prec == -1) ? (opt->prec = 0) : opt->prec;
str1 = "(null)";
while (ret != opt->larg)
{
if (ret < (opt->larg - opt->prec))
write(1, "0", 1);
else
write(1, str1++, 1);
ret++;
}
return (opt->larg);
}
static int ft_aux2(void *str, int ret, t_opt *opt)
{
char *str1;
int ind;
ind = 0;
str1 = (char *)str;
if ((opt->spec == 1 || opt->spec == 2) &&
(opt->flagu && (ft_strchr(opt->flagu, '-'))))
{
write(1, "\0", 1);
ind = 1;
}
while (str1[ret])
{
write(1, str1 + ret, 1);
ret++;
}
if ((opt->spec == 1 || opt->spec == 2) && ind == 0)
write(1, "\0", 1);
if (opt->spec == 1 || opt->spec == 2)
ret++;
return (ret);
}
int disp_n_count(void *str, int flagu, t_opt *opt)
{
int ret;
int tem;
wchar_t *sstr;
tem = 0;
ret = 0;
if (opt->spec == 1)
str++;
if (!str)
return (ft_aux1(opt));
if (flagu == 0)
ret = ft_aux2(str, ret, opt);
else
{
sstr = (wchar_t *)str;
if (opt->spec == 10 && (opt->flagu && ft_strchr(opt->flagu, '-')))
write(1, "\0", 1);
while (sstr[ret])
write(1, sstr + (ret++), 1);
if (opt->spec == 10 && (!opt->flagu || !ft_strchr(opt->flagu, '-')))
write(1, "\0", 1);
if (opt->spec == 10)
ret++;
}
return (ret);
}
char *ft_with_h(t_opt *opt, va_list ap)
{
int i;
char *ret;
if (opt->out == 'd')
{
(opt->mod[1] && opt->mod[1] == 'h') ?
(i = (signed char)va_arg(ap, int))
: (i = (short int)va_arg(ap, int));
ret = int_to_smt(i, opt->out);
}
else
{
(opt->mod[1] && opt->mod[1] == 'h') ?
(i = (unsigned char)va_arg(ap, int))
: (i = (unsigned short int)va_arg(ap, int));
ret = int_to_smt(i, opt->out);
}
return (ret);
}