-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_checkers.c
executable file
·75 lines (68 loc) · 1.24 KB
/
utils_checkers.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
64
65
66
67
68
69
70
71
72
73
74
75
#include "minishell.h"
int ft_isspace(char c)
{
if ((c >= 9 && c <= 13) || c == ' ')
return (1);
return (0);
}
int ft_ismetachar(char c)
{
if (c >= 7 && c <= 13)
return (1);
if (c >= 33 && c <= 47)
return (1);
if (c >= 57 && c <= 64)
return (1);
if (c >= 91 && c <= 96)
return (1);
if (c >= 123 && c <= 126)
return (1);
return (0);
}
int has_output(char *cmd)
{
if (!ft_strncmp(cmd, "pwd", 3) && ft_strlen(cmd) == 3)
return (1);
else if (!ft_strncmp(cmd, "env", 3) && ft_strlen(cmd) == 3)
return (1);
else if (!ft_strncmp(cmd, "echo", 4) && ft_strlen(cmd) == 4)
return (1);
return (0);
}
int check_pipe(t_sh *cmd)
{
char *tmp;
tmp = ft_strtrim(cmd->prompt, " ");
if (tmp[0] == '|' || tmp[ft_strlen(tmp) - 1] == '|')
{
ft_perror(2, NULL, PIPE);
ft_free(&tmp);
return (1);
}
ft_free(&tmp);
return (0);
}
int check_quote(char *input)
{
int i;
int d_quote;
int s_quote;
d_quote = 0;
s_quote = 0;
i = 0;
while (input[i])
{
if (input[i] == 39 && !s_quote && !d_quote)
s_quote++;
else if (input[i] == 39 && !d_quote)
s_quote--;
else if (input[i] == '"' && !s_quote && !d_quote)
d_quote++;
else if (input[i] == '"' && !s_quote)
d_quote--;
i++;
}
if (s_quote || d_quote)
return (1);
return (0);
}