mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🏗️」 wip(buildtins:export): testing things, might broke.
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/26 08:37:31 by mmoussou ### ########.fr */
|
/* Updated: 2024/06/27 15:38:17 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,5 +23,6 @@ char *ret_cwd(void);
|
|||||||
|
|
||||||
void ft_env(t_env *env);
|
void ft_env(t_env *env);
|
||||||
void ft_unset(char *arg, t_env *env);
|
void ft_unset(char *arg, t_env *env);
|
||||||
|
void ft_export(char **args, t_env *env);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,21 +6,61 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
|
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/06/26 10:21:18 by mmoussou ### ########.fr */
|
/* Updated: 2024/06/27 15:52:42 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
uint ft_arraylen(char **s)
|
||||||
|
{
|
||||||
|
char **endptr;
|
||||||
|
|
||||||
|
endptr = s;
|
||||||
|
while (*endptr)
|
||||||
|
endptr++;
|
||||||
|
return (endptr - s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_arraysort(char **env)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
int i;
|
||||||
|
int y;
|
||||||
|
|
||||||
|
i = ft_arraylen(env);
|
||||||
|
while (i)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
while (y < i - 1)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(env[y], env[y + 1]) > 0)
|
||||||
|
{
|
||||||
|
tmp = env[y];
|
||||||
|
env[y] = env[y + 1];
|
||||||
|
env[y + 1] = tmp;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void env_print_in_order(t_env *env_l)
|
void env_print_in_order(t_env *env_l)
|
||||||
{
|
{
|
||||||
char **env;
|
char **env;
|
||||||
|
int i;
|
||||||
|
|
||||||
env = env_get(env_l);
|
env = env_get(env_l);
|
||||||
if (!env)
|
if (!env)
|
||||||
return ;
|
return ;
|
||||||
// sort env
|
ft_arraysort(env);
|
||||||
// printf("declare -x %s\n", env[i]);
|
i = 0;
|
||||||
|
while (env[i])
|
||||||
|
{
|
||||||
|
printf("declare -x %s\n", env[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +84,8 @@ void ft_export(char **args, t_env *env)
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ft_strlcpy(name, *args, ft_strchr(*args, '=') - *args);
|
ft_strlcpy(name, *args, ft_strchr(*args, '=') - *args);
|
||||||
ft_strlcpy(content, ft_strchr(*args, '=') + 1, ft_strlen(ft_strchr(*args, '=')));
|
ft_strlcpy(content, ft_strchr(*args, '=') + 1,
|
||||||
|
ft_strlen(ft_strchr(*args, '=')));
|
||||||
if (env_get_value(name, env))
|
if (env_get_value(name, env))
|
||||||
env_edit(name, content, env);
|
env_edit(name, content, env);
|
||||||
else
|
else
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/06/27 14:27:32 by mmoussou ### ########.fr */
|
/* Updated: 2024/06/27 15:06:45 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/06/26 12:48:14 by adjoly ### ########.fr */
|
/* Updated: 2024/06/27 15:37:43 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -115,13 +115,18 @@ int main(int ac, char **av, char **env)
|
|||||||
ft_pwd();
|
ft_pwd();
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
|
else if (is_str(test, "export"))
|
||||||
|
{
|
||||||
|
ft_export(NULL, &env_l);
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
else if (is_str(test, "cd"))
|
else if (is_str(test, "cd"))
|
||||||
{
|
{
|
||||||
ft_cd(&env_l, lll[1]);
|
ft_cd(&env_l, lll[1]);
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
else if (is_str(test, "exit"))
|
else if (is_str(test, "exit"))
|
||||||
|
;
|
||||||
check_quote(test);
|
check_quote(test);
|
||||||
piped = tokenizer(test);
|
piped = tokenizer(test);
|
||||||
//check_redir(((t_token *)(piped->content))->redirection, av);
|
//check_redir(((t_token *)(piped->content))->redirection, av);
|
||||||
|
Reference in New Issue
Block a user