mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parsing: split minishell_group_or_simple_parse
This commit is contained in:
parent
86e658fcca
commit
dbba36dc44
1 changed files with 35 additions and 30 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/14 17:37:38 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/14 17:45:49 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -44,12 +44,16 @@ t_redirect *minishell_redir_parse(t_minishell *app, t_wordlist *tokens)
|
|||
while (is_redir(tokens->word))
|
||||
{
|
||||
if (tokens->next == NULL)
|
||||
{
|
||||
ft_errno(FT_EERRNO);
|
||||
return (redirect_destroy(redir_list), NULL);
|
||||
}
|
||||
redir_operator = wordlist_pop(&tokens);
|
||||
redir_specifier = wordlist_pop(&tokens);
|
||||
new_redir = redir_from_words(redir_operator, redir_specifier, app);
|
||||
t_redirect_add_back(&redir_list, new_redir);
|
||||
}
|
||||
ft_errno(FT_ESUCCESS);
|
||||
return (redir_list);
|
||||
}
|
||||
|
||||
|
|
@ -110,17 +114,11 @@ t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_wordlist *tokens)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
** TODO NORM -> function is too long
|
||||
*/
|
||||
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
||||
t_cmd *minishell_group_parse(t_minishell *app, t_wordlist *tokens)
|
||||
{
|
||||
t_cmd *subtree;
|
||||
t_cmd *group;
|
||||
|
||||
if (tokens->word->token_type == OPEN_PARENTH_TOKEN)
|
||||
{
|
||||
worddesc_destroy(wordlist_pop(&tokens));
|
||||
subtree = minishell_cmds_parse(app, tokens);
|
||||
if (!subtree
|
||||
|| tokens->word->token_type != CLOSE_PARENTH_TOKEN)
|
||||
|
|
@ -134,17 +132,24 @@ t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
|||
group = ft_calloc(1, sizeof(t_cmd));
|
||||
if (!group)
|
||||
return (ft_errno(FT_ENOMEM), cmd_destroy(subtree), NULL);
|
||||
group->type = FT_GROUP;
|
||||
group->value.group->cmd = subtree;
|
||||
group->value.group->redirects = minishell_redir_parse(app, tokens);
|
||||
if (group->value.group->redirects == NULL
|
||||
&& ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(group), NULL);
|
||||
return (group);
|
||||
}
|
||||
|
||||
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
||||
{
|
||||
if (tokens->word->token_type == OPEN_PARENTH_TOKEN)
|
||||
{
|
||||
worddesc_destroy(wordlist_pop(&tokens));
|
||||
return (minishell_group_parse(app, tokens));
|
||||
}
|
||||
subtree = minishell_simple_parse(app, tokens);
|
||||
if (!subtree)
|
||||
ft_errno(FT_EERRNO);
|
||||
return (subtree);
|
||||
else
|
||||
return (minishell_simple_parse(app, tokens));
|
||||
}
|
||||
|
||||
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue