-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_flag.c
More file actions
96 lines (87 loc) · 2.5 KB
/
process_flag.c
File metadata and controls
96 lines (87 loc) · 2.5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_flag.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtacnet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/18 12:42:52 by mtacnet #+# #+# */
/* Updated: 2017/08/30 12:32:45 by mtacnet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void process_bin(char **tab_arg, t_elem **lst_env, t_elem **lst_path)
{
int i;
char **tmp_env;
t_elem *head;
i = 0;
tmp_env = NULL;
head = (*lst_env);
while ((*lst_env) != NULL)
{
i++;
(*lst_env) = (*lst_env)->next;
}
(*lst_env) = head;
tmp_env = list_to_tab(lst_env);
recup_param(lst_path, tab_arg, tmp_env);
free(tmp_env);
}
void process_flag_i(t_elem **lst_path, char **tab_arg)
{
t_elem *tmp_lst;
char **tmp_tab;
tmp_lst = new_list();
tmp_tab = NULL;
if (tab_arg[2] == NULL)
return ;
tab_to_list(&tmp_lst, tab_arg);
supp_elem(&tmp_lst, "env");
supp_elem(&tmp_lst, "-i");
tmp_tab = list_to_tab(&tmp_lst);
recup_param(lst_path, tmp_tab, NULL);
freelst(&tmp_lst);
freelst(lst_path);
free(tmp_tab);
}
static void process_tmp_bin(char **tab_arg, t_elem **cpy_env,
t_elem **lst_path, int i)
{
char **tmp_env;
int j;
tmp_env = NULL;
tmp_env = list_to_tab(cpy_env);
if ((j = parsing_cmd(tab_arg[i])) != 0)
check_cmd(j, cpy_env, &tab_arg[i], lst_path);
else
recup_param(lst_path, &tab_arg[i], tmp_env);
free(tmp_env);
}
void process_tmp_env(char **tab_arg, t_elem **lst_env,
t_elem **lst_path)
{
t_elem *cpy_env;
int i;
int j;
int k;
i = 1;
j = 0;
k = 0;
cpy_env = new_list();
cpy_lst(&cpy_env, lst_env);
while (tab_arg[i] && tab_arg[i][0] != '\0')
{
if (ft_strchr(tab_arg[i], '=') != NULL &&
verif_list(&cpy_env, tab_arg[i]) == 0)
push_back(&cpy_env, tab_arg[i]);
if (ft_strchr(tab_arg[i], '=') == NULL && j == 0)
j = i;
i++;
}
if (j == 0)
view_list(&cpy_env);
else
process_tmp_bin(tab_arg, &cpy_env, lst_path, j);
freelst(&cpy_env);
}