From 5d09281cb18b8d154595c4c5ecadafb52a7f2fc8 Mon Sep 17 00:00:00 2001 From: Gautier WOJDA Date: Tue, 24 Jan 2017 15:38:10 +0100 Subject: [PATCH] Ajout du fichier pour afficher l'historique --- 42sh/includes/ft_readline.h | 18 ++++++++------ 42sh/src/line-editing/builtin_history.c | 33 +++++++++++++++++++++++++ 42sh/src/line-editing/list_toolz.c | 4 ++- 42sh/src/line-editing/readline.c | 4 ++- 42sh/src/line-editing/toolz2.c | 10 +++++++- 42sh/src/main/main.c | 2 +- 6 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 42sh/src/line-editing/builtin_history.c diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 4e30cff8..42a110af 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/01/23 15:14:03 by gwojda ### ########.fr */ +/* Updated: 2017/01/24 15:14:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,12 +49,6 @@ # define TOUCHE_F5 892427035 # define TOUCHE_F6 925981467 -typedef struct s_line -{ - char *input; - int prompt_size; -} t_line; - typedef struct s_list_history { char *str; @@ -62,6 +56,16 @@ typedef struct s_list_history struct s_list_history *next; } t_list_history; +typedef struct s_line +{ + char *input; + int prompt_size; + int list_size; + t_list_history *list_end; +} t_line; + +void ft_history_builtin(void); +int ft_nbr_len(int nbr); int ft_found_next_char(char *str, size_t i); void ft_check_end_of_line(char *str, size_t pos); void ft_printall(char *str, size_t *pos); diff --git a/42sh/src/line-editing/builtin_history.c b/42sh/src/line-editing/builtin_history.c new file mode 100644 index 00000000..869091a8 --- /dev/null +++ b/42sh/src/line-editing/builtin_history.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_history.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */ +/* Updated: 2017/01/24 15:26:28 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_history_builtin(void) +{ + size_t len; + t_list_history *head; + + head = data_singleton()->line.list_end; + len = 1; + if (!head) + return ; + if (head && !head->str) + head = head->next; + while (head && head->str) + { + ft_putnc(' ', ft_nbr_len(data_singleton()->line.list_size) - ft_nbr_len(len)); + ft_printf("%zu %s\n", len, head->str); + ++len; + head = head->nextm; + } +} diff --git a/42sh/src/line-editing/list_toolz.c b/42sh/src/line-editing/list_toolz.c index 47a389a2..86df0fe5 100644 --- a/42sh/src/line-editing/list_toolz.c +++ b/42sh/src/line-editing/list_toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/01/19 16:42:57 by gwojda ### ########.fr */ +/* Updated: 2017/01/24 15:19:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ t_list_history *ft_create_history_list(char *str) void ft_push_back_history(t_list_history **head, t_list_history *new) { + ++(data_singleton()->line.list_size); if (!*head) { *head = new; @@ -38,6 +39,7 @@ void ft_push_back_history(t_list_history **head, t_list_history *new) (*head)->next = ft_create_history_list(NULL); (*head)->next->prev = (*head); (*head) = (*head)->next; + (data_singleton())->line.list_end = new; return ; } while ((*head)->next) diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 5e783640..121d1930 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/01/22 14:57:05 by gwojda ### ########.fr */ +/* Updated: 2017/01/24 15:29:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ void ft_init_line(void) { data_singleton()->line.input = NULL; data_singleton()->line.prompt_size = 0; + data_singleton()->line.list_size = 0; + data_singleton()->line.list_end = NULL; } struct termios *ft_save_stats_term(void) diff --git a/42sh/src/line-editing/toolz2.c b/42sh/src/line-editing/toolz2.c index 64b2d493..9be15d3e 100644 --- a/42sh/src/line-editing/toolz2.c +++ b/42sh/src/line-editing/toolz2.c @@ -6,12 +6,20 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */ -/* Updated: 2017/01/20 12:36:28 by gwojda ### ########.fr */ +/* Updated: 2017/01/24 15:00:16 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +int ft_nbr_len(int nbr) +{ + if (nbr % 10 != nbr) + return (ft_nbr_len(nbr / 10) + 1); + else + return (1); +} + void ft_puttermcaps(char *str) { char *res; diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 0a8c2043..ce0eae68 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/01/19 16:46:55 by gwojda ### ########.fr */ +/* Updated: 2017/01/24 15:04:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */