-
Notifications
You must be signed in to change notification settings - Fork 0
/
min_expand_two.c
executable file
·81 lines (74 loc) · 1.95 KB
/
min_expand_two.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* min_expand_two.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: potero-d <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/01 12:43:38 by potero-d #+# #+# */
/* Updated: 2022/08/01 12:48:49 by potero-d ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char *change_aux(t_myenv **myenv, int *len, char *key, char *extra)
{
t_myenv *env;
char *print;
char *aux;
env = *myenv;
while (env)
{
if (ft_strcmp(key, env->key) == 0)
{
aux = ft_strdup(env->value);
*len = ft_strlen(aux);
if (extra)
{
print = ft_strjoin(aux, extra);
free(extra);
}
else
print = ft_strdup(aux);
free(aux);
return (print);
}
env = env->next;
}
return (0);
}
static char *change_aux_two(char *extra)
{
char *print;
if (extra == 0)
{
print = malloc(sizeof(char *) * 1);
print[0] = 0;
}
else
print = ft_strdup(extra);
return (print);
}
char *change_str(char *str, t_myenv **myenv, int *len)
{
char *key;
char *extra;
char *print;
int i;
extra = 0;
key = ft_strchr(str, '$') + 1;
i = 0;
while (key[i])
{
if (key[i] == 39 || key[i] == 34 || key[i] == '$' || key[i] == ' ')
{
extra = ft_strdup(ft_strchr(key, key[i]));
key[i] = 0;
break ;
}
i++;
}
print = change_aux(myenv, len, key, extra);
if (print == 0)
print = change_aux_two(extra);
return (print);
}