redirections WIP
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/13 04:35:06 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/13 10:18:51 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/14 06:01:45 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,6 +20,7 @@ enum e_in_quote_state
|
||||
};
|
||||
static int quote_state_change(int *quote_state, const char *s);
|
||||
|
||||
/* Duplicate a string minus the quoting characters ['] and ["]*/
|
||||
char *ft_strdup_quotes(const char *s)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/13 21:27:20 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/14 10:13:38 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,8 +22,6 @@ enum e_in_quote_state
|
||||
t_list *ft_lstnew_generic(size_t lst_sizse, size_t content_size);
|
||||
t_list *expand_token(char *content);
|
||||
char *rejoin_after_expand(t_list *expand_lst);
|
||||
char **ft_split_quotes(char const *s, char c); // Generic
|
||||
char *ft_strdup_quotes(const char *s); // Generic
|
||||
int new_token_for_each_field(char **fields, t_token **t);
|
||||
|
||||
// 1 - chaque bout dans un element d'une t_list
|
||||
@@ -35,39 +33,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 *t)
|
||||
int words_expansions(t_token *token_list)
|
||||
{
|
||||
void *tmp_expand;
|
||||
char **tmp_split;
|
||||
|
||||
while (t)
|
||||
while (token_list)
|
||||
{
|
||||
if (t->id == T_WORD)
|
||||
{
|
||||
// 1
|
||||
tmp_expand = expand_token(t->content);
|
||||
if (!tmp_expand)
|
||||
return (0);
|
||||
// 2
|
||||
tmp_expand = rejoin_after_expand(tmp_expand);
|
||||
if (!tmp_expand)
|
||||
return (0);
|
||||
// 3
|
||||
tmp_split = ft_split_quotes(tmp_expand, ' ');
|
||||
free(tmp_expand);
|
||||
if (!tmp_split)
|
||||
return (0);
|
||||
// 4
|
||||
tmp_expand = ft_dup_2d_arr(tmp_split, (t_dup_func)ft_strdup_quotes);
|
||||
ft_free_2d_arr(tmp_split);
|
||||
tmp_split = tmp_expand;
|
||||
if (!tmp_split)
|
||||
return (0);
|
||||
// 5
|
||||
if (!new_token_for_each_field(tmp_split, &t))
|
||||
return (0);
|
||||
}
|
||||
t = t->next;
|
||||
if (token_list->id == T_WORD)
|
||||
token_expansions(&token_list);
|
||||
token_list = token_list->next;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int token_expansions(t_token **t)
|
||||
{
|
||||
void *tmp;
|
||||
char **tmp_split;
|
||||
|
||||
// 1
|
||||
tmp = expand_token((*t)->content);
|
||||
if (!tmp)
|
||||
return (0);
|
||||
// 2
|
||||
tmp = rejoin_after_expand(tmp);
|
||||
if (!tmp)
|
||||
return (0);
|
||||
// 3
|
||||
tmp_split = ft_split_quotes(tmp, ' ');
|
||||
free(tmp);
|
||||
if (!tmp_split)
|
||||
return (0);
|
||||
// 4
|
||||
tmp = ft_dup_2d_arr(tmp_split, (t_dup_func)ft_strdup_quotes);
|
||||
ft_free_2d_arr(tmp_split);
|
||||
tmp_split = tmp;
|
||||
if (!tmp_split)
|
||||
return (0);
|
||||
// 5
|
||||
if (!new_token_for_each_field(tmp_split, t))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user