mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parse-cmd: Only redirections left to parse.
This commit is contained in:
parent
926774846f
commit
4baad88a44
2 changed files with 44 additions and 19 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/08 13:55:42 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/04/10 18:51:38 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
# include "../minishell.h"
|
||||
# include "../ft_errno.h"
|
||||
# include <stdbool.h>
|
||||
|
||||
typedef struct s_cmd_builder
|
||||
{
|
||||
|
|
@ -29,6 +30,7 @@ typedef struct s_cmd_builder
|
|||
} t_cmd_builder;
|
||||
|
||||
void parse_error(t_minishell *app, t_worddesc *token);
|
||||
t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back);
|
||||
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
||||
|
||||
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
|
|
@ -41,9 +43,5 @@ t_cmd *minishell_opt_pipeline_parse(t_minishell *app,
|
|||
t_cmd_builder *builder);
|
||||
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_simple_lst_parse(t_minishell *app,
|
||||
t_cmd_builder *builder);
|
||||
|
||||
t_connector which_connector_type(t_worddesc *token);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue