]> granicus.if.org Git - neomutt/commitdiff
refactor: move mutt_make_date to lib/date
authorRichard Russon <rich@flatcap.org>
Fri, 4 Aug 2017 02:14:41 +0000 (03:14 +0100)
committerRichard Russon <rich@flatcap.org>
Fri, 4 Aug 2017 21:56:50 +0000 (22:56 +0100)
globals.h
lib/date.c
lib/date.h
protos.h
sendlib.c

index cece5fe56908d9b52cf559ae2b4ae928ec49b81a..2fe3e72261c3a3e81e56121f171b6af57b39edfe 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -342,14 +342,6 @@ WHERE char *NotmuchQueryWindowCurrentSearch;
 #endif
 
 #ifdef MAIN_C
-const char *const Weekdays[] = {
-    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
-};
-const char *const Months[] = {
-    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
-    "Aug", "Sep", "Oct", "Nov", "Dec", "ERR",
-};
-
 const char *const BodyTypes[] = {
     "x-unknown", "audio",     "application", "image", "message",
     "model",     "multipart", "text",        "video",
@@ -358,9 +350,6 @@ const char *const BodyEncodings[] = {
     "x-unknown", "7bit",   "8bit",        "quoted-printable",
     "base64",    "binary", "x-uuencoded",
 };
-#else
-extern const char *const Weekdays[];
-extern const char *const Months[];
 #endif
 
 #endif /* _MUTT_GLOBALS_H */
index 5079281bc5758989f475877a4300f73c8a8ae47e..43926d60a707254356afc08a10d0b2b197fcc2c2 100644 (file)
  * | Function              | Description
  * | :-------------------- | :--------------------------------------------------
  * | mutt_local_tz()       | Calculate the local timezone in seconds east of UTC
+ * | mutt_make_date()      | Write a date in RFC822 format to a buffer
  * | mutt_mktime()         | Convert `struct tm` to `time_t`
  * | mutt_normalize_time() | Fix the contents of a struct tm
  */
 
 #include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <time.h>
 
 #define TM_YEAR_MAX                                                            \
   (1970 + (((((TIME_T_MAX - 59) / 60) - 59) / 60) - 23) / 24 / 366)
 
+const char *const Weekdays[] = {
+    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
+};
+const char *const Months[] = {
+    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
+    "Aug", "Sep", "Oct", "Nov", "Dec", "ERR",
+};
+
 /**
  * compute_tz - Calculate the number of seconds east of UTC
  * @param g   Local time
@@ -242,3 +253,24 @@ void mutt_normalize_time(struct tm *tm)
     }
   }
 }
+
+/**
+ * mutt_make_date - Write a date in RFC822 format to a buffer
+ * @param buf    Buffer for result
+ * @param buflen Length of buffer
+ * @retval ptr Buffer containing result
+ */
+char *mutt_make_date(char *buf, size_t buflen)
+{
+  time_t t = time(NULL);
+  struct tm *l = localtime(&t);
+  time_t tz = mutt_local_tz(t);
+
+  tz /= 60;
+
+  snprintf(buf, buflen, "Date: %s, %d %s %d %02d:%02d:%02d %+03d%02d\n",
+           Weekdays[l->tm_wday], l->tm_mday, Months[l->tm_mon], l->tm_year + 1900,
+           l->tm_hour, l->tm_min, l->tm_sec, (int) tz / 60, (int) abs((int) tz) % 60);
+  return buf;
+}
+
index f20c5eb9ed76da4a35fcb8f60a5f9547cb16fe84..8f04a3421f8295009524a47a4e35bcab4032223f 100644 (file)
 
 #include <time.h>
 
+extern const char *const Weekdays[];
+extern const char *const Months[];
+
 time_t mutt_local_tz(time_t t);
 time_t mutt_mktime(struct tm *t, int local);
 void mutt_normalize_time(struct tm *tm);
+char *mutt_make_date(char *buf, size_t buflen);
 
 #endif /* _LIB_DATE_H */
index 514d94db9fa207bb022e09b2a659da096cca94c5..27fb80c8bc69d41019298a6538ece2d896f7a14d 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -141,7 +141,6 @@ char *mutt_find_hook(int type, const char *pat);
 char *mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw);
 char *mutt_get_body_charset(char *d, size_t dlen, struct Body *b);
 struct List *mutt_crypt_hook(struct Address *adr);
-char *mutt_make_date(char *s, size_t len);
 void mutt_timeout_hook(void);
 void mutt_startup_shutdown_hook(int type);
 int mutt_set_xdg_path(enum XdgType type, char *buf, size_t bufsize);
index cd3ed9fa6fb8b13aa2fc53dbca0415bdc520255f..ae4af6b1f66149f2fafcdf3ae13a05cea2127292 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1530,20 +1530,6 @@ struct Body *mutt_remove_multipart(struct Body *b)
   return b;
 }
 
-char *mutt_make_date(char *s, size_t len)
-{
-  time_t t = time(NULL);
-  struct tm *l = localtime(&t);
-  time_t tz = mutt_local_tz(t);
-
-  tz /= 60;
-
-  snprintf(s, len, "Date: %s, %d %s %d %02d:%02d:%02d %+03d%02d\n",
-           Weekdays[l->tm_wday], l->tm_mday, Months[l->tm_mon], l->tm_year + 1900,
-           l->tm_hour, l->tm_min, l->tm_sec, (int) tz / 60, (int) abs((int) tz) % 60);
-  return s;
-}
-
 /**
  * mutt_write_address_list - wrapper around mutt_write_address()
  *