/
do_stuff.c
56 lines (51 loc) · 1.62 KB
/
do_stuff.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_stuff.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbahus <jbahus@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/09/25 16:31:14 by jbahus #+# #+# */
/* Updated: 2015/10/20 18:49:44 by jbahus ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_minishell.h"
void aff_env(char **env)
{
int i;
i = 0;
while (env[i])
ft_putendl(env[i++]);
}
void do_stuff(char *line, char ***e)
{
int i;
char **split;
i = 0;
split = ft_strsplit(line, ' ');
if (ft_strequ(split[0], "exit"))
{
ft_del_tab_char(split);
ft_strdel(&line);
exit(0);
}
else if (ft_strcmp(split[0], "cd") == 0)
*e = ft_cd(split, *e);
else if (ft_strcmp(split[0], "env") == 0)
{
if (*e)
aff_env(*e);
}
else if (ft_strcmp(split[0], "setenv") == 0)
*e = ft_new_env(*e, split[1]);
else if (ft_strcmp(split[0], "unsetenv") == 0)
*e = ft_del_env(*e, split[1]);
else if (split[0])
ft_check_path(split, *e);
else
{
ft_putstr("zsh: command not found: ");
ft_putendl(split[0]);
}
ft_del_tab_char(split);
}