summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/format.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 32422dfe900..22bfa334ff1 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.215 2019/11/15 11:21:32 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.216 2019/11/25 15:02:48 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1560,15 +1560,15 @@ static int
format_replace(struct format_tree *ft, const char *key, size_t keylen,
char **buf, size_t *len, size_t *off)
{
- struct window_pane *wp = ft->wp;
- const char *errptr, *copy, *cp, *marker = NULL;
- char *copy0, *condition, *found, *new;
- char *value, *left, *right;
- size_t valuelen;
- int modifiers = 0, limit = 0, j;
- struct format_modifier *list, *fm, *cmp = NULL, *search = NULL;
- struct format_modifier *sub = NULL;
- u_int i, count;
+ struct window_pane *wp = ft->wp;
+ const char *errptr, *copy, *cp, *marker = NULL;
+ char *copy0, *condition, *found, *new;
+ char *value, *left, *right;
+ size_t valuelen;
+ int modifiers = 0, limit = 0, j;
+ struct format_modifier *list, *fm, *cmp = NULL, *search = NULL;
+ struct format_modifier **sub = NULL;
+ u_int i, count, nsub = 0;
/* Make a copy of the key. */
copy = copy0 = xstrndup(key, keylen);
@@ -1597,7 +1597,9 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
case 's':
if (fm->argc < 2)
break;
- sub = fm;
+ sub = xreallocarray (sub, nsub + 1,
+ sizeof *sub);
+ sub[nsub++] = fm;
break;
case '=':
if (fm->argc < 1)
@@ -1809,10 +1811,10 @@ done:
}
/* Perform substitution if any. */
- if (sub != NULL) {
- left = format_expand(ft, sub->argv[0]);
- right = format_expand(ft, sub->argv[1]);
- new = format_sub(sub, value, left, right);
+ for (i = 0; i < nsub; i++) {
+ left = format_expand(ft, sub[i]->argv[0]);
+ right = format_expand(ft, sub[i]->argv[1]);
+ new = format_sub(sub[i], value, left, right);
format_log(ft, "substitute '%s' to '%s': %s", left, right, new);
free(value);
value = new;
@@ -1855,12 +1857,15 @@ done:
format_log(ft, "replaced '%s' with '%s'", copy0, value);
free(value);
+ free(sub);
format_free_modifiers(list, count);
free(copy0);
return (0);
fail:
format_log(ft, "failed %s", copy0);
+
+ free(sub);
format_free_modifiers(list, count);
free(copy0);
return (-1);