This commit is contained in:
Jack Halford 2017-03-27 01:04:03 +02:00
commit ef00bf3676

View file

@ -19,7 +19,7 @@ static int history_parsing_nb_and_previous(char *str, int *i)
if (!ft_strncmp("!!", str + *i, 2))
{
ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2);
++(*i);
(*i) += 2;
return (1);
}
else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]) &&
@ -34,10 +34,22 @@ static int history_parsing_nb_and_previous(char *str, int *i)
return (0);
}
static int check_validity(char *str, int i)
{
if (i && str[i - 1] == '\\')
return (0);
else if (!str[i + 1] || str[i + 1] == '"')
return (0);
return (1);
}
static int history_parsing_nb_and_name(char *str, int *i)
{
int tmp;
if (!check_validity(str, *i))
return (0);
if (history_parsing_nb_and_previous(str, i))
return (1);
else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) <
@ -80,23 +92,26 @@ int ft_history_parsing(int has_prompt, char **input)
{
int i;
char boolean;
char quote;
i = 0;
quote = 0;
boolean = 0;
if (!data_singleton()->line.input)
return (0);
while (data_singleton()->line.input && data_singleton()->line.input[i])
{
if (data_singleton()->line.input[i] == '!')
if (data_singleton()->line.input[i] == '\'')
quote = quote ? 0 : 1;
if (!quote && data_singleton()->line.input[i] == '!')
{
boolean = 1;
if (!history_parsing_nb_and_name(data_singleton()->line.input, &i))
boolean = 0;
else
break ;
i = -1;
}
++i;
}
*input = data_singleton()->line.input;
if (boolean)
return (rematch_history_parsing(has_prompt, input));
return (0);