-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtins.c
80 lines (71 loc) · 1.26 KB
/
builtins.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
#include "minishell.h"
int msh_echo(struct s_process *ps)
{
int i;
int virgin;
i = 1;
virgin = 0;
!ft_strcmp(ps->args[1], "-n") && (i = 2);
while (ps->args[i])
{
virgin && printf(" ");
printf("%s", ps->args[i]);
virgin++;
i++;
}
!ft_strcmp(ps->args[1], "-n") || printf("\n");
return (1);
}
int export_ps_args(struct s_process *ps)
{
int i;
int ret;
char **key_value;
i = 0;
while (ps->args[++i])
{
if (check_env_syntax(ps->args[i], 0) == 1)
{
key_value = split_env(ps->args[i], '=');
if (!(key_value))
return (0);
ret = dict_set_default(ps->env, key_value[0], key_value[1]);
free(key_value);
}
else
printf(SHELL_NAME": '%s': %s\n",
ps->args[i], "not a valid identifier");
}
return (ret);
}
int msh_export(struct s_process *ps)
{
int ret;
ret = 1;
if (ps->args[1])
ret = export_ps_args(ps);
else
{
ft_lst_sort_bubble(&ps->env, cmp_dict_keys);
ft_lstiter(ps->env, env_dict_print);
}
return (ret);
}
int msh_unset(struct s_process *ps)
{
struct s_dict *d;
int i;
i = 0;
while (ps->args[++i])
{
ft_lst_rm(&ps->env, (d = new_dict(ps->args[i], 0)),
cmp_dict_keys, del_dict);
free(d);
}
return (1);
}
int msh_env(struct s_process *ps)
{
ft_lstiter(ps->env, dict_print);
return (1);
}