bugfix expansions
This commit is contained in:
@@ -27,6 +27,7 @@ t_list *expand_token(t_token *t)
|
|||||||
{
|
{
|
||||||
int in_quotes;
|
int in_quotes;
|
||||||
int i;
|
int i;
|
||||||
|
int i_exp;
|
||||||
t_list head;
|
t_list head;
|
||||||
t_list *expand;
|
t_list *expand;
|
||||||
|
|
||||||
@@ -39,7 +40,8 @@ t_list *expand_token(t_token *t)
|
|||||||
if (t->content[i] == '$')
|
if (t->content[i] == '$')
|
||||||
{
|
{
|
||||||
expand->next = ret_parameter_expansion(t, &i);
|
expand->next = ret_parameter_expansion(t, &i);
|
||||||
if (!expand->next)
|
expand = expand->next;
|
||||||
|
if (!expand)
|
||||||
{//todo wrap
|
{//todo wrap
|
||||||
perror("expand_token() error");
|
perror("expand_token() error");
|
||||||
return (ft_lstclear(&head.next, free));
|
return (ft_lstclear(&head.next, free));
|
||||||
@@ -48,12 +50,14 @@ t_list *expand_token(t_token *t)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
expand->next = ft_lstnew_generic(sizeof(t_list), ft_strlen(&t->content[i]) + 1);
|
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
|
{//todo wrap
|
||||||
perror("expand_token() error");
|
perror("expand_token() error");
|
||||||
return (ft_lstclear(&head.next, free));
|
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
|
// quoting
|
||||||
if (t->content[i] == '\'' && in_quotes != IN_DQUOTES)
|
if (t->content[i] == '\'' && in_quotes != IN_DQUOTES)
|
||||||
@@ -63,7 +67,7 @@ t_list *expand_token(t_token *t)
|
|||||||
else
|
else
|
||||||
in_quotes = IN_QUOTES;
|
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 '$'
|
(*i)++; // skip '$'
|
||||||
if (t->content[*i] == '?')
|
if (t->content[*i] == '?')
|
||||||
{
|
{
|
||||||
i++;
|
(*i)++;
|
||||||
expand->content = ft_itoa(g_all->last_exit_status);
|
expand->content = ft_itoa(g_all->last_exit_status);
|
||||||
return (ft_retp_free(expand, tmp, free));
|
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;
|
i_tmp = 0;
|
||||||
while (t->content[*i] == '_' || ft_isalnum(t->content[*i]))
|
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);
|
expand->content = getenv(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (expand->content)
|
if (expand->content)
|
||||||
|
|||||||
@@ -28,18 +28,19 @@ int new_token_for_each_field(char **fields, t_token **t)
|
|||||||
while (fields[i])
|
while (fields[i])
|
||||||
{
|
{
|
||||||
insert_lst->next = (t_token *)ft_lstnew_generic(sizeof(*insert_lst), 0);
|
insert_lst->next = (t_token *)ft_lstnew_generic(sizeof(*insert_lst), 0);
|
||||||
if (!insert_lst->next)
|
insert_lst = insert_lst->next;
|
||||||
|
if (!insert_lst)
|
||||||
{//todo wrap
|
{//todo wrap
|
||||||
perror("insert_token_for_each_field() error");
|
perror("insert_token_for_each_field() error");
|
||||||
ft_free_2d_arr(fields);
|
ft_free_2d_arr(fields);
|
||||||
return ((int)ft_lstclear((t_list **)&head.next, NULL));
|
return ((int)ft_lstclear((t_list **)&head.next, NULL));
|
||||||
}
|
}
|
||||||
insert_lst = insert_lst->next;
|
|
||||||
insert_lst->content = fields[i];
|
insert_lst->content = fields[i];
|
||||||
insert_lst->id = T_WORD;
|
insert_lst->id = T_WORD;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
free(fields);
|
free(fields);
|
||||||
*t = insert_tokens(*t, insert_lst);
|
*t = insert_tokens(*t, head.next);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +52,8 @@ static t_token *insert_tokens(t_token *t, t_token *insert_lst)
|
|||||||
t->id = 0;
|
t->id = 0;
|
||||||
free(t->content);
|
free(t->content);
|
||||||
t->content = NULL;
|
t->content = NULL;
|
||||||
|
if (!insert_lst)
|
||||||
|
return (t);
|
||||||
|
|
||||||
tmp = t->next;
|
tmp = t->next;
|
||||||
t->next = insert_lst;
|
t->next = insert_lst;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/07 04:36:52 by lperrey ### ########.fr */
|
/* Updated: 2021/11/08 03:59:02 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -45,8 +45,6 @@ int words_expansions(t_token *t)
|
|||||||
tmp_expand = expand_token(t);
|
tmp_expand = expand_token(t);
|
||||||
if (!tmp_expand)
|
if (!tmp_expand)
|
||||||
return (0);
|
return (0);
|
||||||
if (((t_list*)tmp_expand)->next)
|
|
||||||
{
|
|
||||||
// 2
|
// 2
|
||||||
tmp_expand = rejoin_after_expand(tmp_expand);
|
tmp_expand = rejoin_after_expand(tmp_expand);
|
||||||
if (!tmp_expand)
|
if (!tmp_expand)
|
||||||
@@ -60,9 +58,6 @@ int words_expansions(t_token *t)
|
|||||||
if (!new_token_for_each_field(tmp_split, &t))
|
if (!new_token_for_each_field(tmp_split, &t))
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
ft_lstclear((t_list **)&tmp_expand, free);
|
|
||||||
}
|
|
||||||
t = t->next;
|
t = t->next;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
|
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/07 04:37:30 by lperrey ### ########.fr */
|
/* Updated: 2021/11/08 01:03:29 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -37,13 +37,19 @@ t_cmd **parsing(t_token *token_list)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
// 2.9.1 - 2) Expansion
|
// 2.9.1 - 2) Expansion
|
||||||
|
// TEST TOKENS PRINT
|
||||||
|
ft_putstr_fd("TOKENS LIST :\n-----------\n", 1);
|
||||||
|
ft_lstprint((t_list *)token_list, 1);
|
||||||
|
//
|
||||||
words_expansions(token_list);
|
words_expansions(token_list);
|
||||||
|
//
|
||||||
|
ft_putstr_fd("TOKENS LIST EXPANDED :\n-----------\n", 1);
|
||||||
|
ft_lstprint((t_list *)token_list, 1);
|
||||||
|
|
||||||
// 2.9.1 - 3) Redirection
|
// 2.9.1 - 3) Redirection
|
||||||
|
|
||||||
// Struct CMD fill
|
// Struct CMD fill
|
||||||
|
|
||||||
|
|
||||||
// HUGO WIP
|
// HUGO WIP
|
||||||
// cmd_expansion(cmd_arr, envp);
|
// cmd_expansion(cmd_arr, envp);
|
||||||
// handle_argv(token_list, cmd_arr, cmd_nbr);
|
// handle_argv(token_list, cmd_arr, cmd_nbr);
|
||||||
|
|||||||
Reference in New Issue
Block a user