-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitermux.c
108 lines (101 loc) · 2.84 KB
/
splitermux.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* splitermux.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/23 17:32:41 by ggiannit #+# #+# */
/* Updated: 2023/04/13 17:38:16 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* split che ritorna una matrice del comando, escludendo i redirect */
static void ft_splitermux_bwhile_2(char *s, t_spl *x)
{
while (s[x->i] && s[x->i] != 32 && s[x->i] != '|')
{
while (!ft_iscut(s[x->i]) && s[x->i] != SQUT && s[x->i] != DQUT)
x->new[x->k][x->j++] = 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++];
}
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++];
}
if (ft_iscut(s[x->i]))
break ;
}
}
static void ft_splitermux_bwhile_1(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->i++;
while (s[x->i] && s[x->i] != SQUT)
x->i++;
}
else if (s[x->i] && s[x->i] == DQUT)
{
x->i++;
while (s[x->i] && s[x->i] != DQUT)
x->i++;
}
x->i++;
}
while (s[x->i] == 32)
x->i++;
}
static void ft_splitermux_bwhile_0(char *s, t_spl *x)
{
x->j = 0;
x->new[x->k] = ft_calloc ((ft_strmux_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 + 1] == '>')
x->i += 2;
else if (s[x->i] == '<' && s[x->i + 1] == '<')
x->i += 2;
else
x->i++;
ft_splitermux_bwhile_1(s, x);
}
}
char **ft_splitermux(char *s, t_mish *meta)
{
t_spl x;
x.k = 0;
x.i = 0;
while (s[x.i] == 32)
x.i++;
x.f = x.i;
x.new = (char **) ft_calloc (ft_count_word_mux(s) + 3, sizeof(char *));
while (s[x.i] && s[x.i] != '|')
{
ft_splitermux_bwhile_0(s, &x);
ft_splitermux_bwhile_2(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);
}