Hi,
On Thu, Apr 25, 2013 at 10:55:56PM +0100, Nicholas Marriott wrote:
> Ok. I think you have the right idea about recursing through
> format_expand you are just going to need to pull out the affected format
> differently (ditch strchr and use a custom loop which counts {s and }s).
Yeah, that's one way. But actually, strchr/strchrr would both be doing the
same thing as this manual loop you refer to, it's just that their use would
vary depending on whether we're expanding a terniary-form of a format
replacement or just a single element.
So I think something along the lines of the patch attached might be an idea.
It's certainly the path of least resistance (i.e., not much code changed)
but that doesn't mean I particularly like it. ;P
-- Thomas Adam
diff --git a/format.c b/format.c
index 7de819a..178f201 100644
--- a/format.c
+++ b/format.c
@@ -150,8 +150,8 @@ int
format_replace(struct format_tree *ft,
const char *key, size_t keylen, char **buf, size_t *len, size_t *off)
{
- char *copy, *ptr;
const char *value;
+ char *copy, *ptr;
size_t valuelen;
/* Make a copy of the key. */
@@ -182,6 +182,7 @@ format_replace(struct format_tree *ft,
goto fail;
value = ptr + 1;
}
+ value = format_expand(ft, value);
} else {
value = format_find(ft, copy);
if (value == NULL)
@@ -232,7 +233,11 @@ format_expand(struct format_tree *ft, const char *fmt)
ch = (u_char) *fmt++;
switch (ch) {
case '{':
- ptr = strchr(fmt, '}');
+ if (*fmt++ == '?')
+ ptr = strrchr(--fmt, '}');
+ else
+ ptr = strchr(--fmt, '}');
+
if (ptr == NULL)
break;
n = ptr - fmt;
--
1.7.11.4
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users