-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks2.c
93 lines (84 loc) · 1.93 KB
/
checks2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checks2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smbaabu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 12:37:08 by smbaabu #+# #+# */
/* Updated: 2019/04/13 16:39:03 by smbaabu ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int update(const char *s, int a, int b)
{
char *num;
int ret;
num = ft_strsub(s, a, b);
ret = ft_atoi(num);
free(num);
return (ret);
}
int check_precision(const char *s, int start, int *upto)
{
int i;
int j;
int ret;
i = start;
while (i < *upto)
{
if (s[i] == '.')
{
*upto = i;
j = i + 1;
while (ft_isdigit(s[j]))
j++;
if (j > i + 1)
{
ret = update(s, i + 1, j - i - 1);
return (ret < 0 ? -1 : ret);
}
return (0);
}
i++;
}
return (-1);
}
int check_width(const char *s, int start, int *upto)
{
int i;
int j;
int ret;
i = start;
while (i < *upto && s[i] != '.')
{
if (s[i] == '0')
{
i++;
continue ;
}
j = i;
while (ft_isdigit(s[j]) && s[j] != '.')
j++;
if (j - i)
{
*upto = i;
ret = update(s, i, j - i);
return (ret);
}
i++;
}
return (-1);
}
void check_flags(const char *s, int start, int upto, int *flags)
{
int i;
int idx;
i = start;
while (i < upto)
{
if ((idx = ft_stridx(FLAGS, s[i])) != -1)
flags[idx] = 1;
i++;
}
}