diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 336d1809..3647d65a 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/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_get_size_prev(char *str, size_t pos); void sigwinch_resize(int sig); +size_t ft_hist_len(void); char *ft_read_stdin(void); void ft_end(void); diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index d2ec5ae2..01126335 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -6,7 +6,7 @@ /* 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); 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_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; return (1); } @@ -39,18 +40,19 @@ static int ft_history_parsing_3(char *str, int *i) if (ft_history_parsing_4(str, i)) 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, - data_singleton()->line.list_size - ft_atoi(str + *i + 2), - ft_nbr_len(ft_atoi(str + *i + 2)) + 2); + data_singleton()->line.list_size - ft_atoi(str + *i + 1), + ft_nbr_len(ft_atoi(str + *i + 1)) + 1); i += tmp; } else if (str[*i + 1] == '?') ft_realloc_str_history_3(&(data_singleton()->line.input), *i, 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_strdupi_w(str + *i + 1)); else @@ -85,8 +87,9 @@ char *ft_history_parsing(void) boolean = 1; if (!ft_history_parsing_3(STR, &i)) boolean = 0; + else + break ; } - STR = data_singleton()->line.input; ++i; } if (boolean) diff --git a/42sh/src/history/history_parsing_toolz.c b/42sh/src/history/history_parsing_toolz.c index ef10163e..4c2f00b7 100644 --- a/42sh/src/history/history_parsing_toolz.c +++ b/42sh/src/history/history_parsing_toolz.c @@ -6,7 +6,7 @@ /* 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); if (!list->str) list = list->prev; - while (i < nb_his && list->str) + while (i < nb_his && list && list->str) { list = list->prev; ++i; @@ -63,7 +63,7 @@ static char *ft_strget_histo(char *str) return (NULL); if (!list->str) 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; return (list->str); } diff --git a/42sh/src/history/list_toolz.c b/42sh/src/history/list_toolz.c index abdf45fd..bdf71e76 100644 --- a/42sh/src/history/list_toolz.c +++ b/42sh/src/history/list_toolz.c @@ -6,7 +6,7 @@ /* 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); (*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); +} diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 89ae58be..c74ee555 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,17 +6,15 @@ /* 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" -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) - ft_get_beggin_with_curs(str, pos); - else if (*pos) + if (*pos) { ft_putnc('\b', *pos); (*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) { - ft_clear_prompt(STR, &POS, srch_pos); + ft_clear_prompt(&POS, srch_pos); data_singleton()->line.prompt_size = 21; if (str_srch) 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) { - ft_clear_prompt(STR, &POS, srch_pos); + ft_clear_prompt(&POS, srch_pos); data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); if (STR) { diff --git a/42sh/src/line-editing/init_history.c b/42sh/src/line-editing/init_history.c index 0faa58b2..18ba9c85 100644 --- a/42sh/src/line-editing/init_history.c +++ b/42sh/src/line-editing/init_history.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */