/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   expander_allocate_memory.c                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: qmennen <qmennen@student.codam.nl>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/02/19 13:57:19 by qmennen           #+#    #+#             */
/*   Updated: 2025/02/26 18:05:17 by qmennen          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

char	*expander_allocate_memory(
				t_minishell *msh,
				const char *s,
				t_list *variables)
{
	int				size;
	t_list			*current;
	t_environment	*env;
	char			*string;

	size = 1;
	current = variables;
	while (current)
	{
		if (current->content == NULL)
		{
			current = current->next;
			continue ;
		}
		env = (t_environment *)current->content;
		size += (ft_strlen(env->value) - ft_strlen(env->name));
		current = current->next;
	}
	size += ft_strlen(s);
	string = malloc_safe(msh, size);
	string[0] = 0;
	return (string);
}
