mise a la norme hash - history - edition de ligne
This commit is contained in:
parent
8ffd499c97
commit
80f4294143
9 changed files with 21 additions and 36 deletions
|
|
@ -6,19 +6,19 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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]);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 ;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue