Compare commits

...

2 Commits

Author SHA1 Message Date
dc772d10c2 fix: syntax error on pipe at start was not being detected 2026-02-13 13:48:28 +01:00
e5d7fcf050 fix: fixed leak on variable expansion 2026-02-13 13:33:32 +01:00

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */ /* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/22 18:37:38 by sede-san #+# #+# */ /* Created: 2025/10/22 18:37:38 by sede-san #+# #+# */
/* Updated: 2026/02/13 09:22:58 by sede-san ### ########.fr */ /* Updated: 2026/02/13 13:30:21 by sede-san ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -80,6 +80,8 @@ static t_list *parse_tokens(
return (NULL); return (NULL);
commands = NULL; commands = NULL;
current_token = tokens; current_token = tokens;
if (((t_token *)current_token->content)->type == TOKEN_PIPE)
return (syntax_error_unexpected_token((t_token *)current_token->content), NULL);
while (current_token != NULL) while (current_token != NULL)
{ {
command = command_new(&current_token); command = command_new(&current_token);
@@ -109,6 +111,22 @@ static t_list *parse_tokens(
return (commands); return (commands);
} }
static char *replace_value(
char *original,
char *value,
int start,
int end
)
{
const char *before = ft_substr(original, 0, start);
const char *after = ft_substr(original, end, ft_strlen(original) - end);
const char *expanded = ft_strnjoin(3, before, value, after);
free((char *)before);
free((char *)after);
return ((char *)expanded);
}
static void expand_variable( static void expand_variable(
char **argument, char **argument,
int *i, int *i,
@@ -131,10 +149,7 @@ static void expand_variable(
free(variable_name); free(variable_name);
if (variable == NULL) if (variable == NULL)
variable = ""; variable = "";
expanded = ft_strnjoin(3, expanded = replace_value(*argument, variable, start - 1, end);
ft_substr(*argument, 0, *i),
variable,
ft_substr(*argument,end, ft_strlen(*argument) - end));
if (expanded == NULL) if (expanded == NULL)
return (minishell->exit = true, malloc_error()); return (minishell->exit = true, malloc_error());
*i += ft_strlen(variable) - 1; *i += ft_strlen(variable) - 1;