From 0accf6db59391563abfa8ab01211d4233183def2 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 4 Aug 2017 03:14:41 +0100 Subject: [PATCH] refactor: move mutt_make_date to lib/date --- globals.h | 11 ----------- lib/date.c | 32 ++++++++++++++++++++++++++++++++ lib/date.h | 4 ++++ protos.h | 1 - sendlib.c | 14 -------------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/globals.h b/globals.h index cece5fe56..2fe3e7226 100644 --- 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 */ diff --git a/lib/date.c b/lib/date.c index 5079281bc..43926d60a 100644 --- a/lib/date.c +++ b/lib/date.c @@ -28,11 +28,14 @@ * | 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 +#include #include #include @@ -41,6 +44,14 @@ #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; +} + diff --git a/lib/date.h b/lib/date.h index f20c5eb9e..8f04a3421 100644 --- a/lib/date.h +++ b/lib/date.h @@ -25,8 +25,12 @@ #include +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 */ diff --git a/protos.h b/protos.h index 514d94db9..27fb80c8b 100644 --- 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); diff --git a/sendlib.c b/sendlib.c index cd3ed9fa6..ae4af6b1f 100644 --- 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() * -- 2.40.0