From 230591fa4e4911ffbb38da2ee79650e62d98415f Mon Sep 17 00:00:00 2001 From: Roosembert Palacios Date: Mon, 6 Jun 2016 00:17:27 +0200 Subject: Common: Readline: Ignore newline on '\' escaped line ends. Escape line return when reading from a file with the '\' character. Similar to shell scripts. Signed-off-by: Roosembert Palacios --- common/readline.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'common') diff --git a/common/readline.c b/common/readline.c index 76ed6926..5106172c 100644 --- a/common/readline.c +++ b/common/readline.c @@ -5,17 +5,24 @@ char *read_line(FILE *file) { size_t length = 0, size = 128; char *string = malloc(size); + char lastChar = '\0'; if (!string) { return NULL; } while (1) { int c = getc(file); + if (c == '\n' && lastChar == '\\'){ + --length; // Ignore last character. + lastChar = '\0'; + continue; + } if (c == EOF || c == '\n' || c == '\0') { break; } if (c == '\r') { continue; } + lastChar = c; if (length == size) { char *new_string = realloc(string, size *= 2); if (!new_string) { -- cgit v1.2.3-54-g00ecf