diff --git a/include/parser.h b/include/parser.h index a3986fc..638a8ea 100644 --- a/include/parser.h +++ b/include/parser.h @@ -20,4 +20,6 @@ char **parse_input(char *cmd); int parse_quotes(char *ptr, char **data); char *strcat_realloc(char *dest, char *src); -char *add_to_buffer(char *buffer, char *ptr, int nb); \ No newline at end of file +char *add_to_buffer(char *buffer, char *ptr, int nb, bool inhibitors); + +void remove_inhibitors_symbols_n_limit(char *str, int nb); \ No newline at end of file diff --git a/src/parser/parser.c b/src/parser/parser.c index d99283d..17f2995 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -59,8 +59,8 @@ int manage_specials_parsers(char *cmd, int index, char **buffer, int *inc, char if (new_index == -1) return (-1); if (new_index > 0) { - *buffer = add_to_buffer(*buffer, *ptr, (*inc) - 1); - *buffer = add_to_buffer(*buffer, data, strlen(data)); + *buffer = add_to_buffer(*buffer, *ptr, (*inc) - 1, true); + *buffer = add_to_buffer(*buffer, data, strlen(data), false); free(data); *inc = -1; *ptr = cmd + index + 1; @@ -94,7 +94,7 @@ char **parse_input(char *cmd) inc = 0; continue; } - buffer = add_to_buffer(buffer, ptr, inc - 1); + buffer = add_to_buffer(buffer, ptr, inc - 1, true); if (!buffer) return (NULL); ret[ret_inc++] = buffer; diff --git a/src/parser/parser_utilities.c b/src/parser/parser_utilities.c index 45ca858..04bb2a8 100644 --- a/src/parser/parser_utilities.c +++ b/src/parser/parser_utilities.c @@ -8,6 +8,8 @@ #include #include "parser.h" + + char *strcat_realloc(char *dest, char *src) { if (dest) { @@ -24,7 +26,7 @@ char *strcat_realloc(char *dest, char *src) return (dest); } -char *add_to_buffer(char *buffer, char *ptr, int nb) +char *add_to_buffer(char *buffer, char *ptr, int nb, bool inhibitors) { char *new; @@ -34,7 +36,21 @@ char *add_to_buffer(char *buffer, char *ptr, int nb) if (!new) return (NULL); new[nb] = '\0'; + if (inhibitors) + remove_inhibitors_symbols_n_limit(new, nb); buffer = strcat_realloc(buffer, new); free(new); return (buffer); +} + +void remove_inhibitors_symbols_n_limit(char *str, int nb) +{ + for (int i = 0; str[i] && i < nb; i++) { + if (str[i] == '\\') { + for (int j = i; str[j]; j++) { + str[j] = str[j + 1]; + } + i++; + } + } } \ No newline at end of file