mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parsing: create specialised function to create a t_cmd
This commit is contained in:
parent
fde0bf4dc9
commit
d4197fec38
4 changed files with 54 additions and 10 deletions
|
|
@ -6,12 +6,13 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/14 17:47:43 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/14 17:53:05 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cmd_parsing.h"
|
||||
#include <fcntl.h>
|
||||
#include "cmd/cmd.h"
|
||||
#include "worddesc/worddesc.h"
|
||||
#include "wordlist/wordlist.h"
|
||||
#include <unistd.h>
|
||||
|
|
@ -65,10 +66,9 @@ t_cmd *minishell_simple_parse(t_minishell *app, t_wordlist *tokens)
|
|||
t_cmd *simple;
|
||||
t_redirect *redir;
|
||||
|
||||
simple = ft_calloc(1, sizeof(t_cmd));
|
||||
if (!simple)
|
||||
return (ft_errno(FT_ENOMEM), NULL);
|
||||
simple->type = FT_SIMPLE;
|
||||
simple = cmd_create(FT_SIMPLE);
|
||||
if (simple == NULL)
|
||||
return (NULL);
|
||||
simple->value.simple = ft_calloc(1, sizeof(t_simple_cmd));
|
||||
if (simple->value.simple == NULL)
|
||||
return (ft_errno(FT_ENOMEM), free(simple), NULL);
|
||||
|
|
@ -123,10 +123,9 @@ t_cmd *minishell_group_parse(t_minishell *app, t_wordlist *tokens)
|
|||
return (cmd_destroy(subtree), NULL);
|
||||
}
|
||||
worddesc_destroy(wordlist_pop(&tokens));
|
||||
group = ft_calloc(1, sizeof(t_cmd));
|
||||
group = cmd_create(FT_GROUP);
|
||||
if (!group)
|
||||
return (ft_errno(FT_ENOMEM), cmd_destroy(subtree), NULL);
|
||||
group->type = FT_GROUP;
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
group->value.group->cmd = subtree;
|
||||
group->value.group->redirects = minishell_redir_parse(app, tokens);
|
||||
if (group->value.group->redirects == NULL
|
||||
|
|
@ -172,10 +171,9 @@ t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
|
|||
static t_cmd *connec_reorient_subtree(t_cmd **list, t_cmd **subtree,
|
||||
t_cmd **opt, t_connector connec)
|
||||
{
|
||||
*list = ft_calloc(1, sizeof(t_cmd));
|
||||
*list = cmd_create(FT_CONNECTION);
|
||||
if (!*list)
|
||||
{
|
||||
ft_errno(FT_ENOMEM);
|
||||
cmd_destroy(*subtree);
|
||||
cmd_destroy(*opt);
|
||||
return (NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue