diff options
author | 2016-06-05 18:24:12 -0400 | |
---|---|---|
committer | 2016-06-05 18:24:12 -0400 | |
commit | cb14f5f5765a71630ea3c4bd2143fcc1cd4a2e57 (patch) | |
tree | c77118e96612dad70c00d4c0528b4f3815105b04 /common | |
parent | Merge pull request #697 from zandrmartin/assign-command (diff) | |
parent | Common: Readline: Ignore newline on '\' escaped line ends. (diff) | |
download | sway-cb14f5f5765a71630ea3c4bd2143fcc1cd4a2e57.tar.gz sway-cb14f5f5765a71630ea3c4bd2143fcc1cd4a2e57.tar.zst sway-cb14f5f5765a71630ea3c4bd2143fcc1cd4a2e57.zip |
Merge pull request #699 from roosemberth/master
Sway: Configuration: Support for escaping line breaks.
Diffstat (limited to 'common')
-rw-r--r-- | common/readline.c | 7 |
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 @@ | |||
5 | char *read_line(FILE *file) { | 5 | char *read_line(FILE *file) { |
6 | size_t length = 0, size = 128; | 6 | size_t length = 0, size = 128; |
7 | char *string = malloc(size); | 7 | char *string = malloc(size); |
8 | char lastChar = '\0'; | ||
8 | if (!string) { | 9 | if (!string) { |
9 | return NULL; | 10 | return NULL; |
10 | } | 11 | } |
11 | while (1) { | 12 | while (1) { |
12 | int c = getc(file); | 13 | int c = getc(file); |
14 | if (c == '\n' && lastChar == '\\'){ | ||
15 | --length; // Ignore last character. | ||
16 | lastChar = '\0'; | ||
17 | continue; | ||
18 | } | ||
13 | if (c == EOF || c == '\n' || c == '\0') { | 19 | if (c == EOF || c == '\n' || c == '\0') { |
14 | break; | 20 | break; |
15 | } | 21 | } |
16 | if (c == '\r') { | 22 | if (c == '\r') { |
17 | continue; | 23 | continue; |
18 | } | 24 | } |
25 | lastChar = c; | ||
19 | if (length == size) { | 26 | if (length == size) { |
20 | char *new_string = realloc(string, size *= 2); | 27 | char *new_string = realloc(string, size *= 2); |
21 | if (!new_string) { | 28 | if (!new_string) { |