-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_type.c
More file actions
133 lines (122 loc) · 3.47 KB
/
Copy pathdisplay_type.c
File metadata and controls
133 lines (122 loc) · 3.47 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
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
125
126
127
128
129
130
131
132
133
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* display_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gdannay <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/02 18:22:57 by gdannay #+# #+# */
/* Updated: 2017/12/13 19:10:53 by gdannay ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *manage_neg(t_flag *tmp, char *new, int taille, int n)
{
char *t2;
char *tmptxt;
tmptxt = new;
if ((t2 = ft_bchar('0', 8)) == NULL)
return (NULL);
tmp->nb = 4294967296 - taille;
if (tmp->type == 'x')
new = ltoa_base(tmp, HEXAMIN);
else if (tmp->type == 'X')
new = ltoa_base(tmp, HEXAMAJ);
if (new == NULL)
return (NULL);
tmp->nb = n + 4294967296 * taille;
if (tmp->nb == 0)
new = ft_strjoin(new, ft_bchar('0', 8));
else if (tmp->type == 'x')
new = ft_strjoin(new, ltoa_base(tmp, HEXAMIN));
else if (tmp->type == 'X')
new = ft_strjoin(new, ltoa_base(tmp, HEXAMAJ));
if (new == NULL)
return (NULL);
ft_strdel(&tmptxt);
ft_strdel(&t2);
return (new);
}
static char *manage_hexa(t_flag *tmp)
{
char *new;
new = NULL;
if (tmp->nb <= -4294967296)
{
new = manage_neg(tmp, new,
size_hexa(tmp->nb), tmp->nb);
}
else
{
tmp->nb += 4294967296;
if (tmp->type == 'x')
new = ltoa_base(tmp, HEXAMIN);
else if (tmp->type == 'X')
new = ltoa_base(tmp, HEXAMAJ);
}
if (new == NULL)
return (NULL);
return (new);
}
int manage_nb(t_flag *tmp, char *buff)
{
char *new;
new = NULL;
if (tmp->inttype == 6 && tmp->nb < 0)
new = manage_hexa(tmp);
else if (tmp->inttype == 1)
new = ltoa_base(tmp, DECI);
else if (tmp->type == 'x' && tmp->length == 0)
new = ltoa_base(tmp, HEXAMIN);
else if (tmp->type == 'X' && tmp->length == 0)
new = ltoa_base(tmp, HEXAMAJ);
else if (tmp->type == 'x' || tmp->type == 'p')
new = utoa_base(tmp, HEXAMIN);
else if (tmp->type == 'X')
new = utoa_base(tmp, HEXAMAJ);
else if (tmp->type == 'u' || tmp->type == 'U' || tmp->type == 'D')
new = utoa_base(tmp, DECI);
else if (tmp->type == 'o' || tmp->type == 'O')
new = utoa_base(tmp, OCTA);
if (new == NULL)
return (0);
if (tmp->precision == 0 && ft_strncmp(new, "0", 1) == 0)
ft_strdel(&new);
return (display_flag(new, tmp, buff));
}
int manage_string(t_flag *tmp, char *buff)
{
char *tmptxt;
if (tmp->st == NULL)
{
if ((tmp->st = ft_strdup("(null)")) == NULL)
return (0);
}
if (tmp->precision == 0)
return (display_flag(NULL, tmp, buff));
else if (tmp->precision > 0)
{
if ((tmptxt = ft_strndup(tmp->st, (size_t)tmp->precision)) == NULL)
return (0);
return (display_flag(tmptxt, tmp, buff));
}
else
{
if ((tmptxt = ft_strdup(tmp->st)) == NULL)
return (0);
return (display_flag(tmptxt, tmp, buff));
}
}
int manage_char(t_flag *tmp, char *buff)
{
char *c;
c = NULL;
if (tmp->nb == 0)
return (display_0(tmp, c, buff));
else
{
if ((c = chartostr(tmp->nb)) == NULL)
return (0);
return (display_flag(c, tmp, buff));
}
}