-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_action_bonus5.c
94 lines (85 loc) · 2.95 KB
/
ft_action_bonus5.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_action_bonus5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edelangh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/04 19:22:30 by edelangh #+# #+# */
/* Updated: 2015/01/08 10:46:27 by edelangh ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
long double ft_get_read(t_printf *info, va_list ap)
{
long double res;
if (info->ul)
res = va_arg(ap, long double);
else if (info->l)
res = (long double)va_arg(ap, double);
else
res = (long double)(float)va_arg(ap, double);
return (res);
}
int ft_action_e(char *f, int lenud, va_list ap)
{
t_printf info;
int len;
long double nbr;
char *x;
info.type = 'e';
init_info(&info, f, lenud, ap);
nbr = (long double)va_arg(ap, double);
x = ft_get_expo(&nbr);
info.value = ft_ftoa(nbr);
info.value = ft_fpreci(info.value, (info.is_preci ? info.preci : 6));
info.value = ft_strfjoin(info.value, (x[0] == '-' ? "e" : "e+"), 1, 0);
info.value = ft_strfjoin(info.value, x, 1, 1);
len = ft_strlen(info.value);
info.is_preci = 0;
ft_print_d(info, len, nbr != 0, ft_strjoinnchar(NULL, 1, info.add));
return (len);
}
int ft_action_ue(char *f, int lenud, va_list ap)
{
t_printf info;
int len;
long double nbr;
char *x;
info.type = 'E';
init_info(&info, f, lenud, ap);
nbr = (long double)va_arg(ap, double);
x = ft_get_expo(&nbr);
info.value = ft_ftoa(nbr);
info.value = ft_fpreci(info.value, (info.is_preci ? info.preci : 6));
info.value = ft_strfjoin(info.value, (x[0] == '-' ? "e" : "e+"), 1, 0);
info.value = ft_strfjoin(info.value, x, 1, 1);
ft_upper_case(info.value);
len = ft_strlen(info.value);
info.is_preci = 0;
ft_print_d(info, len, nbr != 0, ft_strjoinnchar(NULL, 1, info.add));
return (len);
}
int ft_action_n(char *f, int lenud, va_list ap)
{
t_printf info;
void *nbr;
info.type = 'n';
init_info(&info, f, lenud, ap);
nbr = va_arg(ap, void*);
if (info.l == 2)
*((long long*)nbr) = *(long long*)ft_static(0, 1);
else if (info.l == 1)
*((long*)nbr) = *(long*)ft_static(0, 1);
else if (info.h == 2)
*((signed char*)nbr) = *(signed char*)ft_static(0, 1);
else if (info.h == 1)
*((short*)nbr) = *(short*)ft_static(0, 1);
else if (info.j == 1)
*((intmax_t*)nbr) = *(intmax_t*)ft_static(0, 1);
else if (info.z == 1)
*((size_t*)nbr) = *(size_t*)ft_static(0, 1);
else
*((int*)nbr) = *(int*)ft_static(0, 1);
return (0);
}