Repository navigation
Expand file tree
/
Copy pathcommands.c
More file actions
44 lines (41 loc) · 1.47 KB
/
Copy pathcommands.c
File metadata and controls
44 lines (41 loc) · 1.47 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* commands.c :+: :+: */
/* +:+ */
/* By: daniel <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2022/01/06 13:29:39 by daniel #+# #+# */
/* Updated: 2022/01/24 13:48:18 by dnoom ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include <fcntl.h>
#include "Libft/libft.h"
t_part *get_commands_between_pipes(t_part *parts, t_pipe pipex, \
t_env *s_env)
{
t_part *cmd;
int i;
int j;
i = 0;
j = 0;
cmd = ft_calloc((pipex.len + 1) * sizeof(*parts), 1);
while (parts[i].part && i < pipex.len && !is_pipe(parts[i]))
{
if (ft_is_redir(parts[i]))
{
if (!is_here_doc(parts[i]) && open(parts[i + 1].part, O_RDONLY) < 0)
{
ft_redir_error(SHELL_NAME, parts[i + 1].part, s_env);
exit(0);
}
i += 2;
}
else if (is_here_doc(parts[i]))
i += 2;
else
cmd[j++] = parts[i++];
}
return (cmd);
}