bugfix expansions

This commit is contained in:
LuckyLaszlo
2021-11-08 04:02:43 +01:00
parent 0a5c7545c1
commit 0ae84abb14
4 changed files with 37 additions and 29 deletions

View File

@@ -27,6 +27,7 @@ t_list *expand_token(t_token *t)
{
int in_quotes;
int i;
int i_exp;
t_list head;
t_list *expand;
@@ -39,7 +40,8 @@ t_list *expand_token(t_token *t)
if (t->content[i] == '$')
{
expand->next = ret_parameter_expansion(t, &i);
if (!expand->next)
expand = expand->next;
if (!expand)
{//todo wrap
perror("expand_token() error");
return (ft_lstclear(&head.next, free));
@@ -48,12 +50,14 @@ t_list *expand_token(t_token *t)
else
{
expand->next = ft_lstnew_generic(sizeof(t_list), ft_strlen(&t->content[i]) + 1);
if (!expand->next)
expand = expand->next;
i_exp = 0;
if (!expand)
{//todo wrap
perror("expand_token() error");
return (ft_lstclear(&head.next, free));
}
while (t->content[i] && (t->content[i] != '$' && in_quotes != IN_QUOTES))
while (t->content[i] && (t->content[i] != '$' || in_quotes == IN_QUOTES))
{
// quoting
if (t->content[i] == '\'' && in_quotes != IN_DQUOTES)
@@ -63,7 +67,7 @@ t_list *expand_token(t_token *t)
else
in_quotes = IN_QUOTES;
}
i++;
((char *)expand->content)[i_exp++] = t->content[i++];
}
}
}
@@ -88,7 +92,7 @@ static t_list *ret_parameter_expansion(t_token *t, int *i)
(*i)++; // skip '$'
if (t->content[*i] == '?')
{
i++;
(*i)++;
expand->content = ft_itoa(g_all->last_exit_status);
return (ft_retp_free(expand, tmp, free));
}
@@ -100,7 +104,7 @@ static t_list *ret_parameter_expansion(t_token *t, int *i)
}
i_tmp = 0;
while (t->content[*i] == '_' || ft_isalnum(t->content[*i]))
tmp[i_tmp++] = t->content[*i++];
tmp[i_tmp++] = t->content[(*i)++];
expand->content = getenv(tmp);
free(tmp);
if (expand->content)