forked from 42-shell/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_reduce_2.c
95 lines (86 loc) · 3.08 KB
/
parser_reduce_2.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_reduce_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkong <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/08 01:52:04 by jkong #+# #+# */
/* Updated: 2022/06/17 02:25:21 by jkong ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "libft.h"
//redirection_list -> redirection_list redirection
t_token_kind parser_reduce_10(t_parser *pst)
{
t_parser_stack val;
t_command command;
t_redirect redirect;
t_list_redirect *r;
ft_memset(&val, 0, sizeof(val));
ft_memset(&command, 0, sizeof(command));
swap_command(&command, &pst->now[-1].command);
ft_memset(&redirect, 0, sizeof(redirect));
swap_redirect(&redirect, &pst->now[0].redirect);
r = append_redirect(&command.value.simple->redirect_list, &redirect);
if (redirect.instruction == R_READING_UNTIL)
push_here_document(pst, r);
val.command = command;
clear_parser_stack_item(&pst->now[-1]);
clear_parser_stack_item(&pst->now[0]);
pst->now -= 2;
*++pst->now = val;
return (TK_NT_REDIRECTION_LIST);
}
//command -> simple_command
t_token_kind parser_reduce_11(t_parser *pst)
{
(void)&pst;
return (TK_NT_COMMAND);
}
//command -> subshell
t_token_kind parser_reduce_12(t_parser *pst)
{
(void)&pst;
return (TK_NT_COMMAND);
}
//command -> subshell redirection_list
t_token_kind parser_reduce_13(t_parser *pst)
{
t_parser_stack val;
t_command command_lhs;
t_command command_rhs;
ft_memset(&val, 0, sizeof(val));
ft_memset(&command_lhs, 0, sizeof(command_lhs));
swap_command(&command_lhs, &pst->now[-1].command);
ft_memset(&command_rhs, 0, sizeof(command_rhs));
swap_command(&command_rhs, &pst->now[0].command);
subshell_apply_redirect(command_lhs.value.subshell,
command_rhs.value.simple->redirect_list);
command_rhs.value.simple->redirect_list = NULL;
val.command = command_lhs;
dispose_command(&command_rhs);
clear_parser_stack_item(&pst->now[-1]);
clear_parser_stack_item(&pst->now[0]);
pst->now -= 2;
*++pst->now = val;
return (TK_NT_COMMAND);
}
//subshell -> '(' list ')'
t_token_kind parser_reduce_14(t_parser *pst)
{
t_parser_stack val;
t_command command;
ft_memset(&val, 0, sizeof(val));
ft_memset(&command, 0, sizeof(command));
swap_command(&command, &pst->now[-1].command);
val.command.type = CMD_SUBSHELL;
val.command.value.subshell = make_subshell(&command);
clear_parser_stack_item(&pst->now[-2]);
clear_parser_stack_item(&pst->now[-1]);
clear_parser_stack_item(&pst->now[0]);
pst->now -= 3;
*++pst->now = val;
return (TK_NT_SUBSHELL);
}