From 01d8cbca7ea6d9647d5a012861df134544ff6e92 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 9 Mar 2017 12:16:23 +0100 Subject: [PATCH] correction bug sur control R + d'autres ptits trucs --- 42sh/includes/ft_readline.h | 4 +++- 42sh/src/builtin/builtin_exit.c | 3 ++- 42sh/src/history/list_toolz.c | 16 +++++++++++++++- 42sh/src/history/surch_in_history.c | 8 ++++++-- 42sh/src/line-editing/init_line.c | 3 ++- .../line-editing/lib_line_editing/tool_line_2.c | 13 ++----------- .../lib_line_editing/toolz_parseur.c | 4 +--- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 89583bc5..17a0434a 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/08 23:48:33 by ariard ### ########.fr */ +/* Updated: 2017/03/09 11:55:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,6 +84,7 @@ typedef struct s_line int prompt_size; int list_size; char opt; + char is_prompt; t_list_history *list_end; t_list_history *list_cur; t_list_history *list_beg; @@ -127,6 +128,7 @@ int ft_nb_last_line(char *str, size_t pos); int ft_put(int nb); void ft_check_line(void); void ft_clear_window(void); +void free_history_list(t_list_history *head); char *ft_read_stdin(void); void ft_end(void); diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index dbb33130..c77af593 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/08 23:25:01 by ariard ### ########.fr */ +/* Updated: 2017/03/09 11:17:21 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,7 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) status = ft_atoi(ft_getenv(data_singleton()->env, "?")); ft_save_termios(-1); ft_free_hash_table(); + free_history_list(data_singleton()->line.list_beg); data_exit(); if (SH_IS_INTERACTIVE(data_singleton()->opts)) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); diff --git a/42sh/src/history/list_toolz.c b/42sh/src/history/list_toolz.c index 51bde359..b3b17fb1 100644 --- a/42sh/src/history/list_toolz.c +++ b/42sh/src/history/list_toolz.c @@ -6,12 +6,26 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:08:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 11:21:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +void free_history_list(t_list_history *head) +{ + t_list_history *prev; + + free(head->prev); + while (head) + { + ft_strdel(&head->str); + prev = head; + head = head->next; + free(prev); + } +} + t_list_history *ft_create_history_list(char *str) { t_list_history *list; diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 28360348..007ad0d8 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/02/04 15:50:26 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 12:15:09 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,7 +52,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos) static void ft_modify_str(char *str_srch, size_t srch_pos) { ft_clear_prompt(STR, &POS, srch_pos); - ft_prompt(); + data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); if (STR) { STR = ft_strdup(STR); @@ -84,6 +84,10 @@ void ft_surch_in_history(void) --srch_pos; str_srch = ft_remove_imput(str_srch, srch_pos); ft_puttermcaps("le"); + if (!*str_srch) + STR = NULL; + else + STR = ft_strget_history(str_srch); } else if (ret != 127) break ; diff --git a/42sh/src/line-editing/init_line.c b/42sh/src/line-editing/init_line.c index 10e73e25..6816e958 100644 --- a/42sh/src/line-editing/init_line.c +++ b/42sh/src/line-editing/init_line.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */ -/* Updated: 2017/03/08 23:52:45 by ariard ### ########.fr */ +/* Updated: 2017/03/09 11:55:21 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,4 +41,5 @@ void readline_init(int prompt) data_singleton()->line.list_cur = data_singleton()->line.list_beg; POS = 0; prompt ? ft_putstr("> ") : ft_prompt(); + data_singleton()->line.is_prompt = prompt ? 0 : 1; } diff --git a/42sh/src/line-editing/lib_line_editing/tool_line_2.c b/42sh/src/line-editing/lib_line_editing/tool_line_2.c index 1059fdd1..8899cf8b 100644 --- a/42sh/src/line-editing/lib_line_editing/tool_line_2.c +++ b/42sh/src/line-editing/lib_line_editing/tool_line_2.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */ -/* Updated: 2017/03/07 17:32:58 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 11:09:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,16 +14,7 @@ void ft_clear_window(void) { - pid_t soon_pid; - char *tab_str[2]; - - tab_str[0] = "/usr/bin/clear"; - tab_str[1] = NULL; - soon_pid = fork(); - if (soon_pid != 0) - wait(NULL); - else - execve("/usr/bin/clear", tab_str, data_singleton()->env); + ft_puttermcaps("cl"); } static void ft_read_tmp(void) diff --git a/42sh/src/line-editing/lib_line_editing/toolz_parseur.c b/42sh/src/line-editing/lib_line_editing/toolz_parseur.c index 7c14dc9b..57612151 100644 --- a/42sh/src/line-editing/lib_line_editing/toolz_parseur.c +++ b/42sh/src/line-editing/lib_line_editing/toolz_parseur.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ -/* Updated: 2017/03/05 15:31:42 by wescande ### ########.fr */ +/* Updated: 2017/03/09 12:07:09 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,10 @@ char *ft_realloc_imput(char *str, int a, size_t pos) { -// int i; char tmp[2]; char *str_tmp; char *new_str; -// i = 0; tmp[0] = (char)a; tmp[1] = '\0'; if (!str)