From b7658d02ecbb27d792b38c4c82555b97290da524 Mon Sep 17 00:00:00 2001 From: tomoron Date: Fri, 3 May 2024 14:30:50 +0200 Subject: [PATCH] fix export a= ->a="" --- srcs/env.c | 6 +++--- srcs/export.c | 6 +++--- srcs/lst_env.c | 11 +++++++---- srcs/main.c | 4 ++-- srcs/minishell.h | 4 ++-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/srcs/env.c b/srcs/env.c index 1726e7c..1c0ed46 100644 --- a/srcs/env.c +++ b/srcs/env.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 10:58:36 by marde-vr #+# #+# */ -/* Updated: 2024/04/26 10:26:03 by tomoron ### ########.fr */ +/* Updated: 2024/05/03 14:25:03 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ t_env *dup_env(t_env *env) res = 0; while (env) { - res = env_add_back(res, env->name, env->value); + res = env_add_back(res, env->name, env->value, 0); env = env->next; } return (res); @@ -67,7 +67,7 @@ void print_env_declare(t_msh *msh, t_env *env_orig) { if (strcmp(env->name, "_")) { - if (env->value && *(env->value)) + if (env->value) ft_printf_fd(msh->out_fd, "declare -x %s=\"%s\"\n", env->name, env->value); else diff --git a/srcs/export.c b/srcs/export.c index c5f508e..f3dbe01 100755 --- a/srcs/export.c +++ b/srcs/export.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */ -/* Updated: 2024/04/26 16:06:09 by tomoron ### ########.fr */ +/* Updated: 2024/05/03 14:29:08 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ t_env *set_env(t_env *env, char *name, char *value, int flags) free(value); return (env); } - if (flags & 0b1) + if ((flags & 0b1) && tmp->value) value = ft_strjoin_free(tmp->value, value, 2); if (!value) return (env); @@ -46,7 +46,7 @@ t_env *set_env(t_env *env, char *name, char *value, int flags) } tmp = tmp->next; } - return (env_add_back(env, name, value)); + return (env_add_back(env, name, value, !(flags & 0b10))); } t_env *export_set_env(t_env *env, char *name, char *value, int flags) diff --git a/srcs/lst_env.c b/srcs/lst_env.c index 92e3f4a..84e5e9b 100755 --- a/srcs/lst_env.c +++ b/srcs/lst_env.c @@ -6,22 +6,25 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ -/* Updated: 2024/04/29 22:11:22 by tomoron ### ########.fr */ +/* Updated: 2024/05/03 14:20:04 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_env *env_add_back(t_env *env, char *name, char *value) +t_env *env_add_back(t_env *env, char *name, char *value, int empty) { t_env *res; t_env *current; + if(empty) + free(value); res = ft_calloc(1, sizeof(t_env)); if (!res) return (env); res->name = name; - res->value = value; + if(!empty) + res->value = value; if (!env) return (res); current = env; @@ -35,7 +38,7 @@ int print_env(t_env *env) { while (env) { - if (*env->value) + if (env->value) ft_printf("%s=%s\n", env->name, env->value); env = env->next; } diff --git a/srcs/main.c b/srcs/main.c index 92c2b63..9389262 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/04/26 14:22:59 by tomoron ### ########.fr */ +/* Updated: 2024/05/03 14:19:08 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,7 @@ t_env *get_env(char **envp) j++; name = ft_substr(*envp, 0, i); value = ft_substr(*envp, i + 1, j); - env = env_add_back(env, name, value); + env = env_add_back(env, name, value, 0); if (!name || !value) free_env(env); if (!name || !value) diff --git a/srcs/minishell.h b/srcs/minishell.h index 7b10b32..8bedfee 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/04/30 14:00:33 by marde-vr ### ########.fr */ +/* Updated: 2024/05/03 14:16:24 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,7 +92,7 @@ t_cmd *cmd_add_back(t_cmd *res, char *cmd, t_cmd_type type); void find_cmd_path(t_msh *msh, char **paths, int *found); void redirect_output(t_msh *msh, int i, char **cmd_args); void redirect_input(t_msh *msh, int i, char **cmd_args); -t_env *env_add_back(t_env *env, char *name, char *value); +t_env *env_add_back(t_env *env, char *name, char *value, int empty); void print_syntax_error_bonus(t_cmd *cmd, t_cmd *cmds); int filename_corresponds(char *wildcard, char *value); void close_all_pipes(t_msh *msh, int cmd_count, int i);