mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parsing: refactor out the last two functions needed to pass the norm
This commit is contained in:
parent
5e84e9a111
commit
4de1d0024a
7 changed files with 134 additions and 59 deletions
|
|
@ -6,20 +6,20 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/15 11:03:25 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/15 11:38:55 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cmd_parsing.h"
|
||||
#include <fcntl.h>
|
||||
#include "cmd/cmd.h"
|
||||
#include "connec_cmd/connec_reorient_subtree.h"
|
||||
#include "worddesc/worddesc.h"
|
||||
#include "wordlist/wordlist.h"
|
||||
#include <unistd.h>
|
||||
#include "simple_cmd/simple_cmd_parse.h"
|
||||
#include "cmd/cmd_destroy.h"
|
||||
#include "group_cmd/group_cmd_parse.h"
|
||||
#include "pipeline/optional_pipeline_parse.h"
|
||||
#include "pipeline/pipeline_parse.h"
|
||||
|
||||
void parse_error(t_minishell *app, t_worddesc *token)
|
||||
{
|
||||
|
|
@ -62,60 +62,6 @@ t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
static t_cmd *connec_reorient_subtree(t_cmd **list, t_cmd **subtree,
|
||||
t_cmd **opt, t_connector connec)
|
||||
{
|
||||
*list = cmd_create(FT_CONNECTION);
|
||||
if (!*list)
|
||||
{
|
||||
cmd_destroy(*subtree);
|
||||
cmd_destroy(*opt);
|
||||
return (NULL);
|
||||
}
|
||||
(*list)->value.connection = ft_calloc(1, sizeof(t_connec_cmd));
|
||||
if (!(*list)->value.connection)
|
||||
{
|
||||
ft_errno(FT_ENOMEM);
|
||||
cmd_destroy(*subtree);
|
||||
cmd_destroy(*opt);
|
||||
return (free(*list), NULL);
|
||||
}
|
||||
(*list)->type = FT_CONNECTION;
|
||||
(*list)->value.connection->connector = connec;
|
||||
(*list)->value.connection->first = *subtree;
|
||||
(*list)->value.connection->second = *opt;
|
||||
*subtree = *list;
|
||||
return (*subtree);
|
||||
}
|
||||
|
||||
t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist *tokens)
|
||||
{
|
||||
t_cmd *subtree;
|
||||
t_cmd *opt;
|
||||
t_cmd *pipeline;
|
||||
|
||||
subtree = minishell_group_or_simple_parse(app, tokens);
|
||||
if (!subtree)
|
||||
return (NULL);
|
||||
opt = minishell_optional_pipeline_parse(app, tokens);
|
||||
if (!opt && ft_errno_get() != FT_ESUCCESS)
|
||||
return (NULL);
|
||||
if (!opt)
|
||||
return (subtree);
|
||||
while (opt)
|
||||
{
|
||||
if (connec_reorient_subtree(&pipeline, &subtree, &opt, FT_PIPE) == NULL)
|
||||
{
|
||||
app->last_return_value = 1;
|
||||
return (ft_perror("minishell_pipeline_parse"), NULL);
|
||||
}
|
||||
opt = minishell_optional_pipeline_parse(app, tokens);
|
||||
}
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
return (pipeline);
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse list of commands or pipeline.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue