-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpiped_cmds.c
67 lines (58 loc) · 1.73 KB
/
piped_cmds.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* piped_cmds.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmachado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/13 16:22:52 by bmachado #+# #+# */
/* Updated: 2022/02/23 15:24:30 by bmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char **slice_less(char **pcmds)
{
int i;
i = 0;
while (pcmds[i])
{
if (is_redir(pcmds[i], 0) && pcmds[i + 1])
{
pcmds[i] = pcmds[i + 1];
pcmds[i + 1] = NULL;
}
i++;
}
return (pcmds);
}
static void checkdoc(t_shell *tab, char **pcmds)
{
int i;
i = ft_arrlen(pcmds) - 1;
if (tab->redir.doc_flag)
pcmds[i] = TMP_PATH;
else
return ;
}
int piped_cmd(t_shell *table, char **cmds, int start, int end)
{
char **pcmds;
pcmds = ft_subarray(cmds, start, end);
if (table->redir.in)
{
pcmds = slice_less(pcmds);
checkdoc(table, pcmds);
}
exec_pipe(table, pcmds);
free(pcmds);
return (end + 1);
}
void last_piped_cmd(t_shell *tab, char **cmds, int start, int end)
{
char **pcmds;
dup_close_fds(tab, 0);
pcmds = redirected(tab, cmds, start, end);
dup_close_fds(tab, 1);
execute_cmd(tab, pcmds);
free(pcmds);
}