refactoring parsing (wip)

This commit is contained in:
LuckyLaszlo
2021-12-11 04:27:57 +01:00
parent 9322ec9ec9
commit d3d55386d9
4 changed files with 48 additions and 36 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
/* Updated: 2021/11/30 18:35:59 by lperrey ### ########.fr */
/* Updated: 2021/12/10 19:51:33 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,7 @@
t_list *expand_token(char *content);
char *rejoin_after_expand(t_list *expand_lst);
int new_token_for_each_field(char **fields, t_token **t);
int new_token_for_each_field(char **fields, t_token *t);
// 1 - chaque bout dans un element d'une t_list
// (telle quelle si non expand, ou VARIABLE de env)
@@ -25,28 +25,43 @@ int new_token_for_each_field(char **fields, t_token **t);
// (ft_lstadd_front() sur le token original, puis set le token orignal à :
// t->id = 0 ; free(t->content) ; t->content = NULL ; pour qu'il soit ignoré sur la suite du parsing)
int words_expansions(t_token *token_list)
int expansions(t_token *t, t_cmd **pipeline)
{
while (token_list)
int i;
t_token *next_token;
i = 0;
while (t)
{
if (token_list->id == T_WORD)
token_expansions(&token_list);
token_list = token_list->next;
if (t->id == '|')
i++;
if (!pipeline[i]->error && t->id == T_WORD)
{
next_token = t->next;
if (!token_expansions(t))
{
pipeline[i]->error = EXIT_EXPANSION;
}
while (t != next_token)
t = t->next;
}
else
t = t->next;
}
return (1);
}
int token_expansions(t_token **t)
int token_expansions(t_token *t)
{
void *tmp;
char **tmp_split;
// 1
tmp = expand_token((*t)->content);
tmp = (t_list*)expand_token(t->content);
if (!tmp)
return (0);
// 2
tmp = rejoin_after_expand(tmp);
tmp = (char*)rejoin_after_expand(tmp);
if (!tmp)
return (0);
// 3
@@ -55,7 +70,7 @@ int token_expansions(t_token **t)
if (!tmp_split)
return (0);
// 4
tmp = ft_dup_2d_arr(tmp_split, (t_dup_f)ft_strdup_quotes);
tmp = (char**)ft_dup_2d_arr(tmp_split, (t_dup_f)ft_strdup_quotes);
ft_free_2d_arr(tmp_split);
tmp_split = tmp;
if (!tmp_split)