X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=date.c;h=44f5a99acd8bb509b8058c20c0b482d93ab61c2b;hp=c6cbd813c444e770bfda2b51c89701417d96600d;hb=8ff934803cb2a0ca4f862aa5e0dd6f8908b78ffa;hpb=e26a2bf48bea7de68fa421c96330928dce07de39 diff --git a/date.c b/date.c index c6cbd813..44f5a99a 100644 --- a/date.c +++ b/date.c @@ -23,54 +23,19 @@ * some glib-isms. */ -#ifdef HAVE_CONFIG_H -#include -#endif +#include "notmuch-private.h" -#define _GNU_SOURCE +#include -#include +#include /* For g_ascii_strncasecmp only. */ -#include -#include -#include -#ifdef HAVE_SYS_PARAM_H -#include /* for MAXHOSTNAMELEN */ -#else -#define MAXHOSTNAMELEN 64 -#endif -#ifdef HAVE_UTSNAME_DOMAINNAME -#include /* for uname() */ +#ifndef FALSE +#define FALSE 0 #endif -#include -#ifdef HAVE_UNISTD_H -#include /* Unix header for getpid() */ -#endif -#ifdef G_OS_WIN32 -#include -#include -#include -#define getpid() _getpid() -#endif -#ifdef HAVE_NETDB_H -#include + +#ifndef TRUE +#define TRUE 1 #endif -#include -#include - -#include "gmime-utils.h" -#include "gmime-table-private.h" -#include "gmime-parse-utils.h" -#include "gmime-part.h" -#include "gmime-charset.h" -#include "gmime-iconv.h" -#include "gmime-iconv-utils.h" - -#ifdef ENABLE_WARNINGS -#define w(x) x -#else -#define w(x) -#endif /* ENABLE_WARNINGS */ #define d(x) @@ -112,9 +77,9 @@ static unsigned char gmime_datetok_table[256] = { 111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111, }; -/* hrm, is there a library for this shit? */ +/* hrm, is there a library for this stuff? */ static struct { - char *name; + const char *name; int offset; } tz_offsets [] = { { "UT", 0 }, @@ -134,12 +99,12 @@ static struct { { "Y", 1200 }, }; -static char *tm_months[] = { +static const char *tm_months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static char *tm_days[] = { +static const char *tm_days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; @@ -152,8 +117,8 @@ typedef struct _date_token { size_t len; } date_token; -#define date_token_free(tok) g_slice_free (date_token, tok) -#define date_token_new() g_slice_new (date_token) +#define date_token_free(tok) free (tok) +#define date_token_new() malloc (sizeof (date_token)) static date_token * datetok (const char *date) @@ -259,8 +224,9 @@ static int get_wday (const char *in, size_t inlen) { int wday; - - g_return_val_if_fail (in != NULL, -1); + + if (in == NULL) + return -1; if (inlen < 3) return -1; @@ -278,7 +244,8 @@ get_mday (const char *in, size_t inlen) { int mday; - g_return_val_if_fail (in != NULL, -1); + if (in == NULL) + return -1; mday = decode_int (in, inlen); @@ -293,7 +260,8 @@ get_month (const char *in, size_t inlen) { int i; - g_return_val_if_fail (in != NULL, -1); + if (in == NULL) + return -1; if (inlen < 3) return -1; @@ -311,7 +279,8 @@ get_year (const char *in, size_t inlen) { int year; - g_return_val_if_fail (in != NULL, -1); + if (in == NULL) + return -1; if ((year = decode_int (in, inlen)) == -1) return -1; @@ -325,7 +294,7 @@ get_year (const char *in, size_t inlen) return year; } -static gboolean +static int get_time (const char *in, size_t inlen, int *hour, int *min, int *sec) { register const char *inptr; @@ -396,6 +365,8 @@ get_tzone (date_token **token) return -1; } +#define HAVE_TIMEZONE + static time_t mktime_utc (struct tm *tm) { @@ -442,7 +413,8 @@ parse_rfc822_date (date_token *tokens, int *tzone) struct tm tm; time_t t; - g_return_val_if_fail (tokens != NULL, (time_t) 0); + if (tokens == NULL) + return 0; token = tokens; @@ -518,7 +490,7 @@ parse_rfc822_date (date_token *tokens, int *tzone) static time_t parse_broken_date (date_token *tokens, int *tzone) { - gboolean got_wday, got_month, got_tzone; + int got_wday, got_month, got_tzone; int hour, min, sec, offset, n; date_token *token; struct tm tm; @@ -668,30 +640,20 @@ gmime_datetok_table_init (void) } #endif - -/** - * g_mime_utils_header_decode_date: - * @str: input date string - * @tz_offset: timezone offset - * - * Decodes the rfc822 date string and saves the GMT offset into - * @tz_offset if non-NULL. - * - * Returns: the time_t representation of the date string specified by - * @str or (time_t) %0 on error. If @tz_offset is non-NULL, the value - * of the timezone offset will be stored. - **/ time_t -g_mime_utils_header_decode_date (const char *str, int *tz_offset) +notmuch_parse_date (const char *str, int *tz_offset) { date_token *token, *tokens; time_t date; - + + if (str == NULL) + return 0; + if (!(tokens = datetok (str))) { if (tz_offset) *tz_offset = 0; - return (time_t) 0; + return 0; } if (!(date = parse_rfc822_date (tokens, tz_offset)))