Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 82 / f7436a0f939d87432459e2e2513ec6316d5c3f
1 Return-Path: <blakej@foo.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 7DDBA431FBF\r
6         for <notmuch@notmuchmail.org>; Tue, 13 Nov 2012 18:10:19 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id FDRSPKaw27p3 for <notmuch@notmuchmail.org>;\r
16         Tue, 13 Nov 2012 18:10:17 -0800 (PST)\r
17 Received: from foo.net (70-36-235-136.dsl.static.sonic.net [70.36.235.136])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 6D714431FBD\r
21         for <notmuch@notmuchmail.org>; Tue, 13 Nov 2012 18:10:12 -0800 (PST)\r
22 Received: from foo.net (localhost [127.0.0.1])\r
23         by foo.net (8.14.5+Sun/8.14.5) with ESMTP id qAE2AASx018948;\r
24         Tue, 13 Nov 2012 18:10:10 -0800 (PST)\r
25 Received: (from blakej@localhost)\r
26         by foo.net (8.14.5+Sun/8.14.5/Submit) id qAE2AAOm018944;\r
27         Tue, 13 Nov 2012 18:10:10 -0800 (PST)\r
28 From: Blake Jones <blakej@foo.net>\r
29 To: notmuch@notmuchmail.org\r
30 Subject: [PATCH v3 10/10] timegm: add portable implementation (Solaris\r
31  support)\r
32 Date: Tue, 13 Nov 2012 18:10:05 -0800\r
33 Message-Id: <1352859005-18631-11-git-send-email-blakej@foo.net>\r
34 X-Mailer: git-send-email 1.7.3.2\r
35 In-Reply-To: <1352859005-18631-1-git-send-email-blakej@foo.net>\r
36 References: <1352859005-18631-1-git-send-email-blakej@foo.net>\r
37 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2\r
38         (foo.net [127.0.0.1]); Tue, 13 Nov 2012 18:10:10 -0800 (PST)\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Wed, 14 Nov 2012 02:10:20 -0000\r
52 \r
53 The timegm(3) function is a non-standard extension to libc which is\r
54 available in GNU libc and on some BSDs.  Although SunOS had this\r
55 function in its libc, Solaris (unfortunately) removed it.  This patch\r
56 implements a very simple version of timegm() which is good enough for\r
57 parse-time-string.c.\r
58 \r
59 One complication of this fix is that libnotmuch.a includes a call to\r
60 parse_time_string() from parse-time-vrp.o, and parse_time_string() in\r
61 libparse-time-string.a is the thing which needs to call timegm().  A\r
62 straightforward attempt to have the two static libraries reconcile their\r
63 symbols from one another fails, because the symbols come from different\r
64 .o's, and the linker only does a single pass on each ".a" looking for\r
65 dependencies.  To solve this, libparse-time-string includes "compat.h",\r
66 and pulls in .o's from the compat directory, in order to get everything\r
67 that it needs.\r
68 ---\r
69  compat/Makefile.local                 |    4 +++\r
70  compat/compat.h                       |   19 ++++++++++------\r
71  compat/have_timegm.c                  |    7 ++++++\r
72  compat/timegm.c                       |   37 +++++++++++++++++++++++++++++++++\r
73  configure                             |   11 +++++++++\r
74  parse-time-string/Makefile.local      |    4 ++-\r
75  parse-time-string/parse-time-string.c |    1 +\r
76  7 files changed, 75 insertions(+), 8 deletions(-)\r
77  create mode 100644 compat/have_timegm.c\r
78  create mode 100644 compat/timegm.c\r
79 \r
80 diff --git a/compat/Makefile.local b/compat/Makefile.local\r
81 index 2c4f65f..b0d5417 100644\r
82 --- a/compat/Makefile.local\r
83 +++ b/compat/Makefile.local\r
84 @@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)\r
85  notmuch_compat_srcs += $(dir)/strsep.c\r
86  endif\r
87  \r
88 +ifneq ($(HAVE_TIMEGM),1)\r
89 +notmuch_compat_srcs += $(dir)/timegm.c\r
90 +endif\r
91 +\r
92  SRCS := $(SRCS) $(notmuch_compat_srcs)\r
93 diff --git a/compat/compat.h b/compat/compat.h\r
94 index 0b5e465..5a402d5 100644\r
95 --- a/compat/compat.h\r
96 +++ b/compat/compat.h\r
97 @@ -30,6 +30,13 @@\r
98  extern "C" {\r
99  #endif\r
100  \r
101 +#if !STD_GETPWUID\r
102 +#define _POSIX_PTHREAD_SEMANTICS 1\r
103 +#endif\r
104 +#if !STD_ASCTIME\r
105 +#define _POSIX_PTHREAD_SEMANTICS 1\r
106 +#endif\r
107 +\r
108  #if !HAVE_GETLINE\r
109  #include <stdio.h>\r
110  #include <unistd.h>\r
111 @@ -50,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);\r
112  char *strsep(char **stringp, const char *delim);\r
113  #endif /* !HAVE_STRSEP */\r
114  \r
115 +#if !HAVE_TIMEGM\r
116 +#include <time.h>\r
117 +time_t timegm (struct tm *tm);\r
118 +#endif /* !HAVE_TIMEGM */\r
119 +\r
120  /* Silence gcc warnings about unused results.  These warnings exist\r
121   * for a reason; any use of this needs to be justified. */\r
122  #ifdef __GNUC__\r
123 @@ -58,13 +70,6 @@ char *strsep(char **stringp, const char *delim);\r
124  #define IGNORE_RESULT(x) x\r
125  #endif /* __GNUC__ */\r
126  \r
127 -#if !STD_GETPWUID\r
128 -#define _POSIX_PTHREAD_SEMANTICS 1\r
129 -#endif\r
130 -#if !STD_ASCTIME\r
131 -#define _POSIX_PTHREAD_SEMANTICS 1\r
132 -#endif\r
133 -\r
134  #ifdef __cplusplus\r
135  }\r
136  #endif\r
137 diff --git a/compat/have_timegm.c b/compat/have_timegm.c\r
138 new file mode 100644\r
139 index 0000000..b62b793\r
140 --- /dev/null\r
141 +++ b/compat/have_timegm.c\r
142 @@ -0,0 +1,7 @@\r
143 +#include <time.h>\r
144 +#include "compat.h"\r
145 +\r
146 +int main()\r
147 +{\r
148 +    return (int) timegm((struct tm *)0);\r
149 +}\r
150 diff --git a/compat/timegm.c b/compat/timegm.c\r
151 new file mode 100644\r
152 index 0000000..6d76164\r
153 --- /dev/null\r
154 +++ b/compat/timegm.c\r
155 @@ -0,0 +1,37 @@\r
156 +#include <time.h>\r
157 +#include "compat.h"\r
158 +\r
159 +static int\r
160 +leapyear (int year)\r
161 +{\r
162 +    return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));\r
163 +}\r
164 +\r
165 +/*\r
166 + * This is a simple implementation of timegm() which does what is needed\r
167 + * by create_output() -- just turns the "struct tm" into a GMT time_t.\r
168 + * It does not normalize any of the fields of the "struct tm", nor does\r
169 + * it set tm_wday or tm_yday.\r
170 + */\r
171 +time_t\r
172 +timegm (struct tm *tm)\r
173 +{\r
174 +    int        monthlen[2][12] = {\r
175 +       { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
176 +       { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
177 +    };\r
178 +    int        year, month, days;\r
179 +\r
180 +    days = 365 * (tm->tm_year - 70);\r
181 +    for (year = 70; year < tm->tm_year; year++) {\r
182 +       if (leapyear(1900 + year)) {\r
183 +           days++;\r
184 +       }\r
185 +    }\r
186 +    for (month = 0; month < tm->tm_mon; month++) {\r
187 +       days += monthlen[leapyear(1900 + year)][month];\r
188 +    }\r
189 +    days += tm->tm_mday - 1;\r
190 +\r
191 +    return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);\r
192 +}\r
193 diff --git a/configure b/configure\r
194 index ab8357f..f3ec9a2 100755\r
195 --- a/configure\r
196 +++ b/configure\r
197 @@ -523,6 +523,17 @@ else\r
198  fi\r
199  rm -f compat/have_strsep\r
200  \r
201 +printf "Checking for timegm... "\r
202 +if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1\r
203 +then\r
204 +    printf "Yes.\n"\r
205 +    have_timegm="1"\r
206 +else\r
207 +    printf "No (will use our own instead).\n"\r
208 +    have_timegm="0"\r
209 +fi\r
210 +rm -f compat/have_timegm\r
211 +\r
212  printf "Checking for standard version of getpwuid_r... "\r
213  if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1\r
214  then\r
215 diff --git a/parse-time-string/Makefile.local b/parse-time-string/Makefile.local\r
216 index 53534f3..c011e0b 100644\r
217 --- a/parse-time-string/Makefile.local\r
218 +++ b/parse-time-string/Makefile.local\r
219 @@ -1,7 +1,9 @@\r
220  dir := parse-time-string\r
221  extra_cflags += -I$(srcdir)/$(dir)\r
222  \r
223 -libparse-time-string_c_srcs := $(dir)/parse-time-string.c\r
224 +libparse-time-string_c_srcs :=         \\r
225 +       $(notmuch_compat_srcs)          \\r
226 +       $(dir)/parse-time-string.c\r
227  \r
228  libparse-time-string_modules := $(libparse-time-string_c_srcs:.c=.o)\r
229  \r
230 diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c\r
231 index 584067d..ccad422 100644\r
232 --- a/parse-time-string/parse-time-string.c\r
233 +++ b/parse-time-string/parse-time-string.c\r
234 @@ -32,6 +32,7 @@\r
235  #include <sys/time.h>\r
236  #include <sys/types.h>\r
237  \r
238 +#include "compat.h"\r
239  #include "parse-time-string.h"\r
240  \r
241  /*\r
242 -- \r
243 1.7.3.2\r
244 \r