From e711ffc92704dea451bd6a2cb7ec1a48a0acc202 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 13:07:46 +0100 Subject: [PATCH] issue #50 done --- 42sh/Makefile | 1 - 42sh/includes/ft_readline.h | 14 ++++++------- 42sh/{ => sample}/laurier.sh | 0 42sh/src/builtin/builtin_exit.c | 12 ++++++------ 42sh/src/exec/launch_builtin.c | 2 +- 42sh/src/exec/process_setexec.c | 2 +- 42sh/src/line-editing/control_c_and_d.c | 2 +- 42sh/src/line-editing/readline.c | 2 +- 42sh/src/main/data_init.c | 3 ++- 42sh/src/main/main.c | 4 ++-- 42sh/src/main/shell_exit.c | 26 ------------------------- 42sh/src/main/shell_init.c | 3 +-- 12 files changed, 22 insertions(+), 49 deletions(-) rename 42sh/{ => sample}/laurier.sh (100%) delete mode 100644 42sh/src/main/shell_exit.c diff --git a/42sh/Makefile b/42sh/Makefile index 2af77340..7e90da5e 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -250,7 +250,6 @@ main/data_singleton.c\ main/ft_putast.c\ main/instruction_free.c\ main/main.c\ -main/shell_exit.c\ main/shell_get_avdata.c\ main/shell_get_opts.c\ main/shell_init.c\ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 419d74df..44fc4bd5 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/07 18:36:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:00:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,12 +54,12 @@ # define TOUCHE_F5 892427035 # define TOUCHE_F6 925981467 -# define IS_QUOTES (1 << 0) -# define IS_BQUOTES (1 << 1) -# define IS_DQUOTES (1 << 2) -# define IS_BSLASH (1 << 3) -# define IS_ACCOLADE (1 << 4) -# define IS_BRACKET (1 << 5) +/* # define IS_QUOTES (1 << 0) */ +/* # define IS_BQUOTES (1 << 1) */ +/* # define IS_DQUOTES (1 << 2) */ +/* # define IS_BSLASH (1 << 3) */ +/* # define IS_ACCOLADE (1 << 4) */ +/* # define IS_BRACKET (1 << 5) */ # define STR data_singleton()->line.input # define POS data_singleton()->line.pos diff --git a/42sh/laurier.sh b/42sh/sample/laurier.sh similarity index 100% rename from 42sh/laurier.sh rename to 42sh/sample/laurier.sh diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index 370e60ac..80a40fca 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/02/18 16:48:42 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:04:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,15 +29,15 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) ft_dprintf(2, "{red}%s: you have live jobs (running or suspended).{eoc}\n", SHELL_NAME); return (0); } - if (av[1]) + if (av && av[1]) status = ft_atoi(av[1]); else - { - /* status = ft_atoi(ft_getenv(data_singleton()->env, "?")); */ - status = 0; - } + status = ft_atoi(ft_getenv(data_singleton()->env, "?")); ft_save_termios(-1); ft_free_hash_table(); + data_exit(); + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); exit(status); return (0); } diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index aed14ec5..47d090cc 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/launch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:51:58 by wescande ### ########.fr */ +/* Updated: 2017/03/08 13:04:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 8d10402f..9ad7aedf 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:42:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:54:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/control_c_and_d.c b/42sh/src/line-editing/control_c_and_d.c index d484cbaa..b80a982c 100644 --- a/42sh/src/line-editing/control_c_and_d.c +++ b/42sh/src/line-editing/control_c_and_d.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/02/14 14:08:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 12:56:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index f9bf13df..19b57e47 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/07 11:20:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:00:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index ce7e2a03..e1155419 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:38:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:05:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ int data_init(void) data = data_singleton(); data->env = ft_sstrdup(environ); + set_exitstatus(0, 1); data->comp = NULL; data->opts = 0; data->exec.fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 798ba6ce..22308690 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:41:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:59:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -124,6 +124,6 @@ int main(int ac, char **av) // parser_clean; ; } - shell_exit(); + builtin_exit(NULL, NULL, NULL); return (0); } diff --git a/42sh/src/main/shell_exit.c b/42sh/src/main/shell_exit.c deleted file mode 100644 index 30d4ab43..00000000 --- a/42sh/src/main/shell_exit.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* shell_exit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 17:37:04 by jhalford #+# #+# */ -/* Updated: 2017/02/21 20:14:43 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void shell_exit(void) -{ - t_data *data; - - /* DG("shell_exit()"); */ - data = data_singleton(); - data_exit(); - if (SH_HAS_JOBC(data->opts)) - job_kill_all(); - if (SH_IS_INTERACTIVE(data->opts)) - tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); -} diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index abf15a8e..d767aebd 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:38:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:04:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ void shell_init(int ac, char **av) data = data_singleton(); data->argc = ac; data->argv = ft_sstrdup(av); - /* atexit(&shell_exit); */ shell_get_opts(ac, av); if (SH_IS_INTERACTIVE(data->opts)) {