-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitered.c
100 lines (93 loc) · 2.67 KB
/
splitered.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* splitered.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/23 17:32:41 by ggiannit #+# #+# */
/* Updated: 2023/04/15 17:55:22 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* split che ritorna una matrice con i soli redirect */
static void ft_splitered_bwhile_2(char *s, t_spl *x)
{
while (s[x->i] == 32)
x->i++;
while (!ft_iscut(s[x->i]))
{
if (s[x->i] && s[x->i] == SQUT)
{
x->new[x->k][x->j++] = s[x->i++];
while (s[x->i] && s[x->i] != SQUT)
x->new[x->k][x->j++] = s[x->i++];
if (s[x->i])
x->new[x->k][x->j++] = s[x->i++];
}
else if (s[x->i] && s[x->i] == DQUT)
{
x->new[x->k][x->j++] = s[x->i++];
while (s[x->i] && s[x->i] != DQUT)
x->new[x->k][x->j++] = s[x->i++];
if (s[x->i])
x->new[x->k][x->j++] = s[x->i++];
}
else
x->new[x->k][x->j++] = s[x->i++];
}
}
static void ft_splitered_bwhile_1(char *s, t_spl *x)
{
if (s[x->i] == '<' || s[x->i] == '>')
{
x->new[x->k][x->j++] = s[x->i++];
if ((s[x->i - 1] == '<' && s[x->i] == '<')
|| (s[x->i - 1] == '>' && s[x->i] == '>'))
x->new[x->k][x->j++] = s[x->i++];
ft_splitered_bwhile_2(s, x);
}
}
static void ft_splitered_bwhile_0(char *s, t_spl *x)
{
x->j = 0;
x->new[x->k] = ft_calloc ((ft_strred_pez(s, &(x->f)) + 1), sizeof(char));
while (s[x->i] == 32 && s[x->i])
x->i++;
while (s[x->i] && s[x->i] != '<' && s[x->i] != '>' && s[x->i] != '|')
{
if (s[x->i] && s[x->i] == SQUT)
{
x->i++;
while (s[x->i] && s[x->i] != SQUT)
x->i++;
}
if (s[x->i] && s[x->i] == DQUT)
{
x->i++;
while (s[x->i] && s[x->i] != DQUT)
x->i++;
}
x->i++;
}
}
char **ft_splitered(char *s, t_mish *meta)
{
t_spl x;
x.k = 0;
x.i = 0;
x.f = 0;
x.new = (char **) ft_calloc (ft_count_word_red(s) + 1, sizeof(char *));
while (s[x.i] && s[x.i] != '|')
{
ft_splitered_bwhile_0(s, &x);
ft_splitered_bwhile_1(s, &x);
x.k++;
if (!s[x.i] || s[x.i] == '|')
break ;
}
x.new[x.k] = NULL;
if (s[x.i] == '|')
meta->flag = 1;
return (x.new);
}