|
|
@ -24,32 +24,29 @@ int file_error(char *cmd, char *file, char *msg) |
|
|
|
return (0); |
|
|
|
} |
|
|
|
|
|
|
|
char *get_var_value(t_datas *datas, char **line, int *name_len) |
|
|
|
char *get_var_value(t_datas *datas, char **line, int name_len) |
|
|
|
{ |
|
|
|
int i; |
|
|
|
char **env; |
|
|
|
char *name; |
|
|
|
char *value; |
|
|
|
|
|
|
|
i = 1; |
|
|
|
while (ft_isalpha((*line)[i]) || ft_isdigit((*line)[i]) || (*line)[i] == '_') |
|
|
|
i++; |
|
|
|
name = ft_substr(*line, 1, i - 1); |
|
|
|
name = ft_substr(*line, 1, name_len - 1); |
|
|
|
i = 0; |
|
|
|
*name_len = ft_strlen(name); |
|
|
|
value = NULL; |
|
|
|
while (datas->envp[i] && !value) |
|
|
|
{ |
|
|
|
env = ft_split(datas->envp[i], '='); |
|
|
|
if (!ft_strncmp(name, env[0], *name_len + 1)) |
|
|
|
if (!ft_strncmp(name, env[0], name_len + 1)) |
|
|
|
value = (free(env[0]), env[1]); |
|
|
|
else if (++i) |
|
|
|
ft_free_split(env); |
|
|
|
} |
|
|
|
if (!datas->envp[i]) |
|
|
|
value = strdup(""); |
|
|
|
else |
|
|
|
free(name); |
|
|
|
if (value) |
|
|
|
free(env); |
|
|
|
else |
|
|
|
value = strdup(""); |
|
|
|
return (value); |
|
|
|
} |
|
|
|
|
|
|
@ -65,12 +62,18 @@ int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i) |
|
|
|
name_len = 2; |
|
|
|
} |
|
|
|
else |
|
|
|
value = get_var_value(datas, line, &name_len); |
|
|
|
{ |
|
|
|
name_len = 1; |
|
|
|
while (ft_isalpha((*line)[name_len]) \ |
|
|
|
|| ft_isdigit((*line)[name_len]) || (*line)[name_len] == '_') |
|
|
|
name_len++; |
|
|
|
value = get_var_value(datas, line, name_len); |
|
|
|
} |
|
|
|
i = 0; |
|
|
|
while (value[i]) |
|
|
|
tmp[tmp_i++] = value[i++]; |
|
|
|
tmp[tmp_i] = 0; |
|
|
|
*line += name_len + 1; |
|
|
|
*line += name_len; |
|
|
|
free(value); |
|
|
|
return (tmp_i); |
|
|
|
} |
|
|
|