-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflag_utils2.c
More file actions
109 lines (99 loc) · 2.35 KB
/
flag_utils2.c
File metadata and controls
109 lines (99 loc) · 2.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flag_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tvandivi <tvandivi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/19 18:18:02 by tvandivi #+# #+# */
/* Updated: 2019/09/27 17:54:32 by tvandivi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int prec_helpr(t_alst *arg, char *fmt)
{
int ret;
ret = 0;
if (ft_isdigit(*fmt))
{
if (*fmt == '0')
arg->info->blank = 1;
arg->info->precision = ft_atoi(fmt);
while (ft_isdigit(*fmt))
{
ret++;
fmt++;
}
}
else
{
arg->info->precision = 0;
arg->info->blank = 1;
}
return (ret);
}
int parse_precision(t_alst *arg, char *fmt)
{
int ret;
ret = 0;
if (*fmt == '.')
{
fmt++;
ret++;
ret += prec_helpr(arg, fmt);
}
else
arg->info->precision = 0;
return (ret);
}
static int precheck(t_alst *arg, int *ret)
{
ZERO_FLAG = 1;
*ret += 1;
return (*ret);
}
int parse_flags(t_alst *arglst, char *fmt)
{
int ret;
ret = 0;
arglst->info->blank_flag = 0;
arglst->info->hash_flag = 0;
arglst->info->minus_flag = 0;
arglst->info->plus_flag = 0;
if (*fmt == '0')
fmt += precheck(arglst, &ret);
while (*fmt == ' ' || *fmt == '#' || *fmt == '-' || *fmt == '+')
{
if (*fmt == ' ')
arglst->info->blank_flag = 1;
if (*fmt == '#')
arglst->info->hash_flag = 1;
if (*fmt == '-')
arglst->info->minus_flag = 1;
if (*fmt == '+')
arglst->info->plus_flag = 1;
fmt++;
ret++;
}
return (ret);
}
int parse_fieldwidth(t_alst *arglst, char *fmt)
{
int ret;
ret = 0;
if (ft_isdigit(*fmt))
{
if (fmt[0] == '0')
arglst->info->zero_flag = 1;
arglst->info->fieldwidth = ft_atoi(fmt);
while (ft_isdigit(*fmt) && *fmt != '\0')
{
fmt++;
ret++;
}
return (ret);
}
else
arglst->info->fieldwidth = 0;
return (0);
}