-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_parse.c
More file actions
63 lines (56 loc) · 1.7 KB
/
ft_parse.c
File metadata and controls
63 lines (56 loc) · 1.7 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sid-bell <sid-bell@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/04 00:33:37 by sid-bell #+# #+# */
/* Updated: 2019/02/24 02:47:14 by sid-bell ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void ft_free_args(t_params *params)
{
char **arg;
arg = params->args;
while (*arg)
{
free(*arg);
arg++;
}
free(params->args);
}
static void ft_helper(char *command, t_params *params)
{
char *cmd;
cmd = params->args[0];
if (params->args && cmd)
{
if (ft_isbuilt_in(cmd))
ft_built_in(cmd, params, &command);
else
ft_execute(cmd, params);
}
}
void ft_parse(char *command, t_params *params)
{
char *str;
char *tmp;
str = ft_getvars(command, params);
tmp = str;
str = ft_gethome(str, params);
free(tmp);
str = ft_joinargs(&str, NULL);
str = ft_strrev(str);
str = ft_joinargs(&str, NULL);
str = ft_strrev(str);
tmp = str;
str = ft_remove_wsapces(str);
free(tmp);
tmp = str;
params->args = ft_strsplit(str, -1);
free(str);
ft_helper(command, params);
ft_free_args(params);
}