From 21276905b7167219cea75973d9f610c2b4978a90 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 10 Jan 2017 11:58:03 +0100 Subject: [PATCH] petit commit avant de merge job_control: unification de data_singleton (Samuel n'utilisais pas le meme) et quelques petites retouches. beau boulet sur le readline @sbenning --- 42sh/Makefile | 2 +- 42sh/includes/ft_input.h | 2 +- 42sh/includes/ft_readline.h | 18 +++++++------- 42sh/includes/line_editing.h | 24 ------------------- 42sh/includes/minishell.h | 5 ++-- 42sh/libft | 2 +- 42sh/src/line-editing/curs_term_setup.c | 2 +- 42sh/src/line-editing/ft_readline.c | 2 +- 42sh/src/line-editing/rl_comp_function.c | 4 ++-- 42sh/src/line-editing/rl_prompt.c | 2 +- 42sh/src/line-editing/rl_setup.c | 2 +- 42sh/src/main/data_init.c | 2 +- .../data_singleton.c} | 24 ++++++++----------- 42sh/src/main/main.c | 15 ++++++------ 14 files changed, 40 insertions(+), 66 deletions(-) delete mode 100644 42sh/includes/line_editing.h rename 42sh/src/{line-editing/ft_interactive_sh.c => main/data_singleton.c} (58%) diff --git a/42sh/Makefile b/42sh/Makefile index 488e22b2..b0d2688e 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -47,7 +47,7 @@ $(D_OBJ)/%.o: $(D_SRC)/minishell-exec/%.c includes/minishell.h @$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS) @echo "Compiling "$<"..." -$(D_OBJ)/%.o: $(D_SRC)/line-editing/%.c includes/line_editing.h +$(D_OBJ)/%.o: $(D_SRC)/line-editing/%.c includes/ft_readline.h @$(MKDIR) $(D_OBJ) @$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS) @echo "Compiling "$<"..." diff --git a/42sh/includes/ft_input.h b/42sh/includes/ft_input.h index 6d83c8c1..5e8c59a3 100644 --- a/42sh/includes/ft_input.h +++ b/42sh/includes/ft_input.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */ -/* Updated: 2016/12/14 13:50:33 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:45:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 2af95c04..51c6a05c 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */ -/* Updated: 2016/12/14 13:51:14 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:46:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,14 +65,14 @@ * QUOTING : Regroup ESC, QUOTE and DQUOTE */ -# define RL_FINISH 0x1 -# define RL_STACK 0x2 -# define RL_INSERT 0x4 -# define RL_SELECT 0x8 -# define RL_ESC 0x10 -# define RL_QUOTE 0x20 -# define RL_DQUOTE 0x40 -# define RL_QUOTING (RL_ESC|RL_QUOTE|RL_DQUOTE) +# define RL_FINISH (1 << 0) +# define RL_STACK (1 << 1) +# define RL_INSERT (1 << 2) +# define RL_SELECT (1 << 3) +# define RL_ESC (1 << 4) +# define RL_QUOTE (1 << 5) +# define RL_DQUOTE (1 << 6) +# define RL_QUOTING (RL_ESC | RL_QUOTE | RL_DQUOTE) typedef struct s_data t_data; typedef struct s_line t_line; diff --git a/42sh/includes/line_editing.h b/42sh/includes/line_editing.h deleted file mode 100644 index 19c01177..00000000 --- a/42sh/includes/line_editing.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* line_editing.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/10 09:41:50 by sbenning #+# #+# */ -/* Updated: 2016/12/10 10:24:12 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LINE_EDITING_H -# define LINE_EDITING_H - -# include "ft_readline.h" -# include "minishell.h" - -typedef struct s_data t_data; - -t_data **data_singleton(void); -int ft_interactive_sh(t_data *data); - -#endif diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 1c48ca09..0bd144e4 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2016/12/10 10:28:20 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:50:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,9 @@ # include "libft.h" -# include "line_editing.h" # include "lexer.h" # include "parser.h" +# include "ft_readline.h" # include "exec.h" # include @@ -68,6 +68,7 @@ extern t_stof g_builtins[]; extern pid_t g_pid; void sig_handler(int signo); +t_data *data_singleton(); int data_init(t_data *data); void data_exit(t_data *data); void ft_cleanup(void); diff --git a/42sh/libft b/42sh/libft index 97bc4fed..d799465c 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 97bc4fed552dce523e2de8fb744ba46ec877f8eb +Subproject commit d799465c2e0d51f24fe4d5cf1e51c5109a1617a0 diff --git a/42sh/src/line-editing/curs_term_setup.c b/42sh/src/line-editing/curs_term_setup.c index bf9a1a87..53aeb0b0 100644 --- a/42sh/src/line-editing/curs_term_setup.c +++ b/42sh/src/line-editing/curs_term_setup.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 16:50:26 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:50:10 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:54:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/src/line-editing/ft_readline.c index 6c477610..bf2f61ce 100644 --- a/42sh/src/line-editing/ft_readline.c +++ b/42sh/src/line-editing/ft_readline.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */ -/* Updated: 2016/12/12 10:48:50 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:51:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_comp_function.c b/42sh/src/line-editing/rl_comp_function.c index 1efd20f3..dd1d9729 100644 --- a/42sh/src/line-editing/rl_comp_function.c +++ b/42sh/src/line-editing/rl_comp_function.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 10:49:03 by sbenning #+# #+# */ -/* Updated: 2016/12/14 13:49:39 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:51:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int rl_comp_function(t_line *line, long int input) { t_data *data; - data = *data_singleton(); + data = data_singleton(); if (ft_autocomp(data) < 0) return (-1); line->size = ft_strlen(line->input); diff --git a/42sh/src/line-editing/rl_prompt.c b/42sh/src/line-editing/rl_prompt.c index 625cd9a5..81d8fdb3 100644 --- a/42sh/src/line-editing/rl_prompt.c +++ b/42sh/src/line-editing/rl_prompt.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/09 01:45:09 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:20:55 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:43:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_setup.c b/42sh/src/line-editing/rl_setup.c index 45c6da1a..64dc7250 100644 --- a/42sh/src/line-editing/rl_setup.c +++ b/42sh/src/line-editing/rl_setup.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:07:47 by sbenning #+# #+# */ -/* Updated: 2016/12/12 13:24:28 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 11:54:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 6fc5a928..1a4fb1bb 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: 2016/12/09 19:15:12 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 11:55:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_interactive_sh.c b/42sh/src/main/data_singleton.c similarity index 58% rename from 42sh/src/line-editing/ft_interactive_sh.c rename to 42sh/src/main/data_singleton.c index 5110f44b..33d75a04 100644 --- a/42sh/src/line-editing/ft_interactive_sh.c +++ b/42sh/src/main/data_singleton.c @@ -1,26 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* interactive_sh.c :+: :+: :+: */ +/* data_singleton.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/10 09:44:43 by sbenning #+# #+# */ -/* Updated: 2016/12/10 10:24:12 by sbenning ### ########.fr */ +/* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */ +/* Updated: 2017/01/10 11:47:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "line_editing.h" +#include "minishell.h" -t_data **data_singleton(void) +t_data *data_singleton() { - static t_data *data; + static t_data *data = NULL; - return (&data); -} - -int ft_interactive_sh(t_data *data) -{ - *data_singleton() = data; - return (ft_readline(&data->line)); + if (data == NULL) + data = malloc(sizeof(t_data)); + return (data); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index b5eeb81c..4103255e 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: 2016/12/09 22:15:07 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 11:56:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,24 +14,25 @@ int main(void) { - t_data data; + t_data *data; t_list *token; t_btree *ast; token = NULL; ast = NULL; - if (data_init(&data)) + data = data_singleton(); + if (data_init(data)) return (1); if (signal(SIGINT, sig_handler) == SIG_ERR) ft_dprintf(STDERR, "\ncan't catch SIGINT\n"); DG("{inv}{bol}{gre}start of shell"); while (1) { - if (ft_interactive_sh(&data)) + if (ft_readline(&data->line)) return (1); - DG("{inv}{mag}got command '%s'", data.line.input); + DG("{inv}{mag}got command '%s'", data->line.input); token = NULL; - if (ft_tokenize(&token, data.line.input, DEFAULT)) + if (ft_tokenize(&token, data->line.input, DEFAULT)) return (1); if (!token) continue ; @@ -41,7 +42,7 @@ int main(void) btree_print(STDERR, ast, &ft_putast); /* ft_dprintf(STDERR, "\n--- INFIX BREAKDOWN ---\n"); */ /* btree_apply_infix(ast, &ft_putast2); */ - if (ft_exec(&ast, &data)) + if (ft_exec(&ast, data)) return (1); } return (0);