diff options
author | Roosembert Palacios <roosembert.palacios@epfl.ch> | 2016-06-06 00:17:27 +0200 |
---|---|---|
committer | Roosembert Palacios <roosembert.palacios@epfl.ch> | 2016-06-06 00:17:27 +0200 |
commit | 230591fa4e4911ffbb38da2ee79650e62d98415f (patch) | |
tree | c77118e96612dad70c00d4c0528b4f3815105b04 /sway | |
parent | Sway: Configuration: Support for escaping line breaks. (diff) | |
download | sway-230591fa4e4911ffbb38da2ee79650e62d98415f.tar.gz sway-230591fa4e4911ffbb38da2ee79650e62d98415f.tar.zst sway-230591fa4e4911ffbb38da2ee79650e62d98415f.zip |
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 'sway')
-rw-r--r-- | sway/config.c | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/sway/config.c b/sway/config.c index c1eec22f..15108123 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -455,11 +455,10 @@ bool load_include_configs(const char *path, struct sway_config *config) { | |||
455 | 455 | ||
456 | bool read_config(FILE *file, struct sway_config *config) { | 456 | bool read_config(FILE *file, struct sway_config *config) { |
457 | bool success = true; | 457 | bool success = true; |
458 | bool multiline = false; | ||
459 | enum cmd_status block = CMD_BLOCK_END; | 458 | enum cmd_status block = CMD_BLOCK_END; |
460 | 459 | ||
461 | int line_number = 0; | 460 | int line_number = 0; |
462 | char *line, *mlinebuf = NULL; | 461 | char *line; |
463 | while (!feof(file)) { | 462 | while (!feof(file)) { |
464 | line = read_line(file); | 463 | line = read_line(file); |
465 | line_number++; | 464 | line_number++; |
@@ -468,45 +467,6 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
468 | free(line); | 467 | free(line); |
469 | continue; | 468 | continue; |
470 | } | 469 | } |
471 | size_t length = strlen(line); | ||
472 | if (line[length-1] == '\\') { | ||
473 | // Start of multiline | ||
474 | if (feof(file)){ | ||
475 | sway_log(L_ERROR, "Error on line %i '%s': Unexpected EOF on "\ | ||
476 | "multiline command", line_number, line); | ||
477 | free(line); | ||
478 | continue; | ||
479 | } | ||
480 | line[length-1] = '\0'; | ||
481 | multiline = true; | ||
482 | } else | ||
483 | multiline = false; | ||
484 | |||
485 | if (multiline || mlinebuf){ | ||
486 | size_t mlinebuf_length; | ||
487 | if (mlinebuf) | ||
488 | mlinebuf_length = strlen(mlinebuf); | ||
489 | else | ||
490 | mlinebuf_length = 0; | ||
491 | |||
492 | char *tmp = malloc(mlinebuf_length+length+1); // + '\0' | ||
493 | tmp[0]='\0'; // if mlinebuf_length==0 strncpy won't do anything. Make a null string. | ||
494 | strncpy(tmp, mlinebuf, mlinebuf_length); | ||
495 | tmp[mlinebuf_length]='\0'; // strncpy won't add '\0' at the end... | ||
496 | strcat(tmp, line); | ||
497 | if (mlinebuf) | ||
498 | free(mlinebuf); | ||
499 | free(line); | ||
500 | mlinebuf = tmp; | ||
501 | if (multiline) // The following line is part of a multi line config. | ||
502 | continue; | ||
503 | else { // This is the last line of a multi line config. | ||
504 | line = mlinebuf; | ||
505 | sway_log(L_INFO, "Processing parsed multiline command '%s'", line); | ||
506 | mlinebuf = NULL; | ||
507 | } | ||
508 | } | ||
509 | |||
510 | struct cmd_results *res = config_command(line, block); | 470 | struct cmd_results *res = config_command(line, block); |
511 | switch(res->status) { | 471 | switch(res->status) { |
512 | case CMD_FAILURE: | 472 | case CMD_FAILURE: |