From af4e2152422d35730bf488882e7540e2959a1946 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Wed, 5 Mar 2025 21:42:59 +0100 Subject: [PATCH] some more refactor and todo --- inc/parser.h | 3 +-- src/parser/parser_get_arguments.c | 15 +++++++++------ src/parser/parser_process_token.c | 8 +++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/inc/parser.h b/inc/parser.h index b198232..7a67d31 100644 --- a/inc/parser.h +++ b/inc/parser.h @@ -25,7 +25,6 @@ char **parser_get_arguments(t_list *list, t_minishell *msh); int parser_validate_command(t_command *command); int parser_count_arguments(t_list *list); char *parser_concatenate(t_minishell *msh, char *str1, char *str2); -char *parser_process_token(t_minishell *msh, char **args, t_list *prev - , t_list *t_head); +char *parser_process_token(t_minishell *msh, t_list *prev, t_list *t_head); #endif diff --git a/src/parser/parser_get_arguments.c b/src/parser/parser_get_arguments.c index 16756c7..bfa7ff9 100644 --- a/src/parser/parser_get_arguments.c +++ b/src/parser/parser_get_arguments.c @@ -11,8 +11,9 @@ /* ************************************************************************** */ #include "minishell.h" +#include "typedef.h" -static int parser_should_concact(t_minishell *msh, int argi, t_list *tkns) +static int parser_should_concact(t_minishell *msh, int argi, t_list *cur, t_list *prev) { t_token *c_tkn; t_token *p_tkn; @@ -20,19 +21,20 @@ static int parser_should_concact(t_minishell *msh, int argi, t_list *tkns) if (argi < 1) return (0); - p_tkn = token_from_list(token_list_index(tkns, argi - 1)); - c_tkn = token_from_list(token_list_index(tkns, argi)); + p_tkn = token_from_list(prev); + c_tkn = token_from_list(cur); lexer_char = 0; if (!p_tkn || !c_tkn || c_tkn->position <= 0) return (0); lexer_char = msh->lexer->input[c_tkn->position - 1]; - // if current & previous token is word and inbetween is no space, concat + // Determine exact separation position return (c_tkn->type < 3 && p_tkn->type < 3 && !ft_isspace(lexer_char)); } char **parser_get_arguments(t_list *list, t_minishell *msh) { t_list *current; + t_list *prev; char *str; char **args; int argc; @@ -46,13 +48,14 @@ char **parser_get_arguments(t_list *list, t_minishell *msh) { if (token_from_list(current)->type < 3) { - str = parser_process_token(msh, args, token_list_index(list, i - 1), current); - if (parser_should_concact(msh, i, list)) + str = parser_process_token(msh, token_list_index(list, i - 1), current); + if (parser_should_concact(msh, i, current, prev)) args[i - 1] = parser_concatenate(msh, args[i - 1], str); else if (str) args[i++] = str; argc--; } + prev = current; current = current->next; } args[i] = 0; diff --git a/src/parser/parser_process_token.c b/src/parser/parser_process_token.c index 9e153b2..4c5a6c8 100644 --- a/src/parser/parser_process_token.c +++ b/src/parser/parser_process_token.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/05 21:12:15 by qmennen #+# #+# */ -/* Updated: 2025/03/05 21:14:09 by qmennen ### ########.fr */ +/* Updated: 2025/03/05 21:42:44 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,15 +36,17 @@ static int parser_should_expand(t_list *value) return (0); } -char *parser_process_token(t_minishell *msh, char **args, t_list *prev - , t_list *t_head) +//TODO: Make an exception for this `echo hey""you "" test`. here echo actually interprets "" as an extra space. Just check if its empty and surrounded by spaces or sth. Can't be asked rn +char *parser_process_token(t_minishell *msh, t_list *prev, t_list *t_head) { char *str; t_token *token; + t_token *p_token; if (!t_head) return (NULL); token = (t_token *)t_head->content; + p_token = (t_token *)prev->content; str = NULL; if (ft_strcmp(token->value, "") == 0) return (NULL);