🏗️」 wip(buildtins:export): testing things, might broke.

This commit is contained in:
y-syo
2024-06-28 10:12:19 +02:00
parent 15f87d9a37
commit 5e68b7342d
4 changed files with 55 additions and 8 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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_unset(char *arg, t_env *env);
void ft_export(char **args, t_env *env);
#endif

View File

@ -6,21 +6,61 @@
/* 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 */
/* Updated: 2024/06/27 15:52:42 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#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)
{
char **env;
int i;
env = env_get(env_l);
if (!env)
return ;
// sort env
// printf("declare -x %s\n", env[i]);
ft_arraysort(env);
i = 0;
while (env[i])
{
printf("declare -x %s\n", env[i]);
i++;
}
return ;
}
@ -44,7 +84,8 @@ void ft_export(char **args, t_env *env)
return ;
}
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))
env_edit(name, content, env);
else

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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();
continue ;
}
else if (is_str(test, "export"))
{
ft_export(NULL, &env_l);
continue ;
}
else if (is_str(test, "cd"))
{
ft_cd(&env_l, lll[1]);
continue ;
}
else if (is_str(test, "exit"))
;
check_quote(test);
piped = tokenizer(test);
//check_redir(((t_token *)(piped->content))->redirection, av);