-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_syntax.c
55 lines (52 loc) · 1.9 KB
/
error_syntax.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* error_syntax.c :+: :+: */
/* +:+ */
/* By: sde-rijk <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/01/05 10:25:58 by sde-rijk #+# #+# */
/* Updated: 2022/01/24 13:50:30 by dnoom ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Libft/libft.h"
#include "minishell.h"
#include <stdio.h>
int ft_syntax_error(t_part *parts, int i, t_env *s_env, char *token)
{
if (isatty(STDIN_FILENO))
{
ft_putstr_fd(SHELL_NAME, 2);
ft_putstr_fd(": syntax error near unexpected token `", 2);
ft_putstr_fd(token, 2);
ft_putstr_fd("'\n", 2);
}
else
{
ft_putstr_fd(SHELL_NAME, 2);
ft_print_line_nr(s_env->line_nr);
ft_putstr_fd("syntax error near unexpected token `", 2);
ft_putstr_fd(token, 2);
ft_putstr_fd("'\n", 2);
ft_putstr_fd(SHELL_NAME, 2);
ft_print_line_nr(s_env->line_nr);
ft_putstr_fd("`", 2);
i = print_parts_error(parts);
ft_putstr_fd(parts[i].part, 2);
ft_putstr_fd("'\n", 2);
}
return (2);
}
int ft_invalid_identifier(t_part *parts, int i, t_env *s_env)
{
ft_putstr_fd(SHELL_NAME, 2);
if (isatty(STDIN_FILENO))
ft_putstr_fd(": ", 2);
else
ft_print_line_nr(s_env->line_nr);
ft_putstr_fd(parts[i].part, 2);
ft_putstr_fd(": `", 2);
ft_putstr_fd(parts[i + 1].part, 2);
ft_putstr_fd("': not a valid identifier\n", 2);
return (1);
}