]> granicus.if.org Git - neomutt/commitdiff
use nested angle brackets
authorDavid Champion <dgc@uchicago.edu>
Mon, 1 Feb 2016 03:19:24 +0000 (03:19 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:33:38 +0000 (03:33 +0100)
muttlib.c

index cd14782f1a4dd0fe4c19dc704eb6404f382dfee9..f5b60d8a5631aa154bd4199e844121b73e20d4c2 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1212,6 +1212,20 @@ void mutt_FormatString (char *dest,              /* output buffer */
       }
 
       if (*src == '?')
+      {
+       /* change original %? to new %< notation */
+       /* %?x?y&z? to %<x?y&z> where y and z are nestable */
+       char *p = (char *)src;
+       *p = '<';
+       for ( ; *p && *p != '?'; p++);
+       if (*p == '?')
+         p++;
+       for ( ; *p && *p != '?'; p++);
+       if (*p == '?')
+         *p = '>';
+      }
+
+      if (*src == '<')
       {
        flags |= M_FORMAT_OPTIONAL;
        src++;
@@ -1239,6 +1253,8 @@ void mutt_FormatString (char *dest,               /* output buffer */
 
       if (flags & M_FORMAT_OPTIONAL)
       {
+       int lrbalance;
+
         if (*src != '?')
           break; /* bad format */
         src++;
@@ -1246,14 +1262,22 @@ void mutt_FormatString (char *dest,             /* output buffer */
         /* eat the `if' part of the string */
         cp = ifstring;
        count = 0;
-        while (count < sizeof (ifstring) && *src && *src != '?' && *src != '&')
+       lrbalance = 1;
+        while (lrbalance > 0 && count < sizeof (ifstring) && *src)
        {
          if (*src == '\\')
          {
            src++;
-           if (!*src)
-             break;
+           *cp++ = *src++;
          }
+         else if (src[0] == '%' && src[1] == '<')
+           lrbalance++;
+         else if (src[0] == '>')
+           lrbalance--;
+         if (lrbalance == 0)
+           break;
+         if (lrbalance == 1 && src[0] == '&')
+           break;
           *cp++ = *src++;
          count++;
        }
@@ -1264,14 +1288,21 @@ void mutt_FormatString (char *dest,             /* output buffer */
          src++; /* skip the & */
        cp = elsestring;
        count = 0;
-       while (count < sizeof (elsestring) && *src && *src != '?')
+       while (lrbalance > 0 && count < sizeof (elsestring) && *src)
        {
          if (*src == '\\')
          {
            src++;
-           if (!*src)
-             break;
+           *cp++ = *src++;
          }
+         else if (src[0] == '%' && src[1] == '<')
+           lrbalance++;
+         else if (src[0] == '>')
+           lrbalance--;
+         if (lrbalance == 0)
+           break;
+         if (lrbalance == 1 && src[0] == '&')
+           break;
           *cp++ = *src++;
          count++;
        }
@@ -1280,7 +1311,7 @@ void mutt_FormatString (char *dest,               /* output buffer */
        if (!*src)
          break; /* bad format */
 
-        src++; /* move past the trailing `?' */
+        src++; /* move past the trailing `>' (formerly '?') */
       }
 
       /* handle generic cases first */