From 163c93c0c2078ba21106b244bf4bfb3634086933 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 13 Mar 2017 14:48:40 +0100 Subject: [PATCH] issue #81, probleme de protection free historique, p-e resolu #77 aussi --- 42sh/includes/job_control.h | 2 +- 42sh/src/builtin/builtin_exit.c | 2 +- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/launch_process.c | 2 +- 42sh/src/history/add_str_in_history.c | 3 +-- 42sh/src/history/list_toolz.c | 6 +++--- 42sh/src/line-editing/readline.c | 10 +++------- 42sh/src/main/main.c | 10 ++++------ 42sh/src/parser/error_syntax.c | 2 +- 9 files changed, 16 insertions(+), 23 deletions(-) diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index e3b6293f..00985ade 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/13 13:52:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:29:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index ea146188..f00c59da 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/03/09 15:14:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:47:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 44704e32..de370722 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/13 14:21:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:37:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index ce74fee7..3d6a30ed 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:12:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:43:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/history/add_str_in_history.c b/42sh/src/history/add_str_in_history.c index 65b7fe8d..0a8c95ee 100644 --- a/42sh/src/history/add_str_in_history.c +++ b/42sh/src/history/add_str_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */ -/* Updated: 2017/03/13 14:23:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:30:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ void ft_add_in_history_file(char *str) char **hist; i = 0; - /* DG("gonna add [%s] in history"); */ hist = ft_strsplit(str, '\n'); if (!(home = ft_getenv(data_singleton()->env, "HOME"))) return ; diff --git a/42sh/src/history/list_toolz.c b/42sh/src/history/list_toolz.c index b3b17fb1..a12fd6a8 100644 --- a/42sh/src/history/list_toolz.c +++ b/42sh/src/history/list_toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/03/09 11:21:06 by gwojda ### ########.fr */ +/* Updated: 2017/03/13 14:47:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,13 @@ void free_history_list(t_list_history *head) { t_list_history *prev; - free(head->prev); + if (!head) + return ; while (head) { ft_strdel(&head->str); prev = head; head = head->next; - free(prev); } } diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 5c75131c..a30d7d38 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/10 15:48:30 by gwojda ### ########.fr */ +/* Updated: 2017/03/13 14:43:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,15 +15,11 @@ int readline(int fd, int prompt, char **input) { if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - { - if (get_next_line(fd, input) == 0) - return (1); - return (0); - } + return (get_next_line(fd, input) == 0); readline_init(prompt); *input = ft_read_stdin(); if (STR) - ft_current_str(STR, POS); + ft_current_str(STR, POS); ft_putchar('\n'); if (!prompt) *input = ft_history_parsing(); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index f36d7962..d186be71 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/13 14:23:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:47:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,11 +31,13 @@ int handle_instruction(int fd) if ((ret = readline(fd, get_lexer_stack(lexer) || parser.state == UNDEFINED || lexer.state == HEREDOC, &str))) { + DG("readline trap"); if (ret == -1) return (-1); return (parser.state == UNDEFINED ? error_eof(&token, &parser, &ast) : 1); } + DG("INPUT STRING IS [%s]", str); if (lexer.state == HEREDOC) { ft_strappend(&lexer.str, (char[]){'\n', 0}); @@ -71,7 +73,6 @@ int handle_instruction(int fd) } } btree_print(STDBUG, ast, &ft_putast); - /* ft_show_heredoc_data(ast->left->item); */ if (ft_exec(&ast)) return (1); instruction_free(&token, &parser, &ast); @@ -124,11 +125,8 @@ int main(int ac, char **av) } DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); while (handle_instruction(fd) == 0) - { -// lexer_clean; -// parser_clean; ; - } + DG("gonna exit"); builtin_exit(NULL, NULL, NULL); return (0); } diff --git a/42sh/src/parser/error_syntax.c b/42sh/src/parser/error_syntax.c index 6165e443..f74ae423 100644 --- a/42sh/src/parser/error_syntax.c +++ b/42sh/src/parser/error_syntax.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:15:35 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:10:56 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:41:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */