correct concat

This commit is contained in:
Quinten Mennen 2025-03-05 16:53:54 +01:00
parent 6514dfa49b
commit cccc203425
3 changed files with 27 additions and 14 deletions

View File

@ -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);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* history_write.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* 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 <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -14,5 +14,7 @@
t_token *token_from_list(t_list *list)
{
if (!list)
return (NULL);
return ((t_token *)list->content);
}