WIP parsing expansions
This commit is contained in:
69
srcs/parsing/expansions/words_expansions.c
Normal file
69
srcs/parsing/expansions/words_expansions.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* words_expansions.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/07 04:36:52 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
enum e_in_quote_state
|
||||
{
|
||||
NOT_IN = 0,
|
||||
IN_QUOTES = '\'',
|
||||
IN_DQUOTES = '\"'
|
||||
};
|
||||
|
||||
t_list *ft_lstnew_generic(size_t lst_sizse, size_t content_size);
|
||||
t_list *expand_token(t_token *t);
|
||||
char *rejoin_after_expand(t_list *expand_lst);
|
||||
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)
|
||||
// 2 - strjoin() le tout
|
||||
// 3 - split avec un ft_strplit() modifié (ne splitant pas dans les quotes)
|
||||
// 4 - creer un token T_WORD pour chaque *string du **split_arr
|
||||
// (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 *t)
|
||||
{
|
||||
void *tmp_expand;
|
||||
char **tmp_split;
|
||||
|
||||
while (t)
|
||||
{
|
||||
if (t->id == T_WORD)
|
||||
{
|
||||
// 1
|
||||
tmp_expand = expand_token(t);
|
||||
if (!tmp_expand)
|
||||
return (0);
|
||||
if (((t_list*)tmp_expand)->next)
|
||||
{
|
||||
// 2
|
||||
tmp_expand = rejoin_after_expand(tmp_expand);
|
||||
if (!tmp_expand)
|
||||
return (0);
|
||||
// 3 WIP PLACEHOLDER, MUST WRITE A ft_split_quoted() FOR NO SPLIT IN QUOTES
|
||||
tmp_split = ft_split(tmp_expand, ' ');
|
||||
free(tmp_expand);
|
||||
if (!tmp_split)
|
||||
return (0);
|
||||
// 4
|
||||
if (!new_token_for_each_field(tmp_split, &t))
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
ft_lstclear((t_list **)&tmp_expand, free);
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
Reference in New Issue
Block a user