-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printaltx.c
More file actions
112 lines (101 loc) · 3.28 KB
/
Copy pathft_printaltx.c
File metadata and controls
112 lines (101 loc) · 3.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printaltx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gconde-m <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/27 08:37:27 by gconde-m #+# #+# */
/* Updated: 2019/12/27 08:37:36 by gconde-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_printaltx(t_struct *str)
{
unsigned int c;
char *p;
int len;
int lenpre;
char k;
lenpre = str->pre;
k = '7';
c = va_arg(str->ap, unsigned int);
p = ft_itoa_base(c, 16, 'A');
len = ft_strlen(p);
if (c == 0 && str->pre == 0 && str->p == 1)
str->pre = 0;
else
str->pre = str->pre < len ? len : str->pre;
if (str->w == 0 && str->flag == 0 && str->p == 0)
ft_putnbrmemory(c, k, str);
else if (str->flag == 1)
numberminusx(c, str, k, len);
else if (str->flag == 2)
numbercerox(c, str, k, len);
else if (str->p == 1 && str->w == 0)
numberprecx(c, str, k, lenpre);
else
numberprecwidthx(c, str, k, len);
}
void numberminusx(unsigned int c, t_struct *str, char k, int len)
{
int hotia;
char *p;
p = ft_itoa_base(c, 16, 'A');
hotia = ft_strlen(p);
str->pre = c < 0 && str->pre == len ? str->pre - 1 : str->pre;
if (str->pre > hotia && str->p == 1)
putminuscero(str->pre, hotia, "0");
if (!(c == 0 && str->pre == 0 && str->p == 1))
ft_putnbrmemory(c, k, str);
if (str->flag != 2)
putminuscero(str->w = c < 0 ? str->w - 1 : str->w, str->pre, " ");
}
void numbercerox(unsigned int c, t_struct *str, char k, int len)
{
char *p;
p = ft_itoa_base(c, 16, 'A');
str->pre = c < 0 && str->pre == len ? str->pre - 1 : str->pre;
if (str->p == 1)
putminuscero(str->w, str->pre = c < 0 ? str->pre + 1 : str->pre, " ");
putminuscero(str->pre = str->p == 1 ? str->pre : str->w, len, "0");
if (!(c == 0 && str->pre == 0 && str->p == 1))
ft_putnbrmemory(c, k, str);
}
void numberprecx(unsigned int c, t_struct *str, char k, int lenpre)
{
int omg;
char *p;
p = ft_itoa_base(c, 16, 'A');
omg = ft_strlen(p);
if (lenpre >= omg)
{
putminuscero(lenpre, omg, "0");
if (!(c == 0 && str->pre == 0 && str->p == 1))
ft_putnbrmemory(c, k, str);
}
else
{
if (!(c == 0 && str->pre == 0 && str->p == 1))
ft_putnbrmemory(c, k, str);
}
}
void numberprecwidthx(unsigned int c, t_struct *str, char k, int len)
{
char *p;
int hotia;
p = ft_itoa_base(c, 16, 'A');
hotia = str->pre == 0 && c == 0 ? 0 : ft_strlen(p);
str->pre = c < 0 && str->pre == len ? str->pre - 1 : str->pre;
if (str->flag != 2)
putminuscero(str->w, str->pre, " ");
if (str->pre > hotia && str->p == 1)
putminuscero(str->pre, hotia, "0");
if (str->pre == 0 && c == 0 && str->p != 1)
write(1, "0", 1);
else
{
if (!(c == 0 && str->pre == 0 && str->p == 1))
ft_putnbrmemory(c, k, str);
}
}