parse-cmd: Only redirections left to parse.

This commit is contained in:
Jérôme Guélen 2025-04-10 18:57:04 +02:00
parent 926774846f
commit 4baad88a44
No known key found for this signature in database
2 changed files with 44 additions and 19 deletions

View file

@ -6,7 +6,7 @@
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
/* Updated: 2025/04/08 19:56:28 by jguelen ### ########.fr */
/* Updated: 2025/04/10 18:56:45 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,26 +44,39 @@ t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back)
return (*init);
}
t_cmd *minishell_simple_lst_parse(t_minishell *app, t_cmd_builder *builder)
static bool is_redir(t_worddesc *token)
{
return ((t_cmd *)NULL);
}
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder)
{
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
return ((t_redirect *)NULL);
return (token->token_type == OUT_APPEND_REDIR_TOKEN
|| token->token_type == OUT_TRUNC_REDIR_TOKEN
|| token->token_type == IN_REDIR_TOKEN
|| token->token_type == HERE_DOC_REDIR_TOKEN);
}
/*
** TODO
** TODO Deal with heredocs properly and fill type, source, open_flags, cflags
** and redirectee (Don't know about here_doc_eof).
*/
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder)
{
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_redirect *redir;
redir = NULL;
while (is_redir(builder->tokens->word->token_type))
{
}
return (redir);
}
/*
** TODO NORM
*/
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder)
{
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_cmd *simple;
t_redirect *redir;
t_worddesc *word;
simple = ft_calloc(1, sizeof(t_cmd));
if (!simple)
@ -76,9 +89,23 @@ t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder)
if (simple->value.simple == NULL)
{
ft_errno(FT_ENOMEM);
return (NULL);
return (free(simple), NULL);
}
////////////////
redir = minishell_redir_parse(app, builder);
t_redirect_add_back(&simple->value.simple->redirections, redir);
if (ft_errno_get() != FT_ESUCCESS)
return (simple_cmd_destroy(simple), NULL);
while (builder->tokens && builder->tokens->word->token_type == WORD_TOKEN)
{
simple->value.simple->words = wordlist_push(simple->value.simple->words,
wordlist_pop(&builder->tokens));
if (!simple->value.simple->words)
return (ft_errno(FT_EERRNO), simple_cmd_destroy(simple), NULL);
redir = minishell_redir_parse(app, builder);
t_redirect_add_back(&simple->value.simple->redirections, redir);
}
if (!simple->value.simple->words)
return (parse_error(app, builder->tokens->word), NULL);
return (simple);
}