-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitered_utils.c
129 lines (121 loc) · 2.54 KB
/
splitered_utils.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
121
122
123
124
125
126
127
128
129
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* splitered_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/23 17:32:41 by ggiannit #+# #+# */
/* Updated: 2023/04/15 17:54:27 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void ft_strred_pez_2(char *s, int *f, int *i)
{
if (s[*f] == SQUT)
{
*i += 1;
*f += 1;
while (s[*f] != SQUT)
{
*i += 1;
*f += 1;
}
}
if (s[*f] == DQUT)
{
*i += 1;
*f += 1;
while (s[*f] != DQUT)
{
*i += 1;
*f += 1;
}
}
*i += 1;
*f += 1;
}
static void ft_strred_pez_1(char *s, int *f, int *i)
{
if ((s[*f] == '<' && s[*f + 1] == '<')
&& (s[*f] == '>' && s[*f + 1] == '>'))
{
*i += 1;
*f += 1;
}
*i += 1;
*f += 1;
while (s[*f] == 32)
*f += 1;
while (!ft_iscut(s[*f]))
ft_strred_pez_2(s, f, i);
}
int ft_strred_pez(char *s, int *f)
{
int i;
i = 5;
while (s[*f] && s[*f] != '<' && s[*f] != '>')
{
if (s[*f] == SQUT)
{
*f += 1;
while (s[*f] != SQUT)
*f += 1;
}
if (s[*f] == DQUT)
{
*f += 1;
while (s[*f] != DQUT)
*f += 1;
}
*f += 1;
}
if ((s[*f] && s[*f] == '<') || (s[*f] && s[*f] == '>'))
ft_strred_pez_1(s, f, &i);
return (i);
}
static int ft_count_word_skip(char *str, int *i)
{
while (str[*i] && str[*i] != '<' && str[*i] != '>')
{
if (str[*i] && str[*i] == SQUT)
{
*i += 1;
while (str[*i] && str[*i] != SQUT)
*i += 1;
}
if (str[*i] && str[*i] == DQUT)
{
*i += 1;
while (str[*i] && str[*i] != DQUT)
*i += 1;
}
if (str[*i] == '|')
return (0);
*i += 1;
}
return (1);
}
int ft_count_word_red(char *str)
{
int i;
int word;
i = 0;
word = 1;
if (!str)
return (1);
while (str && str[i])
{
if (!ft_count_word_skip(str, &i))
return (word);
if (str[i] == '<' || str[i] == '>')
{
i++;
if ((str[i] == '<' && str[i + 1] == '<')
|| (str[i] == '>' && str[i + 1] == '>'))
i++;
}
word++;
}
return (word);
}