]> git.sur5r.net Git - i3/i3/blobdiff - src/config_parser.c
Ensure config variables match on longest-length (#2306)
[i3/i3] / src / config_parser.c
index 0f3d33ec0600ca23b56e2e25a1d7e1dd34a6d804..5ee69e8d170388c830c6347aa7881dd7a8dcd217 100644 (file)
@@ -843,7 +843,7 @@ bool parse_file(const char *f, bool use_nagbar) {
                 break;
             die("Could not read configuration file\n");
         }
-        if (buffer[strlen(buffer) - 1] != '\n') {
+        if (buffer[strlen(buffer) - 1] != '\n' && !feof(fstr)) {
             ELOG("Your line continuation is too long, it exceeds %zd bytes\n", sizeof(buffer));
         }
         continuation = strstr(buffer, "\\\n");
@@ -879,9 +879,23 @@ bool parse_file(const char *f, bool use_nagbar) {
                 v_value++;
 
             struct Variable *new = scalloc(1, sizeof(struct Variable));
+            struct Variable *test = NULL, *loc = NULL;
             new->key = sstrdup(v_key);
             new->value = sstrdup(v_value);
-            SLIST_INSERT_HEAD(&variables, new, variables);
+            /* ensure that the correct variable is matched in case of one being
+             * the prefix of another */
+            SLIST_FOREACH(test, &variables, variables) {
+                if (strlen(new->key) >= strlen(test->key))
+                    break;
+                loc = test;
+            }
+
+            if (loc == NULL) {
+                SLIST_INSERT_HEAD(&variables, new, variables);
+            } else {
+                SLIST_INSERT_AFTER(loc, new, variables);
+            }
+
             DLOG("Got new variable %s = %s\n", v_key, v_value);
             continue;
         }
@@ -910,7 +924,7 @@ bool parse_file(const char *f, bool use_nagbar) {
     FREE(bufcopy);
 
     /* Then, allocate a new buffer and copy the file over to the new one,
-     * but replace occurences of our variables */
+     * but replace occurrences of our variables */
     char *walk = buf, *destwalk;
     char *new = smalloc(stbuf.st_size + extra_bytes + 1);
     destwalk = new;