diff options
author | nicm <nicm> | 2018-05-29 09:10:30 +0000 |
---|---|---|
committer | nicm <nicm> | 2018-05-29 09:10:30 +0000 |
commit | d1f5142daba11baf77f7ec1753b5a660585e96f9 (patch) | |
tree | 885b9e0a916b4b954a66f67c726238b671ce04e8 /format.c | |
parent | c177a627d26d0e254390d27ad6348ea681ff0f7d (diff) | |
download | rtmux-d1f5142daba11baf77f7ec1753b5a660585e96f9.tar.gz rtmux-d1f5142daba11baf77f7ec1753b5a660585e96f9.tar.bz2 rtmux-d1f5142daba11baf77f7ec1753b5a660585e96f9.zip |
If foo doesn't exist and can't be expanded in #{?foo,a,b} then assume it
is false.
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1042,8 +1042,18 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, *ptr = '\0'; found = format_find(ft, copy + 1, modifiers); - if (found == NULL) + if (found == NULL) { + /* + * If the conditional not found, try to expand it. If + * the expansion doesn't have any effect, then assume + * false. + */ found = format_expand(ft, copy + 1); + if (strcmp(found, copy + 1) == 0) { + free(found); + found = xstrdup(""); + } + } if (format_choose(ptr + 1, &left, &right) != 0) goto fail; @@ -1098,8 +1108,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, value = new; } - /* Expand the buffer and copy in the value. */ done: + /* Expand the buffer and copy in the value. */ valuelen = strlen(value); while (*len - *off < valuelen + 1) { *buf = xreallocarray(*buf, 2, *len); |