From 80f42941430eed1628bab8cd7710ba95894c5144 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 16 Mar 2017 10:43:42 +0100 Subject: [PATCH] mise a la norme hash - history - edition de ligne --- 42sh/src/hash_table/ft_add_hash.c | 8 ++++---- 42sh/src/history/add_str_in_history.c | 4 ++-- 42sh/src/history/surch_in_history.c | 10 +++------- 42sh/src/line-editing/completion.c | 7 ++----- 42sh/src/line-editing/ft_prompt.c | 10 ++++------ 42sh/src/line-editing/get_key.c | 3 +-- 42sh/src/line-editing/init_history.c | 6 ++---- 42sh/src/line-editing/init_line.c | 4 ++-- 42sh/src/line-editing/move_up_and_down.c | 5 +---- 9 files changed, 21 insertions(+), 36 deletions(-) diff --git a/42sh/src/hash_table/ft_add_hash.c b/42sh/src/hash_table/ft_add_hash.c index 5e2d95d3..b347f82a 100644 --- a/42sh/src/hash_table/ft_add_hash.c +++ b/42sh/src/hash_table/ft_add_hash.c @@ -6,19 +6,19 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:20:11 by gwojda #+# #+# */ -/* Updated: 2017/03/07 16:56:04 by wescande ### ########.fr */ +/* Updated: 2017/03/16 10:39:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ -# include "minishell.h" +#include "minishell.h" int ft_add_hash(t_process *p) { int id; t_hash hash; - if (!(hash.path = ft_findexec( - ft_getenv(data_singleton()->env, "PATH"), p->data.cmd.av[0]))) + if (!(hash.path = ft_findexec(ft_getenv( + data_singleton()->env, "PATH"), p->data.cmd.av[0]))) return (0); hash.key = ft_strdup(p->data.cmd.av[0]); id = ft_hash_str(p->data.cmd.av[0]); diff --git a/42sh/src/history/add_str_in_history.c b/42sh/src/history/add_str_in_history.c index 79c80b30..d770c59d 100644 --- a/42sh/src/history/add_str_in_history.c +++ b/42sh/src/history/add_str_in_history.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */ -/* Updated: 2017/03/14 14:58:41 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 10:40:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void ft_add_in_history_file(char *str) +void ft_add_in_history_file(char *str) { int fd; int i; diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 007ad0d8..89ae58be 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/03/09 12:15:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 10:41:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,8 +70,7 @@ void ft_surch_in_history(void) srch_pos = 0; str_srch = NULL; - if (STR) - ft_strdel(&STR); + (STR) ? ft_strdel(&STR) : 0; while (42) { ft_give_new_prompt(str_srch, srch_pos); @@ -84,10 +83,7 @@ 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); + STR = (!*str_srch) ? NULL : ft_strget_history(str_srch); } else if (ret != 127) break ; diff --git a/42sh/src/line-editing/completion.c b/42sh/src/line-editing/completion.c index 10caf891..15828894 100644 --- a/42sh/src/line-editing/completion.c +++ b/42sh/src/line-editing/completion.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */ -/* Updated: 2017/03/09 15:20:18 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 10:33:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,10 +44,7 @@ int ft_completion(int ret) boolean = completion(ret); if (boolean || ret == 10) { - if (pos_tmp) - --pos_tmp; - else - ft_puttermcaps("nd"); + (pos_tmp) ? --pos_tmp : ft_puttermcaps("nd"); ft_get_beggin_with_curs(STR, &pos_tmp); tmp = pos_tmp; ft_puttermcaps("cd"); diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index 8a6614fa..da8baabe 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/03/15 18:14:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 10:38:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,16 +38,15 @@ static int promt_git_status(int fd) free(tmp); len = ft_strlen(line); ft_strdel(&line); - fflush(NULL); return (len + 8); } static int ft_git_status(void) { + static char *exec[] = {"git", "status", "--porcelain", "--branch", NULL}; int pip[2]; - pid_t soon; - char *exec[] = {"git", "status", "--porcelain", "--branch", NULL}; - int ret; + pid_t soon; + int ret; pipe(pip); if ((soon = fork())) @@ -104,7 +103,6 @@ void ft_prompt(void) ft_printf("\x1b[38;5;1m➜ "); else ft_printf("\x1b[38;5;10m➜ "); - fflush(NULL); ft_putstr("\x1b[38;5;361m"); ret += ft_currend_dir(); ret += ft_git_status(); diff --git a/42sh/src/line-editing/get_key.c b/42sh/src/line-editing/get_key.c index 811d7aa8..b9549e21 100644 --- a/42sh/src/line-editing/get_key.c +++ b/42sh/src/line-editing/get_key.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ -/* Updated: 2017/03/15 14:07:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 10:34:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,7 +63,6 @@ char *ft_read_stdin(void) ret = 0; j = 0; read(0, &ret, sizeof(int)); - DG("key hexa value = %X", ret); if (ft_completion(ret)) continue ; while (g_key[j].value && g_key[j].value != ret) diff --git a/42sh/src/line-editing/init_history.c b/42sh/src/line-editing/init_history.c index 44b56f87..0faa58b2 100644 --- a/42sh/src/line-editing/init_history.c +++ b/42sh/src/line-editing/init_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */ -/* Updated: 2017/03/14 13:48:23 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 10:36:36 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,8 +39,6 @@ void ft_init_history(void) return ; path = ft_str3join(home, "/", ".42sh_history"); fd = open(path, O_RDONLY); - if (fd == -1) - return ; while (get_next_line(fd, &str) > 0) { if (ft_str_is_print(str) && *str) @@ -51,7 +49,7 @@ void ft_init_history(void) free(str); } if (corrupt) - ft_putendl_fd("42sh: corrupt history file /Users/gwojda/.zsh_history", 2); + ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home); free(path); free(str); close(fd); diff --git a/42sh/src/line-editing/init_line.c b/42sh/src/line-editing/init_line.c index 6816e958..f25e1df6 100644 --- a/42sh/src/line-editing/init_line.c +++ b/42sh/src/line-editing/init_line.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */ -/* Updated: 2017/03/09 11:55:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 10:37:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void ft_init_line(void) +void ft_init_line(void) { data_singleton()->line.input = NULL; data_singleton()->line.copy_tmp = NULL; diff --git a/42sh/src/line-editing/move_up_and_down.c b/42sh/src/line-editing/move_up_and_down.c index 742f232a..af382007 100644 --- a/42sh/src/line-editing/move_up_and_down.c +++ b/42sh/src/line-editing/move_up_and_down.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */ -/* Updated: 2017/03/05 15:32:18 by wescande ### ########.fr */ +/* Updated: 2017/03/16 10:31:54 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,9 +40,6 @@ static void ft_up_2(size_t *pos, char *str) void ft_up(void) { -// int i; - -// i = 0; if (!STR || !POS) return ; if (STR[POS - 1] == '\n')