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> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
/* 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))
|
while (is_redir(tokens->word))
|
||||||
{
|
{
|
||||||
if (tokens->next == NULL)
|
if (tokens->next == NULL)
|
||||||
|
{
|
||||||
|
ft_errno(FT_EERRNO);
|
||||||
return (redirect_destroy(redir_list), NULL);
|
return (redirect_destroy(redir_list), NULL);
|
||||||
|
}
|
||||||
redir_operator = wordlist_pop(&tokens);
|
redir_operator = wordlist_pop(&tokens);
|
||||||
redir_specifier = wordlist_pop(&tokens);
|
redir_specifier = wordlist_pop(&tokens);
|
||||||
new_redir = redir_from_words(redir_operator, redir_specifier, app);
|
new_redir = redir_from_words(redir_operator, redir_specifier, app);
|
||||||
t_redirect_add_back(&redir_list, new_redir);
|
t_redirect_add_back(&redir_list, new_redir);
|
||||||
}
|
}
|
||||||
|
ft_errno(FT_ESUCCESS);
|
||||||
return (redir_list);
|
return (redir_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,17 +114,11 @@ t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_wordlist *tokens)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
t_cmd *minishell_group_parse(t_minishell *app, t_wordlist *tokens)
|
||||||
** TODO NORM -> function is too long
|
|
||||||
*/
|
|
||||||
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
|
||||||
{
|
{
|
||||||
t_cmd *subtree;
|
t_cmd *subtree;
|
||||||
t_cmd *group;
|
t_cmd *group;
|
||||||
|
|
||||||
if (tokens->word->token_type == OPEN_PARENTH_TOKEN)
|
|
||||||
{
|
|
||||||
worddesc_destroy(wordlist_pop(&tokens));
|
|
||||||
subtree = minishell_cmds_parse(app, tokens);
|
subtree = minishell_cmds_parse(app, tokens);
|
||||||
if (!subtree
|
if (!subtree
|
||||||
|| tokens->word->token_type != CLOSE_PARENTH_TOKEN)
|
|| tokens->word->token_type != CLOSE_PARENTH_TOKEN)
|
||||||
|
|
@ -134,6 +132,7 @@ t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
||||||
group = ft_calloc(1, sizeof(t_cmd));
|
group = ft_calloc(1, sizeof(t_cmd));
|
||||||
if (!group)
|
if (!group)
|
||||||
return (ft_errno(FT_ENOMEM), cmd_destroy(subtree), NULL);
|
return (ft_errno(FT_ENOMEM), cmd_destroy(subtree), NULL);
|
||||||
|
group->type = FT_GROUP;
|
||||||
group->value.group->cmd = subtree;
|
group->value.group->cmd = subtree;
|
||||||
group->value.group->redirects = minishell_redir_parse(app, tokens);
|
group->value.group->redirects = minishell_redir_parse(app, tokens);
|
||||||
if (group->value.group->redirects == NULL
|
if (group->value.group->redirects == NULL
|
||||||
|
|
@ -141,10 +140,16 @@ t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
||||||
return (cmd_destroy(group), NULL);
|
return (cmd_destroy(group), NULL);
|
||||||
return (group);
|
return (group);
|
||||||
}
|
}
|
||||||
subtree = minishell_simple_parse(app, tokens);
|
|
||||||
if (!subtree)
|
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
|
||||||
ft_errno(FT_EERRNO);
|
{
|
||||||
return (subtree);
|
if (tokens->word->token_type == OPEN_PARENTH_TOKEN)
|
||||||
|
{
|
||||||
|
worddesc_destroy(wordlist_pop(&tokens));
|
||||||
|
return (minishell_group_parse(app, tokens));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (minishell_simple_parse(app, tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
|
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue