-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_export.c
More file actions
97 lines (88 loc) · 2.33 KB
/
ft_export.c
File metadata and controls
97 lines (88 loc) · 2.33 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
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/10 12:49:37 by mamoussa #+# #+# */
/* Updated: 2020/12/11 16:42:44 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
size_t search_for_key(char *key, char *value)
{
t_env *current;
current = g_env_head;
while (current)
{
if (!ft_strncmp(current->key, key, ft_strlen(current->key)))
{
g_tmp = current->value;
current->value = ft_strdup(value);
simple_pointer_free(g_tmp);
return (1);
}
current = current->next;
}
return (0);
}
void ft_export_helper(char *ptr)
{
char *key;
char *value;
char *tmp;
t_env *new_node;
t_env *current;
tmp = ptr + 1;
current = g_env_head;
*ptr = '\0';
key = ft_strdup(g_cmd_head->string);
value = ft_strdup(tmp);
if (search_for_key(key, value))
{
simple_pointer_free(key);
simple_pointer_free(value);
*ptr = '=';
return ;
}
new_node = ft_lstnewenv(key, value);
ft_lstadd_backenv(¤t, new_node);
*ptr = '=';
}
size_t export_pipe_checker(void)
{
t_cmd *current;
char *ptr_equ;
ptr_equ = NULL;
current = g_cmd_head;
current = current->next;
while (current)
{
if (current->type == pipee)
return (1);
current = current->next;
}
return (0);
}
void ft_export(void)
{
char *ptr_to_equ;
ptr_to_equ = NULL;
if (ft_strncmp("export", g_cmd_head->string,
ft_strlen(g_cmd_head->string)))
{
ft_error(g_cmd_head->string);
write(2, ": command not found\n", ft_strlen(": command not found\n"));
g_status = 127;
return ;
}
g_cmd_head = g_cmd_head->next;
if (!g_cmd_head || (g_cmd_head->type == semicolumn) ||
(g_cmd_head->type == pipee))
{
print_in_sort();
return ;
}
ft_export_2();
}