From 1352a826b11148a23633504c9d3c246aeaacb1f7 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 11 Oct 2020 21:11:57 +0200 Subject: Fixing empty cd segfault --- libft | 2 +- minishell_test | 2 +- src/builtin/cd.c | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libft b/libft index 39951f0..c333433 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 39951f08a2938683d800c677c3a244e9ff8dbe19 +Subproject commit c33343322ef66d96337533082313b1256862023a diff --git a/minishell_test b/minishell_test index fb0a727..a36a27b 160000 --- a/minishell_test +++ b/minishell_test @@ -1 +1 @@ -Subproject commit fb0a727a9885b80b855f470ae6d5c1bfac614439 +Subproject commit a36a27b8ca85adf57b2a9926a53e74e3a3863d3d diff --git a/src/builtin/cd.c b/src/builtin/cd.c index a350cf4..b566272 100644 --- a/src/builtin/cd.c +++ b/src/builtin/cd.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:20 by charles #+# #+# */ -/* Updated: 2020/10/09 12:44:55 by cacharle ### ########.fr */ +/* Updated: 2020/10/11 21:11:40 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,13 +37,12 @@ int builtin_cd(char **argv, t_env env) if (argv[1] != NULL && argv[1][0] == '\0') return (env_export(env, "OLDPWD", oldwd) == NULL ? EVAL_FATAL : 0); if (argv[1] == NULL) - { if ((home = env_search(env, "HOME", NULL)) == NULL) return (errorf_ret(1, "cd: HOME not set\n")); - argv[1] = home; - } - if (chdir(argv[1]) == -1) - return (errorf_ret(1, "cd: %s: %s\n", argv[1], strerror(errno))); + else + home = argv[1]; + if (chdir(home) == -1) + return (errorf_ret(1, "cd: %s: %s\n", home, strerror(errno))); if (env_export(env, "OLDPWD", oldwd) == NULL) return (EVAL_FATAL); if (getcwd(cwd, PATH_MAX) == NULL) -- cgit From 753630fe796eb53976696972ee7e20aebd8b1365 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 15 Oct 2020 09:42:53 +0200 Subject: Fixing case insensitive executable path, Removing prompt basename --- .gitmodules | 4 ++-- minishell_test | 2 +- src/builtin/cd.c | 4 +++- src/eval/cmd.c | 2 +- src/path.c | 4 ++-- src/utils.c | 6 +----- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.gitmodules b/.gitmodules index 690d5bf..1834c00 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "libft"] path = libft - url = https://github.com/HappyTramp/libft + url = https://github.com/cacharle/libft branch = minishell [submodule "minishell_test"] path = minishell_test - url = https://github.com/HappyTramp/minishell_test + url = https://github.com/cacharle/minishell_test branch = master diff --git a/minishell_test b/minishell_test index a36a27b..acf8e5d 160000 --- a/minishell_test +++ b/minishell_test @@ -1 +1 @@ -Subproject commit a36a27b8ca85adf57b2a9926a53e74e3a3863d3d +Subproject commit acf8e5d268bc0a0da7a49e878400097a6d824c4c diff --git a/src/builtin/cd.c b/src/builtin/cd.c index b566272..1ccfdcb 100644 --- a/src/builtin/cd.c +++ b/src/builtin/cd.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:20 by charles #+# #+# */ -/* Updated: 2020/10/11 21:11:40 by charles ### ########.fr */ +/* Updated: 2020/10/15 09:38:55 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,8 +37,10 @@ int builtin_cd(char **argv, t_env env) if (argv[1] != NULL && argv[1][0] == '\0') return (env_export(env, "OLDPWD", oldwd) == NULL ? EVAL_FATAL : 0); if (argv[1] == NULL) + { if ((home = env_search(env, "HOME", NULL)) == NULL) return (errorf_ret(1, "cd: HOME not set\n")); + } else home = argv[1]; if (chdir(home) == -1) diff --git a/src/eval/cmd.c b/src/eval/cmd.c index 5bc397d..6b419f7 100644 --- a/src/eval/cmd.c +++ b/src/eval/cmd.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ -/* Updated: 2020/10/10 12:57:23 by cacharle ### ########.fr */ +/* Updated: 2020/10/15 09:41:48 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/path.c b/src/path.c index 3819555..a49cc6d 100644 --- a/src/path.c +++ b/src/path.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */ -/* Updated: 2020/10/09 13:36:26 by cacharle ### ########.fr */ +/* Updated: 2020/10/15 09:35:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,7 @@ static bool st_dir_search( return (false); while ((entry = readdir(dir)) != NULL) { - if (ft_strcmp(entry->d_name, exec_name) == 0) + if (ft_strcasecmp(entry->d_name, exec_name) == 0) { ft_strcpy(exec_path, dirname); ft_strcat(exec_path, "/"); diff --git a/src/utils.c b/src/utils.c index 4125eba..6efc0d1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:56:31 by cacharle #+# #+# */ -/* Updated: 2020/10/10 11:12:47 by cacharle ### ########.fr */ +/* Updated: 2020/10/15 09:39:27 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,6 @@ void print_prompt(void) { char cwd[PATH_MAX + 1]; - char *last_slash; ft_bzero(cwd, PATH_MAX + 1); if (getcwd(cwd, PATH_MAX) == NULL) @@ -32,9 +31,6 @@ void print_prompt(void) ft_putstr_fd("$ ", STDERR_FILENO); return ; } - last_slash = ft_strrchr(cwd, '/'); - if (last_slash != NULL && ft_strlen(cwd) != 1) - ft_strcpy(cwd, last_slash + 1); ft_putstr_fd("\033[0;32m", STDERR_FILENO); ft_putstr_fd(cwd, STDERR_FILENO); ft_putstr_fd("\033[0m$ ", STDERR_FILENO); -- cgit From 5e327efa642d03bf960716b5058c3d618f5b893f Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 15 Oct 2020 10:34:16 +0200 Subject: Fixing append redirection labeled has truncate redirection --- minishell_test | 2 +- src/eval/eval.c | 2 +- src/eval/redir.c | 2 +- src/lexer/utils.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/minishell_test b/minishell_test index acf8e5d..689138c 160000 --- a/minishell_test +++ b/minishell_test @@ -1 +1 @@ -Subproject commit acf8e5d268bc0a0da7a49e878400097a6d824c4c +Subproject commit 689138c699f15c7a892a79cf4ffe07b9fc6abb10 diff --git a/src/eval/eval.c b/src/eval/eval.c index c2aaf8c..d7229f7 100644 --- a/src/eval/eval.c +++ b/src/eval/eval.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/13 20:38:06 by charles #+# #+# */ -/* Updated: 2020/10/10 13:00:11 by cacharle ### ########.fr */ +/* Updated: 2020/10/15 10:28:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/eval/redir.c b/src/eval/redir.c index 8c154d5..257f26a 100644 --- a/src/eval/redir.c +++ b/src/eval/redir.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/15 11:05:34 by charles #+# #+# */ -/* Updated: 2020/10/10 11:40:16 by cacharle ### ########.fr */ +/* Updated: 2020/10/15 10:28:23 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lexer/utils.c b/src/lexer/utils.c index 0d8080c..b16a69a 100644 --- a/src/lexer/utils.c +++ b/src/lexer/utils.c @@ -6,7 +6,7 @@ /* By: nahaddac +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/07/16 08:18:15 by nahaddac #+# #+# */ -/* Updated: 2020/10/10 08:38:46 by cacharle ### ########.fr */ +/* Updated: 2020/10/15 10:32:00 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,12 +22,12 @@ enum e_tok tok_assign_tag(char *content) return (TAG_OR); if (content[0] == '|') return (TAG_PIPE); + if (ft_strncmp(content, ">>", 2) == 0) + return (TAG_REDIR_APPEND); if (content[0] == '>') return (TAG_REDIR_OUT); if (content[0] == '<') return (TAG_REDIR_IN); - if (ft_strncmp(content, ">>", 2) == 0) - return (TAG_REDIR_APPEND); if (content[0] == '(') return (TAG_PARENT_OPEN); if (content[0] == ')') -- cgit