-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax_error.c
More file actions
82 lines (77 loc) · 2.41 KB
/
syntax_error.c
File metadata and controls
82 lines (77 loc) · 2.41 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntax_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ferenc <ferenc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/07 16:09:56 by ferenc #+# #+# */
/* Updated: 2025/07/24 16:54:16 by ferenc ### ########.fr */
/* */
/* ************************************************************************** */
#include "Minishell.h"
static int syntax_pipe(t_token *tokens, t_shell *shell)
{
if (!tokens || !tokens->com)
return (0);
if (tokens->com[0] && is_pipe(tokens->com[0]) && !tokens->quoted)
{
printf("*** Syntax error: Missing Command before |. ***\n");
shell->exit_stat = 127;
return (1);
}
while (tokens)
{
if (tokens->com && is_pipe(tokens->com[0]) && !tokens->quoted)
{
if (!tokens->next || is_meta(tokens->next->com[0])
|| (tokens->com[1] && is_pipe(tokens->com[1])))
{
printf("*** Syntax error: Missing Command after |. ***\n");
shell->exit_stat = 127;
return (1);
}
}
tokens = tokens->next;
}
return (0);
}
static int syntax_redir(t_token *tokens, t_shell *shell)
{
while (tokens)
{
if (tokens->com && (tokens->com[0] == '>' || tokens->com[0] == '<')
&& !tokens->quoted)
{
if (tokens->com[1] && (tokens->com[1] == '>'
|| tokens->com[1] == '<') && tokens->com[2]
&& (tokens->com[2] == '>' || tokens->com[2] == '<'))
{
printf("*** Syntax error: Multiple Redirection. ***\n");
shell->exit_stat = 127;
return (4);
}
if (!tokens->next || is_meta(tokens->next->com[0])
|| tokens->com[1] == '|')
{
printf("*** Syntax error: Missing Target ***\n");
shell->exit_stat = 127;
return (4);
}
}
tokens = tokens->next;
}
return (0);
}
int syntax_error(t_token **tokens, t_shell *shell)
{
int len;
len = 0;
if (len == 0)
len = syntax_pipe(*tokens, shell);
if (len == 0)
len = syntax_redir(*tokens, shell);
if (len > 0)
deallocate(tokens);
return (len);
}