-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmake_command.c
More file actions
69 lines (59 loc) · 2.08 KB
/
make_command.c
File metadata and controls
69 lines (59 loc) · 2.08 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* make_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkong <jkong@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/26 18:10:34 by jkong #+# #+# */
/* Updated: 2022/06/19 00:34:08 by jkong ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "safe_mem.h"
#include "generic_list.h"
t_simple_command *make_simple_command(void)
{
t_simple_command *cmd;
cmd = malloc_safe(sizeof(*cmd));
cmd->flags = 0;
cmd->word_list = NULL;
cmd->redirect_list = NULL;
return (cmd);
}
t_subshell_command *make_subshell(t_command *container)
{
t_subshell_command *cmd;
cmd = malloc_safe(sizeof(*cmd));
cmd->flags = 0;
cmd->container = *container;
cmd->redirect_list = NULL;
return (cmd);
}
t_command_connection *connect_command(t_command *lhs, t_command *rhs,
t_token_kind connector)
{
t_command_connection *cmd;
cmd = malloc_safe(sizeof(*cmd));
cmd->flags = 0;
cmd->connector = connector;
cmd->first = *lhs;
cmd->second = *rhs;
return (cmd);
}
void append_word(t_list_word **list, t_word *item)
{
t_list_word *elem;
elem = calloc_safe(1, sizeof(t_list_word));
elem->word = *item;
list_append((void *)list, (void *)elem);
}
void combine_simple_command(t_simple_command *lhs, t_simple_command *rhs)
{
lhs->flags |= rhs->flags;
rhs->flags = 0;
list_append((void *)&lhs->word_list, (void *)rhs->word_list);
rhs->word_list = NULL;
list_append((void *)&lhs->redirect_list, (void *)rhs->redirect_list);
rhs->redirect_list = NULL;
}