/
lx_detail.c
56 lines (50 loc) · 1.72 KB
/
lx_detail.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lx_detail.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vjacquie <vjacquie@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/05 12:49:50 by vjacquie #+# #+# */
/* Updated: 2014/03/27 15:23:57 by vjacquie ### ########.fr */
/* */
/* ************************************************************************** */
#include "sh.h"
/*
** main function for the detail lexing
** cut the string with '|', '>', '<' or ">>"
** save the first part and return the second
*/
static char *lx_op(char *str, t_cmd *op, int n)
{
char *tmp;
char *cpy;
int start;
start = 0;
if (n == 1)
start = lx_pos_op(str, "|");
else if (n == 3)
start = lx_pos_op(str, ">");
else if (n == 4)
start = lx_pos_op(str, ">>");
else if (n == 2)
start = lx_pos_op(str, "<");
tmp = ft_strsub(str, 0, start);
lx_add_more(op, lx_new_more(tmp, n));
if (n == 4)
cpy = ft_strsub(str, start + 2, ft_strlen(str) - start);
else
cpy = ft_strsub(str, start + 1, ft_strlen(str) - start);
free(str);
return (cpy);
}
void lx_detail(t_cmd *op)
{
char *str;
str = ft_strdup(op->cmd);
while (lx_is_op(str) > 0)
{
str = lx_op(str, op, lx_is_op(str));
}
lx_add_more(op, lx_new_more(str, 0));
}