mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parse-cmd: fixes and partial norm.
This commit is contained in:
parent
10a3c9c411
commit
72714855f7
1 changed files with 29 additions and 15 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/08 10:21:41 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/04/08 13:01:32 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -108,19 +108,42 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
|||
return (subtree);
|
||||
}
|
||||
|
||||
static t_cmd *cmds_parse_reorient_subtree(t_cmd **list, t_cmd **subtree,
|
||||
t_cmd **opt, t_connector connec)
|
||||
{
|
||||
*list = ft_calloc(1, sizeof(t_cmd));
|
||||
if (!*list)
|
||||
{
|
||||
ft_errno(FT_ENOMEM);
|
||||
return (ft_perror("minishell_cmds_parse"), NULL);
|
||||
}
|
||||
(*list)->value.connection = ft_calloc(1, sizeof(t_connec_cmd));
|
||||
if (!(*list)->value.connection)
|
||||
{
|
||||
ft_errno(FT_ENOMEM);
|
||||
return (ft_perror("minishell_cmds_parse"), NULL);
|
||||
}
|
||||
(*list)->type = FT_CONNECTION;
|
||||
(*list)->value.connection->connector = connec;
|
||||
(*list)->value.connection->first = *subtree;
|
||||
(*list)->value.connection->second = *opt;
|
||||
*subtree = *list;
|
||||
return (*subtree);
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse list of commands or pipeline.
|
||||
*/
|
||||
// TODO refactor
|
||||
// TODO remove debugs
|
||||
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
|
||||
t_cmd *subtree;
|
||||
t_cmd *opt;
|
||||
t_cmd *list;
|
||||
t_connector connec;
|
||||
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
|
||||
subtree = minishell_pipeline_parse(app, builder);
|
||||
if (!subtree)
|
||||
return (NULL); //ft_errno?
|
||||
|
|
@ -131,18 +154,11 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
|||
return (subtree);
|
||||
while (opt)
|
||||
{
|
||||
list = ft_calloc(1, sizeof(t_cmd));
|
||||
if (!list)
|
||||
if (cmds_parse_reorient_subtree(&list, &subtree, &opt, connec) == NULL)
|
||||
{
|
||||
app->last_return_value = 1;
|
||||
ft_errno(FT_ENOMEM);
|
||||
return (ft_perror("minishell_cmds_parse"), NULL);
|
||||
return (NULL);
|
||||
}
|
||||
list->type = FT_CONNECTION;
|
||||
list->connector = connec;
|
||||
list->first = subtree;
|
||||
list->second = opt;
|
||||
subtree = list;
|
||||
opt = minishell_opt_cmds_parse(app, builder, &connec);
|
||||
}
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
|
|
@ -151,8 +167,6 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
|||
}
|
||||
|
||||
/*
|
||||
** TODO Recheck error cases to see if allocation error occurred or something
|
||||
** else and if this is necessary.
|
||||
** TODO Include destruction of builder contents if necessary.
|
||||
*/
|
||||
t_cmd *minishell_parse(t_minishell *app, char *command_line)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue