From 6f0daec1cb282346219f5d2de6cbb345a950cdfc Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 8 Mar 2017 11:51:21 +0100 Subject: [PATCH] oups, c'etait pas dans le bon dossier --- 42sh/src/line-editing/init_history.c | 37 +++++++++++++++++++++++ 42sh/src/line-editing/init_line.c | 44 ++++++++++++++++++++++++++++ 42sh/test | 10 ------- 3 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 42sh/src/line-editing/init_history.c create mode 100644 42sh/src/line-editing/init_line.c delete mode 100644 42sh/test diff --git a/42sh/src/line-editing/init_history.c b/42sh/src/line-editing/init_history.c new file mode 100644 index 00000000..c0be9d22 --- /dev/null +++ b/42sh/src/line-editing/init_history.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* init_history.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */ +/* Updated: 2017/03/07 17:34:35 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_init_history(void) +{ + int fd; + char *str; + char *home; + char *path; + + if (!(home = ft_getenv(data_singleton()->env, "HOME"))) + return ; + path = ft_str3join(home, "/", ".42sh_history"); + fd = open(path, O_RDONLY); + if (fd == -1) + return ; + while (get_next_line(fd, &str) > 0) + { + ft_push_back_history(&data_singleton()->line.list_beg, + ft_create_history_list(str)); + free(str); + } + free(path); + free(str); + close(fd); +} diff --git a/42sh/src/line-editing/init_line.c b/42sh/src/line-editing/init_line.c new file mode 100644 index 00000000..07862a71 --- /dev/null +++ b/42sh/src/line-editing/init_line.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* init_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */ +/* Updated: 2017/03/07 17:35:09 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_init_line(void) +{ + data_singleton()->line.input = NULL; + data_singleton()->line.copy_tmp = NULL; + data_singleton()->line.pos = 0; + data_singleton()->line.prompt_size = 0; + data_singleton()->line.list_size = 0; + data_singleton()->line.list_end = NULL; + data_singleton()->line.list_beg = NULL; + data_singleton()->line.opt = 0; +} + +void readline_init(char *prompt) +{ + static int beg = 0; + + if (!beg) + { + ft_init_line(); + ft_init_history(); + ft_save_termios(1); + beg = 1; + } + ft_init_termios(); + if (STR) + ft_strdel(&STR); + data_singleton()->line.list_cur = data_singleton()->line.list_beg; + POS = 0; + prompt ? ft_putstr(prompt) : ft_prompt(); +} diff --git a/42sh/test b/42sh/test deleted file mode 100644 index 148702e1..00000000 --- a/42sh/test +++ /dev/null @@ -1,10 +0,0 @@ - main.c 86  - main.c 86  - shell_init.c 27 interactive shell settings - token_print.c 29 11:[] - token_print.c 29 13:[ls] - token_print.c 29 06:[] - token_print.c 29 12:[] - ; - +----+----+ - COM OTHER