-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_redir5.c
70 lines (65 loc) · 1.51 KB
/
ft_redir5.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
#include "minishell.h"
void exec_m_chev_buf(t_struct *d, char *str)
{
if (d->l.buf && d->l.buf[3] == 'q')
{
if (fork() == 0)
execve(str, d->l.arg_chev, d->my_envp);
waitpid(0, &g_global.g_build_error_exec, 0);
}
}
int exec_chev_last(t_struct *d, int last, int fd, int fd2)
{
if (ft_strcmp(d->l.chev_tab[last - 1], "<<") == 0)
{
fd = d_chevron_left(d, last);
fd2 = exec_chev_last_in(fd, fd2);
}
else if (ft_strcmp(d->l.chev_tab[last - 1], "<") == 0)
{
fd = s_chevron_left(d, last);
if (fd == -1)
exit (1);
fd2 = exec_chev_last_in(fd, fd2);
}
else if (ft_strcmp(d->l.chev_tab[last - 1], ">") == 0)
{
fd = s_chevron_right(d, last);
fd2 = exec_chev_last_out(d, fd, fd2);
}
else if (ft_strcmp(d->l.chev_tab[last - 1], ">>") == 0)
{
fd = d_chevron_right(d, last);
fd2 = exec_chev_last_out(d, fd, fd2);
}
return (fd2);
}
void exec_chev_nolast(t_struct *d, int i)
{
if (ft_strncmp(d->l.chev_tab[i - 1], "<<", 2) == 0)
d->l.fd3 = d_chevron_left(d, i);
else if (ft_strcmp(d->l.chev_tab[i - 1], ">>") == 0)
d_chevron_right(d, i);
else if (ft_strcmp(d->l.chev_tab[i - 1], ">") == 0)
s_chevron_right(d, i);
else if (ft_strcmp(d->l.chev_tab[i - 1], "<") == 0)
{
d->l.fd3 = s_chevron_left(d, i);
if (d->l.fd3 == -1)
exit (1);
}
}
int exec_chev_last_in(int fd, int fd2)
{
fd2 = dup2(fd, STDIN_FILENO);
close(fd);
return (fd2);
}
int exec_chev_last_out(t_struct *d, int fd, int fd2)
{
dup2(fd, STDOUT_FILENO);
close(fd);
fd2 = dup2(d->l.fd3, STDOUT_FILENO);
close(d->l.fd3);
return (fd2);
}