From d1d946315a6d7f5b704f85573b91ec41c8ecb3db Mon Sep 17 00:00:00 2001 From: narnaud Date: Mon, 16 May 2022 11:59:15 +0200 Subject: [PATCH] -fix: quotes after redir, exit with multiple args, return code save only on last pipe cmd --- built-in.c | 8 +++++--- caller.c | 4 ++-- lexer.c | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/built-in.c b/built-in.c index fffc6f5..b3a3ba3 100755 --- a/built-in.c +++ b/built-in.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */ -/* Updated: 2022/05/16 10:48:07 by mea ### ########.fr */ +/* Updated: 2022/05/16 11:55:41 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,9 +94,11 @@ int ft_cd(t_command *cmd) int ft_exit(t_datas *datas, t_command *cmd) { - if (cmd->argc < 2) + if (cmd->argc == 1) halt(datas, EXIT_SUCCESS, 0); - else + else if (cmd->argc == 2) halt(datas, ft_atoi(cmd->argv[1]), 0); + else + ft_putstr_fd("minishell: exit: too many arguments\n", 2); return (1); } diff --git a/caller.c b/caller.c index d219c39..a461368 100755 --- a/caller.c +++ b/caller.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ -/* Updated: 2022/05/16 10:42:40 by mea ### ########.fr */ +/* Updated: 2022/05/16 11:57:13 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -119,9 +119,9 @@ int caller(t_datas *datas, t_command *cmd) if (cmd->ope == PIPE) caller(datas, cmd->next); waitpid(cmd->pid, &status, 0); - datas->exit_code = handle_status(datas, status); if (cmd->ope != PIPE) { + datas->exit_code = handle_status(datas, status); while (cmd->next && !((cmd->ope == AND && !datas->exit_code) \ || (cmd->ope == OR && datas->exit_code))) cmd = cmd->next; diff --git a/lexer.c b/lexer.c index edb56f7..0a023ad 100755 --- a/lexer.c +++ b/lexer.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ -/* Updated: 2022/05/16 10:21:34 by mea ### ########.fr */ +/* Updated: 2022/05/16 11:46:13 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ void tmp_dealer(t_datas *datas, t_lexer *lex, char *line, char *tmp) } else if (check_register(lex, &line, tmp)) tmp_i = (ft_bzero(tmp, STR_MAX_SIZE), 0); - else + else if (!(lex->state == ROOT_ST && lex->deep == 0 && (*line == '"' || *line == '\''))) tmp[tmp_i++] = *(line++); } }