/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   environment_unset.c                                :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: sede-san <sede-san@student.42madrid.com    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2026/02/09 22:16:00 by codex             #+#    #+#             */
/*   Updated: 2026/02/09 22:16:00 by codex            ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"
#include "core.h"

void	unset_env(
	const char *env_name,
	t_minishell *msh
){
	t_hashmap	*new_env;
	t_list		*entries;
	t_list		*current;
	t_map_entry	*entry;

	new_env = ft_hashmap_new(32, ft_hashmap_hashstr, ft_hashmap_strcmp);
	if (new_env == NULL)
		return ;
	entries = ft_hashmap_entries(msh->variables.environment);
	current = entries;
	while (current != NULL)
	{
		entry = current->content;
		if (ft_strcmp(entry->key, env_name) != 0)
			ft_hashmap_put(new_env,
				ft_strdup(entry->key), ft_strdup(entry->value));
		current = current->next;
	}
	ft_lstclear_nodes(&entries);
	ft_hashmap_clear(&msh->variables.environment, free);
	msh->variables.environment = new_env;
}
