mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🏗️」 wip(builtins): working on builtins...
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
|
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/06/25 17:01:43 by adjoly ### ########.fr */
|
/* Updated: 2024/06/26 08:37:31 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,4 +21,7 @@ void ft_pwd(void);
|
|||||||
void ft_cd(t_env *env, char *args);
|
void ft_cd(t_env *env, char *args);
|
||||||
char *ret_cwd(void);
|
char *ret_cwd(void);
|
||||||
|
|
||||||
|
void ft_env(t_env *env);
|
||||||
|
void ft_unset(char *arg, t_env *env);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
22
src/builtins/ft_env.c
Normal file
22
src/builtins/ft_env.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_env.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/06/25 16:56:34 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2024/06/25 16:59:09 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void ft_env(t_env *env)
|
||||||
|
{
|
||||||
|
while (env)
|
||||||
|
{
|
||||||
|
printf("%s=%s\n", env->name, env->content);
|
||||||
|
env = env->next;
|
||||||
|
}
|
||||||
|
}
|
54
src/builtins/ft_export.c
Normal file
54
src/builtins/ft_export.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_export.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2024/06/26 10:21:18 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void env_print_in_order(t_env *env_l)
|
||||||
|
{
|
||||||
|
char **env;
|
||||||
|
|
||||||
|
env = env_get(env_l);
|
||||||
|
if (!env)
|
||||||
|
return ;
|
||||||
|
// sort env
|
||||||
|
// printf("declare -x %s\n", env[i]);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_export(char **args, t_env *env)
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
char *content;
|
||||||
|
|
||||||
|
if (!args || !args[0])
|
||||||
|
{
|
||||||
|
env_print_in_order(env);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
while (*args)
|
||||||
|
{
|
||||||
|
name = ft_calloc(sizeof(char), ft_strchr(*args, '=') - *args + 1);
|
||||||
|
content = ft_calloc(sizeof(char), ft_strlen(ft_strchr(*args, '=')));
|
||||||
|
if (!name || !content)
|
||||||
|
{
|
||||||
|
ft_free("cc", &name, &content);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
ft_strlcpy(name, *args, ft_strchr(*args, '=') - *args);
|
||||||
|
ft_strlcpy(content, ft_strchr(*args, '=') + 1, ft_strlen(ft_strchr(*args, '=')));
|
||||||
|
if (env_get_value(name, env))
|
||||||
|
env_edit(name, content, env);
|
||||||
|
else
|
||||||
|
env_append(name, content, env);
|
||||||
|
args++;
|
||||||
|
}
|
||||||
|
}
|
53
src/builtins/ft_unset.c
Normal file
53
src/builtins/ft_unset.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_unset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/06/25 16:45:04 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2024/06/25 17:13:38 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void pop_first_el(t_env *env)
|
||||||
|
{
|
||||||
|
t_env *tmp;
|
||||||
|
|
||||||
|
ft_free("cc", &env->name, &env->content);
|
||||||
|
env->name = env->next->name;
|
||||||
|
env->content = env->next->content;
|
||||||
|
tmp = env->next;
|
||||||
|
env->next = env->next->next;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_unset(char *arg, t_env *env)
|
||||||
|
{
|
||||||
|
t_env *tmp;
|
||||||
|
|
||||||
|
if (!arg)
|
||||||
|
{
|
||||||
|
printf("unset: not enough arguments");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (!ft_strcmp(env->name, arg))
|
||||||
|
{
|
||||||
|
pop_first_el(env);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
while (env->next)
|
||||||
|
{
|
||||||
|
if (!ft_strcmp(env->next->name, arg))
|
||||||
|
{
|
||||||
|
ft_free("cc", &env->next->name, &env->next->content);
|
||||||
|
tmp = env->next;
|
||||||
|
env->next = env->next->next;
|
||||||
|
free(tmp);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
env = env->next;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user