diff --git a/src/minishell.c b/src/minishell.c index 8f65990..ad95947 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* minishell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ -/* Updated: 2025/04/07 18:07:30 by jguelen ### ########.fr */ +/* Created: 2025/04/14 12:53/08 by khais #+# #+# */ +/* Updated: 2025/04/14 12:53:08 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ #include #include "env/env_convert.h" #include "postprocess/expansion/expand_vars.h" - +#include "parser/cmd_parsing.h" /* ** Parse shell commands from line. @@ -76,35 +76,20 @@ static void app_init(t_minishell *app, char **envp) app->env = env_from_envp(envp); } - - - -t_cmd *minishell_parse(t_minishell *app, char *command_line); - int main(int argc, char *argv[], char **envp) { char *line; t_simple_cmd *cmd; t_minishell app; - - -(void)argc; -(void)argv; -app_init(&app, envp); - - -line = "echo coucou"; - -minishell_parse(&app, line); - -return (0); - - - - (void)argc; (void)argv; + app_init(&app, envp); + + line = "echo coucou"; + minishell_parse(&app, line); + return (0); + app_init(&app, envp); line = get_command(); while (line != NULL) diff --git a/src/minishell.h b/src/minishell.h index 9d7641e..4eacea1 100644 --- a/src/minishell.h +++ b/src/minishell.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* minishell.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/28 14:55:31 by khais #+# #+# */ -/* Updated: 2025/04/08 19:46:43 by jguelen ### ########.fr */ +/* Created: 2025/04/14 12:50/31 by khais #+# #+# */ +/* Updated: 2025/04/14 12:50:31 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -128,6 +128,6 @@ void redirect_destroy(t_redirect *redirections); /* ** This function recursively destroys the whole command tree. */ -void t_cmd_destroy(t_cmd *cmd); +void t_cmd_destroy(t_cmd *cmd); #endif diff --git a/src/parser/cmd_parsing.c b/src/parser/cmd_parsing.c index 4233281..d63fad4 100644 --- a/src/parser/cmd_parsing.c +++ b/src/parser/cmd_parsing.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */ -/* Updated: 2025/04/14 12:48:26 by khais ### ########.fr */ +/* Updated: 2025/04/14 12:57:46 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,8 +88,8 @@ static int redir_open_flags_from_type(t_redir_type type) return (0); } - -static t_redirect *redir_from_words(t_worddesc *operator, t_worddesc *specifier, t_minishell *app) +static t_redirect *redir_from_words(t_worddesc *operator, + t_worddesc *specifier, t_minishell *app) { t_redirect *redir; @@ -117,12 +117,12 @@ static t_redirect *redir_from_words(t_worddesc *operator, t_worddesc *specifier, 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_list; t_worddesc *redir_operator; t_worddesc *redir_specifier; t_redirect *new_redir; + ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); redir_list = NULL; while (is_redir(builder->tokens->word)) { @@ -141,11 +141,10 @@ t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder) */ 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; + ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); simple = ft_calloc(1, sizeof(t_cmd)); if (!simple) { @@ -166,7 +165,7 @@ t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder) while (builder->tokens && builder->tokens->word->token_type == WORD_TOKEN) { simple->value.simple->words = wordlist_push(simple->value.simple->words, - wordlist_pop(&builder->tokens)); + wordlist_pop(&builder->tokens)); if (!simple->value.simple->words) return (ft_errno(FT_EERRNO), t_cmd_destroy(simple), NULL); redir = minishell_redir_parse(app, builder); @@ -200,10 +199,10 @@ t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd_builder *builder) */ t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder) { -ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); t_cmd *subtree; t_cmd *group; + ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); if (builder->tokens->word->token_type == OPEN_PARENTH_TOKEN) { worddesc_destroy(wordlist_pop(&builder->tokens)); @@ -222,7 +221,8 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); return (ft_errno(FT_ENOMEM), t_cmd_destroy(subtree), NULL); group->value.group->cmd = subtree; group->value.group->redirects = minishell_redir_parse(app, builder); - if (group->value.group->redirects == NULL && ft_errno_get() != FT_ESUCCESS) + if (group->value.group->redirects == NULL + && ft_errno_get() != FT_ESUCCESS) return (t_cmd_destroy(group), NULL); return (group); } @@ -235,11 +235,10 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder, t_connector *connec) { -ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); - t_worddesc *token; t_cmd *opt; + ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); token = builder->tokens->word; if (token->token_type == OR_TOKEN || token->token_type == AND_TOKEN) { @@ -290,8 +289,7 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder) t_cmd *opt; t_cmd *pipeline; -ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); - + ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); subtree = minishell_group_or_smp_parse(app, builder); if (!subtree) return (NULL); @@ -325,7 +323,7 @@ t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder) t_cmd *list; t_connector connec; -ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); + ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); subtree = minishell_pipeline_parse(app, builder); if (!subtree) return (NULL); @@ -371,7 +369,7 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line) return (wordlist_destroy(builder.tokens), NULL); } if (builder.tokens) - { + { parse_error(app, builder.tokens->word); wordlist_destroy(builder.tokens); t_cmd_destroy(root_cmd); diff --git a/src/parser/cmd_parsing.h b/src/parser/cmd_parsing.h index 4cff00a..7ad2540 100644 --- a/src/parser/cmd_parsing.h +++ b/src/parser/cmd_parsing.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* cmd_parsing.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */ -/* Updated: 2025/04/10 18:51:38 by jguelen ### ########.fr */ +/* Created: 2025/04/14 12:53/43 by khais #+# #+# */ +/* Updated: 2025/04/14 12:53:43 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,11 +36,11 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line); t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder); t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder); t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder, - t_connector *connec); + t_connector *connec); t_cmd *minishell_group_or_smp_parse(t_minishell *app, - t_cmd_builder *builder); + t_cmd_builder *builder); t_cmd *minishell_opt_pipeline_parse(t_minishell *app, - t_cmd_builder *builder); + 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);