This commit is contained in:
Tom Moron
2024-02-09 16:43:35 +01:00
parent 22403b127e
commit ce72dde43e
12 changed files with 242 additions and 244 deletions

View File

@ -6,16 +6,16 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/02/08 16:58:48 by tomoron ### ########.fr */
/* Updated: 2024/02/09 15:24:59 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_env *ft_env_add_back(t_env *env, char *name, char *value)
t_env *ft_env_add_back(t_env *env, char *name, char *value)
{
t_env *res;
t_env *current;
t_env *res;
t_env *current;
res = ft_calloc(1, sizeof(t_env));
if (!res)
@ -27,15 +27,15 @@ t_env *ft_env_add_back(t_env *env, char *name, char *value)
current = env;
while (current->next)
current = current->next;
current->next = res;
current->next = res;
return (env);
}
void ft_free_env(t_env *env)
{
if(env && env->next)
if (env && env->next)
ft_free_env(env->next);
if(env)
if (env)
{
free(env->name);
free(env->value);
@ -45,10 +45,33 @@ void ft_free_env(t_env *env)
int ft_print_env(t_env *env)
{
while(env)
while (env)
{
printf("%s=%s\n",env->name, env->value);
ft_printf("%s=%s\n", env->name, env->value);
env = env->next;
}
return(0);
return (0);
}
char *ft_getenv(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);
}