From: Johannes Lange Date: Sat, 7 May 2016 22:20:08 +0000 (+0200) Subject: Do not count '\' in comment as line continuation (#2181) X-Git-Tag: 4.13~80 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a8757625c32e58676a3aa99c1859734b7ac09c8d;p=i3%2Fi3 Do not count '\' in comment as line continuation (#2181) fixes #2176 --- diff --git a/docs/userguide b/docs/userguide index f46a0be7..d0ac2ddb 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1115,11 +1115,15 @@ show_marks yes Config files support line continuation, meaning when you end a line in a backslash character (`\`), the line-break will be ignored by the parser. This feature can be used to create more readable configuration files. +Commented lines are not continued. *Examples*: ------------------- bindsym Mod1+f \ fullscreen toggle + +# this line is not continued \ +bindsym Mod1+F fullscreen toggle ------------------- == Configuring i3bar diff --git a/src/config_parser.c b/src/config_parser.c index 5ee69e8d..b197eb22 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -846,17 +846,26 @@ bool parse_file(const char *f, bool use_nagbar) { if (buffer[strlen(buffer) - 1] != '\n' && !feof(fstr)) { ELOG("Your line continuation is too long, it exceeds %zd bytes\n", sizeof(buffer)); } + + /* sscanf implicitly strips whitespace. */ + const bool skip_line = (sscanf(buffer, "%511s %511[^\n]", key, value) < 1 || strlen(key) < 3); + const bool comment = (key[0] == '#'); + continuation = strstr(buffer, "\\\n"); if (continuation) { - continue; + if (!comment) { + continue; + } + DLOG("line continuation in comment is ignored: \"%.*s\"\n", (int)strlen(buffer) - 1, buffer); + continuation = NULL; } strncpy(buf + strlen(buf), buffer, strlen(buffer) + 1); - /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */ - if (sscanf(buffer, "%511s %511[^\n]", key, value) < 1 || - key[0] == '#' || strlen(key) < 3) + /* Skip comments and empty lines. */ + if (skip_line || comment) { continue; + } if (strcasecmp(key, "set") == 0) { if (value[0] != '$') { diff --git a/testcases/t/247-config-line-continuation.t b/testcases/t/247-config-line-continuation.t index 0396d872..cb429083 100644 --- a/testcases/t/247-config-line-continuation.t +++ b/testcases/t/247-config-line-continuation.t @@ -198,4 +198,20 @@ EOT is(launch_get_border($config), 'none', 'no border'); +##################################################################### +# test ignoring of line continuation within a comment +##################################################################### + +$config = <<'EOT'; +# i3 config file (v4) +font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 + +set $vartest \"special title\" +for_window [title="$vartest"] border pixel 1 +# this line is not continued, so the following is not contained in this comment\ +for_window [title="$vartest"] border none +EOT + +is(launch_get_border($config), 'none', 'no border'); + done_testing;