From f242affc9ac14be1cbc61706b6915e98f7211a79 Mon Sep 17 00:00:00 2001 From: Takuma Tsubo Date: Thu, 1 May 2025 14:05:39 +0900 Subject: [PATCH 1/5] =?UTF-8?q?key=E3=81=AE=E3=81=BF=E3=81=AE=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AB+=3D=E3=81=A7=E8=BF=BD=E5=8A=A0=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtin/export_exec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/builtin/export_exec.c b/src/builtin/export_exec.c index 86ca39d..819a9b2 100644 --- a/src/builtin/export_exec.c +++ b/src/builtin/export_exec.c @@ -6,7 +6,7 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/28 14:11:06 by ttsubo #+# #+# */ -/* Updated: 2025/04/29 14:52:09 by ttsubo ### ########.fr */ +/* Updated: 2025/05/01 14:04:19 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,10 +41,13 @@ static int _append_value(char *key, char *value, t_minish *minish) return (EXIT_FAILURE); if (node->value) join_str = ft_strjoin(node->value, value); + else + join_str = ft_strdup(value); if (!join_str) return (EXIT_FAILURE); free(node->value); node->value = join_str; + node->is_exported = 1; return (EXIT_SUCCESS); } From 33955df979d9cf179bdd1febcfe37cabd43517af Mon Sep 17 00:00:00 2001 From: cacapon Date: Fri, 2 May 2025 13:46:14 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=8F=E3=81=AA=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/builtin/test_cd.c | 4 ++-- tests/builtin/test_echo.c | 4 ++-- tests/builtin/test_exit.c | 4 ++-- tests/builtin/test_pwd.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/builtin/test_cd.c b/tests/builtin/test_cd.c index 6894ba8..e28ab3b 100644 --- a/tests/builtin/test_cd.c +++ b/tests/builtin/test_cd.c @@ -6,7 +6,7 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 11:33:50 by ttsubo #+# #+# */ -/* Updated: 2025/04/14 12:34:48 by ttsubo ### ########.fr */ +/* Updated: 2025/05/02 13:44:11 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int main(int argc, char **argv) printf("cd %s\n", argv[1]); getcwd(path, PATH_MAX); printf("before:path=%s\n", path); - builtin_cd(argc, argv); + builtin_cd(argc, argv, NULL); getcwd(path, PATH_MAX); printf("after :path=%s\n", path); return (0); diff --git a/tests/builtin/test_echo.c b/tests/builtin/test_echo.c index f909f01..7078d70 100644 --- a/tests/builtin/test_echo.c +++ b/tests/builtin/test_echo.c @@ -6,7 +6,7 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 11:39:28 by ttsubo #+# #+# */ -/* Updated: 2025/04/15 12:24:20 by ttsubo ### ########.fr */ +/* Updated: 2025/05/02 13:44:35 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ int main(void) continue ; cmds = ft_split(line, ' '); if (!ft_strncmp(cmds[0], "echo", 4)) - builtin_echo(_count_words(cmds), cmds); + builtin_echo(_count_words(cmds), cmds, NULL); cmds_free(cmds); free(line); } diff --git a/tests/builtin/test_exit.c b/tests/builtin/test_exit.c index c2eb068..bf6f05a 100644 --- a/tests/builtin/test_exit.c +++ b/tests/builtin/test_exit.c @@ -6,7 +6,7 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 14:48:09 by dayano #+# #+# */ -/* Updated: 2025/04/18 22:00:46 by ttsubo ### ########.fr */ +/* Updated: 2025/05/02 13:44:49 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ int main(void) if (strcmp("exit", line) == 0) { strings_line = ft_split(line, ' '); - if (builtin_exit(1, strings_line) == 1) + if (builtin_exit(1, strings_line, NULL) == 1) { printf("error\n"); free(line); diff --git a/tests/builtin/test_pwd.c b/tests/builtin/test_pwd.c index 0ae58b3..2af77e1 100644 --- a/tests/builtin/test_pwd.c +++ b/tests/builtin/test_pwd.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* test_pwd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dayano +#+ +:+ +#+ */ +/* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 16:07:28 by dayano #+# #+# */ -/* Updated: 2025/04/14 16:11:42 by dayano ### ########.fr */ +/* Updated: 2025/05/02 13:45:05 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ int main(int argc, char **argv) i++; } printf("========================\n"); - if (builtin_pwd(argc, argv)) + if (builtin_pwd(argc, argv, NULL)) printf("error\n"); return (0); } From 721488d3c8f14c06eed620af2efdb7502493a9b3 Mon Sep 17 00:00:00 2001 From: cacapon Date: Fri, 2 May 2025 14:04:46 +0900 Subject: [PATCH 3/5] _split_key_value -> _set_envp --- src/initialize.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/initialize.c b/src/initialize.c index 218d638..aa3c35a 100644 --- a/src/initialize.c +++ b/src/initialize.c @@ -6,25 +6,28 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:42:46 by dayano #+# #+# */ -/* Updated: 2025/05/01 13:46:27 by ttsubo ### ########.fr */ +/* Updated: 2025/05/02 14:04:39 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ #include "main.h" -static int _split_key_value(char *env_val, char **key_out, char **val_out) +static int _set_envp(char *env_val, t_env *node) { size_t env_len; size_t eq_pos; + if (!env_val || !node) + return (1); env_len = ft_strlen(env_val); eq_pos = ft_strlen_until(env_val, '='); - if (eq_pos == ft_strlen(env_val)) + if (eq_pos == env_len) return (1); - *key_out = ft_substr(env_val, 0, eq_pos); - *val_out = ft_substr(env_val, eq_pos + 1, env_len - eq_pos - 1); - if (!*key_out || !*val_out) + node->key = ft_substr(env_val, 0, eq_pos); + node->value = ft_substr(env_val, eq_pos + 1, env_len - eq_pos - 1); + if (!node->key || !node->value) return (1); + node->is_exported = 1; return (0); } @@ -68,7 +71,7 @@ static t_env *create_envp_list(char **envp) node = ft_calloc(1, sizeof(t_env)); if (!node) return (NULL); - if (_split_key_value(envp[i], &(node->key), &(node->value))) + if (!_set_envp(envp[i], node)) return (_free_nodes(&head), _free_node(node), NULL); node->next = NULL; if (!head) From b405fedebc30ea28631272414f1895e52b7fbe2e Mon Sep 17 00:00:00 2001 From: cacapon Date: Fri, 2 May 2025 14:33:49 +0900 Subject: [PATCH 4/5] =?UTF-8?q?makefile=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 18f196e..d0d5ef8 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # -# By: dayano +#+ +:+ +#+ # +# By: ttsubo +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/04/03 12:55:20 by ttsubo #+# #+# # -# Updated: 2025/04/29 16:48:58 by dayano ### ########.fr # +# Updated: 2025/05/02 14:33:45 by ttsubo ### ########.fr # # # # **************************************************************************** # @@ -87,8 +87,8 @@ $(foreach DIR,$(MODULE_DIRS), \ clean: $(MAKE) -C $(FT_DIR) clean - find $(OBJ_DIR) -type f -name '*.o' -exec rm -f {} + - find $(OBJ_DIR) -type d -empty -not -name '.' -exec rmdir {} + + [ -d $(OBJ_DIR) ] && find $(OBJ_DIR) -type f -name '*.o' -exec rm -f {} + || true + [ -d $(OBJ_DIR) ] && find $(OBJ_DIR) -type d -empty -not -name '.' -exec rmdir {} + || true fclean: $(MAKE) -C $(FT_DIR) fclean From 20944ab4a09fe2ca935a9afb4ec633f5a021437a Mon Sep 17 00:00:00 2001 From: cacapon Date: Fri, 2 May 2025 14:34:41 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=5Fset=5Fenvp=E3=81=AE=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=BC=8F=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/initialize.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/initialize.c b/src/initialize.c index aa3c35a..66362dd 100644 --- a/src/initialize.c +++ b/src/initialize.c @@ -6,7 +6,7 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:42:46 by dayano #+# #+# */ -/* Updated: 2025/05/02 14:04:39 by ttsubo ### ########.fr */ +/* Updated: 2025/05/02 14:11:51 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ static t_env *create_envp_list(char **envp) node = ft_calloc(1, sizeof(t_env)); if (!node) return (NULL); - if (!_set_envp(envp[i], node)) + if (_set_envp(envp[i], node)) return (_free_nodes(&head), _free_node(node), NULL); node->next = NULL; if (!head)