-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.c
63 lines (56 loc) · 1.72 KB
/
misc.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* misc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ekinnune <ekinnune@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 12:08:01 by ekinnune #+# #+# */
/* Updated: 2023/07/18 13:57:07 by ekinnune ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int syntax_error(void)
{
write(2, "MINISHELL: syntax error\n", 24);
return (-1);
}
int count_quotes(char *input)
{
int i;
int j;
i = 0;
j = 0;
while (*input)
{
if (*input == '\'' && !(j % 2))
i++;
if (*input == '\"' && !(i % 2))
j++;
input++;
}
if (i % 2 + j % 2)
return (syntax_error());
return (0);
}
t_token *handle_name_symbol(const char *input)
{
return (is_progname(input));
}
t_token *handle_special_symbol(const char *input)
{
if (*input == '\'' || *input == '"')
return (is_quote(input));
else if (*input == '<' | *input == '>')
return (is_redir(input));
else if (*input == '|')
return (is_pipe(input));
else
return (NULL);
}
int special_symbol(char input)
{
return (input == '>' | input == '<'
| input == '|' | input == '\'' | input == '"'
| input == ' ' | input == '\t' | input == '\0');
}