-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_parser.c
126 lines (117 loc) · 2.52 KB
/
pre_parser.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pre_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebalgruu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/27 01:28:55 by ebalgruu #+# #+# */
/* Updated: 2021/11/27 01:28:56 by ebalgruu ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int pre_pre(char *str)
{
int i;
i = 0;
if (str[i] == '|')
return (1);
while (str[i])
{
if (str[i] == '|')
i++;
while (str[i] == ' ')
i++;
if (!str[i] || str[i] == '|')
return (1);
while (str[i] && str[i] != '|')
{
if (str[i] == '\'')
ft_gap(str, &i);
else if (str[i] == '\"')
ft_gap2(str, &i);
else
i++;
}
}
return (0);
}
static void find_red(char *str, int *i)
{
while (str[*i] && str[*i] != '<' && str[*i] != '>')
{
if (str[*i] == '\'')
ft_gap(str, i);
else if (str[*i] == '\"')
ft_gap2(str, i);
else
(*i)++;
}
}
int pre_pre2(char *str)
{
int i;
i = 0;
find_red(str, &i);
while (str[i])
{
if (str[i])
i++;
if (str[i] == str[i - 1])
i++;
while (str[i] == ' ')
i++;
if (!str[i] || str[i] == '|' || str[i] == '<' || str[i] == '>')
return (1);
find_red(str, &i);
}
return (0);
}
int check_one_cmd(char *str, int *i)
{
while (str[*i] && str[*i] != '|')
{
if (str[*i] == '>' || str[*i] == '<')
{
(*i)++;
if (str[*i] == str[*i - 1])
(*i)++;
while (str[*i] == ' ')
(*i)++;
if (!str[*i] || str[*i] == '>' || str[*i] == '<' || str[*i] == '|')
return (1);
}
else if (str[*i] == '\'')
ft_gap(str, i);
else if (str[*i] == '\"')
ft_gap2(str, i);
else
(*i)++;
}
return (0);
}
int pre_parse(char *str)
{
int i;
if (pre_pre(str) || pre_pre2(str))
return (1);
i = 0;
while (str[i])
{
while (str[i] == ' ')
i++;
if (!str[i] || str[i] == '|')
return (1);
if (check_one_cmd(str, &i))
return (1);
if (str[i] == '|')
{
i++;
if (!str[i])
return (1);
}
else
return (0);
}
return (0);
}