-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.c
More file actions
79 lines (74 loc) · 2.12 KB
/
operators.c
File metadata and controls
79 lines (74 loc) · 2.12 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operators.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/03 11:05:47 by mbani #+# #+# */
/* Updated: 2020/12/11 12:30:50 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
int operators(char **line, int i, char **op)
{
int j;
j = 0;
op[0] = malloc(3);
if (line[0][i] == '>' && line[0][i + 1] == '>')
{
line[0][i] = '\0';
line[0][i + 1] = '\0';
op[0][0] = '>';
op[0][1] = '>';
op[0][2] = '\0';
j = 2;
}
else
{
op[0][0] = line[0][i];
op[0][1] = '\0';
line[0][i] = '\0';
j = 1;
}
return (j);
}
enum e_type operators_check(char *op)
{
if (op[0] == '|')
return (pipee);
if (op[0] == ';')
return (semicolumn);
if (op[0] == '<')
return (input_red);
if (op[0] == '>' && op[1] == '\0')
return (output_red);
if (op[0] == '>' && op[1] == '>')
return (append_output);
return (arg);
}
int separators_check(char **tmp, int *i, char **op, int *j)
{
if ((tmp[0][*i] == ' ' || tmp[0][*i] == '\t') || ((tmp[0][*i] == ';' ||
tmp[0][*i] == '|' || tmp[0][*i] == '<' ||
tmp[0][*i] == '>') && not_escaped(tmp[0], *i)))
{
if ((tmp[0][*i] == ' ' || tmp[0][*i] == '\t')
&& !not_escaped(tmp[0], *i))
{
*i += 1;
return (1);
}
if (((tmp[0][*i] == ';' ||
tmp[0][*i] == '|' || tmp[0][*i] == '<' ||
tmp[0][*i] == '>') && not_escaped(tmp[0], *i)))
{
*i += operators(&tmp[0], *i, &op[0]);
*j = 1;
return (0);
}
tmp[0][*i] = '\0';
return (0);
}
return (10);
}