-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser_utils.c
More file actions
85 lines (75 loc) · 2.25 KB
/
parser_utils.c
File metadata and controls
85 lines (75 loc) · 2.25 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkong <jkong@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/08 01:52:04 by jkong #+# #+# */
/* Updated: 2022/06/17 01:54:17 by jkong ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "libft.h"
char *get_token_str(t_token_kind token)
{
if (token == TK_PAREN_L)
return ("(");
else if (token == TK_PAREN_R)
return (")");
else if (token == TK_LESS)
return ("<");
else if (token == TK_GREATER)
return (">");
else if (token == TK_OR)
return ("|");
else if (token == TK_WORD)
return ("word");
else if (token == TK_LESS_LESS)
return ("<<");
else if (token == TK_GREATER_GREATER)
return (">>");
else if (token == TK_AND_AND)
return ("&&");
else if (token == TK_OR_OR)
return ("||");
else if (token == TK_EOF)
return ("newline");
return ("unknown");
}
void swap_word(t_word *a, t_word *b)
{
t_word x;
x = *a;
*a = *b;
*b = x;
}
void swap_redirect(t_redirect *a, t_redirect *b)
{
t_redirect x;
x = *a;
*a = *b;
*b = x;
}
void swap_command(t_command *a, t_command *b)
{
t_command x;
x = *a;
*a = *b;
*b = x;
}
void clear_parser_stack_item(t_parser_stack *item)
{
t_word temp_word;
t_redirect temp_redirect;
t_command temp_command;
ft_memset(&temp_word, 0, sizeof(temp_word));
ft_memset(&temp_redirect, 0, sizeof(temp_redirect));
ft_memset(&temp_command, 0, sizeof(temp_command));
swap_word(&temp_word, &item->word);
swap_redirect(&temp_redirect, &item->redirect);
swap_command(&temp_command, &item->command);
dispose_word(&temp_word);
dispose_redirect(&temp_redirect);
dispose_command(&temp_command);
}