-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_init.c
120 lines (111 loc) · 2.47 KB
/
ft_init.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vkinnune <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/02 13:26:14 by vkinnune #+# #+# */
/* Updated: 2022/02/02 13:30:22 by vkinnune ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *check_flags(t_info *var, char *ptr)
{
char c;
ptr++;
while (1)
{
c = *ptr;
if (c == '#')
var->alt = TRUE;
else if (c == '-')
var->ladjust = TRUE;
else if (c == '+')
var->sign = '+';
else if (c == ' ')
{
if (var->sign == 0)
var->sign = ' ';
}
else if (*ptr == '0' && var->ladjust == FALSE)
var->padc = '0';
else
break ;
ptr++;
}
return (ptr);
}
char *get_width(t_info *var, char *ptr)
{
char c;
c = *ptr;
if (ft_isdigit(c))
{
while (ft_isdigit(c))
{
var->length = 10 * var->length + c - '0';
c = *++ptr;
}
var->iswidth = TRUE;
}
return (ptr);
}
char *get_precision(t_info *var, char *ptr)
{
char c;
c = *ptr;
if (c == '.')
{
c = *++ptr;
if (ft_isdigit(c))
{
var->prec = 0;
while (ft_isdigit(c))
{
var->prec = 10 * var->prec + c - '0';
c = *++ptr;
}
}
else
var->prec = 0;
}
return (ptr);
}
char *get_modifier(t_info *var, char *ptr)
{
if (!ft_strncmp(ptr, "ll", 2) || !ft_strncmp(ptr, "hh", 2))
{
if (!ft_strncmp(ptr, "ll", 2))
var->bytes = 64;
else if (!ft_strncmp(ptr, "hh", 2))
var->bytes = 8;
return (ptr + 2);
}
if (*ptr == 'L')
var->bytes = 64;
else if (*ptr == 'l')
var->bytes = 32;
else if (*ptr == 'h')
var->bytes = 16;
else
return (ptr);
return (ptr + 1);
}
void setdefaultvalues(t_info *var)
{
var->alt = FALSE;
var->ladjust = FALSE;
var->blank = FALSE;
var->issign = FALSE;
var->sign = 0;
var->padc = ' ';
var->length = 0;
var->prec = -1;
var->bytes = 0;
var->size = 0;
var->base = 10;
var->capitals = 0;
var->prefix = 0;
var->iswidth = FALSE;
}