-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_syntax.c
More file actions
64 lines (59 loc) · 1.99 KB
/
check_syntax.c
File metadata and controls
64 lines (59 loc) · 1.99 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_syntax.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: almelo <almelo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 14:37:44 by almelo #+# #+# */
/* Updated: 2023/04/06 14:38:27 by almelo ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int handle_append_syntax(t_token *curr, t_token *prev)
{
if (prev == NULL || curr->next->next == NULL
|| curr->next->label != WORD || prev->label != WORD)
{
printf("minishell: syntax error near unexpected token `>>'\n");
return (2);
}
return (0);
}
int handle_heredoc_syntax(t_token *curr, t_token *prev)
{
if (prev == NULL || curr->next->next == NULL
|| curr->next->next->label != WORD || prev->label != WORD)
{
printf("minishell: syntax error near unexpected token `<<'\n");
return (2);
}
return (0);
}
int check_syntax(t_tokenl *token_lst)
{
t_token *curr;
t_token *prev;
prev = NULL;
curr = token_lst->head;
while (curr)
{
if (curr->label == PIPE || curr->label == IN || curr->label == OUT)
{
if (prev == NULL || curr->next == NULL
|| curr->next->label != WORD
|| prev->label != WORD)
{
printf("minishell: syntax error\n");
return (2);
}
}
else if (curr->label == APPEND)
return (handle_append_syntax(curr, prev));
else if (curr->label == HEREDOC)
return (handle_heredoc_syntax(curr, prev));
prev = curr;
curr = curr->next;
}
return (0);
}