diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index 70372393..802e92e1 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -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] == '"') + 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,14 +92,18 @@ 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; + else if (!quote && data_singleton()->line.input[i] == '!') { boolean = 1; if (!history_parsing_nb_and_name(data_singleton()->line.input, &i))