-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_spot.c
76 lines (70 loc) · 2.29 KB
/
parse_spot.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_spot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aoizel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 11:01:51 by aoizel #+# #+# */
/* Updated: 2024/01/18 15:03:37 by aoizel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void spot_operators(t_wordlst *wordlst)
{
while (wordlst->next)
{
if (wordlst->type == OPERATOR && !ft_strcmp(wordlst->word, "|"))
wordlst->type = PIPE;
if (wordlst->type == OPERATOR && !ft_strcmp(wordlst->word, "<"))
wordlst->type = REDIR_IN;
if (wordlst->type == OPERATOR && !ft_strcmp(wordlst->word, ">"))
wordlst->type = REDIR_OUT;
if (wordlst->type == OPERATOR && !ft_strcmp(wordlst->word, ">>"))
wordlst->type = REDIR_APPEND;
if (wordlst->type == OPERATOR && !ft_strcmp(wordlst->word, "<<"))
wordlst->type = REDIR_HEREDOC;
if (wordlst->type == REDIR_IN || wordlst->type == REDIR_OUT
|| wordlst->type == REDIR_APPEND)
wordlst->next->type = REDIR_FILE;
if (wordlst->type == REDIR_HEREDOC)
wordlst->next->type = DELIMITER;
wordlst = wordlst->next;
}
}
int spot_builtin(t_wordlst *wordlst, t_shell *shell)
{
int i;
i = 0;
while (shell->builtins[i])
{
if (!ft_strcmp(wordlst->word, shell->builtins[i]))
{
wordlst->type = BUILTIN + i;
return (0);
}
i++;
}
return (-1);
}
void spot_words(t_shell *shell)
{
int first;
t_wordlst *wordlst;
first = 1;
wordlst = shell->wordlst;
while (wordlst)
{
if (wordlst->type == WORD && first == 1)
{
if (spot_builtin(wordlst, shell) == -1)
wordlst->type = CMD;
first = 0;
}
else if (wordlst->type == WORD)
wordlst->type = ARG;
if (wordlst->type == PIPE)
first = 1;
wordlst = wordlst->next;
}
}