- add freelist to minishell - add t_minishell *minishell to all function calling malloc_free - substituted all malloc calls but the first to malloc_safe
60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* :::::::: */
|
|
/* expander_parse_string.c :+: :+: */
|
|
/* +:+ */
|
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
|
/* +#+ */
|
|
/* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */
|
|
/* Updated: 2025/02/25 14:32:59 by whaffman ######## odam.nl */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
static void free_variables(t_list *variables)
|
|
{
|
|
t_list *current;
|
|
t_list *last;
|
|
|
|
current = variables;
|
|
while (current)
|
|
{
|
|
last = current;
|
|
current = current->next;
|
|
free(last);
|
|
}
|
|
}
|
|
|
|
char *expander_parse_string(char *s, t_minishell *minishell)
|
|
{
|
|
t_list *variables;
|
|
t_list *current;
|
|
char *string;
|
|
int i;
|
|
int j;
|
|
|
|
variables = expander_parse_variables(s, minishell);
|
|
string = expander_allocate_memory(minishell, s, variables);
|
|
i = 0;
|
|
j = 0;
|
|
current = variables;
|
|
while (s[i])
|
|
{
|
|
if (s[i] == '$' && s[i + 1])
|
|
{
|
|
i++;
|
|
i += expander_expand_dollar(s + i, string, &j, current);
|
|
if (current)
|
|
current = current->next;
|
|
}
|
|
else
|
|
string[j++] = s[i++];
|
|
}
|
|
//TODO: Figure out why echo "> echo "\as"" breaks
|
|
|
|
string[j] = 0;
|
|
free_variables(variables);
|
|
return (string);
|
|
}
|