diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-05-30 22:23:11 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-06-02 08:07:44 -0400 |
commit | 8bfa2def8876bb507aa0174e6b159a0a226889b4 (patch) | |
tree | cb913921a89cf5436a6f0912fcdf680dde973216 /sway/config.c | |
parent | Support braces on next line for config blocks (diff) | |
download | sway-8bfa2def8876bb507aa0174e6b159a0a226889b4.tar.gz sway-8bfa2def8876bb507aa0174e6b159a0a226889b4.tar.zst sway-8bfa2def8876bb507aa0174e6b159a0a226889b4.zip |
Address first round of review for generic blocks
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/sway/config.c b/sway/config.c index edb10bd7..88cc6843 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -518,21 +518,20 @@ static int detect_brace_on_following_line(FILE *file, char *line, | |||
518 | int lines = 0; | 518 | int lines = 0; |
519 | if (line[strlen(line) - 1] != '{' && line[strlen(line) - 1] != '}') { | 519 | if (line[strlen(line) - 1] != '{' && line[strlen(line) - 1] != '}') { |
520 | char *peeked = NULL; | 520 | char *peeked = NULL; |
521 | long position = 0; | ||
521 | do { | 522 | do { |
522 | wlr_log(L_DEBUG, "Peeking line %d", line_number + lines + 1); | 523 | wlr_log(L_DEBUG, "Peeking line %d", line_number + lines + 1); |
523 | free(peeked); | 524 | free(peeked); |
524 | peeked = peek_line(file, lines); | 525 | peeked = peek_line(file, lines, &position); |
525 | if (peeked) { | 526 | if (peeked) { |
526 | peeked = strip_whitespace(peeked); | 527 | peeked = strip_whitespace(peeked); |
527 | } | 528 | } |
529 | wlr_log(L_DEBUG, "Peeked line: `%s`", peeked); | ||
528 | lines++; | 530 | lines++; |
529 | } while (peeked && strlen(peeked) == 0); | 531 | } while (peeked && strlen(peeked) == 0); |
530 | 532 | ||
531 | if (peeked && strlen(peeked) == 1 && peeked[0] == '{') { | 533 | if (peeked && strlen(peeked) == 1 && peeked[0] == '{') { |
532 | for (int i = 0; i < lines; i++) { | 534 | fseek(file, position, SEEK_SET); |
533 | free(peeked); | ||
534 | peeked = read_line(file); | ||
535 | } | ||
536 | } else { | 535 | } else { |
537 | lines = 0; | 536 | lines = 0; |
538 | } | 537 | } |
@@ -541,7 +540,7 @@ static int detect_brace_on_following_line(FILE *file, char *line, | |||
541 | return lines; | 540 | return lines; |
542 | } | 541 | } |
543 | 542 | ||
544 | static char *expand_line(char *block, char *line, bool add_brace) { | 543 | static char *expand_line(const char *block, const char *line, bool add_brace) { |
545 | int size = (block ? strlen(block) + 1 : 0) + strlen(line) | 544 | int size = (block ? strlen(block) + 1 : 0) + strlen(line) |
546 | + (add_brace ? 2 : 0) + 1; | 545 | + (add_brace ? 2 : 0) + 1; |
547 | char *expanded = calloc(1, size); | 546 | char *expanded = calloc(1, size); |
@@ -549,10 +548,8 @@ static char *expand_line(char *block, char *line, bool add_brace) { | |||
549 | wlr_log(L_ERROR, "Cannot allocate expanded line buffer"); | 548 | wlr_log(L_ERROR, "Cannot allocate expanded line buffer"); |
550 | return NULL; | 549 | return NULL; |
551 | } | 550 | } |
552 | strcat(expanded, block ? block : ""); | 551 | snprintf(expanded, size, "%s%s%s%s", block ? block : "", |
553 | strcat(expanded, block ? " " : ""); | 552 | block ? " " : "", line, add_brace ? " {" : ""); |
554 | strcat(expanded, line); | ||
555 | strcat(expanded, add_brace ? " {" : ""); | ||
556 | return expanded; | 553 | return expanded; |
557 | } | 554 | } |
558 | 555 | ||
@@ -594,9 +591,7 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
594 | // Special case | 591 | // Special case |
595 | res = config_commands_command(expanded); | 592 | res = config_commands_command(expanded); |
596 | } else { | 593 | } else { |
597 | wlr_log(L_DEBUG, "Entering c_c"); | ||
598 | res = config_command(expanded); | 594 | res = config_command(expanded); |
599 | wlr_log(L_DEBUG, "Exiting c_c"); | ||
600 | } | 595 | } |
601 | free(expanded); | 596 | free(expanded); |
602 | switch(res->status) { | 597 | switch(res->status) { |