-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_choose.c
executable file
·84 lines (76 loc) · 2.32 KB
/
ft_choose.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_choose.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbourdon <pbourdon@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/07/04 17:45:28 by pbourdon #+# #+# */
/* Updated: 2016/09/03 13:32:39 by pbourdon ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_search_file(char *arg)
{
return (arg);
}
char *ft_get_file(char *arg)
{
char *tmp;
int index;
int index2;
index = 1;
index2 = 0;
tmp = malloc(sizeof(char) * ft_strlen(arg) + 1);
while (arg[index] != '\0' && arg[index] != ' ' && arg[index] != '\t')
{
tmp[index2] = arg[index];
index++;
index2++;
}
tmp[index2] = '\0';
return (ft_search_file(tmp));
}
char **ft_init_tab(char *arg)
{
char **tab;
int index;
int index2;
tab = malloc(sizeof(char *) * ft_strlen(arg));
index2 = 0;
index = ft_strlen(ft_get_file(arg));
while (arg[index] != '\0')
{
tab[index2][0] = arg[index];
tab[index2][1] = '\0';
index++;
index2++;
}
return (tab);
}
t_dlist *ft_choose(char *arg, t_dlist *list)
{
int index;
index = 0;
while (arg[index] == ' ' || arg[index] == '\t' ||
arg[index] == '\n' || arg[index] == '\r')
index++;
if (ft_strncmp("cd", arg, 2) == 0)
ft_run_cd(arg, list, NULL, NULL);
else if (ft_strncmp("echo", arg, 4) == 0)
ft_run_echo(arg, list);
else if (ft_strncmp("setenv", arg, 6) == 0)
ft_run_setenv(arg, list);
else if (ft_strncmp("env", arg, 3) == 0)
ft_display_list(list);
else if (ft_strncmp("unsetenv", arg, 8) == 0)
ft_run_unsetenv(arg + 8, list);
else if (ft_strncmp("exit", arg, 4) == 0 && ft_strlen(arg) == 4)
{
ft_delete_list(&list);
return (list);
}
else if (ft_check_arg(arg + index, list, 0, ft_boucle(arg)) == 0)
ft_error(arg, 3);
return (list);
}