diff options
author | nicm <nicm> | 2015-10-27 09:28:31 +0000 |
---|---|---|
committer | nicm <nicm> | 2015-10-27 09:28:31 +0000 |
commit | 9952201ca72b42819d64a9174fa7b5b898215668 (patch) | |
tree | 002f1cb7f07623b973c97078559a11bf15f8f755 | |
parent | 17c2c4219df2a8fec4c2f46f718a3fbbbfebe50a (diff) | |
download | rtmux-9952201ca72b42819d64a9174fa7b5b898215668.tar.gz rtmux-9952201ca72b42819d64a9174fa7b5b898215668.tar.bz2 rtmux-9952201ca72b42819d64a9174fa7b5b898215668.zip |
Count brackets in #{?...} so that nested conditional formats work, from
Daniel De Graaf.
-rw-r--r-- | format.c | 32 | ||||
-rw-r--r-- | screen.c | 2 |
2 files changed, 19 insertions, 15 deletions
@@ -670,7 +670,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, char *copy, *copy0, *endptr, *ptr, *saved, *trimmed, *value; size_t valuelen; u_long limit = 0; - int modifiers = 0; + int modifiers = 0, brackets; /* Make a copy of the key. */ copy0 = copy = xmalloc(keylen + 1); @@ -718,20 +718,26 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, goto fail; *ptr = '\0'; - value = saved = format_find(ft, copy + 1, modifiers); - if (value != NULL && *value != '\0' && - (value[0] != '0' || value[1] != '\0')) { - value = ptr + 1; - ptr = strchr(value, ','); - if (ptr == NULL) - goto fail; + value = ptr + 1; + saved = format_find(ft, copy + 1, modifiers); + + brackets = 0; + for (ptr = ptr + 1; *ptr != '\0'; ptr++) { + if (*ptr == '{') + brackets++; + if (*ptr == '}') + brackets--; + if (*ptr == ',' && brackets == 0) + break; + } + if (*ptr == '\0') + goto fail; + + if (saved != NULL && *saved != '\0' && + (saved[0] != '0' || saved[1] != '\0')) { *ptr = '\0'; - } else { - ptr = strchr(ptr + 1, ','); - if (ptr == NULL) - goto fail; + } else value = ptr + 1; - } value = format_expand(ft, value); free(saved); saved = value; @@ -194,8 +194,6 @@ screen_resize_y(struct screen *s, u_int sy) * Now just increase the history size, if possible, to take * over the lines which are left. If history is off, delete * lines from the top. - * - * XXX Should apply history limit? */ available = s->cy; if (gd->flags & GRID_HISTORY) |