This commit is contained in:
gwojda 2017-03-22 12:23:37 +01:00
parent 06b2ad21ba
commit b06deca9c0
2 changed files with 16 additions and 16 deletions

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
static int ft_history_parsing_4(char *str, int *i)
static int history_parsing_nb_and_previous(char *str, int *i)
{
int tmp;
@ -34,11 +34,11 @@ static int ft_history_parsing_4(char *str, int *i)
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;
if (ft_history_parsing_4(str, i))
if (history_parsing_nb_and_previous(str, i))
return (1);
else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) <
ft_hist_len())
@ -60,18 +60,20 @@ static int ft_history_parsing_3(char *str, int *i)
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;
has_prompt ? ft_prompt() : ft_putstr("> ");
if (ft_read_stdin(input) < 0)
if ((ret = ft_read_stdin(input)) < 0)
return (-1);
if (data_singleton()->line.input)
ft_current_str(data_singleton()->line.input,
data_singleton()->line.pos);
ft_putchar('\n');
ft_history_parsing(has_prompt, input);
return (0);
return (ret);
}
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] == '!')
{
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;
else
break ;
}
++i;
}
if (boolean && ft_history_parsing_2(has_prompt, input))
return (-1);
if (boolean)
return (rematch_history_parsing(has_prompt, input));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
new_str2 = ft_strjoin(new_str, new_str3);
free(new_str);
new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2);
free(new_str2);
}
else
new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2);
free(s);
free(*str);
free(new_str);
ft_strdel(str);
*str = new_str3;
free(s);
}