1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-06-25 02:13:35 +02:00

🔨」 fix: fixed export and remade format quotes

This commit is contained in:
yosyo
2024-07-17 02:28:50 +02:00
parent e0987139dd
commit 013b9e62af
6 changed files with 89 additions and 75 deletions

View File

@ -6,37 +6,13 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
/* Updated: 2024/07/15 18:02:16 by mmoussou ### ########.fr */
/* Updated: 2024/07/17 02:17:05 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "builtins.h"
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;
@ -66,7 +42,7 @@ int export_value(char *arg, t_env *env)
name = ft_strdup(arg);
if (name)
add_to_env(name, NULL, env);
return (-1);
return (0);
}
name = ft_calloc(sizeof(char), ft_strchr(arg, '=') - arg + 1);
content = ft_calloc(sizeof(char), ft_strlen(ft_strchr(arg, '=')));
@ -82,6 +58,20 @@ int export_value(char *arg, t_env *env)
return (0);
}
void append_process(char *name, char *content, t_env *env_t, t_env *env)
{
if (env_t)
{
if (env_t->content)
env_append(name, content, env);
else
env_edit(name, content, env);
free(name);
}
else
ft_envadd_back(&env, ft_envnew(name, content));
}
int export_append_value(char *arg, t_env *env)
{
char *name;
@ -101,10 +91,7 @@ int export_append_value(char *arg, t_env *env)
env_t = env;
while (env_t && ft_strcmp(env_t->name, name))
env_t = env_t->next;
if (env_t)
env_append(name, content, env);
else
ft_envadd_back(&env, ft_envnew(name, content));
append_process(name, content, env_t, env);
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/11 18:59:27 by mmoussou #+# #+# */
/* Updated: 2024/07/15 18:02:49 by mmoussou ### ########.fr */
/* Updated: 2024/07/17 01:03:58 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,7 +72,11 @@ void add_to_env(char *name, char *content, t_env *env)
while (env_t && ft_strcmp(env_t->name, name))
env_t = env_t->next;
if (env_t)
env_edit(name, content, env);
{
if (content)
env_edit(name, content, env);
free(name);
}
else
ft_envadd_back(&env, ft_envnew(name, content));
}

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_export_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 01:29:28 by mmoussou #+# #+# */
/* Updated: 2024/07/17 01:29:58 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "builtins.h"
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--;
}
}