aboutsummaryrefslogtreecommitdiff
path: root/common/readline.c
diff options
context:
space:
mode:
authorRoosembert Palacios <roosembert.palacios@epfl.ch>2016-06-06 00:17:27 +0200
committerRoosembert Palacios <roosembert.palacios@epfl.ch>2016-06-06 00:17:27 +0200
commit230591fa4e4911ffbb38da2ee79650e62d98415f (patch)
treec77118e96612dad70c00d4c0528b4f3815105b04 /common/readline.c
parente8c0ef98b1c1068783350c76b44c4e40b7534137 (diff)
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 <roosembert.palacios@epfl.ch>
Diffstat (limited to 'common/readline.c')
-rw-r--r--common/readline.c7
1 files changed, 7 insertions, 0 deletions
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) {