mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 00:08:47 +02:00
「✨」 feat(env): added environment functions :D
This commit is contained in:
28
src/env/env_list/ft_envadd_back.c
vendored
Normal file
28
src/env/env_list/ft_envadd_back.c
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:42:57 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/05/03 16:03:57 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_envadd_back(t_env **env, t_env *new)
|
||||
{
|
||||
t_env *tmp;
|
||||
|
||||
if (!env || !new)
|
||||
return ;
|
||||
if (!*env)
|
||||
{
|
||||
*env = new;
|
||||
return ;
|
||||
}
|
||||
tmp = ft_envlast(*env);
|
||||
tmp->next = new;
|
||||
}
|
26
src/env/env_list/ft_envadd_front.c
vendored
Normal file
26
src/env/env_list/ft_envadd_front.c
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:03:15 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/04/30 11:06:17 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_envadd_front(t_env **lst, t_env *new)
|
||||
{
|
||||
t_env *tmp;
|
||||
|
||||
tmp = *lst;
|
||||
*lst = new;
|
||||
if (!new || !lst)
|
||||
return ;
|
||||
while (new->next)
|
||||
new = new->next;
|
||||
new->next = tmp;
|
||||
}
|
27
src/env/env_list/ft_envclear.c
vendored
Normal file
27
src/env/env_list/ft_envclear.c
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 21:44:04 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/04/30 11:06:23 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_envclear(t_env **lst, void (*del)(void *))
|
||||
{
|
||||
t_env *tmp;
|
||||
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
while (*lst)
|
||||
{
|
||||
tmp = (*lst)->next;
|
||||
ft_envdelone(*lst, del);
|
||||
*lst = tmp;
|
||||
}
|
||||
}
|
23
src/env/env_list/ft_envdelone.c
vendored
Normal file
23
src/env/env_list/ft_envdelone.c
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 20:40:46 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/04/30 11:06:32 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_envdelone(t_env *lst, void (*del)(void *))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->name);
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
lst = NULL;
|
||||
}
|
22
src/env/env_list/ft_envlast.c
vendored
Normal file
22
src/env/env_list/ft_envlast.c
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:38:47 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/04/30 11:06:41 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_env *ft_envlast(t_env *env)
|
||||
{
|
||||
if (!env)
|
||||
return (NULL);
|
||||
while (env->next)
|
||||
env = env->next;
|
||||
return (env);
|
||||
}
|
26
src/env/env_list/ft_envnew.c
vendored
Normal file
26
src/env/env_list/ft_envnew.c
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:02:40 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/05/03 15:47:23 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_env *ft_envnew(char *name, char *content)
|
||||
{
|
||||
t_env *r;
|
||||
|
||||
r = malloc(sizeof(t_env));
|
||||
if (!r)
|
||||
return (NULL);
|
||||
r->name = name;
|
||||
r->content = content;
|
||||
r->next = NULL;
|
||||
return (r);
|
||||
}
|
28
src/env/env_list/ft_envsize.c
vendored
Normal file
28
src/env/env_list/ft_envsize.c
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_envsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:33:51 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/04/30 11:06:55 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
uint ft_envsize(t_env *lst)
|
||||
{
|
||||
uint i;
|
||||
|
||||
i = 1;
|
||||
if (!lst)
|
||||
return (0);
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
Reference in New Issue
Block a user