diff options
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/sway/config.c b/sway/config.c index cd0857f4..5ca4806c 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -573,15 +573,18 @@ bool load_include_configs(const char *path, struct sway_config *config, | |||
573 | } | 573 | } |
574 | 574 | ||
575 | // get line, with backslash continuation | 575 | // get line, with backslash continuation |
576 | static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file) { | 576 | static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file, |
577 | int *nlines) { | ||
577 | char *next_line = NULL; | 578 | char *next_line = NULL; |
578 | size_t next_line_size = 0; | 579 | size_t next_line_size = 0; |
579 | ssize_t nread = getline(lineptr, line_size, file); | 580 | ssize_t nread = getline(lineptr, line_size, file); |
581 | *nlines = nread == -1 ? 0 : 1; | ||
580 | while (nread >= 2 && strcmp(&(*lineptr)[nread - 2], "\\\n") == 0) { | 582 | while (nread >= 2 && strcmp(&(*lineptr)[nread - 2], "\\\n") == 0) { |
581 | ssize_t next_nread = getline(&next_line, &next_line_size, file); | 583 | ssize_t next_nread = getline(&next_line, &next_line_size, file); |
582 | if (next_nread == -1) { | 584 | if (next_nread == -1) { |
583 | break; | 585 | break; |
584 | } | 586 | } |
587 | (*nlines)++; | ||
585 | 588 | ||
586 | nread += next_nread - 2; | 589 | nread += next_nread - 2; |
587 | if ((ssize_t) *line_size < nread + 1) { | 590 | if ((ssize_t) *line_size < nread + 1) { |
@@ -599,6 +602,7 @@ static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file) | |||
599 | } | 602 | } |
600 | 603 | ||
601 | static int detect_brace(FILE *file) { | 604 | static int detect_brace(FILE *file) { |
605 | int ret = 0; | ||
602 | int lines = 0; | 606 | int lines = 0; |
603 | long pos = ftell(file); | 607 | long pos = ftell(file); |
604 | char *line = NULL; | 608 | char *line = NULL; |
@@ -607,15 +611,17 @@ static int detect_brace(FILE *file) { | |||
607 | lines++; | 611 | lines++; |
608 | strip_whitespace(line); | 612 | strip_whitespace(line); |
609 | if (*line) { | 613 | if (*line) { |
610 | if (strcmp(line, "{") != 0) { | 614 | if (strcmp(line, "{") == 0) { |
611 | fseek(file, pos, SEEK_SET); | 615 | ret = lines; |
612 | lines = 0; | ||
613 | } | 616 | } |
614 | break; | 617 | break; |
615 | } | 618 | } |
616 | } | 619 | } |
617 | free(line); | 620 | free(line); |
618 | return lines; | 621 | if (ret == 0) { |
622 | fseek(file, pos, SEEK_SET); | ||
623 | } | ||
624 | return ret; | ||
619 | } | 625 | } |
620 | 626 | ||
621 | static char *expand_line(const char *block, const char *line, bool add_brace) { | 627 | static char *expand_line(const char *block, const char *line, bool add_brace) { |
@@ -662,7 +668,8 @@ bool read_config(FILE *file, struct sway_config *config, | |||
662 | ssize_t nread; | 668 | ssize_t nread; |
663 | list_t *stack = create_list(); | 669 | list_t *stack = create_list(); |
664 | size_t read = 0; | 670 | size_t read = 0; |
665 | while ((nread = getline_with_cont(&line, &line_size, file)) != -1) { | 671 | int nlines = 0; |
672 | while ((nread = getline_with_cont(&line, &line_size, file, &nlines)) != -1) { | ||
666 | if (reading_main_config) { | 673 | if (reading_main_config) { |
667 | if (read + nread > config_size) { | 674 | if (read + nread > config_size) { |
668 | wlr_log(WLR_ERROR, "Config file changed during reading"); | 675 | wlr_log(WLR_ERROR, "Config file changed during reading"); |
@@ -678,7 +685,7 @@ bool read_config(FILE *file, struct sway_config *config, | |||
678 | line[nread - 1] = '\0'; | 685 | line[nread - 1] = '\0'; |
679 | } | 686 | } |
680 | 687 | ||
681 | line_number++; | 688 | line_number += nlines; |
682 | wlr_log(WLR_DEBUG, "Read line %d: %s", line_number, line); | 689 | wlr_log(WLR_DEBUG, "Read line %d: %s", line_number, line); |
683 | 690 | ||
684 | strip_whitespace(line); | 691 | strip_whitespace(line); |