summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-10-27 09:28:32 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-10-27 09:28:32 +0000
commit969b07d812ebfc2e865ad4882496bacea22f7014 (patch)
tree537aad12c218cb80e8aa1ec2291b7f75b59717a5
parenta53e6806569857ff5bd87c29144b66176c312683 (diff)
Count brackets in #{?...} so that nested conditional formats work, from
Daniel De Graaf.
-rw-r--r--usr.bin/tmux/format.c34
-rw-r--r--usr.bin/tmux/screen.c4
2 files changed, 21 insertions, 17 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index f449651804d..98398a7b07c 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.88 2015/10/27 09:18:06 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.89 2015/10/27 09:28:31 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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;
diff --git a/usr.bin/tmux/screen.c b/usr.bin/tmux/screen.c
index 94e093378a2..b6fe4f5c6eb 100644
--- a/usr.bin/tmux/screen.c
+++ b/usr.bin/tmux/screen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen.c,v 1.34 2015/08/28 17:11:12 nicm Exp $ */
+/* $OpenBSD: screen.c,v 1.35 2015/10/27 09:28:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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)