diff --git a/src/parser/parser_get_arguments.c b/src/parser/parser_get_arguments.c index 4d4effd..4d47b6b 100644 --- a/src/parser/parser_get_arguments.c +++ b/src/parser/parser_get_arguments.c @@ -10,10 +10,7 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "minishell.h" -#include "parser.h" -#include "utils.h" static int parser_should_expand(t_list *value) { @@ -38,6 +35,20 @@ static int parser_should_expand(t_list *value) return (0); } +static int parser_should_concact(t_minishell *msh, int argi, t_list *prev) +{ + t_token *prev_tkn; + char c; + + prev_tkn = token_from_list(prev); + c = 0; + if (!prev_tkn || argi < 1) + return (0); + if (prev_tkn->position > 0) + c = msh->lexer->input[prev_tkn->position - 1]; + return (ft_strcmp(prev_tkn->value, "") == 0 && c && !ft_isspace(c)); +} + static char *parser_process_token(t_minishell *msh, char **args, t_list *prev, t_list *t_head) { char *str; @@ -77,10 +88,10 @@ char **parser_get_arguments(t_list *list, t_minishell *msh) prev = NULL; while (argc > 0 && current) { - if (token_from_list(current)->type < 3 && (!prev || ((t_token *)prev->content)->type < 3)) + if (token_from_list(current)->type < 3 && (!prev || token_from_list(prev)->type < 3)) { str = parser_process_token(msh, args, prev, current); - if (i > 0 && prev && ft_strcmp(((t_token *)prev->content)->value, "") == 0) + if (parser_should_concact(msh, i, prev)) { cat = malloc_safe(msh, ft_strlen(str) + ft_strlen(args[i - 1]) + 1); ft_strlcpy(cat, args[i - 1], ft_strlen(args[i - 1]) + 1); diff --git a/src/prompt/history_write.c b/src/prompt/history_write.c index 86caf61..4c9b1d9 100644 --- a/src/prompt/history_write.c +++ b/src/prompt/history_write.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* history_write.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/02/05 17:12:17 by whaffman #+# #+# */ -/* Updated: 2025/02/12 12:53:42 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* history_write.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/05 17:12:17 by whaffman #+# #+# */ +/* Updated: 2025/03/05 15:11:38 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ void history_write(char *line) fd = open(".minishell_history", O_WRONLY | O_APPEND | O_CREAT, 0644); if (fd < 0) return ; - if (*line) - ft_putendl_fd(line, fd); + // if (*line) + // ft_putendl_fd(line, fd); close(fd); } diff --git a/src/token/token_from_list.c b/src/token/token_from_list.c index cd95ba2..f875c6a 100644 --- a/src/token/token_from_list.c +++ b/src/token/token_from_list.c @@ -14,5 +14,7 @@ t_token *token_from_list(t_list *list) { + if (!list) + return (NULL); return ((t_token *)list->content); }