oups, c'etait pas dans le bon dossier
This commit is contained in:
parent
ff13c21d37
commit
6f0daec1cb
3 changed files with 81 additions and 10 deletions
37
42sh/src/line-editing/init_history.c
Normal file
37
42sh/src/line-editing/init_history.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* init_history.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
44
42sh/src/line-editing/init_line.c
Normal file
44
42sh/src/line-editing/init_line.c
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* init_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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();
|
||||||
|
}
|
||||||
10
42sh/test
10
42sh/test
|
|
@ -1,10 +0,0 @@
|
||||||
[7m[33m main.c [1m[34m86 [0m[0m
|
|
||||||
[7m[33m main.c [1m[34m86 [0m[0m
|
|
||||||
[7m[33m shell_init.c [1m[34m27 [0minteractive shell settings[0m
|
|
||||||
[7m[33m token_print.c [1m[34m29 [0m11:[][0m
|
|
||||||
[7m[33m token_print.c [1m[34m29 [0m13:[ls][0m
|
|
||||||
[7m[33m token_print.c [1m[34m29 [0m06:[][0m
|
|
||||||
[7m[33m token_print.c [1m[34m29 [0m12:[][0m
|
|
||||||
;
|
|
||||||
+----+----+
|
|
||||||
COM OTHER
|
|
||||||
Loading…
Reference in a new issue