-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.c
More file actions
57 lines (53 loc) · 2.01 KB
/
errors.c
File metadata and controls
57 lines (53 loc) · 2.01 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aylaaouf <aylaaouf@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/11 10:40:46 by ayelasef #+# #+# */
/* Updated: 2025/07/13 00:34:22 by aylaaouf ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int check_syntax(t_token *tokens)
{
t_token *current;
if (!tokens)
return (0);
current = tokens;
if (current->type == TOKEN_PIPE)
return (printf("bash: syntax error near unexpected token `|'\n"), 0);
while (current)
{
if (current->type == TOKEN_PIPE && (!current->next
|| current->next->type == TOKEN_PIPE))
return (printf("bash: syntax error near unexpected token `|'\n"),
0);
else if ((current->type == TOKEN_OUTPUT || current->type == TOKEN_APPEND
|| current->type == TOKEN_INPUT
|| current->type == TOKEN_HEREDOC) && (!current->next
|| (current->next->type != TOKEN_WORD
&& current->next->type != TOKEN_SQUOTE
&& current->next->type != TOKEN_DQUOTE)))
return (printf("bash: syntax error near unexpected token `%s'\n",
current->value), 0);
current = current->next;
}
return (1);
}
void is_not_found(char *cmnd)
{
if (ft_strchr(cmnd, '/'))
{
write(2, "minishell: ", 11);
write(2, cmnd, ft_strlen(cmnd));
write(2, ": No such file or directory\n", 28);
}
else
{
write(2, "minishell: ", 11);
write(2, cmnd, ft_strlen(cmnd));
write(2, ": command not found\n", 20);
}
}