|
|
@ -3,10 +3,10 @@ |
|
|
|
/* ::: :::::::: */ |
|
|
|
/* lexer.c :+: :+: :+: */ |
|
|
|
/* +:+ +:+ +:+ */ |
|
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/05 11:47:15 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/05/05 13:12:49 by mea ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
@ -85,23 +85,13 @@ int check_register(t_lexer *lex, char **line, char *tmp) |
|
|
|
return (create_token(lex, tmp)); |
|
|
|
} |
|
|
|
|
|
|
|
char *ft_strreplace(char *dest, char *src) |
|
|
|
{ |
|
|
|
int len; |
|
|
|
|
|
|
|
len = ft_strlen(src); |
|
|
|
while (*src) |
|
|
|
*(dest++) = *(src++); |
|
|
|
return (dest); |
|
|
|
} |
|
|
|
|
|
|
|
int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i) |
|
|
|
{ |
|
|
|
int name_len; |
|
|
|
int i; |
|
|
|
char *var_name; |
|
|
|
char *value; |
|
|
|
|
|
|
|
char **env; |
|
|
|
i = 1; |
|
|
|
if ((*line)[1] == '?') |
|
|
|
{ |
|
|
@ -113,7 +103,18 @@ int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i) |
|
|
|
while (ft_isalpha((*line)[i]) || ft_isdigit((*line)[i]) || (*line)[i] == '_') |
|
|
|
i++; |
|
|
|
var_name = ft_substr(*line, 1, i - 1); |
|
|
|
value = getenv(var_name); |
|
|
|
i = 0; |
|
|
|
while (datas->envp[i]) |
|
|
|
{ |
|
|
|
env = ft_split(datas->envp[i], '='); |
|
|
|
if (!ft_strncmp(var_name, env[0], ft_strlen(var_name) + 1)) |
|
|
|
break ; |
|
|
|
i++; |
|
|
|
} |
|
|
|
if (!datas->envp[i]) |
|
|
|
value = strdup(""); |
|
|
|
else |
|
|
|
value = env[1]; |
|
|
|
name_len = ft_strlen(var_name) + 1; |
|
|
|
} |
|
|
|
i = 0; |
|
|
|