Rocco Rutte:
[apps/madmutt.git] / muttlib.c
index c3ec12b..711b3d8 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  */ 
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mime.h"
@@ -452,6 +456,13 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
       }
       break;
       
+      case '^':
+      {
+        strfcpy (p, NONULL(CurrentFolder), sizeof (p));
+        tail = s + 1;
+      }
+      break;
       default:
       {
        *p = '\0';
@@ -925,6 +936,23 @@ void mutt_safe_path (char *s, size_t l, ADDRESS *a)
       *p = '_';
 }
 
+/* counts how many characters in s can be skipped while none of the
+ * characters of c appears */
+int mutt_skipchars (const char* s, const char* c) {
+  int ret = 0;
+  const char* p = s;
+  while (s && *s) {
+    register const char* t = c;
+    while (t && *t) {
+      if (*t == *s)
+        return (ret);
+      t++;
+    }
+    ret++;
+    s++;
+  }
+  return (mutt_strlen (p));
+}
 
 void mutt_FormatString (char *dest,            /* output buffer */
                        size_t destlen,         /* output buffer len */
@@ -935,11 +963,12 @@ void mutt_FormatString (char *dest,               /* output buffer */
 {
   char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
   char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
-  size_t wlen, count, len;
+  size_t wlen, count, len, col, wid;
 
   prefix[0] = '\0';
   destlen--; /* save room for the terminal \0 */
   wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
+  col = wlen;
     
   while (*src && wlen < destlen)
   {
@@ -949,6 +978,7 @@ void mutt_FormatString (char *dest,         /* output buffer */
       {
        *wptr++ = '%';
        wlen++;
+       col++;
        src++;
        continue;
       }
@@ -1020,27 +1050,30 @@ void mutt_FormatString (char *dest,             /* output buffer */
        ch = *src++; /* pad char */
        /* calculate space left on line.  if we've already written more data
           than will fit on the line, ignore the rest of the line */
-       if ( DrawFullLine )
+       if ( DrawFullLine  || option(OPTSTATUSONTOP))
          count = (COLS < destlen ? COLS : destlen);
        else
-         count = ((COLS-SidebarWidth) < destlen ? COLS - SidebarWidth : destlen);
-       if (count > wlen)
+         count = ((COLS-SidebarWidth) < destlen ? (COLS - SidebarWidth) : destlen);
+       if (count > col)
        {
-         count -= wlen; /* how many chars left on this line */
+         count -= col; /* how many columns left on this line */
          mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
-         len = mutt_strlen (buf);
-         if (count > len)
+         wid = mutt_strlen (buf);
+         if (count > wid)
          {
-           count -= len; /* how many chars to pad */
+           count -= wid; /* how many chars to pad */
            memset (wptr, ch, count);
            wptr += count;
-           wlen += count;
+           col += count;
          }
-         if (len + wlen > destlen)
+         if (wid + wlen > destlen)
            len = destlen - wlen;
+    else
+      len = wid;
          memcpy (wptr, buf, len);
          wptr += len;
          wlen += len;
+         col += mutt_strwidth (buf);
        }
        break; /* skip rest of input */
       }
@@ -1092,6 +1125,7 @@ void mutt_FormatString (char *dest,               /* output buffer */
        memcpy (wptr, buf, len);
        wptr += len;
        wlen += len;
+       col += mutt_strwidth (buf);
       }
     }
     else if (*src == '\\')
@@ -1122,11 +1156,19 @@ void mutt_FormatString (char *dest,             /* output buffer */
       src++;
       wptr++;
       wlen++;
+      col++;
     }
     else
     {
-      *wptr++ = *src++;
-      wlen++;
+      unsigned int bar = mutt_skipchars (src, "%\\");
+      char* bar2 = safe_malloc (bar+1);
+      strfcpy (bar2, src, bar+1);
+      while (bar--) {
+        *wptr++ = *src++;
+        wlen++;
+      }
+      col += mutt_strwidth (bar2);
+      FREE(&bar2);
     }
   }
   *wptr = 0;
@@ -1276,8 +1318,10 @@ void state_prefix_putc (char c, STATE *s)
       while (regexec ((regex_t *) QuoteRegexp.rx, &Quotebuf[offset], 1, pmatch, 0) == 0)
        offset += pmatch->rm_eo;
 
-      if (!option (OPTQUOTEEMPTY) && Quotebuf[0] == '\n')
-       strcpy (buf, Quotebuf);
+      if (!option (OPTQUOTEEMPTY) && Quotebuf[offset] == '\n') {
+        buf[0] = '\n';
+        buf[1] = '\0';
+      }
       else if (option (OPTQUOTEQUOTED) && offset)
       {
        for (i = 0; i < offset; i++)
@@ -1459,7 +1503,7 @@ time_t mutt_decrease_mtime (const char *f, struct stat *st)
 const char *mutt_make_version (void)
 {
   static char vstring[STRING];
-  snprintf (vstring, sizeof (vstring), "Mutt %s (%s)",
+  snprintf (vstring, sizeof (vstring), "Mutt-ng %s (%s)",
            MUTT_VERSION, ReleaseDate);
   return vstring;
 }