Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 39 / b28b5a9921a028bd4b446044847460f71193ce
1 Return-Path: <jani@nikula.org>\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 AA331429E34\r
6         for <notmuch@notmuchmail.org>; Wed, 10 Aug 2011 03:23:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id EqsqxWvrYV13 for <notmuch@notmuchmail.org>;\r
17         Wed, 10 Aug 2011 03:23:42 -0700 (PDT)\r
18 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
19         [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id C2ECC429E33\r
22         for <notmuch@notmuchmail.org>; Wed, 10 Aug 2011 03:23:41 -0700 (PDT)\r
23 Received: by qyk34 with SMTP id 34so596577qyk.5\r
24         for <notmuch@notmuchmail.org>; Wed, 10 Aug 2011 03:22:21 -0700 (PDT)\r
25 Received: by 10.229.160.12 with SMTP id l12mr47462qcx.258.1312971741415;\r
26         Wed, 10 Aug 2011 03:22:21 -0700 (PDT)\r
27 Received: from localhost (nikula.org [92.243.24.172])\r
28         by mx.google.com with ESMTPS id s14sm710886qct.30.2011.08.10.03.22.17\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Wed, 10 Aug 2011 03:22:19 -0700 (PDT)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [RFC PATCH 2/3] Compile the date/time parser into notmuch library\r
34 Date: Wed, 10 Aug 2011 10:22:06 +0000\r
35 Message-Id:\r
36  <09761de1bad20ecc80888a7dd472bcd6a14d504b.1312964528.git.jani@nikula.org>\r
37 X-Mailer: git-send-email 1.7.1\r
38 In-Reply-To: <cover.1312964528.git.jani@nikula.org>\r
39 References: <cover.1312964528.git.jani@nikula.org>\r
40 In-Reply-To: <cover.1312964528.git.jani@nikula.org>\r
41 References: <cover.1312964528.git.jani@nikula.org>\r
42 Cc: amdragon@mit.edu\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Wed, 10 Aug 2011 10:23:47 -0000\r
56 \r
57 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
58 \r
59 ---\r
60  Makefile.local     |    3 +\r
61  configure          |    8 ++\r
62  lib/Makefile.local |    5 +-\r
63  lib/config.h       |   45 +++++++++++++\r
64  lib/getdate.c      |  185 +++++++++++++++++++++++++++-------------------------\r
65  lib/getdate.h      |    9 +++\r
66  lib/getdate.y      |   15 ++++-\r
67  7 files changed, 178 insertions(+), 92 deletions(-)\r
68  create mode 100644 lib/config.h\r
69 \r
70 diff --git a/Makefile.local b/Makefile.local\r
71 index e3d4d03..3da9ad9 100644\r
72 --- a/Makefile.local\r
73 +++ b/Makefile.local\r
74 @@ -234,6 +234,9 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))\r
75  %.o: %.c $(global_deps)\r
76         $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@\r
77  \r
78 +%.c: %.y\r
79 +       $(call quiet,YACC $(YFLAGS)) $(YFLAGS) $< -o $@\r
80 +\r
81  .deps/%.d: %.c $(global_deps)\r
82         @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \\r
83         $(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@.$$$$ 2>/dev/null ; \\r
84 diff --git a/configure b/configure\r
85 index 3999ce8..f385c79 100755\r
86 --- a/configure\r
87 +++ b/configure\r
88 @@ -25,9 +25,11 @@ fi\r
89  # environment variables)\r
90  CC=${CC:-gcc}\r
91  CXX=${CXX:-g++}\r
92 +YACC=${YACC:-yacc}\r
93  CFLAGS=${CFLAGS:--O2}\r
94  CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}\r
95  LDFLAGS=${LDFLAGS:-}\r
96 +YFLAGS=${YFLAGS}\r
97  XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}\r
98  \r
99  # We don't allow the EMACS or GZIP Makefile variables inherit values\r
100 @@ -571,6 +573,9 @@ CC = ${CC}\r
101  # The C++ compiler to use\r
102  CXX = ${CXX}\r
103  \r
104 +# The parser generator to use\r
105 +YACC = ${YACC}\r
106 +\r
107  # Command to execute emacs from Makefiles\r
108  EMACS = emacs --quick\r
109  \r
110 @@ -589,6 +594,9 @@ WARN_CXXFLAGS=${WARN_CXXFLAGS}\r
111  # Flags to enable warnings when using the C compiler\r
112  WARN_CFLAGS=${WARN_CFLAGS}\r
113  \r
114 +# Default FLAGS for parser generator (can be overridden by user such as "make YFLAGS=-y")\r
115 +YFLAGS = ${YFLAGS}\r
116 +\r
117  # The prefix to which notmuch should be installed\r
118  # Note: If you change this value here, be sure to ensure that the\r
119  # LIBDIR_IN_LDCONFIG value below is still set correctly.\r
120 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
121 index fbc2f6a..a1c234f 100644\r
122 --- a/lib/Makefile.local\r
123 +++ b/lib/Makefile.local\r
124 @@ -56,7 +56,10 @@ libnotmuch_c_srcs =          \\r
125         $(dir)/messages.c       \\r
126         $(dir)/sha1.c           \\r
127         $(dir)/tags.c           \\r
128 -       $(dir)/xutil.c\r
129 +       $(dir)/xutil.c          \\r
130 +       $(dir)/getdate.c        \\r
131 +       $(dir)/c-ctype.c        \\r
132 +       $(dir)/gettime.c\r
133  \r
134  libnotmuch_cxx_srcs =          \\r
135         $(dir)/database.cc      \\r
136 diff --git a/lib/config.h b/lib/config.h\r
137 new file mode 100644\r
138 index 0000000..e8bc5b7\r
139 --- /dev/null\r
140 +++ b/lib/config.h\r
141 @@ -0,0 +1,45 @@\r
142 +/* lib/config.h.  Generated from config.hin by configure.  */\r
143 +/* lib/config.hin.  Generated from configure.ac by autoheader.  */\r
144 +\r
145 +/* Define to 1 if you have the `clock_gettime' function. */\r
146 +#define HAVE_CLOCK_GETTIME 1\r
147 +\r
148 +/* Define if you have compound literals. */\r
149 +#define HAVE_COMPOUND_LITERALS 1\r
150 +\r
151 +/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.\r
152 +   */\r
153 +/* #undef HAVE_DECL_TZNAME */\r
154 +\r
155 +/* Define to 1 if you have the `nanotime' function. */\r
156 +/* #undef HAVE_NANOTIME */\r
157 +\r
158 +/* Define to 1 if `tm_zone' is a member of `struct tm'. */\r
159 +#define HAVE_STRUCT_TM_TM_ZONE 1\r
160 +\r
161 +/* Define if struct tm has the tm_gmtoff member. */\r
162 +#define HAVE_TM_GMTOFF 1\r
163 +\r
164 +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use\r
165 +   `HAVE_STRUCT_TM_TM_ZONE' instead. */\r
166 +#define HAVE_TM_ZONE 1\r
167 +\r
168 +/* Define to 1 if you don't have `tm_zone' but do have the external array\r
169 +   `tzname'. */\r
170 +/* #undef HAVE_TZNAME */\r
171 +\r
172 +/* Define to 1 if you have the `tzset' function. */\r
173 +#define HAVE_TZSET 1\r
174 +\r
175 +\r
176 +/* Define as a marker that can be attached to declarations that might not\r
177 +    be used.  This helps to reduce warnings, such as from\r
178 +    GCC -Wunused-parameter.  */\r
179 +#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)\r
180 +# define _GL_UNUSED __attribute__ ((__unused__))\r
181 +#else\r
182 +# define _GL_UNUSED\r
183 +#endif\r
184 +/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name\r
185 +   is a misnomer outside of parameter lists.  */\r
186 +#define _UNUSED_PARAMETER_ _GL_UNUSED\r
187 diff --git a/lib/getdate.c b/lib/getdate.c\r
188 index 5b20eeb..57f33e9 100644\r
189 --- a/lib/getdate.c\r
190 +++ b/lib/getdate.c\r
191 @@ -68,7 +68,7 @@\r
192  /* Copy the first part of user declarations.  */\r
193  \r
194  /* Line 189 of yacc.c  */\r
195 -#line 1 "getdate.y"\r
196 +#line 1 "lib/getdate.y"\r
197  \r
198  /* Parse a string into an internal time stamp.\r
199  \r
200 @@ -102,6 +102,8 @@\r
201  /* FIXME: Check for arithmetic overflow in all cases, not just\r
202     some of them.  */\r
203  \r
204 +#include "notmuch-private.h"   /* For xmalloc() */\r
205 +\r
206  #include <config.h>\r
207  \r
208  #include "getdate.h"\r
209 @@ -137,9 +139,6 @@\r
210  #include <stdlib.h>\r
211  #include <string.h>\r
212  \r
213 -#include "xalloc.h"\r
214 -\r
215 -\r
216  /* ISDIGIT differs from isdigit, as follows:\r
217     - Its arg may be any int or unsigned int; it need not be an unsigned char\r
218       or EOF.\r
219 @@ -344,7 +343,7 @@ set_hhmmss (parser_control *pc, long int hour, long int minutes,\r
220  \r
221  \r
222  /* Line 189 of yacc.c  */\r
223 -#line 348 "getdate.c"\r
224 +#line 347 "lib/getdate.c"\r
225  \r
226  /* Enabling traces.  */\r
227  #ifndef YYDEBUG\r
228 @@ -423,7 +422,7 @@ typedef union YYSTYPE\r
229  {\r
230  \r
231  /* Line 214 of yacc.c  */\r
232 -#line 285 "getdate.y"\r
233 +#line 284 "lib/getdate.y"\r
234  \r
235    long int intval;\r
236    textint textintval;\r
237 @@ -433,7 +432,7 @@ typedef union YYSTYPE\r
238  \r
239  \r
240  /* Line 214 of yacc.c  */\r
241 -#line 437 "getdate.c"\r
242 +#line 436 "lib/getdate.c"\r
243  } YYSTYPE;\r
244  # define YYSTYPE_IS_TRIVIAL 1\r
245  # define yystype YYSTYPE /* obsolescent; will be withdrawn */\r
246 @@ -445,7 +444,7 @@ typedef union YYSTYPE\r
247  \r
248  \r
249  /* Line 264 of yacc.c  */\r
250 -#line 449 "getdate.c"\r
251 +#line 448 "lib/getdate.c"\r
252  \r
253  #ifdef short\r
254  # undef short\r
255 @@ -759,15 +758,15 @@ static const yytype_int8 yyrhs[] =\r
256  /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */\r
257  static const yytype_uint16 yyrline[] =\r
258  {\r
259 -       0,   311,   311,   312,   316,   323,   325,   329,   331,   333,\r
260 -     335,   337,   339,   340,   341,   345,   350,   355,   362,   367,\r
261 -     377,   382,   390,   392,   395,   397,   399,   404,   409,   414,\r
262 -     419,   427,   432,   452,   459,   467,   475,   480,   486,   491,\r
263 -     500,   502,   504,   509,   511,   513,   515,   517,   519,   521,\r
264 -     523,   525,   527,   529,   531,   533,   535,   537,   539,   541,\r
265 -     543,   545,   547,   549,   553,   555,   557,   559,   561,   563,\r
266 -     568,   572,   572,   575,   576,   581,   582,   587,   592,   603,\r
267 -     604,   610,   611\r
268 +       0,   310,   310,   311,   315,   322,   324,   328,   330,   332,\r
269 +     334,   336,   338,   339,   340,   344,   349,   354,   361,   366,\r
270 +     376,   381,   389,   391,   394,   396,   398,   403,   408,   413,\r
271 +     418,   426,   431,   451,   458,   466,   474,   479,   485,   490,\r
272 +     499,   501,   503,   508,   510,   512,   514,   516,   518,   520,\r
273 +     522,   524,   526,   528,   530,   532,   534,   536,   538,   540,\r
274 +     542,   544,   546,   548,   552,   554,   556,   558,   560,   562,\r
275 +     567,   571,   571,   574,   575,   580,   581,   586,   591,   602,\r
276 +     603,   609,   610\r
277  };\r
278  #endif\r
279  \r
280 @@ -1742,7 +1741,7 @@ yyreduce:\r
281          case 4:\r
282  \r
283  /* Line 1455 of yacc.c  */\r
284 -#line 317 "getdate.y"\r
285 +#line 316 "lib/getdate.y"\r
286      {\r
287          pc->seconds = (yyvsp[(2) - (2)].timespec);\r
288          pc->timespec_seen = true;\r
289 @@ -1752,42 +1751,42 @@ yyreduce:\r
290    case 7:\r
291  \r
292  /* Line 1455 of yacc.c  */\r
293 -#line 330 "getdate.y"\r
294 +#line 329 "lib/getdate.y"\r
295      { pc->times_seen++; }\r
296      break;\r
297  \r
298    case 8:\r
299  \r
300  /* Line 1455 of yacc.c  */\r
301 -#line 332 "getdate.y"\r
302 +#line 331 "lib/getdate.y"\r
303      { pc->local_zones_seen++; }\r
304      break;\r
305  \r
306    case 9:\r
307  \r
308  /* Line 1455 of yacc.c  */\r
309 -#line 334 "getdate.y"\r
310 +#line 333 "lib/getdate.y"\r
311      { pc->zones_seen++; }\r
312      break;\r
313  \r
314    case 10:\r
315  \r
316  /* Line 1455 of yacc.c  */\r
317 -#line 336 "getdate.y"\r
318 +#line 335 "lib/getdate.y"\r
319      { pc->dates_seen++; }\r
320      break;\r
321  \r
322    case 11:\r
323  \r
324  /* Line 1455 of yacc.c  */\r
325 -#line 338 "getdate.y"\r
326 +#line 337 "lib/getdate.y"\r
327      { pc->days_seen++; }\r
328      break;\r
329  \r
330    case 15:\r
331  \r
332  /* Line 1455 of yacc.c  */\r
333 -#line 346 "getdate.y"\r
334 +#line 345 "lib/getdate.y"\r
335      {\r
336          set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);\r
337          pc->meridian = (yyvsp[(2) - (2)].intval);\r
338 @@ -1797,7 +1796,7 @@ yyreduce:\r
339    case 16:\r
340  \r
341  /* Line 1455 of yacc.c  */\r
342 -#line 351 "getdate.y"\r
343 +#line 350 "lib/getdate.y"\r
344      {\r
345          set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);\r
346          pc->meridian = (yyvsp[(4) - (4)].intval);\r
347 @@ -1807,7 +1806,7 @@ yyreduce:\r
348    case 17:\r
349  \r
350  /* Line 1455 of yacc.c  */\r
351 -#line 356 "getdate.y"\r
352 +#line 355 "lib/getdate.y"\r
353      {\r
354          set_hhmmss (pc, (yyvsp[(1) - (5)].textintval).value, (yyvsp[(3) - (5)].textintval).value, 0, 0);\r
355          pc->meridian = MER24;\r
356 @@ -1819,7 +1818,7 @@ yyreduce:\r
357    case 18:\r
358  \r
359  /* Line 1455 of yacc.c  */\r
360 -#line 363 "getdate.y"\r
361 +#line 362 "lib/getdate.y"\r
362      {\r
363          set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);\r
364          pc->meridian = (yyvsp[(6) - (6)].intval);\r
365 @@ -1829,7 +1828,7 @@ yyreduce:\r
366    case 19:\r
367  \r
368  /* Line 1455 of yacc.c  */\r
369 -#line 368 "getdate.y"\r
370 +#line 367 "lib/getdate.y"\r
371      {\r
372          set_hhmmss (pc, (yyvsp[(1) - (7)].textintval).value, (yyvsp[(3) - (7)].textintval).value, (yyvsp[(5) - (7)].timespec).tv_sec, (yyvsp[(5) - (7)].timespec).tv_nsec);\r
373          pc->meridian = MER24;\r
374 @@ -1841,7 +1840,7 @@ yyreduce:\r
375    case 20:\r
376  \r
377  /* Line 1455 of yacc.c  */\r
378 -#line 378 "getdate.y"\r
379 +#line 377 "lib/getdate.y"\r
380      {\r
381          pc->local_isdst = (yyvsp[(1) - (1)].intval);\r
382          pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));\r
383 @@ -1851,7 +1850,7 @@ yyreduce:\r
384    case 21:\r
385  \r
386  /* Line 1455 of yacc.c  */\r
387 -#line 383 "getdate.y"\r
388 +#line 382 "lib/getdate.y"\r
389      {\r
390          pc->local_isdst = 1;\r
391          pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;\r
392 @@ -1861,14 +1860,14 @@ yyreduce:\r
393    case 22:\r
394  \r
395  /* Line 1455 of yacc.c  */\r
396 -#line 391 "getdate.y"\r
397 +#line 390 "lib/getdate.y"\r
398      { pc->time_zone = (yyvsp[(1) - (1)].intval); }\r
399      break;\r
400  \r
401    case 23:\r
402  \r
403  /* Line 1455 of yacc.c  */\r
404 -#line 393 "getdate.y"\r
405 +#line 392 "lib/getdate.y"\r
406      { pc->time_zone = (yyvsp[(1) - (2)].intval);\r
407          apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }\r
408      break;\r
409 @@ -1876,28 +1875,28 @@ yyreduce:\r
410    case 24:\r
411  \r
412  /* Line 1455 of yacc.c  */\r
413 -#line 396 "getdate.y"\r
414 +#line 395 "lib/getdate.y"\r
415      { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }\r
416      break;\r
417  \r
418    case 25:\r
419  \r
420  /* Line 1455 of yacc.c  */\r
421 -#line 398 "getdate.y"\r
422 +#line 397 "lib/getdate.y"\r
423      { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }\r
424      break;\r
425  \r
426    case 26:\r
427  \r
428  /* Line 1455 of yacc.c  */\r
429 -#line 400 "getdate.y"\r
430 +#line 399 "lib/getdate.y"\r
431      { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }\r
432      break;\r
433  \r
434    case 27:\r
435  \r
436  /* Line 1455 of yacc.c  */\r
437 -#line 405 "getdate.y"\r
438 +#line 404 "lib/getdate.y"\r
439      {\r
440          pc->day_ordinal = 0;\r
441          pc->day_number = (yyvsp[(1) - (1)].intval);\r
442 @@ -1907,7 +1906,7 @@ yyreduce:\r
443    case 28:\r
444  \r
445  /* Line 1455 of yacc.c  */\r
446 -#line 410 "getdate.y"\r
447 +#line 409 "lib/getdate.y"\r
448      {\r
449          pc->day_ordinal = 0;\r
450          pc->day_number = (yyvsp[(1) - (2)].intval);\r
451 @@ -1917,7 +1916,7 @@ yyreduce:\r
452    case 29:\r
453  \r
454  /* Line 1455 of yacc.c  */\r
455 -#line 415 "getdate.y"\r
456 +#line 414 "lib/getdate.y"\r
457      {\r
458          pc->day_ordinal = (yyvsp[(1) - (2)].intval);\r
459          pc->day_number = (yyvsp[(2) - (2)].intval);\r
460 @@ -1927,7 +1926,7 @@ yyreduce:\r
461    case 30:\r
462  \r
463  /* Line 1455 of yacc.c  */\r
464 -#line 420 "getdate.y"\r
465 +#line 419 "lib/getdate.y"\r
466      {\r
467          pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;\r
468          pc->day_number = (yyvsp[(2) - (2)].intval);\r
469 @@ -1937,7 +1936,7 @@ yyreduce:\r
470    case 31:\r
471  \r
472  /* Line 1455 of yacc.c  */\r
473 -#line 428 "getdate.y"\r
474 +#line 427 "lib/getdate.y"\r
475      {\r
476          pc->month = (yyvsp[(1) - (3)].textintval).value;\r
477          pc->day = (yyvsp[(3) - (3)].textintval).value;\r
478 @@ -1947,7 +1946,7 @@ yyreduce:\r
479    case 32:\r
480  \r
481  /* Line 1455 of yacc.c  */\r
482 -#line 433 "getdate.y"\r
483 +#line 432 "lib/getdate.y"\r
484      {\r
485          /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,\r
486             otherwise as MM/DD/YY.\r
487 @@ -1972,7 +1971,7 @@ yyreduce:\r
488    case 33:\r
489  \r
490  /* Line 1455 of yacc.c  */\r
491 -#line 453 "getdate.y"\r
492 +#line 452 "lib/getdate.y"\r
493      {\r
494          /* ISO 8601 format.  YYYY-MM-DD.  */\r
495          pc->year = (yyvsp[(1) - (3)].textintval);\r
496 @@ -1984,7 +1983,7 @@ yyreduce:\r
497    case 34:\r
498  \r
499  /* Line 1455 of yacc.c  */\r
500 -#line 460 "getdate.y"\r
501 +#line 459 "lib/getdate.y"\r
502      {\r
503          /* e.g. 17-JUN-1992.  */\r
504          pc->day = (yyvsp[(1) - (3)].textintval).value;\r
505 @@ -1997,7 +1996,7 @@ yyreduce:\r
506    case 35:\r
507  \r
508  /* Line 1455 of yacc.c  */\r
509 -#line 468 "getdate.y"\r
510 +#line 467 "lib/getdate.y"\r
511      {\r
512          /* e.g. JUN-17-1992.  */\r
513          pc->month = (yyvsp[(1) - (3)].intval);\r
514 @@ -2010,7 +2009,7 @@ yyreduce:\r
515    case 36:\r
516  \r
517  /* Line 1455 of yacc.c  */\r
518 -#line 476 "getdate.y"\r
519 +#line 475 "lib/getdate.y"\r
520      {\r
521          pc->month = (yyvsp[(1) - (2)].intval);\r
522          pc->day = (yyvsp[(2) - (2)].textintval).value;\r
523 @@ -2020,7 +2019,7 @@ yyreduce:\r
524    case 37:\r
525  \r
526  /* Line 1455 of yacc.c  */\r
527 -#line 481 "getdate.y"\r
528 +#line 480 "lib/getdate.y"\r
529      {\r
530          pc->month = (yyvsp[(1) - (4)].intval);\r
531          pc->day = (yyvsp[(2) - (4)].textintval).value;\r
532 @@ -2031,7 +2030,7 @@ yyreduce:\r
533    case 38:\r
534  \r
535  /* Line 1455 of yacc.c  */\r
536 -#line 487 "getdate.y"\r
537 +#line 486 "lib/getdate.y"\r
538      {\r
539          pc->day = (yyvsp[(1) - (2)].textintval).value;\r
540          pc->month = (yyvsp[(2) - (2)].intval);\r
541 @@ -2041,7 +2040,7 @@ yyreduce:\r
542    case 39:\r
543  \r
544  /* Line 1455 of yacc.c  */\r
545 -#line 492 "getdate.y"\r
546 +#line 491 "lib/getdate.y"\r
547      {\r
548          pc->day = (yyvsp[(1) - (3)].textintval).value;\r
549          pc->month = (yyvsp[(2) - (3)].intval);\r
550 @@ -2052,238 +2051,238 @@ yyreduce:\r
551    case 40:\r
552  \r
553  /* Line 1455 of yacc.c  */\r
554 -#line 501 "getdate.y"\r
555 +#line 500 "lib/getdate.y"\r
556      { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), -1); }\r
557      break;\r
558  \r
559    case 41:\r
560  \r
561  /* Line 1455 of yacc.c  */\r
562 -#line 503 "getdate.y"\r
563 +#line 502 "lib/getdate.y"\r
564      { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }\r
565      break;\r
566  \r
567    case 42:\r
568  \r
569  /* Line 1455 of yacc.c  */\r
570 -#line 505 "getdate.y"\r
571 +#line 504 "lib/getdate.y"\r
572      { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }\r
573      break;\r
574  \r
575    case 43:\r
576  \r
577  /* Line 1455 of yacc.c  */\r
578 -#line 510 "getdate.y"\r
579 +#line 509 "lib/getdate.y"\r
580      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }\r
581      break;\r
582  \r
583    case 44:\r
584  \r
585  /* Line 1455 of yacc.c  */\r
586 -#line 512 "getdate.y"\r
587 +#line 511 "lib/getdate.y"\r
588      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }\r
589      break;\r
590  \r
591    case 45:\r
592  \r
593  /* Line 1455 of yacc.c  */\r
594 -#line 514 "getdate.y"\r
595 +#line 513 "lib/getdate.y"\r
596      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }\r
597      break;\r
598  \r
599    case 46:\r
600  \r
601  /* Line 1455 of yacc.c  */\r
602 -#line 516 "getdate.y"\r
603 +#line 515 "lib/getdate.y"\r
604      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }\r
605      break;\r
606  \r
607    case 47:\r
608  \r
609  /* Line 1455 of yacc.c  */\r
610 -#line 518 "getdate.y"\r
611 +#line 517 "lib/getdate.y"\r
612      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }\r
613      break;\r
614  \r
615    case 48:\r
616  \r
617  /* Line 1455 of yacc.c  */\r
618 -#line 520 "getdate.y"\r
619 +#line 519 "lib/getdate.y"\r
620      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }\r
621      break;\r
622  \r
623    case 49:\r
624  \r
625  /* Line 1455 of yacc.c  */\r
626 -#line 522 "getdate.y"\r
627 +#line 521 "lib/getdate.y"\r
628      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }\r
629      break;\r
630  \r
631    case 50:\r
632  \r
633  /* Line 1455 of yacc.c  */\r
634 -#line 524 "getdate.y"\r
635 +#line 523 "lib/getdate.y"\r
636      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }\r
637      break;\r
638  \r
639    case 51:\r
640  \r
641  /* Line 1455 of yacc.c  */\r
642 -#line 526 "getdate.y"\r
643 +#line 525 "lib/getdate.y"\r
644      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }\r
645      break;\r
646  \r
647    case 52:\r
648  \r
649  /* Line 1455 of yacc.c  */\r
650 -#line 528 "getdate.y"\r
651 +#line 527 "lib/getdate.y"\r
652      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }\r
653      break;\r
654  \r
655    case 53:\r
656  \r
657  /* Line 1455 of yacc.c  */\r
658 -#line 530 "getdate.y"\r
659 +#line 529 "lib/getdate.y"\r
660      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }\r
661      break;\r
662  \r
663    case 54:\r
664  \r
665  /* Line 1455 of yacc.c  */\r
666 -#line 532 "getdate.y"\r
667 +#line 531 "lib/getdate.y"\r
668      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }\r
669      break;\r
670  \r
671    case 55:\r
672  \r
673  /* Line 1455 of yacc.c  */\r
674 -#line 534 "getdate.y"\r
675 +#line 533 "lib/getdate.y"\r
676      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }\r
677      break;\r
678  \r
679    case 56:\r
680  \r
681  /* Line 1455 of yacc.c  */\r
682 -#line 536 "getdate.y"\r
683 +#line 535 "lib/getdate.y"\r
684      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }\r
685      break;\r
686  \r
687    case 57:\r
688  \r
689  /* Line 1455 of yacc.c  */\r
690 -#line 538 "getdate.y"\r
691 +#line 537 "lib/getdate.y"\r
692      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }\r
693      break;\r
694  \r
695    case 58:\r
696  \r
697  /* Line 1455 of yacc.c  */\r
698 -#line 540 "getdate.y"\r
699 +#line 539 "lib/getdate.y"\r
700      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }\r
701      break;\r
702  \r
703    case 59:\r
704  \r
705  /* Line 1455 of yacc.c  */\r
706 -#line 542 "getdate.y"\r
707 +#line 541 "lib/getdate.y"\r
708      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }\r
709      break;\r
710  \r
711    case 60:\r
712  \r
713  /* Line 1455 of yacc.c  */\r
714 -#line 544 "getdate.y"\r
715 +#line 543 "lib/getdate.y"\r
716      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }\r
717      break;\r
718  \r
719    case 61:\r
720  \r
721  /* Line 1455 of yacc.c  */\r
722 -#line 546 "getdate.y"\r
723 +#line 545 "lib/getdate.y"\r
724      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }\r
725      break;\r
726  \r
727    case 62:\r
728  \r
729  /* Line 1455 of yacc.c  */\r
730 -#line 548 "getdate.y"\r
731 +#line 547 "lib/getdate.y"\r
732      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }\r
733      break;\r
734  \r
735    case 64:\r
736  \r
737  /* Line 1455 of yacc.c  */\r
738 -#line 554 "getdate.y"\r
739 +#line 553 "lib/getdate.y"\r
740      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }\r
741      break;\r
742  \r
743    case 65:\r
744  \r
745  /* Line 1455 of yacc.c  */\r
746 -#line 556 "getdate.y"\r
747 +#line 555 "lib/getdate.y"\r
748      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }\r
749      break;\r
750  \r
751    case 66:\r
752  \r
753  /* Line 1455 of yacc.c  */\r
754 -#line 558 "getdate.y"\r
755 +#line 557 "lib/getdate.y"\r
756      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }\r
757      break;\r
758  \r
759    case 67:\r
760  \r
761  /* Line 1455 of yacc.c  */\r
762 -#line 560 "getdate.y"\r
763 +#line 559 "lib/getdate.y"\r
764      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }\r
765      break;\r
766  \r
767    case 68:\r
768  \r
769  /* Line 1455 of yacc.c  */\r
770 -#line 562 "getdate.y"\r
771 +#line 561 "lib/getdate.y"\r
772      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }\r
773      break;\r
774  \r
775    case 69:\r
776  \r
777  /* Line 1455 of yacc.c  */\r
778 -#line 564 "getdate.y"\r
779 +#line 563 "lib/getdate.y"\r
780      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }\r
781      break;\r
782  \r
783    case 70:\r
784  \r
785  /* Line 1455 of yacc.c  */\r
786 -#line 569 "getdate.y"\r
787 +#line 568 "lib/getdate.y"\r
788      { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }\r
789      break;\r
790  \r
791    case 74:\r
792  \r
793  /* Line 1455 of yacc.c  */\r
794 -#line 577 "getdate.y"\r
795 +#line 576 "lib/getdate.y"\r
796      { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }\r
797      break;\r
798  \r
799    case 76:\r
800  \r
801  /* Line 1455 of yacc.c  */\r
802 -#line 583 "getdate.y"\r
803 +#line 582 "lib/getdate.y"\r
804      { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }\r
805      break;\r
806  \r
807    case 77:\r
808  \r
809  /* Line 1455 of yacc.c  */\r
810 -#line 588 "getdate.y"\r
811 +#line 587 "lib/getdate.y"\r
812      { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }\r
813      break;\r
814  \r
815    case 78:\r
816  \r
817  /* Line 1455 of yacc.c  */\r
818 -#line 593 "getdate.y"\r
819 +#line 592 "lib/getdate.y"\r
820      {\r
821          /* Hybrid all-digit and relative offset, so that we accept e.g.,\r
822             "YYYYMMDD +N days" as well as "YYYYMMDD N days".  */\r
823 @@ -2295,35 +2294,35 @@ yyreduce:\r
824    case 79:\r
825  \r
826  /* Line 1455 of yacc.c  */\r
827 -#line 603 "getdate.y"\r
828 +#line 602 "lib/getdate.y"\r
829      { (yyval.intval) = -1; }\r
830      break;\r
831  \r
832    case 80:\r
833  \r
834  /* Line 1455 of yacc.c  */\r
835 -#line 605 "getdate.y"\r
836 +#line 604 "lib/getdate.y"\r
837      { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }\r
838      break;\r
839  \r
840    case 81:\r
841  \r
842  /* Line 1455 of yacc.c  */\r
843 -#line 610 "getdate.y"\r
844 +#line 609 "lib/getdate.y"\r
845      { (yyval.intval) = MER24; }\r
846      break;\r
847  \r
848    case 82:\r
849  \r
850  /* Line 1455 of yacc.c  */\r
851 -#line 612 "getdate.y"\r
852 +#line 611 "lib/getdate.y"\r
853      { (yyval.intval) = (yyvsp[(1) - (1)].intval); }\r
854      break;\r
855  \r
856  \r
857  \r
858  /* Line 1455 of yacc.c  */\r
859 -#line 2327 "getdate.c"\r
860 +#line 2326 "lib/getdate.c"\r
861        default: break;\r
862      }\r
863    YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);\r
864 @@ -2535,7 +2534,7 @@ yyreturn:\r
865  \r
866  \r
867  /* Line 1675 of yacc.c  */\r
868 -#line 615 "getdate.y"\r
869 +#line 614 "lib/getdate.y"\r
870  \r
871  \r
872  static table const meridian_table[] =\r
873 @@ -3104,6 +3103,16 @@ mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)\r
874     Use heap allocation if TZ's length exceeds this.  */\r
875  enum { TZBUFSIZE = 100 };\r
876  \r
877 +/* Clone an object P of size S, with error checking.  There's no need\r
878 +   for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any\r
879 +   need for an arithmetic overflow check.  */\r
880 +\r
881 +static void *\r
882 +xmemdup (void const *p, size_t s)\r
883 +{\r
884 +  return memcpy (xmalloc (s), p, s);\r
885 +}\r
886 +\r
887  /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated\r
888     otherwise.  */\r
889  static char *\r
890 diff --git a/lib/getdate.h b/lib/getdate.h\r
891 index 22cc2c0..ad1283c 100644\r
892 --- a/lib/getdate.h\r
893 +++ b/lib/getdate.h\r
894 @@ -19,4 +19,13 @@\r
895  #include <stdbool.h>\r
896  #include <time.h>\r
897  \r
898 +#ifdef __cplusplus\r
899 +extern "C" {\r
900 +#endif\r
901 +\r
902  bool get_date (struct timespec *, char const *, struct timespec const *);\r
903 +\r
904 +#ifdef __cplusplus\r
905 +}\r
906 +#endif\r
907 +\r
908 diff --git a/lib/getdate.y b/lib/getdate.y\r
909 index 445865b..d423f5b 100644\r
910 --- a/lib/getdate.y\r
911 +++ b/lib/getdate.y\r
912 @@ -31,6 +31,8 @@\r
913  /* FIXME: Check for arithmetic overflow in all cases, not just\r
914     some of them.  */\r
915  \r
916 +#include "notmuch-private.h"   /* For xmalloc() */\r
917 +\r
918  #include <config.h>\r
919  \r
920  #include "getdate.h"\r
921 @@ -66,9 +68,6 @@\r
922  #include <stdlib.h>\r
923  #include <string.h>\r
924  \r
925 -#include "xalloc.h"\r
926 -\r
927 -\r
928  /* ISDIGIT differs from isdigit, as follows:\r
929     - Its arg may be any int or unsigned int; it need not be an unsigned char\r
930       or EOF.\r
931 @@ -1180,6 +1179,16 @@ mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)\r
932     Use heap allocation if TZ's length exceeds this.  */\r
933  enum { TZBUFSIZE = 100 };\r
934  \r
935 +/* Clone an object P of size S, with error checking.  There's no need\r
936 +   for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any\r
937 +   need for an arithmetic overflow check.  */\r
938 +\r
939 +static void *\r
940 +xmemdup (void const *p, size_t s)\r
941 +{\r
942 +  return memcpy (xmalloc (s), p, s);\r
943 +}\r
944 +\r
945  /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated\r
946     otherwise.  */\r
947  static char *\r
948 -- \r
949 1.7.1\r
950 \r