-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_create_cmds.c
58 lines (53 loc) · 1.81 KB
/
ft_create_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_create_cmds.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpizzolo <mpizzolo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 10:41:40 by ralopez- #+# #+# */
/* Updated: 2023/06/01 14:50:07 by mpizzolo ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void prepare_args(t_inf *info)
{
t_command *tmp;
int i;
tmp = info->commands;
i = 0;
while (tmp)
{
if (tmp->cmd != NULL && !is_builtin(tmp->cmd))
tmp->args = join_arguments(ft_split(tmp->cmd, ' '), tmp->args);
tmp = tmp->next;
i++;
}
}
int create_commands(t_inf *info)
{
t_list *tmp;
if (info->tokens == NULL)
return (0);
tmp = info->tokens;
while (tmp && info->must_continue)
{
if (tmp != NULL && tmp->type == WORD)
tmp = save_word(info, tmp);
else if (tmp->type == LESS)
tmp = save_input(info, tmp);
else if (tmp->type == GREATER)
tmp = save_output(info, tmp, O_TRUNC);
else if (tmp->type == APPEND)
tmp = save_output(info, tmp, O_APPEND);
else if (tmp->type == PIPE)
tmp = save_pipe(info, tmp, 1);
else if (tmp->type == HEREDOC)
tmp = save_heredoc(info, tmp);
else if (tmp != NULL && tmp->type == END)
break ;
}
if (info->must_continue)
prepare_args(info);
return (0);
}