-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplft.c
More file actions
104 lines (94 loc) · 2.35 KB
/
complft.c
File metadata and controls
104 lines (94 loc) · 2.35 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
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* complft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccharrie <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/06 18:28:07 by ccharrie #+# #+# */
/* Updated: 2018/02/05 15:55:36 by ccharrie ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_changevarvalue(t_env *env, char *newvalue)
{
ft_strdel(&env->value);
env->value = ft_strdup(newvalue);
}
t_env *ft_putpath(t_env *env)
{
char buf[BUF_SIZE];
if (getcwd(buf, BUF_SIZE))
{
ft_putformat(getcwd(buf, BUF_SIZE), CYAN, NULL, "BOLD");
ft_putformat(" ➜ ", GREEN, NULL, "BOLD");
}
else
{
ft_putformat("Your path doesn't exist anymore, let's go home ! 😃 \n",
RED, NULL, "BOLD");
env = ft_gohome(env);
env = ft_putpath(env);
}
return (env);
}
t_env *ft_setvarvalue(t_env *env, char **args)
{
t_env *begin;
begin = env;
while (env)
{
if (ft_strcmp(args[1], env->name) == 0)
{
ft_strdel(&env->value);
env->value = ft_strdup(args[2]);
break ;
}
env = env->next;
}
env = begin;
return (env);
}
t_env *ft_unsetvar(char **args, t_env *env)
{
t_env *begin;
t_env *before;
begin = env;
before = NULL;
while (env)
{
if (ft_strcmp(env->name, args[1]) == 0)
{
before->next = env->next;
ft_strdel(&env->name);
ft_strdel(&env->value);
free(env);
break ;
}
before = env;
env = env->next;
}
env = begin;
return (env);
}
char **getpath(t_env *env)
{
char **path;
t_env *begin;
path = NULL;
begin = env;
while (env)
{
if (ft_strcmp("PATH", env->name) == 0)
{
path = ft_strsplit(env->value, ':');
break ;
}
env = env->next;
}
if (env == NULL)
ft_putformat("error : command not found, everyone make mistakes 😉\n",
RED, NULL, "BOLD");
env = begin;
return (path);
}