-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_utils_three.c
95 lines (88 loc) · 1.82 KB
/
find_utils_three.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
#include "minishell.h"
void init_find_for_split(t_source *src)
{
src->foundpipe = 0;
src->npipe = 0;
src->nred = 0;
src->dquotes = 0;
src->foundred = 0;
src->squotes = 0;
}
void find_for_split(char *cmd, t_source *src)
{
int i;
i = 0;
init_find_for_split(src);
while (cmd[i] != '\0')
{
if (cmd[i] == '|' && src->dquotes == 0
&& src->squotes == 0 && src->aslash == 0)
{
src->foundpipe = 1;
src->npipe++;
}
else if ((cmd[i] == '>' || cmd[i] == '<') && src->dquotes == 0
&& src->squotes == 0 && src->aslash == 0)
{
src->foundred = 1;
src->nred++;
}
finding_quotes_split(cmd, i, src);
i++;
}
}
int find_equal_length(char **envp, int c, int b)
{
int length;
length = 0;
while (envp[c][b] != '=' && envp[c][b] != '\0')
{
b++;
length++;
}
return (length);
}
int finding_quotes_split(char *s, int i, t_source *src)
{
if (s[i] == '\"' && i == 0)
src->dquotes = 1;
else if (s[i] == '\'' && i == 0 && src->dquotes == 0)
src->squotes = 1;
else if (s[i] == '\"' && src->squotes == 0 && src->aslash == 0)
{
if (src->dquotes == 0)
{
src->dquotes = 1;
}
else
src->dquotes = 0;
}
else if (s[i] == '\'' && src->dquotes == 0)
{
if (src->squotes == 0)
src->squotes = 1;
else
src->squotes = 0;
}
finding_aslash_split(s, i, src);
return (0);
}
int finding_aslash_split(char *s, int i, t_source *src)
{
if (s[i] == '\\' && s[i + 1] == '\'' && src->dquotes == 1)
src->aslash = 0;
else if (s[i] == '\\' && (s[i + 1] == '\"' || s[i + 1] == '\\'
|| s[i + 1] == '\'' || s[i + 1] == '$' || s[i + 1] == '|')
&& src->aslash == 0 && src->squotes == 0 && src->dquotes == 0)
src->aslash = 1;
else if (s[i] == '\\' && (src->dquotes == 0 && src->squotes == 0))
{
if (ft_isascii(s[i + 1]) == 0)
src->founderror = 1;
else
return (1);
}
else
src->aslash = 0;
return (0);
}