diff --git a/.gitignore b/.gitignore index 09f18b8..070b7f7 100755 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ minishell # Makefile mini_tester/** minishell-tester/** +mini_tester diff --git a/Makefile b/Makefile index 4f2918c..577d46b 100755 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # -# By: vmoreau +#+ +:+ +#+ # +# By: hthomas +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/15 20:30:49 by hthomas #+# #+# # -# Updated: 2020/12/07 18:07:07 by vmoreau ### ########.fr # +# Updated: 2020/12/15 22:18:39 by hthomas ### ########.fr # # # # **************************************************************************** # @@ -22,6 +22,7 @@ SRCS += srcs/main.c #---------------Commands---------------# SRCS += srcs/commands/ft_cd.c \ + srcs/commands/ft_cd2.c \ srcs/commands/ft_echo.c \ srcs/commands/ft_env.c \ srcs/commands/ft_exit.c \ @@ -95,7 +96,7 @@ fclean: clean echoFCLEAN re: fclean all -.PHONY: clean fclean +.PHONY: all re clean fclean .SILENT: ###########################COLOR diff --git a/includes/minishell.h b/includes/minishell.h index 74fa841..a98c3e1 100755 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -6,7 +6,7 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/04 09:33:37 by hthomas #+# #+# */ -/* Updated: 2020/12/07 19:20:30 by hthomas ### ########.fr */ +/* Updated: 2020/12/15 22:20:29 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,6 +107,11 @@ t_glob g_glob; */ char *ft_echo(t_list_cmd *args); char *ft_cd(t_list_cmd *args, t_list *env); +char *ft_cd2(t_list_cmd *args, t_list *env, + struct stat *stats); +char *error_cd(char *arg, int err_status); +int test_cd_home(t_list_cmd *args, t_list *env, + struct stat *stats); char *ft_pwd(void); char *ft_export(t_list_cmd *args, t_list *env); void add_quote(char **tri); @@ -115,7 +120,7 @@ int have_equal(char *str); void print_exp_err(char **key, char **value); char *ft_unset(t_list_cmd *args, t_list *env); char *ft_env(t_list *env); -char *ft_exit(t_list_cmd *args, t_list *env); +char *ft_exit(t_list_line *lst_line, t_list *env); void clear_env_lst(t_list *env); /* @@ -161,14 +166,14 @@ void delete_empty_elements(t_list_cmd **cmd); void parse_error(char *input, t_list_line *lst_line); int print_synt_err(void); void print_prompt(void); -void not_found(char *cmd); +void not_found(t_list_line *lst_line, t_list *env); /* ** exec_line.c */ void exec_line(t_list_line *lst_line, t_list *env); t_list_cmd *reparse_var_env(t_list_cmd *cmd); -char *exec_cmd(t_list_cmd *cmd, t_list *env); +char *exec_cmd(t_list_line *lst_line, t_list *env); int make_and_exec_cmd(t_list_line *lst_line, t_list *env); t_list_cmd *split_add_back(t_list_cmd *cmd, void (*del)(t_list_cmd *), t_list_cmd *to_del); @@ -187,7 +192,7 @@ void set_env(char **envp, t_list **env); ** pipe.c */ int create_pipe(t_list_line **lst_line, t_list \ - *env, int fd_inold); + *env, int fd_inold, int *nb_wait); /* ** redirection.c @@ -197,7 +202,7 @@ int redirections(t_list_line *lst_line); /* ** searche_command.c */ -int search_command(t_list_cmd *cmd, t_list *env); +int search_command(t_list_line *lst_line, t_list *env); /* ** List diff --git a/srcs/commands/ft_cd.c b/srcs/commands/ft_cd.c index 9c0f22c..f71424c 100644 --- a/srcs/commands/ft_cd.c +++ b/srcs/commands/ft_cd.c @@ -6,7 +6,7 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/10/22 16:16:24 by vmoreau #+# #+# */ -/* Updated: 2020/12/07 18:57:59 by hthomas ### ########.fr */ +/* Updated: 2020/12/15 22:20:37 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ static void modif_oldpwd_pwd(t_list *env) modif_var_env(env, "OLDPWD", &find_var_env(env, "PWD=")[4]); if (!pwd) { + ft_putstr_fd("No such file or directory\n", STDERR); free(pwd); pwd = ft_strdup(&find_var_env(env, "PWD=")[4]); pwd = ft_strjoin_free(pwd, "/.."); @@ -30,7 +31,7 @@ static void modif_oldpwd_pwd(t_list *env) free(pwd); } -static char *error_cd(char *arg, int err_status) +char *error_cd(char *arg, int err_status) { char *ret; @@ -75,7 +76,7 @@ static char *cd_oldpwd(t_list *env, t_list_cmd *arg, struct stat *stats) return (ret); } -static int test_cd_home(t_list_cmd *args, t_list *env, struct stat *stats) +int test_cd_home(t_list_cmd *args, t_list *env, struct stat *stats) { if (stat(&find_var_env(env, "HOME=")[5], stats) != 0) return (1); @@ -88,18 +89,13 @@ static int test_cd_home(t_list_cmd *args, t_list *env, struct stat *stats) char *ft_cd(t_list_cmd *args, t_list *env) { struct stat stats; + char *ret; g_glob.exit = 0; if ((!args || !args->str)) { - if (chdir(&find_var_env(env, "HOME=")[5])) - if (find_var_env(env, "HOME=") == NULL) - return (error_cd("« HOME »", 3)); - else if (find_var_env(env, "HOME=")[5] == '\0') - return (ft_strdup("")); - else if (test_cd_home(args, env, &stats)) - return (error_cd(&find_var_env(env, "HOME=")[5], - test_cd_home(args, env, &stats))); + if ((ret = ft_cd2(args, env, &stats))) + return (ret); } else if (c_lst_size(args) > 1) return (error_cd(args->str, 0)); diff --git a/srcs/commands/ft_cd2.c b/srcs/commands/ft_cd2.c new file mode 100644 index 0000000..fdd5f09 --- /dev/null +++ b/srcs/commands/ft_cd2.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_cd2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/15 22:17:31 by hthomas #+# #+# */ +/* Updated: 2020/12/16 10:01:30 by hthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" + +char *ft_cd2(t_list_cmd *args, t_list *env, struct stat *stats) +{ + if (chdir(&find_var_env(env, "HOME=")[5])) + { + if (find_var_env(env, "HOME=") == NULL) + return (error_cd("« HOME »", 3)); + else if (find_var_env(env, "HOME=")[5] == '\0') + return (ft_strdup("")); + else if (test_cd_home(args, env, stats)) + return (error_cd(&find_var_env(env, "HOME=")[5], + test_cd_home(args, env, stats))); + } + return (NULL); +} diff --git a/srcs/commands/ft_exit.c b/srcs/commands/ft_exit.c index b629c9c..d77268c 100644 --- a/srcs/commands/ft_exit.c +++ b/srcs/commands/ft_exit.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_exit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hthomas +#+ +:+ +#+ */ +/* By: vmoreau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/10/22 16:16:34 by vmoreau #+# #+# */ -/* Updated: 2020/12/07 19:10:11 by hthomas ### ########.fr */ +/* Updated: 2020/12/10 16:35:05 by vmoreau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,18 +64,20 @@ static int check_args(t_list_cmd *args) return (ret); } -char *ft_exit(t_list_cmd *args, t_list *env) +char *ft_exit(t_list_line *lst_line, t_list *env) { int err; - err = check_args(args); + err = check_args(lst_line->cmd->next); if (err >= 0) { clear_env_lst(env); free(g_glob.path); if (!err) - if (args && (err = ft_atoi_strict(args->str))) + if (lst_line->cmd->next && + (err = ft_atoi_strict(lst_line->cmd->next->str))) g_glob.exit = err; + l_lst_clear(lst_line); exit(g_glob.exit); } return (NULL); diff --git a/srcs/commands/ft_export2.c b/srcs/commands/ft_export2.c index ba8b46d..eaf0426 100644 --- a/srcs/commands/ft_export2.c +++ b/srcs/commands/ft_export2.c @@ -6,7 +6,7 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/10/22 16:16:36 by vmoreau #+# #+# */ -/* Updated: 2020/12/07 19:05:39 by hthomas ### ########.fr */ +/* Updated: 2020/12/15 21:48:32 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,12 @@ int have_equal(char *str) while (str[i]) { if (str[i] == '=') + { if (i == 0) return (1); else return (i); + } i++; } return (0); diff --git a/srcs/commands/ft_unset.c b/srcs/commands/ft_unset.c index 0175bd8..e0e6d61 100644 --- a/srcs/commands/ft_unset.c +++ b/srcs/commands/ft_unset.c @@ -6,12 +6,11 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/10/22 16:16:41 by vmoreau #+# #+# */ -/* Updated: 2020/12/07 19:02:23 by hthomas ### ########.fr */ +/* Updated: 2020/12/15 21:49:42 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" -#include static char **catch_arg(t_list_cmd *args) { @@ -44,7 +43,7 @@ static void lst_del_next_node(t_list *env, char *var) tmp = env->next->next; free(env->next->content); free(env->next); - env->next == NULL; + env->next = NULL; env->next = tmp; break ; } @@ -69,7 +68,7 @@ char *ft_unset(t_list_cmd *args, t_list *env) else { g_glob.exit = 1; - ft_putstr_fd("minishell: export: « ", STDERR); + ft_putstr_fd("minishell: unset: « ", STDERR); ft_putstr_fd(var[i], STDERR); ft_putstr_fd(" » : not valid identifier\n", STDERR); } diff --git a/srcs/main.c b/srcs/main.c index 16f2568..d367019 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hthomas +#+ +:+ +#+ */ +/* By: vmoreau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/15 19:21:43 by hthomas #+# #+# */ -/* Updated: 2020/12/07 19:20:36 by hthomas ### ########.fr */ +/* Updated: 2020/12/11 16:32:54 by vmoreau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,14 +38,12 @@ static void sighandler(int signum) { kill(g_glob.pid, signum); ft_putstr_fd("\n", STDERR); - g_glob.exit = 130; g_glob.pid = 0; } else if (g_glob.pid && signum == SIGQUIT) { kill(g_glob.pid, signum); ft_putstr_fd("Quit (core dumped)\n", STDERR); - g_glob.exit = 131; g_glob.pid = 0; } else @@ -53,6 +51,10 @@ static void sighandler(int signum) ft_putstr_fd("\n", STDERR); print_prompt(); } + if (signum == SIGINT) + g_glob.exit = 130; + if (signum == SIGQUIT) + g_glob.exit = 131; } static void init_main(t_list **env, char **envp) diff --git a/srcs/other/exec_line.c b/srcs/other/exec_line.c index 0a11a3e..12078bd 100644 --- a/srcs/other/exec_line.c +++ b/srcs/other/exec_line.c @@ -6,54 +6,12 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/24 16:36:04 by hthomas #+# #+# */ -/* Updated: 2020/12/07 18:41:22 by hthomas ### ########.fr */ +/* Updated: 2020/12/16 10:53:48 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" -char *exec_cmd(t_list_cmd *cmd, t_list *env) -{ - if (!cmd) - return (NULL); - else if (!ft_strcmp(cmd->str, "echo")) - return (ft_echo(cmd->next)); - else if (!ft_strcmp(cmd->str, "cd")) - return (ft_cd(cmd->next, env)); - else if (!ft_strcmp(cmd->str, "pwd")) - return (ft_pwd()); - else if (!ft_strcmp(cmd->str, "export")) - return (ft_export(cmd->next, env)); - else if (!ft_strcmp(cmd->str, "unset")) - return (ft_unset(cmd->next, env)); - else if (!ft_strcmp(cmd->str, "env")) - return (ft_env(env)); - else if (!ft_strcmp(cmd->str, "exit")) - return (ft_exit(cmd->next, env)); - else if (!search_command(cmd, env)) - not_found(cmd->str); - return (NULL); -} - -t_list_cmd *reparse_var_env(t_list_cmd *cmd) -{ - t_list_cmd *start; - - start = NULL; - while (cmd) - { - if (cmd->flags & F_VAR_ENV && !(cmd->flags & F_DOUBLE_QUOTE)) - cmd = split_add_back(cmd, c_lst_free_one, cmd); - if (cmd->next && cmd->next->flags & F_VAR_ENV && - !(cmd->next->flags & F_DOUBLE_QUOTE)) - cmd->next = split_add_back(cmd->next, c_lst_remove_next_one, cmd); - if (!start) - start = cmd; - cmd = cmd->next; - } - return (start); -} - static void init_exec(int *fd_outold, int *fd_inold, t_list_line **start, t_list_line **lst_line) { @@ -68,31 +26,48 @@ static void reset_fds(int fd_outold, int fd_inold) dup2(fd_inold, STDIN); } +static void wait_all(int nb_wait) +{ + while (nb_wait--) + if (wait(&g_glob.exit) == g_glob.pid) + g_glob.exit = WEXITSTATUS(g_glob.exit); +} + +static int function(t_list_line *lst_line, t_list *env, int fd_outold, +int fd_inold) +{ + if (make_and_exec_cmd(lst_line, env)) + { + reset_fds(fd_outold, fd_inold); + return (FAILURE); + } + return (SUCCESS); +} + void exec_line(t_list_line *lst_line, t_list *env) { - char *ret; t_list_line *start; + int nb_wait; + int ret; int fd_outold; int fd_inold; - int i; + nb_wait = 0; init_exec(&fd_outold, &fd_inold, &start, &lst_line); while (lst_line) { while (lst_line && lst_line->pipe) { - if ((i = create_pipe(&lst_line, env, fd_inold)) == 42) + if ((ret = create_pipe(&lst_line, env, fd_inold, &nb_wait)) == 42) return (l_lst_clear(start)); - else if (i) + else if (ret) break ; } - if (make_and_exec_cmd(lst_line, env)) - { - reset_fds(fd_outold, fd_inold); + if (function(lst_line, env, fd_outold, fd_inold)) break ; - } reset_fds(fd_outold, fd_inold); lst_line = lst_line->next; } + wait_all(nb_wait); l_lst_clear(start); } diff --git a/srcs/other/exec_line2.c b/srcs/other/exec_line2.c index a79b555..a770f5a 100644 --- a/srcs/other/exec_line2.c +++ b/srcs/other/exec_line2.c @@ -6,7 +6,7 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/24 16:36:04 by hthomas #+# #+# */ -/* Updated: 2020/12/07 18:26:12 by hthomas ### ########.fr */ +/* Updated: 2020/12/16 10:54:56 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,6 +52,49 @@ t_list_cmd *split_add_back(t_list_cmd *cmd, void (*del)(t_list_cmd *),\ return (cmd); } +t_list_cmd *reparse_var_env(t_list_cmd *cmd) +{ + t_list_cmd *start; + + start = NULL; + while (cmd) + { + if (cmd->flags & F_VAR_ENV && !(cmd->flags & F_DOUBLE_QUOTE)) + cmd = split_add_back(cmd, c_lst_free_one, cmd); + if (cmd->next && cmd->next->flags & F_VAR_ENV && + !(cmd->next->flags & F_DOUBLE_QUOTE)) + cmd->next = split_add_back(cmd->next, c_lst_remove_next_one, cmd); + if (!start) + start = cmd; + cmd = cmd->next; + } + return (start); +} + +char *exec_cmd(t_list_line *lst_line, t_list *env) +{ + if (!lst_line->cmd) + return (NULL); + else if (!ft_strcmp(lst_line->cmd->str, "echo")) + return (ft_echo(lst_line->cmd->next)); + else if (!ft_strcmp(lst_line->cmd->str, "cd")) + return (ft_cd(lst_line->cmd->next, env)); + else if (!ft_strcmp(lst_line->cmd->str, "pwd")) + return (ft_pwd()); + else if (!ft_strcmp(lst_line->cmd->str, "export")) + return (ft_export(lst_line->cmd->next, env)); + else if (!ft_strcmp(lst_line->cmd->str, "unset")) + return (ft_unset(lst_line->cmd->next, env)); + else if (!ft_strcmp(lst_line->cmd->str, "env")) + return (ft_env(env)); + else if (!ft_strcmp(lst_line->cmd->str, "exit")) + return (ft_exit(lst_line, env)); + else if (!search_command(lst_line, env)) + not_found(lst_line, env); + g_glob.pid = 0; + return (NULL); +} + int make_and_exec_cmd(t_list_line *lst_line, t_list *env) { char *ret; @@ -64,14 +107,12 @@ int make_and_exec_cmd(t_list_line *lst_line, t_list *env) delete_empty_elements(&(lst_line->cmd)); if (redirections(lst_line)) return (FAILURE); - if (ret = exec_cmd(lst_line->cmd, env)) + if ((ret = exec_cmd(lst_line, env))) { - ft_putstr_fd(ret, lst_line->output); + ft_putstr(ret); free(ret); } if (lst_line->output > 2 && close(lst_line->output) < 0) ft_putstr_fd("error close output\n", STDERR); - if (lst_line->input > 2 && close(lst_line->input) < 0) - ft_putstr_fd("error close input\n", STDERR); return (SUCCESS); } diff --git a/srcs/other/pipe.c b/srcs/other/pipe.c index d741073..2f7ceaf 100644 --- a/srcs/other/pipe.c +++ b/srcs/other/pipe.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* pipe.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hthomas +#+ +:+ +#+ */ +/* By: vmoreau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/24 16:38:15 by hthomas #+# #+# */ -/* Updated: 2020/12/07 18:24:49 by hthomas ### ########.fr */ +/* Updated: 2020/12/15 11:31:32 by vmoreau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,21 +20,21 @@ static int last_pipe_exit(t_list_line **lst_line, int fd_inold) return (42); } -static int create_pipe2(int fdpipe[2], t_list_line **lst_line, t_list *env,\ +static int create_pipe2(int fdpipe[2], t_list_line **lst_line, t_list *env, int fd_inold) { if (g_glob.pid > 0) { close(fdpipe[1]); - wait(NULL); if ((*lst_line)->pipe && !((*lst_line)->next->next) &&\ !ft_strncmp((*lst_line)->next->cmd->str, "exit", 5)) return (last_pipe_exit(lst_line, fd_inold)); *lst_line = (*lst_line)->next; (*lst_line)->input = fdpipe[0]; dup2((*lst_line)->input, STDIN); + close(fdpipe[0]); } - else + else if (g_glob.pid == 0) { close(fdpipe[0]); (*lst_line)->output = fdpipe[1]; @@ -47,7 +47,8 @@ int fd_inold) return (SUCCESS); } -int create_pipe(t_list_line **lst_line, t_list *env, int fd_inold) +int create_pipe(t_list_line **lst_line, t_list *env, + int fd_inold, int *nb_wait) { t_list_cmd *cmd; int fdpipe[2]; @@ -59,6 +60,7 @@ int create_pipe(t_list_line **lst_line, t_list *env, int fd_inold) ft_putstr_fd("pipe: pipe failed\n", STDERR); return (FAILURE); } + (*nb_wait)++; g_glob.pid = fork(); if (g_glob.pid < 0) { diff --git a/srcs/other/print.c b/srcs/other/print.c index 4a56485..483d3f9 100644 --- a/srcs/other/print.c +++ b/srcs/other/print.c @@ -6,7 +6,7 @@ /* By: vmoreau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/20 18:23:14 by hthomas #+# #+# */ -/* Updated: 2020/12/07 14:19:25 by vmoreau ### ########.fr */ +/* Updated: 2020/12/16 10:59:37 by vmoreau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,10 @@ void print_prompt(void) { char *pwd; - ft_putstr_fd("\033[1;32m➜ \033[1;36m", STDERR); + if (g_glob.exit == 0) + ft_putstr_fd("\033[1;32m➜ \033[1;36m", STDERR); + else + ft_putstr_fd("\033[1;31m➜ \033[1;36m", STDERR); pwd = getcwd(NULL, 0); if (!pwd) ft_putstr_fd(g_glob.path, STDERR); @@ -26,15 +29,18 @@ void print_prompt(void) ft_putstr_fd("\033[0m$ ", STDERR); } -void not_found(char *str) +void not_found(t_list_line *lst_line, t_list *env) { char *ret; - ret = ft_strdup(str); + ret = ft_strdup(lst_line->cmd->str); ret = ft_strjoin_free(ret, ": command not found\n"); g_glob.exit = CMD_NOT_FOUND; ft_putstr_fd(ret, STDERR); free(ret); + clear_env_lst(env); + l_lst_clear(lst_line); + free(g_glob.path); exit(CMD_NOT_FOUND); } diff --git a/srcs/other/search_command.c b/srcs/other/search_command.c index fb16e0f..caf7864 100755 --- a/srcs/other/search_command.c +++ b/srcs/other/search_command.c @@ -6,7 +6,7 @@ /* By: hthomas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/24 13:04:47 by hthomas #+# #+# */ -/* Updated: 2020/12/07 18:44:55 by hthomas ### ########.fr */ +/* Updated: 2020/12/15 21:59:15 by hthomas ### ########.fr */ /* */ /* ************************************************************************** */ @@ -103,7 +103,7 @@ static int try_path(t_list_cmd *cmd, char **envp) return (ret); } -int search_command(t_list_cmd *cmd, t_list *env) +int search_command(t_list_line *lst_line, t_list *env) { int ret; int status; @@ -114,13 +114,15 @@ int search_command(t_list_cmd *cmd, t_list *env) envp = lst_to_chartab(env); if (g_glob.pid == 0) { - if (try_path(cmd, envp)) + if (lst_line->output > 2 && close(lst_line->output) < 0) + ft_putstr_fd("error close output\n", STDERR); + if (try_path(lst_line->cmd, envp)) exit(g_glob.exit); } else { wait(&g_glob.exit); - g_glob.exit = g_glob.exit >> 8; + g_glob.exit = WEXITSTATUS(g_glob.exit); ret = FAILURE; } ft_free_tab(envp); diff --git a/srcs/other/var_env.c b/srcs/other/var_env.c index 935f27d..3ce9e88 100644 --- a/srcs/other/var_env.c +++ b/srcs/other/var_env.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* var_env.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hthomas +#+ +:+ +#+ */ +/* By: vmoreau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/03 17:46:52 by hthomas #+# #+# */ -/* Updated: 2020/12/07 18:51:54 by hthomas ### ########.fr */ +/* Updated: 2020/12/10 16:34:57 by vmoreau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,11 +104,12 @@ void replace_all_var_env(t_list_cmd *cmd, t_list *env) if (cmd->str[i] == '$' && cmd->str[i + 1] != '\\' && cmd->str[i + 1] != '%' && !escaped(cmd->str, i) && !(cmd->flags & F_SIMPLE_QUOTE) && (cmd->str[i + 1] > '$' || - (!cmd->str[i + 1] && cmd->flags & F_NO_SP_AFTER))) + (!cmd->str[i + 1] && cmd->flags & F_NO_SP_AFTER))) { if (cmd->str[i + 1] == '?') err_code(cmd, env, i); - else if (cmd->str[i + 1] != '/') + else if (cmd->str[i + 1] != '/' && + cmd->flags != 5 && cmd->flags != 6) { test_var_env(cmd, env, &i); continue ; diff --git a/srcs/parse/parse.c b/srcs/parse/parse.c index 8e74524..6e3fcae 100755 --- a/srcs/parse/parse.c +++ b/srcs/parse/parse.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parse.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hthomas +#+ +:+ +#+ */ +/* By: vmoreau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/17 15:52:09 by hthomas #+# #+# */ -/* Updated: 2020/12/08 10:19:30 by hthomas ### ########.fr */ +/* Updated: 2020/12/10 15:27:41 by vmoreau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,9 +50,9 @@ static int flag_dollar_and_replace_tild(t_list_cmd *cmd, t_list *env) i = 0; while (cmd->str && cmd->str[i]) { - if (cmd->str[i] == '$' && !escaped(cmd->str, i) &&\ - !(cmd->flags & F_SIMPLE_QUOTE) && cmd->str[i + 1] > 32 && - !(cmd->flags & F_VAR_ENV)) + if (cmd->str[i] == '$' && !escaped(cmd->str, i) + && !(cmd->flags & F_SIMPLE_QUOTE) && cmd->str[i + 1] > 32 + && !(cmd->flags & F_VAR_ENV)) cmd->flags += F_VAR_ENV; else if (cmd->str[i] == '~' && !escaped(cmd->str, i) &&\ !in_quotes(cmd) && (!cmd->str[i + 1] || cmd->str[i + 1] == '/'))