-
Notifications
You must be signed in to change notification settings - Fork 1
/
count_argument.c
69 lines (65 loc) · 1.39 KB
/
count_argument.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
# include "minishell.h"
int count_argument_three(char *s, int **i, t_source *src)
{
if (s[(**i)] == '\"' && (**i) == 0)
src->dquotes = 1;
else if (s[(**i)] == '\'' && (**i) == 0)
src->squotes = 1;
else
finding_quotes2(s, (**i), src);
if ((s[(**i)] == ';' || s[(**i)] == '|') && (src->dquotes == 0
&& src->squotes == 0 && src->aslash == 0) && s[(**i) - 1] != '\\')
return (1);
else
return (0);
}
int count_argument_two(char *s, int *i, int *count, t_source *src)
{
if (count_argument_three(s, &i, src) == 1)
return (1);
if (s[(*i)] == ' ' && src->dquotes == 0 && src->squotes == 0)
{
while (s[(*i)] == ' ')
(*i)++;
if ((s[(*i)] == '|' || s[(*i)] == ';') && src->dquotes == 0
&& src->squotes == 0 && src->aslash == 0 && s[(*i) - 1] != '\\')
return (1);
if (s[(*i)] == '\0' || s[(*i)] == '\n')
return (1);
if (s[(*i)] != '>' && s[(*i)] != '<' && src->tmp == 0)
(*count)++;
else
src->tmp = 0;
}
else if (s[(*i)] == '>' || s[(*i)] == '<')
{
(*count)++;
src->tmp = 1;
(*i)++;
}
else
(*i)++;
return (0);
}
int count_argument(char *s, t_source *src)
{
int i;
int jump;
int count;
i = src->offset;
count = 0;
jump = 0;
if (s[0] == '\n')
return (0);
if (i < 0)
return (0);
if (s[i] == '|')
return (0);
src->tmp = 0;
while (s[i] != '\0' && s[i] != '\n')
{
if (count_argument_two(s, &i, &count, src) == 1)
return (count);
}
return (count);
}