This commit is contained in:
2024-02-16 21:53:38 +01:00
parent 2a2ef1d63c
commit 79f99ce489
14 changed files with 29 additions and 46 deletions

77
srcs/lst_env.c Executable file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lst_env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/02/13 16:21:41 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_env *env_add_back(t_env *env, char *name, char *value)
{
t_env *res;
t_env *current;
res = ft_calloc(1, sizeof(t_env));
if (!res)
return (env);
res->name = name;
res->value = value;
if (!env)
return (res);
current = env;
while (current->next)
current = current->next;
current->next = res;
return (env);
}
void free_env(t_env *env)
{
if (env && env->next)
free_env(env->next);
if (env)
{
free(env->name);
free(env->value);
}
free(env);
}
int print_env(t_env *env)
{
while (env)
{
ft_printf("%s=%s\n", env->name, env->value);
env = env->next;
}
return (0);
}
char *ft_get_env(t_env *env, char *name)
{
while (env)
{
if (!ft_strcmp(env->name, name))
return (env->value);
env = env->next;
}
return (0);
}
int get_var_name_len(char *command)
{
int res;
res = 0;
if (command[res] == '?')
return (1);
while (ft_isalnum(command[res]) || command[res] == '_')
res++;
return (res);
}