From 56b5e7c0a5b2799bbb0049ba138292099c851928 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Wed, 5 Mar 2025 13:12:46 +0100 Subject: [PATCH] moving some files around --- inc/minishell.h | 1 + inc/parser.h | 1 + inc/token.h | 20 ++++++++++++++++ src/parser/parser_count_arguments.c | 36 +++++++++++++++++++++++++++++ src/parser/parser_get_arguments.c | 25 ++------------------ src/token/token_from_list.c | 18 +++++++++++++++ 6 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 inc/token.h create mode 100644 src/parser/parser_count_arguments.c create mode 100644 src/token/token_from_list.c diff --git a/inc/minishell.h b/inc/minishell.h index 37ee81a..e60db1e 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -20,6 +20,7 @@ # include "environment.h" # include "prompt.h" # include "tokenizer.h" +# include "token.h" # include "builtin.h" # include "executor.h" # include "parser.h" diff --git a/inc/parser.h b/inc/parser.h index f293dad..b0a6c71 100644 --- a/inc/parser.h +++ b/inc/parser.h @@ -23,5 +23,6 @@ void parser_create_command(t_minishell *msh, t_command *cmd, t_list **l_tkn); char **parser_get_arguments(t_list *list, t_minishell *msh); int parser_validate_command(t_command *command); +int parser_count_arguments(t_list *list); #endif diff --git a/inc/token.h b/inc/token.h new file mode 100644 index 0000000..cbdbf41 --- /dev/null +++ b/inc/token.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/05 13:11:41 by qmennen #+# #+# */ +/* Updated: 2025/03/05 13:11:58 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef TOKEN_H +# define TOKEN_H + +# include "minishell.h" + +t_token *token_from_list(t_list *list); + +#endif diff --git a/src/parser/parser_count_arguments.c b/src/parser/parser_count_arguments.c new file mode 100644 index 0000000..da72901 --- /dev/null +++ b/src/parser/parser_count_arguments.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parser_count_arguments.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/05 13:09:30 by qmennen #+# #+# */ +/* Updated: 2025/03/05 13:09:47 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int parser_count_arguments(t_list *list) +{ + int cmds; + t_list *current; + t_list *prev; + t_token *token; + + cmds = 0; + current = list; + prev = NULL; + while (current) + { + token = ((t_token *)current->content); + if (token->type < 3 && (!prev || ((t_token *)prev->content)->type < 3)) + cmds++; + prev = current; + current = current->next; + } + return (cmds); +} + + diff --git a/src/parser/parser_get_arguments.c b/src/parser/parser_get_arguments.c index bf01a9b..4d4effd 100644 --- a/src/parser/parser_get_arguments.c +++ b/src/parser/parser_get_arguments.c @@ -15,27 +15,6 @@ #include "parser.h" #include "utils.h" -static int count_cmds(t_list *list) -{ - int cmds; - t_list *current; - t_list *prev; - t_token *token; - - cmds = 0; - current = list; - prev = NULL; - while (current) - { - token = ((t_token *)current->content); - if (token->type < 3 && (!prev || ((t_token *)prev->content)->type < 3)) - cmds++; - prev = current; - current = current->next; - } - return (cmds); -} - static int parser_should_expand(t_list *value) { t_token *token; @@ -91,14 +70,14 @@ char **parser_get_arguments(t_list *list, t_minishell *msh) char *str; char *cat; - argc = count_cmds(list); + argc = parser_count_arguments(list); args = malloc_safe(msh, (argc + 1) * sizeof(char *)); current = list; i = 0; prev = NULL; while (argc > 0 && current) { - if (((t_token *)current->content)->type < 3 && (!prev || ((t_token *)prev->content)->type < 3)) + if (token_from_list(current)->type < 3 && (!prev || ((t_token *)prev->content)->type < 3)) { str = parser_process_token(msh, args, prev, current); if (i > 0 && prev && ft_strcmp(((t_token *)prev->content)->value, "") == 0) diff --git a/src/token/token_from_list.c b/src/token/token_from_list.c new file mode 100644 index 0000000..cd95ba2 --- /dev/null +++ b/src/token/token_from_list.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token_from_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/05 13:10:47 by qmennen #+# #+# */ +/* Updated: 2025/03/05 13:11:17 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_token *token_from_list(t_list *list) +{ + return ((t_token *)list->content); +}