mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parsing: refactor group_cmd_parse into own file
This commit is contained in:
parent
b7871be426
commit
218be08049
4 changed files with 67 additions and 29 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/15 10:43:57 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/15 10:47:29 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
#include <unistd.h>
|
||||
#include "simple_cmd/simple_cmd_parse.h"
|
||||
#include "cmd/cmd_destroy.h"
|
||||
#include "redirect/redirect_parse.h"
|
||||
#include "group_cmd/group_cmd_parse.h"
|
||||
#include "pipeline/optional_pipeline_parse.h"
|
||||
|
||||
void parse_error(t_minishell *app, t_worddesc *token)
|
||||
|
|
@ -28,38 +28,12 @@ void parse_error(t_minishell *app, t_worddesc *token)
|
|||
app->last_return_value = 2;
|
||||
}
|
||||
|
||||
t_cmd *minishell_group_parse(t_minishell *app, t_wordlist *tokens)
|
||||
{
|
||||
t_cmd *subtree;
|
||||
t_cmd *group;
|
||||
|
||||
subtree = minishell_cmds_parse(app, tokens);
|
||||
if (!subtree
|
||||
|| tokens->word->token_type != CLOSE_PARENTH_TOKEN)
|
||||
{
|
||||
ft_errno(FT_EERRNO);
|
||||
if (tokens->word->token_type != CLOSE_PARENTH_TOKEN)
|
||||
parse_error(app, tokens->word);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
}
|
||||
worddesc_destroy(wordlist_pop(&tokens));
|
||||
group = cmd_create(FT_GROUP);
|
||||
if (!group)
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
group->value.group->cmd = subtree;
|
||||
group->value.group->redirects = minishell_redirect_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));
|
||||
return (minishell_group_cmd_parse(app, tokens));
|
||||
}
|
||||
else
|
||||
return (minishell_simple_cmd_parse(app, tokens));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue