-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd3.c
115 lines (104 loc) · 2.85 KB
/
cmd3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mleclair <mleclair@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/18 16:39:32 by mleclair #+# #+# */
/* Updated: 2017/05/19 18:12:07 by mleclair ### ########.fr */
/* */
/* ************************************************************************** */
#include "chell.h"
int cmprevtruc(t_env *env, char **input)
{
int i;
i = ft_strlen(*input);
if (bs_strstr(*input, "&&") != -1 || bs_strstr(*input, "||") != -1)
{
while (i >= 0 && ((*input)[i] != '&' || (*input)[i - 1] != '&')
&& ((*input)[i] != '|' || (*input)[i - 1] != '|'))
--i;
free2(env->inp1, env->inp2);
env->inp1 = ft_strcdup((*input), i - 1);
env->inp2 = ft_strdup((*input) + i + 1);
if ((*input)[i] == '&')
{
oprt_and(env);
return (1);
}
else
{
oprt_or(env);
return (1);
}
}
return (0);
}
int cmprev(char *str, char *tofind)
{
int cut;
cut = bs_strstr(str, tofind);
if (cut == -1)
return (-1);
free2(env()->inp1, env()->inp2);
env()->inp1 = ft_strsub(str, 0, cut);
env()->inp2 = ft_strdup(str + cut + ft_strlen(tofind));
return (1);
}
void extract_rd_output(t_env *env, char *input)
{
int i;
int j;
int u;
i = 0;
while (input[i] && input[i] != '<')
++i;
j = i + 1;
while (input[j] == ' ' || input[j] == '\t')
++j;
u = j;
while (input[j] && ft_isascii(input[j]) && (input[j] != ' ' ||
(input[j] == ' ' && input[j - 1] == '\\')))
++j;
free(env->inp2);
env->inp2 = ft_strcdup(input + u, j - i);
env->inp2[j - i] = 0;
ft_remstr(input, i, j);
free(env->inp1);
env->inp1 = ft_strdup(input);
}
void extract_heredoc(t_env *env)
{
int i;
int j;
i = 0;
while (env->input[i] && env->input[i] != '<')
++i;
j = i + 2;
while (env->input[j] == ' ' || env->input[j] == '\t')
++j;
while (ft_isalpha(env->input[j]))
++j;
free(env->inp2);
env->inp2 = ft_strcdup(env->input + i, j);
ft_remstr(env->input, i, j);
free(env->inp1);
env->inp1 = ft_strdup(env->input);
}
int parserror(t_env *env)
{
int i;
i = 0;
if (strstr_bool("&&&", ft_strdup(env->input), 0) == 1)
i = -1;
if (strstr_bool("|||", ft_strdup(env->input), 0) == 1)
i = -1;
if (strstr_bool("|&|", ft_strdup(env->input), 0) == 1)
i = -1;
if (strstr_bool("&|&", ft_strdup(env->input), 0) == 1)
i = -1;
if (i == -1)
error(-15, NULL, NULL);
return (i);
}