The branch, master has been updated
       via  04288fcd4c99117f730f37f8a63ded96fcc04c9d (commit)
      from  84c22d053b5ec1cd25e1694fa3889922b9cbe11b (commit)

- Log -----------------------------------------------------------------
commit 04288fcd4c99117f730f37f8a63ded96fcc04c9d
Author: Nicholas Marriott <nicholas.marri...@gmail.com>
Commit: Nicholas Marriott <nicholas.marri...@gmail.com>

    Allow nested format expansion.
---
 format.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/format.c b/format.c
index ee3339d..98fc55d 100644
--- a/format.c
+++ b/format.c
@@ -193,7 +193,7 @@ int
 format_replace(struct format_tree *ft, const char *key, size_t keylen,
     char **buf, size_t *len, size_t *off)
 {
-       char            *copy, *copy0, *endptr, *ptr;
+       char            *copy, *copy0, *endptr, *ptr, *saved;
        const char      *value;
        size_t           valuelen;
        u_long           limit = ULONG_MAX;
@@ -247,10 +247,13 @@ format_replace(struct format_tree *ft, const char *key, 
size_t keylen,
                                goto fail;
                        value = ptr + 1;
                }
+               saved = format_expand(ft, value);
+               value = saved;
        } else {
                value = format_find(ft, copy);
                if (value == NULL)
                        value = "";
+               saved = NULL;
        }
        valuelen = strlen(value);
 
@@ -266,6 +269,7 @@ format_replace(struct format_tree *ft, const char *key, 
size_t keylen,
        memcpy(*buf + *off, value, valuelen);
        *off += valuelen;
 
+       free(saved);
        free(copy0);
        return (0);
 
@@ -278,10 +282,10 @@ fail:
 char *
 format_expand(struct format_tree *ft, const char *fmt)
 {
-       char            *buf, *ptr;
-       const char      *s;
+       char            *buf;
+       const char      *ptr, *s;
        size_t           off, len, n;
-       int              ch;
+       int              ch, brackets;
 
        len = 64;
        buf = xmalloc(len);
@@ -299,11 +303,16 @@ format_expand(struct format_tree *ft, const char *fmt)
                fmt++;
 
                ch = (u_char) *fmt++;
-
                switch (ch) {
                case '{':
-                       ptr = strchr(fmt, '}');
-                       if (ptr == NULL)
+                       brackets = 1;
+                       for (ptr = fmt; *ptr != '\0'; ptr++) {
+                               if (*ptr == '{')
+                                       brackets++;
+                               if (*ptr == '}' && --brackets == 0)
+                                       break;
+                       }
+                       if (*ptr != '}' || brackets != 0)
                                break;
                        n = ptr - fmt;
 


-----------------------------------------------------------------------

Summary of changes:
 format.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to