-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsing.c
63 lines (57 loc) · 1.62 KB
/
parsing.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abuzdin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 14:47:50 by mthiry #+# #+# */
/* Updated: 2022/08/11 14:43:48 by abuzdin ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void init_all(t_node *tmp, t_cmd *arg, t_input *data)
{
t_cmd *new_con;
while (tmp)
{
tmp = next_elem(tmp);
if (!tmp)
break ;
new_con = init_elem(tmp, data);
if (new_con)
{
new_con->prev = arg;
arg->next = new_con;
arg = arg->next;
}
}
}
t_cmd *parse_cmd(t_input *data)
{
t_cmd *first_elem;
t_cmd *arg;
t_node *tmp;
tmp = data->args;
if (tmp->type == 999)
return (NULL);
while (tmp)
{
first_elem = init_elem(tmp, data);
if (first_elem)
break ;
tmp = next_elem(tmp);
}
if (!first_elem)
return (NULL);
arg = first_elem;
init_all(tmp, arg, data);
return (first_elem);
}
int parsing(t_input *data)
{
data->cmds = parse_cmd(data);
if (!data->cmds || !data->exec)
return (1);
return (0);
}