-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckers.c
More file actions
125 lines (117 loc) · 3.07 KB
/
Copy pathcheckers.c
File metadata and controls
125 lines (117 loc) · 3.07 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checkers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jamrabhi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/22 22:21:07 by jamrabhi #+# #+# */
/* Updated: 2020/02/22 22:40:01 by jamrabhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int check_format(const char *fmt, int i)
{
while (fmt[i])
{
if (fmt[i] == 'c' || fmt[i] == 's' || fmt[i] == 'p'
|| fmt[i] == 'd' || fmt[i] == 'i' || fmt[i] == 'u'
|| fmt[i] == 'x' || fmt[i] == 'X' || fmt[i] == '%')
return (1);
i++;
}
return (0);
}
int check_flag(const char *fmt, int i, t_specif *specif)
{
if (fmt[i] == '0' || fmt[i] == '-')
{
if (fmt[i] && fmt[i] == '-')
specif->left = 1;
if (fmt[i] && fmt[i] == '0')
specif->zero = 1;
i++;
while (fmt[i] == '0' || fmt[i] == '-')
{
if (fmt[i] && fmt[i] == '-')
specif->left = 1;
if (fmt[i] && fmt[i] == '0')
specif->zero = 1;
i++;
}
if (specif->left == 1 && specif->zero == 1)
specif->zero = 0;
}
return (i);
}
int check_width(va_list arg, const char *fmt, int start, t_specif *specif)
{
int len;
int i;
char *tmp;
len = 0;
i = start;
if (fmt[i] == '*')
{
specif->width = va_arg(arg, int);
if (specif->width < 0)
{
specif->left = 1;
specif->zero == 1 ? specif->zero = 0 : 0;
specif->width *= -1;
}
return (i + 1);
}
while (ft_isdigit(fmt[i]) == 1 && i++)
len++;
tmp = ft_substr(fmt, start, len);
specif->width = ft_atoi(tmp);
free(tmp);
return (i);
}
int check_precis(va_list arg, const char *fmt, int start, t_specif *specif)
{
int i;
int len;
char *tmp;
i = start;
len = 0;
if (fmt[i] == '.')
{
specif->precision = 1;
i++;
if (fmt[i] == '*')
{
specif->precision_value = va_arg(arg, int);
specif->precision_value < 0 ? specif->precision = 0 : 0;
specif->precision_value < 0 ? specif->precision_value = 0 : 0;
return (i + 1);
}
start++;
while (ft_isdigit(fmt[i]) == 1 && i++)
len++;
tmp = ft_substr(fmt, start, len);
specif->precision_value = ft_atoi(tmp);
free(tmp);
}
return (i);
}
void check_type(va_list arg, const char *fmt, int i, t_specif *specif)
{
if (fmt[i] == 's')
type_s(arg, specif);
if (fmt[i] == 'c')
type_c(arg, specif);
if (fmt[i] == 'd' || fmt[i] == 'i')
type_d(arg, specif);
if (fmt[i] == 'p')
type_p(arg, specif);
if (fmt[i] == 'u')
type_u(arg, specif);
if (fmt[i] == '%')
type_percent(specif);
if (fmt[i] == 'x')
type_x(arg, specif);
if (fmt[i] == 'X')
type_x_upper(arg, specif);
}