emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-25 b71c717: Make the code in movemail_strftime more


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-25 b71c717: Make the code in movemail_strftime more general
Date: Sun, 06 Mar 2016 16:28:11 +0000

branch: emacs-25
commit b71c717f952d57995c54a2d276b10af87529dcd3
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Make the code in movemail_strftime more general
    
    * lib-src/movemail.c (movemail_strftime): Transform the format
    string passed by the caller instead of using a separate format
    string.
---
 lib-src/movemail.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 873d85d..fa4c029 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -807,7 +807,34 @@ static size_t
 movemail_strftime (char *s, size_t size, char const *format,
                   struct tm const *tm)
 {
-  size_t n = strftime (s, size, "From movemail %a %b %d %H:%M:%S %Y\n", tm);
+  char fmt[size + 6], *q;
+  const char *p;
+
+  for (p = format, q = &fmt[0]; *p; )
+    {
+      if (*p == '%' && p[1] == 'e')
+       {
+         memcpy (q, "%d", 2);
+         q += 2;
+         p += 2;
+       }
+      else if (*p == '%' && p[1] == 'T')
+       {
+         memcpy (q, "%H:%M:%S", 8);
+         q += 8;
+         p += 2;
+       }
+      else if (*p == '%' && p[1] == '%')
+       {
+         memcpy (q, p, 2);
+         q += 2;
+         p += 2;
+       }
+      else
+       *q++ = *p++;
+    }
+
+  size_t n = strftime (s, size, fmt, tm);
   char *mday = s + sizeof "From movemail Sun Jan " - 1;
   if (*mday == '0')
     *mday = ' ';



reply via email to

[Prev in Thread] Current Thread [Next in Thread]