This commit is contained in:
Jack Halford 2017-03-22 12:45:10 +01:00
commit 297228e6b0
2 changed files with 16 additions and 16 deletions

View file

@ -6,13 +6,13 @@
/* 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/03/18 15:04:16 by gwojda ### ########.fr */ /* Updated: 2017/03/22 12:09:59 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int ft_history_parsing_4(char *str, int *i) static int history_parsing_nb_and_previous(char *str, int *i)
{ {
int tmp; int tmp;
@ -34,11 +34,11 @@ static int ft_history_parsing_4(char *str, int *i)
return (0); return (0);
} }
static int ft_history_parsing_3(char *str, int *i) static int history_parsing_nb_and_name(char *str, int *i)
{ {
int tmp; int tmp;
if (ft_history_parsing_4(str, i)) if (history_parsing_nb_and_previous(str, i))
return (1); return (1);
else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) < else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) <
ft_hist_len()) ft_hist_len())
@ -60,18 +60,20 @@ static int ft_history_parsing_3(char *str, int *i)
return (1); return (1);
} }
static int ft_history_parsing_2(int has_prompt, char **input) static int rematch_history_parsing(int has_prompt, char **input)
{ {
int ret;
data_singleton()->line.pos = 0; data_singleton()->line.pos = 0;
has_prompt ? ft_prompt() : ft_putstr("> "); has_prompt ? ft_prompt() : ft_putstr("> ");
if (ft_read_stdin(input) < 0) if ((ret = ft_read_stdin(input)) < 0)
return (-1); return (-1);
if (data_singleton()->line.input) if (data_singleton()->line.input)
ft_current_str(data_singleton()->line.input, ft_current_str(data_singleton()->line.input,
data_singleton()->line.pos); data_singleton()->line.pos);
ft_putchar('\n'); ft_putchar('\n');
ft_history_parsing(has_prompt, input); ft_history_parsing(has_prompt, input);
return (0); return (ret);
} }
int ft_history_parsing(int has_prompt, char **input) int ft_history_parsing(int has_prompt, char **input)
@ -88,14 +90,14 @@ int ft_history_parsing(int has_prompt, char **input)
if (data_singleton()->line.input[i] == '!') if (data_singleton()->line.input[i] == '!')
{ {
boolean = 1; boolean = 1;
if (!ft_history_parsing_3(data_singleton()->line.input, &i)) if (!history_parsing_nb_and_name(data_singleton()->line.input, &i))
boolean = 0; boolean = 0;
else else
break ; break ;
} }
++i; ++i;
} }
if (boolean && ft_history_parsing_2(has_prompt, input)) if (boolean)
return (-1); return (rematch_history_parsing(has_prompt, input));
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 20:04:16 by gwojda #+# #+# */ /* Created: 2017/01/25 20:04:16 by gwojda #+# #+# */
/* Updated: 2017/01/26 11:33:22 by gwojda ### ########.fr */ /* Updated: 2017/03/22 11:56:47 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,13 +52,11 @@ void ft_realloc_str_history_3(char **str, size_t pos, char *s)
if (new_str3) if (new_str3)
{ {
new_str2 = ft_strjoin(new_str, new_str3); new_str2 = ft_strjoin(new_str, new_str3);
free(new_str);
new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2); new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2);
free(new_str2); free(new_str2);
} }
else free(new_str);
new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2); ft_strdel(str);
free(s);
free(*str);
*str = new_str3; *str = new_str3;
free(s);
} }