-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_tools.c
108 lines (99 loc) · 2.51 KB
/
check_tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nhamid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/08/08 23:38:36 by nhamid #+# #+# */
/* Updated: 2019/08/09 14:12:54 by ymoukhli ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtparse.h"
char *ft_pobj_str(char *str, char *start, char *end)
{
char *p_s;
char *p_e;
p_s = ft_strstr(str, start);
if (p_s == NULL)
return (NULL);
if (p_s[1] != '\0')
p_e = ft_strstr(p_s + 1, end);
else
return (NULL);
if (p_s == NULL || p_e == NULL)
return (NULL);
return (p_s);
}
void ft_init_obj_pick(int *i, char *start, int *count, int *j)
{
*i = ft_strlen(start);
*count = 0;
*j = 0;
}
char *ft_obj_pick_str(char *str, char *start, char end, char skip_end)
{
char *p_s;
int i;
int count;
int j;
if (!(p_s = ft_strstr(str, start)))
return (NULL);
ft_init_obj_pick(&i, start, &count, &j);
while (p_s[i] != 0)
{
if (p_s[i] == end)
{
if (count == 0)
{
j = i;
break ;
}
count != 0 ? count-- : count;
}
p_s[i] == skip_end ? count++ : count;
i++;
}
if (j == 0)
return (0);
return (ft_strsub(p_s, 0, j + 1));
}
int ft_check2(char *str_pick, int i, int *k)
{
while (str_pick[i] != '\0')
{
if (str_pick[i] == '-' || str_pick[i] == '+')
i++;
if (ft_isdigit(str_pick[i]))
{
*k += 1;
while (ft_isdigit(str_pick[i]))
i++;
if (str_pick[i] == '-' || str_pick[i] == '+')
return (-1);
}
if (str_pick[i] == ';')
return (i);
else if (str_pick[i] != ',' && str_pick[i] != ' ' &&
str_pick[i] != '\t' && str_pick[i] != '\n')
return (-1);
if (str_pick[i] != '\0')
i++;
}
return (i);
}
int ft_check(char *str, char *pick, int nnum)
{
char *str_pick;
int i;
int k;
if (!(str_pick = ft_strstr(str, pick)))
return (-1);
i = ft_strlen(pick);
k = 0;
if (ft_check2(str_pick, i, &k) == -1)
return (-1);
if (k == nnum)
return (0);
return (-1);
}