fixe somes history bugs

This commit is contained in:
gwojda 2017-03-16 12:42:00 +01:00
parent 80f4294143
commit 1c8148af3f
6 changed files with 40 additions and 23 deletions

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/15 18:52:11 by jhalford ### ########.fr */ /* Updated: 2017/03/16 12:10:24 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -129,6 +129,7 @@ void free_history_list(t_list_history *head);
int ft_nb_of_line(char *str, size_t pos); int ft_nb_of_line(char *str, size_t pos);
int ft_get_size_prev(char *str, size_t pos); int ft_get_size_prev(char *str, size_t pos);
void sigwinch_resize(int sig); void sigwinch_resize(int sig);
size_t ft_hist_len(void);
char *ft_read_stdin(void); char *ft_read_stdin(void);
void ft_end(void); void ft_end(void);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
/* Updated: 2017/02/16 12:28:52 by gwojda ### ########.fr */ /* Updated: 2017/03/16 12:39:45 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,11 +22,12 @@ static int ft_history_parsing_4(char *str, int *i)
++(*i); ++(*i);
return (1); return (1);
} }
else if (ft_isdigit(str[(*i) + 1])) else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]) &&
(size_t)ft_atoi(str + (*i) + 2) < ft_hist_len())
{ {
tmp = ft_nbr_len(ft_atoi(str + *i + 1)); tmp = ft_nbr_len(ft_atoi(str + *i + 2));
ft_realloc_str_history(&(data_singleton()->line.input), *i, ft_realloc_str_history(&(data_singleton()->line.input), *i,
ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1); ft_atoi(str + (*i) + 2), ft_nbr_len(ft_atoi(str + *i + 2)) + 2);
(*i) += tmp; (*i) += tmp;
return (1); return (1);
} }
@ -39,18 +40,19 @@ static int ft_history_parsing_3(char *str, int *i)
if (ft_history_parsing_4(str, i)) if (ft_history_parsing_4(str, i))
return (1); return (1);
else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2])) else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) <
ft_hist_len())
{ {
tmp = ft_nbr_len(ft_atoi(str + *i + 2)); tmp = ft_nbr_len(ft_atoi(str + *i + 1));
ft_realloc_str_history(&(data_singleton()->line.input), *i, ft_realloc_str_history(&(data_singleton()->line.input), *i,
data_singleton()->line.list_size - ft_atoi(str + *i + 2), data_singleton()->line.list_size - ft_atoi(str + *i + 1),
ft_nbr_len(ft_atoi(str + *i + 2)) + 2); ft_nbr_len(ft_atoi(str + *i + 1)) + 1);
i += tmp; i += tmp;
} }
else if (str[*i + 1] == '?') else if (str[*i + 1] == '?')
ft_realloc_str_history_3(&(data_singleton()->line.input), *i, ft_realloc_str_history_3(&(data_singleton()->line.input), *i,
ft_strdupi_w(str + *i + 2)); ft_strdupi_w(str + *i + 2));
else if (str[*i + 1] != ' ') else if (str[*i + 1] && str[*i + 1] != ' ')
ft_realloc_str_history_2(&(data_singleton()->line.input), *i, ft_realloc_str_history_2(&(data_singleton()->line.input), *i,
ft_strdupi_w(str + *i + 1)); ft_strdupi_w(str + *i + 1));
else else
@ -85,8 +87,9 @@ char *ft_history_parsing(void)
boolean = 1; boolean = 1;
if (!ft_history_parsing_3(STR, &i)) if (!ft_history_parsing_3(STR, &i))
boolean = 0; boolean = 0;
else
break ;
} }
STR = data_singleton()->line.input;
++i; ++i;
} }
if (boolean) if (boolean)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */ /* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */
/* Updated: 2017/02/19 11:55:44 by gwojda ### ########.fr */ /* Updated: 2017/03/16 11:58:10 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,7 @@ static char *ft_nget_histo(size_t nb_his)
return (NULL); return (NULL);
if (!list->str) if (!list->str)
list = list->prev; list = list->prev;
while (i < nb_his && list->str) while (i < nb_his && list && list->str)
{ {
list = list->prev; list = list->prev;
++i; ++i;
@ -63,7 +63,7 @@ static char *ft_strget_histo(char *str)
return (NULL); return (NULL);
if (!list->str) if (!list->str)
list = list->prev; list = list->prev;
while (list->str && ft_strncmp(list->str, str, ft_strlen(str))) while (list && list->str && ft_strncmp(list->str, str, ft_strlen(str)))
list = list->prev; list = list->prev;
return (list->str); return (list->str);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */
/* Updated: 2017/03/14 15:20:22 by gwojda ### ########.fr */ /* Updated: 2017/03/16 12:10:14 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -67,3 +67,18 @@ void ft_push_back_history(t_list_history **head, t_list_history *new)
new->next = (*head); new->next = (*head);
(*head)->prev = new; (*head)->prev = new;
} }
size_t ft_hist_len(void)
{
size_t len;
t_list_history *list;
len = 0;
list = data_singleton()->line.list_beg;
while (list)
{
++len;
list = list->prev;
}
return (len);
}

View file

@ -6,17 +6,15 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
/* Updated: 2017/03/16 10:41:53 by gwojda ### ########.fr */ /* Updated: 2017/03/16 11:53:55 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static void ft_clear_prompt(char *str, size_t *pos, size_t srch_pos) static void ft_clear_prompt(size_t *pos, size_t srch_pos)
{ {
if (str) if (*pos)
ft_get_beggin_with_curs(str, pos);
else if (*pos)
{ {
ft_putnc('\b', *pos); ft_putnc('\b', *pos);
(*pos) = 0; (*pos) = 0;
@ -35,7 +33,7 @@ static void ft_surch_and_realloc(char **str, char **str_srch,
static void ft_give_new_prompt(char *str_srch, size_t srch_pos) static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
{ {
ft_clear_prompt(STR, &POS, srch_pos); ft_clear_prompt(&POS, srch_pos);
data_singleton()->line.prompt_size = 21; data_singleton()->line.prompt_size = 21;
if (str_srch) if (str_srch)
ft_printf("\033[35m(reverse-i-search)`\033[32m%s\033[35m': \033[37m", ft_printf("\033[35m(reverse-i-search)`\033[32m%s\033[35m': \033[37m",
@ -51,7 +49,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
static void ft_modify_str(char *str_srch, size_t srch_pos) static void ft_modify_str(char *str_srch, size_t srch_pos)
{ {
ft_clear_prompt(STR, &POS, srch_pos); ft_clear_prompt(&POS, srch_pos);
data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> ");
if (STR) if (STR)
{ {

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */ /* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */
/* Updated: 2017/03/16 10:36:36 by gwojda ### ########.fr */ /* Updated: 2017/03/16 11:32:29 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */