mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parsing: refactor minishell_redirect_parse to own file
This commit is contained in:
parent
d4197fec38
commit
9a58198303
5 changed files with 69 additions and 42 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/14 17:53:05 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/15 10:32:24 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,15 +18,8 @@
|
|||
#include <unistd.h>
|
||||
#include "redirect/redirect.h"
|
||||
#include "cmd/cmd_destroy.h"
|
||||
#include "redirect/redirect_from_words.h"
|
||||
#include "redirect/redirect_parse.h"
|
||||
|
||||
/*
|
||||
** NOTE: This file will temporarily include way more functions than allowed.
|
||||
*/
|
||||
/*
|
||||
** TODO Add a function to write a message and set errno in case of allocation
|
||||
** error.
|
||||
*/
|
||||
void parse_error(t_minishell *app, t_worddesc *token)
|
||||
{
|
||||
ft_dprintf(STDERR_FILENO, "minishell: syntax error near unexpected "
|
||||
|
|
@ -34,33 +27,6 @@ void parse_error(t_minishell *app, t_worddesc *token)
|
|||
app->last_return_value = 2;
|
||||
}
|
||||
|
||||
t_redirect *minishell_redir_parse(t_minishell *app, t_wordlist *tokens)
|
||||
{
|
||||
t_redirect *redir_list;
|
||||
t_worddesc *redir_operator;
|
||||
t_worddesc *redir_specifier;
|
||||
t_redirect *new_redir;
|
||||
|
||||
redir_list = NULL;
|
||||
while (is_redir(tokens->word))
|
||||
{
|
||||
if (tokens->next == NULL)
|
||||
{
|
||||
ft_errno(FT_EERRNO);
|
||||
return (redirect_destroy(redir_list), NULL);
|
||||
}
|
||||
redir_operator = wordlist_pop(&tokens);
|
||||
redir_specifier = wordlist_pop(&tokens);
|
||||
new_redir = redir_from_words(redir_operator, redir_specifier, app);
|
||||
t_redirect_add_back(&redir_list, new_redir);
|
||||
}
|
||||
ft_errno(FT_ESUCCESS);
|
||||
return (redir_list);
|
||||
}
|
||||
|
||||
/*
|
||||
** TODO NORM
|
||||
*/
|
||||
t_cmd *minishell_simple_parse(t_minishell *app, t_wordlist *tokens)
|
||||
{
|
||||
t_cmd *simple;
|
||||
|
|
@ -72,7 +38,7 @@ t_cmd *minishell_simple_parse(t_minishell *app, t_wordlist *tokens)
|
|||
simple->value.simple = ft_calloc(1, sizeof(t_simple_cmd));
|
||||
if (simple->value.simple == NULL)
|
||||
return (ft_errno(FT_ENOMEM), free(simple), NULL);
|
||||
redir = minishell_redir_parse(app, tokens);
|
||||
redir = minishell_redirect_parse(app, tokens);
|
||||
t_redirect_add_back(&simple->value.simple->redirections, redir);
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(simple), NULL);
|
||||
|
|
@ -82,7 +48,7 @@ t_cmd *minishell_simple_parse(t_minishell *app, t_wordlist *tokens)
|
|||
wordlist_pop(&tokens));
|
||||
if (!simple->value.simple->words)
|
||||
return (ft_errno(FT_EERRNO), cmd_destroy(simple), NULL);
|
||||
redir = minishell_redir_parse(app, tokens);
|
||||
redir = minishell_redirect_parse(app, tokens);
|
||||
t_redirect_add_back(&simple->value.simple->redirections, redir);
|
||||
}
|
||||
if (!simple->value.simple->words)
|
||||
|
|
@ -127,7 +93,7 @@ t_cmd *minishell_group_parse(t_minishell *app, t_wordlist *tokens)
|
|||
if (!group)
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
group->value.group->cmd = subtree;
|
||||
group->value.group->redirects = minishell_redir_parse(app, tokens);
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue