s3:modules: Fix size type in getdate
[samba.git] / source3 / modules / getdate.c
1 /* A Bison parser, made by GNU Bison 2.3.  */
2
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6    Free Software Foundation, Inc.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2, or (at your option)
11    any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22
23 /* As a special exception, you may create a larger work that contains
24    part or all of the Bison parser skeleton and distribute that work
25    under terms of your choice, so long as that work isn't itself a
26    parser generator using the skeleton or a modified version thereof
27    as a parser skeleton.  Alternatively, if you modify or redistribute
28    the parser skeleton itself, you may (at your option) remove this
29    special exception, which will cause the skeleton and the resulting
30    Bison output files to be licensed under the GNU General Public
31    License without this special exception.
32
33    This special exception was added by the Free Software Foundation in
34    version 2.2 of Bison.  */
35
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37    simplifying the original so-called "semantic" parser.  */
38
39 /* All symbols defined below should begin with yy or YY, to avoid
40    infringing on user name space.  This should be done even for local
41    variables, as they might otherwise be expanded by user macros.
42    There are some unavoidable exceptions within include files to
43    define necessary library symbols; they are noted "INFRINGES ON
44    USER NAME SPACE" below.  */
45
46 /* Identify Bison output.  */
47 #define YYBISON 1
48
49 /* Bison version.  */
50 #define YYBISON_VERSION "2.3"
51
52 /* Skeleton name.  */
53 #define YYSKELETON_NAME "yacc.c"
54
55 /* Pure parsers.  */
56 #define YYPURE 1
57
58 /* Using locations.  */
59 #define YYLSP_NEEDED 0
60
61
62
63 /* Tokens.  */
64 #ifndef YYTOKENTYPE
65 # define YYTOKENTYPE
66    /* Put the tokens into the symbol table, so that GDB and other debuggers
67       know about them.  */
68    enum yytokentype {
69      tAGO = 258,
70      tDST = 259,
71      tDAY = 260,
72      tDAY_UNIT = 261,
73      tDAYZONE = 262,
74      tHOUR_UNIT = 263,
75      tLOCAL_ZONE = 264,
76      tMERIDIAN = 265,
77      tMINUTE_UNIT = 266,
78      tMONTH = 267,
79      tMONTH_UNIT = 268,
80      tSEC_UNIT = 269,
81      tYEAR_UNIT = 270,
82      tZONE = 271,
83      tSNUMBER = 272,
84      tUNUMBER = 273
85    };
86 #endif
87 /* Tokens.  */
88 #define tAGO 258
89 #define tDST 259
90 #define tDAY 260
91 #define tDAY_UNIT 261
92 #define tDAYZONE 262
93 #define tHOUR_UNIT 263
94 #define tLOCAL_ZONE 264
95 #define tMERIDIAN 265
96 #define tMINUTE_UNIT 266
97 #define tMONTH 267
98 #define tMONTH_UNIT 268
99 #define tSEC_UNIT 269
100 #define tYEAR_UNIT 270
101 #define tZONE 271
102 #define tSNUMBER 272
103 #define tUNUMBER 273
104
105
106
107
108 /* Copy the first part of user declarations.  */
109 #line 1 "getdate.y"
110
111 /* Parse a string into an internal time stamp.
112    Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
113
114    This program is free software; you can redistribute it and/or modify
115    it under the terms of the GNU General Public License as published by
116    the Free Software Foundation; either version 2, or (at your option)
117    any later version.
118
119    This program is distributed in the hope that it will be useful,
120    but WITHOUT ANY WARRANTY; without even the implied warranty of
121    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
122    GNU General Public License for more details.
123
124    You should have received a copy of the GNU General Public License
125    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
126
127 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
128    at the University of North Carolina at Chapel Hill.  Later tweaked by
129    a couple of people on Usenet.  Completely overhauled by Rich $alz
130    <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
131
132    Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
133    the right thing about local DST.  Unlike previous versions, this
134    version is reentrant.  */
135
136 #ifdef HAVE_CONFIG_H
137 # include <config.h>
138 # ifdef HAVE_ALLOCA_H
139 #  include <alloca.h>
140 # endif
141 #endif
142
143 /* Since the code of getdate.y is not included in the Emacs executable
144    itself, there is no need to #define static in this file.  Even if
145    the code were included in the Emacs executable, it probably
146    wouldn't do any harm to #undef it here; this will only cause
147    problems if we try to write to a static variable, which I don't
148    think this code needs to do.  */
149 #ifdef emacs
150 # undef static
151 #endif
152
153 #include <ctype.h>
154 #include <string.h>
155
156 #if HAVE_STDLIB_H
157 # include <stdlib.h> /* for `free'; used by Bison 1.27 */
158 #endif
159
160 #if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
161 # define IN_CTYPE_DOMAIN(c) 1
162 #else
163 # define IN_CTYPE_DOMAIN(c) isascii (c)
164 #endif
165
166 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
167 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
168 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
169 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
170
171 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
172    - Its arg may be any int or unsigned int; it need not be an unsigned char.
173    - It's guaranteed to evaluate its argument exactly once.
174    - It's typically faster.
175    POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
176    ISDIGIT_LOCALE unless it's important to use the locale's definition
177    of `digit' even when the host does not conform to POSIX.  */
178 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
179
180 #if STDC_HEADERS || HAVE_STRING_H
181 # include <string.h>
182 #endif
183
184 #ifndef HAVE___ATTRIBUTE__
185 # define __attribute__(x)
186 #endif
187
188 #ifndef ATTRIBUTE_UNUSED
189 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
190 #endif
191
192 #define EPOCH_YEAR 1970
193 #define TM_YEAR_BASE 1900
194
195 #define HOUR(x) ((x) * 60)
196
197 /* An integer value, and the number of digits in its textual
198    representation.  */
199 typedef struct
200 {
201   int value;
202   int digits;
203 } textint;
204
205 /* An entry in the lexical lookup table.  */
206 typedef struct
207 {
208   char const *name;
209   int type;
210   int value;
211 } table;
212
213 /* Meridian: am, pm, or 24-hour style.  */
214 enum { MERam, MERpm, MER24 };
215
216 /* Information passed to and from the parser.  */
217 typedef struct
218 {
219   /* The input string remaining to be parsed. */
220   const char *input;
221
222   /* N, if this is the Nth Tuesday.  */
223   int day_ordinal;
224
225   /* Day of week; Sunday is 0.  */
226   int day_number;
227
228   /* tm_isdst flag for the local zone.  */
229   int local_isdst;
230
231   /* Time zone, in minutes east of UTC.  */
232   int time_zone;
233
234   /* Style used for time.  */
235   int meridian;
236
237   /* Gregorian year, month, day, hour, minutes, and seconds.  */
238   textint year;
239   int month;
240   int day;
241   int hour;
242   int minutes;
243   int seconds;
244
245   /* Relative year, month, day, hour, minutes, and seconds.  */
246   int rel_year;
247   int rel_month;
248   int rel_day;
249   int rel_hour;
250   int rel_minutes;
251   int rel_seconds;
252
253   /* Counts of nonterminals of various flavors parsed so far.  */
254   int dates_seen;
255   int days_seen;
256   int local_zones_seen;
257   int rels_seen;
258   int times_seen;
259   int zones_seen;
260
261   /* Table of local time zone abbrevations, terminated by a null entry.  */
262   table local_time_zone_table[3];
263 } parser_control;
264
265 #define PC (* (parser_control *) parm)
266 #define YYLEX_PARAM parm
267 #define YYPARSE_PARAM parm
268
269
270
271 /* Enabling traces.  */
272 #ifndef YYDEBUG
273 # define YYDEBUG 0
274 #endif
275
276 /* Enabling verbose error messages.  */
277 #ifdef YYERROR_VERBOSE
278 # undef YYERROR_VERBOSE
279 # define YYERROR_VERBOSE 1
280 #else
281 # define YYERROR_VERBOSE 0
282 #endif
283
284 /* Enabling the token table.  */
285 #ifndef YYTOKEN_TABLE
286 # define YYTOKEN_TABLE 0
287 #endif
288
289 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
290 typedef union YYSTYPE
291 #line 169 "getdate.y"
292 {
293   int intval;
294   textint textintval;
295 }
296 /* Line 187 of yacc.c.  */
297 #line 298 "getdate.c"
298         YYSTYPE;
299 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
300 # define YYSTYPE_IS_DECLARED 1
301 # define YYSTYPE_IS_TRIVIAL 1
302 #endif
303
304
305
306 /* Copy the second part of user declarations.  */
307 #line 174 "getdate.y"
308
309
310 static int yyerror(const char *);
311 static int yylex(YYSTYPE *, parser_control *);
312
313
314
315 /* Line 216 of yacc.c.  */
316 #line 317 "getdate.c"
317
318 #ifdef short
319 # undef short
320 #endif
321
322 #ifdef YYTYPE_UINT8
323 typedef YYTYPE_UINT8 yytype_uint8;
324 #else
325 typedef unsigned char yytype_uint8;
326 #endif
327
328 #ifdef YYTYPE_INT8
329 typedef YYTYPE_INT8 yytype_int8;
330 #elif (defined __STDC__ || defined __C99__FUNC__ \
331      || defined __cplusplus || defined _MSC_VER)
332 typedef signed char yytype_int8;
333 #else
334 typedef short int yytype_int8;
335 #endif
336
337 #ifdef YYTYPE_UINT16
338 typedef YYTYPE_UINT16 yytype_uint16;
339 #else
340 typedef unsigned short int yytype_uint16;
341 #endif
342
343 #ifdef YYTYPE_INT16
344 typedef YYTYPE_INT16 yytype_int16;
345 #else
346 typedef short int yytype_int16;
347 #endif
348
349 #ifndef YYSIZE_T
350 # ifdef __SIZE_TYPE__
351 #  define YYSIZE_T __SIZE_TYPE__
352 # elif defined size_t
353 #  define YYSIZE_T size_t
354 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
355      || defined __cplusplus || defined _MSC_VER)
356 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
357 #  define YYSIZE_T size_t
358 # else
359 #  define YYSIZE_T unsigned int
360 # endif
361 #endif
362
363 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
364
365 #ifndef YY_
366 # if YYENABLE_NLS
367 #  if ENABLE_NLS
368 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
369 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
370 #  endif
371 # endif
372 # ifndef YY_
373 #  define YY_(msgid) msgid
374 # endif
375 #endif
376
377 /* Suppress unused-variable warnings by "using" E.  */
378 #if ! defined lint || defined __GNUC__
379 # define YYUSE(e) ((void) (e))
380 #else
381 # define YYUSE(e) /* empty */
382 #endif
383
384 /* Identity function, used to suppress warnings about constant conditions.  */
385 #ifndef lint
386 # define YYID(n) (n)
387 #else
388 #if (defined __STDC__ || defined __C99__FUNC__ \
389      || defined __cplusplus || defined _MSC_VER)
390 static int
391 YYID (int i)
392 #else
393 static int
394 YYID (i)
395     int i;
396 #endif
397 {
398   return i;
399 }
400 #endif
401
402 #if ! defined yyoverflow || YYERROR_VERBOSE
403
404 /* The parser invokes alloca or malloc; define the necessary symbols.  */
405
406 # ifdef YYSTACK_USE_ALLOCA
407 #  if YYSTACK_USE_ALLOCA
408 #   ifdef __GNUC__
409 #    define YYSTACK_ALLOC __builtin_alloca
410 #   elif defined __BUILTIN_VA_ARG_INCR
411 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
412 #   elif defined _AIX
413 #    define YYSTACK_ALLOC __alloca
414 #   elif defined _MSC_VER
415 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
416 #    define alloca _alloca
417 #   else
418 #    define YYSTACK_ALLOC alloca
419 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
420      || defined __cplusplus || defined _MSC_VER)
421 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
422 #     ifndef _STDLIB_H
423 #      define _STDLIB_H 1
424 #     endif
425 #    endif
426 #   endif
427 #  endif
428 # endif
429
430 # ifdef YYSTACK_ALLOC
431    /* Pacify GCC's `empty if-body' warning.  */
432 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
433 #  ifndef YYSTACK_ALLOC_MAXIMUM
434     /* The OS might guarantee only one guard page at the bottom of the stack,
435        and a page size can be as small as 4096 bytes.  So we cannot safely
436        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
437        to allow for a few compiler-allocated temporary stack slots.  */
438 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
439 #  endif
440 # else
441 #  define YYSTACK_ALLOC YYMALLOC
442 #  define YYSTACK_FREE YYFREE
443 #  ifndef YYSTACK_ALLOC_MAXIMUM
444 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
445 #  endif
446 #  if (defined __cplusplus && ! defined _STDLIB_H \
447        && ! ((defined YYMALLOC || defined malloc) \
448              && (defined YYFREE || defined free)))
449 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
450 #   ifndef _STDLIB_H
451 #    define _STDLIB_H 1
452 #   endif
453 #  endif
454 #  ifndef YYMALLOC
455 #   define YYMALLOC malloc
456 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
457      || defined __cplusplus || defined _MSC_VER)
458 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
459 #   endif
460 #  endif
461 #  ifndef YYFREE
462 #   define YYFREE free
463 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
464      || defined __cplusplus || defined _MSC_VER)
465 void free (void *); /* INFRINGES ON USER NAME SPACE */
466 #   endif
467 #  endif
468 # endif
469 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
470
471
472 #if (! defined yyoverflow \
473      && (! defined __cplusplus \
474          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
475
476 /* A type that is properly aligned for any stack member.  */
477 union yyalloc
478 {
479   yytype_int16 yyss;
480   YYSTYPE yyvs;
481   };
482
483 /* The size of the maximum gap between one aligned stack and the next.  */
484 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
485
486 /* The size of an array large to enough to hold all stacks, each with
487    N elements.  */
488 # define YYSTACK_BYTES(N) \
489      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
490       + YYSTACK_GAP_MAXIMUM)
491
492 /* Copy COUNT objects from FROM to TO.  The source and destination do
493    not overlap.  */
494 # ifndef YYCOPY
495 #  if defined __GNUC__ && 1 < __GNUC__
496 #   define YYCOPY(To, From, Count) \
497       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
498 #  else
499 #   define YYCOPY(To, From, Count)              \
500       do                                        \
501         {                                       \
502           YYSIZE_T yyi;                         \
503           for (yyi = 0; yyi < (Count); yyi++)   \
504             (To)[yyi] = (From)[yyi];            \
505         }                                       \
506       while (YYID (0))
507 #  endif
508 # endif
509
510 /* Relocate STACK from its old location to the new one.  The
511    local variables YYSIZE and YYSTACKSIZE give the old and new number of
512    elements in the stack, and YYPTR gives the new location of the
513    stack.  Advance YYPTR to a properly aligned location for the next
514    stack.  */
515 # define YYSTACK_RELOCATE(Stack)                                        \
516     do                                                                  \
517       {                                                                 \
518         YYSIZE_T yynewbytes;                                            \
519         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
520         Stack = &yyptr->Stack;                                          \
521         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
522         yyptr += yynewbytes / sizeof (*yyptr);                          \
523       }                                                                 \
524     while (YYID (0))
525
526 #endif
527
528 /* YYFINAL -- State number of the termination state.  */
529 #define YYFINAL  2
530 /* YYLAST -- Last index in YYTABLE.  */
531 #define YYLAST   52
532
533 /* YYNTOKENS -- Number of terminals.  */
534 #define YYNTOKENS  22
535 /* YYNNTS -- Number of nonterminals.  */
536 #define YYNNTS  12
537 /* YYNRULES -- Number of rules.  */
538 #define YYNRULES  54
539 /* YYNRULES -- Number of states.  */
540 #define YYNSTATES  64
541
542 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
543 #define YYUNDEFTOK  2
544 #define YYMAXUTOK   273
545
546 #define YYTRANSLATE(YYX)                                                \
547   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
548
549 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
550 static const yytype_uint8 yytranslate[] =
551 {
552        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
553        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
554        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
555        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
556        2,     2,     2,     2,    20,     2,     2,    21,     2,     2,
557        2,     2,     2,     2,     2,     2,     2,     2,    19,     2,
558        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
559        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
560        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
561        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
562        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
563        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
564        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
565        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
566        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
567        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
568        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
569        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
570        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
571        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
572        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
573        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
574        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
575        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
576        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
577        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
578        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
579       15,    16,    17,    18
580 };
581
582 #if YYDEBUG
583 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
584    YYRHS.  */
585 static const yytype_uint8 yyprhs[] =
586 {
587        0,     0,     3,     4,     7,     9,    11,    13,    15,    17,
588       19,    21,    24,    29,    34,    41,    48,    50,    53,    55,
589       57,    60,    62,    65,    68,    72,    78,    82,    86,    89,
590       94,    97,   101,   104,   106,   109,   112,   114,   117,   120,
591      122,   125,   128,   130,   133,   136,   138,   141,   144,   146,
592      149,   152,   154,   156,   157
593 };
594
595 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
596 static const yytype_int8 yyrhs[] =
597 {
598       23,     0,    -1,    -1,    23,    24,    -1,    25,    -1,    26,
599       -1,    27,    -1,    29,    -1,    28,    -1,    30,    -1,    32,
600       -1,    18,    10,    -1,    18,    19,    18,    33,    -1,    18,
601       19,    18,    17,    -1,    18,    19,    18,    19,    18,    33,
602       -1,    18,    19,    18,    19,    18,    17,    -1,     9,    -1,
603        9,     4,    -1,    16,    -1,     7,    -1,    16,     4,    -1,
604        5,    -1,     5,    20,    -1,    18,     5,    -1,    18,    21,
605       18,    -1,    18,    21,    18,    21,    18,    -1,    18,    17,
606       17,    -1,    18,    12,    17,    -1,    12,    18,    -1,    12,
607       18,    20,    18,    -1,    18,    12,    -1,    18,    12,    18,
608       -1,    31,     3,    -1,    31,    -1,    18,    15,    -1,    17,
609       15,    -1,    15,    -1,    18,    13,    -1,    17,    13,    -1,
610       13,    -1,    18,     6,    -1,    17,     6,    -1,     6,    -1,
611       18,     8,    -1,    17,     8,    -1,     8,    -1,    18,    11,
612       -1,    17,    11,    -1,    11,    -1,    18,    14,    -1,    17,
613       14,    -1,    14,    -1,    18,    -1,    -1,    10,    -1
614 };
615
616 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
617 static const yytype_uint16 yyrline[] =
618 {
619        0,   192,   192,   194,   198,   200,   202,   204,   206,   208,
620      210,   214,   221,   228,   236,   243,   255,   257,   262,   264,
621      266,   271,   276,   281,   289,   294,   314,   321,   329,   334,
622      340,   345,   354,   363,   367,   369,   371,   373,   375,   377,
623      379,   381,   383,   385,   387,   389,   391,   393,   395,   397,
624      399,   401,   406,   443,   444
625 };
626 #endif
627
628 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
629 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
630    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
631 static const char *const yytname[] =
632 {
633   "$end", "error", "$undefined", "tAGO", "tDST", "tDAY", "tDAY_UNIT",
634   "tDAYZONE", "tHOUR_UNIT", "tLOCAL_ZONE", "tMERIDIAN", "tMINUTE_UNIT",
635   "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tYEAR_UNIT", "tZONE", "tSNUMBER",
636   "tUNUMBER", "':'", "','", "'/'", "$accept", "spec", "item", "time",
637   "local_zone", "zone", "day", "date", "rel", "relunit", "number",
638   "o_merid", 0
639 };
640 #endif
641
642 # ifdef YYPRINT
643 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
644    token YYLEX-NUM.  */
645 static const yytype_uint16 yytoknum[] =
646 {
647        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
648      265,   266,   267,   268,   269,   270,   271,   272,   273,    58,
649       44,    47
650 };
651 # endif
652
653 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
654 static const yytype_uint8 yyr1[] =
655 {
656        0,    22,    23,    23,    24,    24,    24,    24,    24,    24,
657       24,    25,    25,    25,    25,    25,    26,    26,    27,    27,
658       27,    28,    28,    28,    29,    29,    29,    29,    29,    29,
659       29,    29,    30,    30,    31,    31,    31,    31,    31,    31,
660       31,    31,    31,    31,    31,    31,    31,    31,    31,    31,
661       31,    31,    32,    33,    33
662 };
663
664 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
665 static const yytype_uint8 yyr2[] =
666 {
667        0,     2,     0,     2,     1,     1,     1,     1,     1,     1,
668        1,     2,     4,     4,     6,     6,     1,     2,     1,     1,
669        2,     1,     2,     2,     3,     5,     3,     3,     2,     4,
670        2,     3,     2,     1,     2,     2,     1,     2,     2,     1,
671        2,     2,     1,     2,     2,     1,     2,     2,     1,     2,
672        2,     1,     1,     0,     1
673 };
674
675 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
676    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
677    means the default is an error.  */
678 static const yytype_uint8 yydefact[] =
679 {
680        2,     0,     1,    21,    42,    19,    45,    16,    48,     0,
681       39,    51,    36,    18,     0,    52,     3,     4,     5,     6,
682        8,     7,     9,    33,    10,    22,    17,    28,    20,    41,
683       44,    47,    38,    50,    35,    23,    40,    43,    11,    46,
684       30,    37,    49,    34,     0,     0,     0,    32,     0,    27,
685       31,    26,    53,    24,    29,    54,    13,     0,    12,     0,
686       53,    25,    15,    14
687 };
688
689 /* YYDEFGOTO[NTERM-NUM].  */
690 static const yytype_int8 yydefgoto[] =
691 {
692       -1,     1,    16,    17,    18,    19,    20,    21,    22,    23,
693       24,    58
694 };
695
696 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
697    STATE-NUM.  */
698 #define YYPACT_NINF -17
699 static const yytype_int8 yypact[] =
700 {
701      -17,     0,   -17,     1,   -17,   -17,   -17,    19,   -17,   -14,
702      -17,   -17,   -17,    32,    26,    14,   -17,   -17,   -17,   -17,
703      -17,   -17,   -17,    27,   -17,   -17,   -17,    22,   -17,   -17,
704      -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,
705      -16,   -17,   -17,   -17,    29,    25,    30,   -17,    31,   -17,
706      -17,   -17,    28,    23,   -17,   -17,   -17,    33,   -17,    34,
707       -7,   -17,   -17,   -17
708 };
709
710 /* YYPGOTO[NTERM-NUM].  */
711 static const yytype_int8 yypgoto[] =
712 {
713      -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,
714      -17,   -10
715 };
716
717 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
718    positive, shift that token.  If negative, reduce the rule which
719    number is the opposite.  If zero, do what YYDEFACT says.
720    If YYTABLE_NINF, syntax error.  */
721 #define YYTABLE_NINF -1
722 static const yytype_uint8 yytable[] =
723 {
724        2,    49,    50,    55,    27,     3,     4,     5,     6,     7,
725       62,     8,     9,    10,    11,    12,    13,    14,    15,    35,
726       36,    25,    37,    26,    38,    39,    40,    41,    42,    43,
727       47,    44,    29,    45,    30,    46,    28,    31,    55,    32,
728       33,    34,    48,    52,    59,    56,    51,    57,    53,    54,
729       63,    60,    61
730 };
731
732 static const yytype_uint8 yycheck[] =
733 {
734        0,    17,    18,    10,    18,     5,     6,     7,     8,     9,
735       17,    11,    12,    13,    14,    15,    16,    17,    18,     5,
736        6,    20,     8,     4,    10,    11,    12,    13,    14,    15,
737        3,    17,     6,    19,     8,    21,     4,    11,    10,    13,
738       14,    15,    20,    18,    21,    17,    17,    19,    18,    18,
739       60,    18,    18
740 };
741
742 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
743    symbol of state STATE-NUM.  */
744 static const yytype_uint8 yystos[] =
745 {
746        0,    23,     0,     5,     6,     7,     8,     9,    11,    12,
747       13,    14,    15,    16,    17,    18,    24,    25,    26,    27,
748       28,    29,    30,    31,    32,    20,     4,    18,     4,     6,
749        8,    11,    13,    14,    15,     5,     6,     8,    10,    11,
750       12,    13,    14,    15,    17,    19,    21,     3,    20,    17,
751       18,    17,    18,    18,    18,    10,    17,    19,    33,    21,
752       18,    18,    17,    33
753 };
754
755 #define yyerrok         (yyerrstatus = 0)
756 #define yyclearin       (yychar = YYEMPTY)
757 #define YYEMPTY         (-2)
758 #define YYEOF           0
759
760 #define YYACCEPT        goto yyacceptlab
761 #define YYABORT         goto yyabortlab
762 #define YYERROR         goto yyerrorlab
763
764
765 /* Like YYERROR except do call yyerror.  This remains here temporarily
766    to ease the transition to the new meaning of YYERROR, for GCC.
767    Once GCC version 2 has supplanted version 1, this can go.  */
768
769 #define YYFAIL          goto yyerrlab
770
771 #define YYRECOVERING()  (!!yyerrstatus)
772
773 #define YYBACKUP(Token, Value)                                  \
774 do                                                              \
775   if (yychar == YYEMPTY && yylen == 1)                          \
776     {                                                           \
777       yychar = (Token);                                         \
778       yylval = (Value);                                         \
779       yytoken = YYTRANSLATE (yychar);                           \
780       YYPOPSTACK (1);                                           \
781       goto yybackup;                                            \
782     }                                                           \
783   else                                                          \
784     {                                                           \
785       yyerror (YY_("syntax error: cannot back up")); \
786       YYERROR;                                                  \
787     }                                                           \
788 while (YYID (0))
789
790
791 #define YYTERROR        1
792 #define YYERRCODE       256
793
794
795 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
796    If N is 0, then set CURRENT to the empty location which ends
797    the previous symbol: RHS[0] (always defined).  */
798
799 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
800 #ifndef YYLLOC_DEFAULT
801 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
802     do                                                                  \
803       if (YYID (N))                                                    \
804         {                                                               \
805           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
806           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
807           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
808           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
809         }                                                               \
810       else                                                              \
811         {                                                               \
812           (Current).first_line   = (Current).last_line   =              \
813             YYRHSLOC (Rhs, 0).last_line;                                \
814           (Current).first_column = (Current).last_column =              \
815             YYRHSLOC (Rhs, 0).last_column;                              \
816         }                                                               \
817     while (YYID (0))
818 #endif
819
820
821 /* YY_LOCATION_PRINT -- Print the location on the stream.
822    This macro was not mandated originally: define only if we know
823    we won't break user code: when these are the locations we know.  */
824
825 #ifndef YY_LOCATION_PRINT
826 # if YYLTYPE_IS_TRIVIAL
827 #  define YY_LOCATION_PRINT(File, Loc)                  \
828      fprintf (File, "%d.%d-%d.%d",                      \
829               (Loc).first_line, (Loc).first_column,     \
830               (Loc).last_line,  (Loc).last_column)
831 # else
832 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
833 # endif
834 #endif
835
836
837 /* YYLEX -- calling `yylex' with the right arguments.  */
838
839 #ifdef YYLEX_PARAM
840 # define YYLEX yylex (&yylval, YYLEX_PARAM)
841 #else
842 # define YYLEX yylex (&yylval)
843 #endif
844
845 /* Enable debugging if requested.  */
846 #if YYDEBUG
847
848 # ifndef YYFPRINTF
849 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
850 #  define YYFPRINTF fprintf
851 # endif
852
853 # define YYDPRINTF(Args)                        \
854 do {                                            \
855   if (yydebug)                                  \
856     YYFPRINTF Args;                             \
857 } while (YYID (0))
858
859 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
860 do {                                                                      \
861   if (yydebug)                                                            \
862     {                                                                     \
863       YYFPRINTF (stderr, "%s ", Title);                                   \
864       yy_symbol_print (stderr,                                            \
865                   Type, Value); \
866       YYFPRINTF (stderr, "\n");                                           \
867     }                                                                     \
868 } while (YYID (0))
869
870
871 /*--------------------------------.
872 | Print this symbol on YYOUTPUT.  |
873 `--------------------------------*/
874
875 /*ARGSUSED*/
876 #if (defined __STDC__ || defined __C99__FUNC__ \
877      || defined __cplusplus || defined _MSC_VER)
878 static void
879 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
880 #else
881 static void
882 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
883     FILE *yyoutput;
884     int yytype;
885     YYSTYPE const * const yyvaluep;
886 #endif
887 {
888   if (!yyvaluep)
889     return;
890 # ifdef YYPRINT
891   if (yytype < YYNTOKENS)
892     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
893 # else
894   YYUSE (yyoutput);
895 # endif
896   switch (yytype)
897     {
898       default:
899         break;
900     }
901 }
902
903
904 /*--------------------------------.
905 | Print this symbol on YYOUTPUT.  |
906 `--------------------------------*/
907
908 #if (defined __STDC__ || defined __C99__FUNC__ \
909      || defined __cplusplus || defined _MSC_VER)
910 static void
911 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
912 #else
913 static void
914 yy_symbol_print (yyoutput, yytype, yyvaluep)
915     FILE *yyoutput;
916     int yytype;
917     YYSTYPE const * const yyvaluep;
918 #endif
919 {
920   if (yytype < YYNTOKENS)
921     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
922   else
923     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
924
925   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
926   YYFPRINTF (yyoutput, ")");
927 }
928
929 /*------------------------------------------------------------------.
930 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
931 | TOP (included).                                                   |
932 `------------------------------------------------------------------*/
933
934 #if (defined __STDC__ || defined __C99__FUNC__ \
935      || defined __cplusplus || defined _MSC_VER)
936 static void
937 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
938 #else
939 static void
940 yy_stack_print (bottom, top)
941     yytype_int16 *bottom;
942     yytype_int16 *top;
943 #endif
944 {
945   YYFPRINTF (stderr, "Stack now");
946   for (; bottom <= top; ++bottom)
947     YYFPRINTF (stderr, " %d", *bottom);
948   YYFPRINTF (stderr, "\n");
949 }
950
951 # define YY_STACK_PRINT(Bottom, Top)                            \
952 do {                                                            \
953   if (yydebug)                                                  \
954     yy_stack_print ((Bottom), (Top));                           \
955 } while (YYID (0))
956
957
958 /*------------------------------------------------.
959 | Report that the YYRULE is going to be reduced.  |
960 `------------------------------------------------*/
961
962 #if (defined __STDC__ || defined __C99__FUNC__ \
963      || defined __cplusplus || defined _MSC_VER)
964 static void
965 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
966 #else
967 static void
968 yy_reduce_print (yyvsp, yyrule)
969     YYSTYPE *yyvsp;
970     int yyrule;
971 #endif
972 {
973   int yynrhs = yyr2[yyrule];
974   int yyi;
975   unsigned long int yylno = yyrline[yyrule];
976   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
977              yyrule - 1, yylno);
978   /* The symbols being reduced.  */
979   for (yyi = 0; yyi < yynrhs; yyi++)
980     {
981       fprintf (stderr, "   $%d = ", yyi + 1);
982       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
983                        &(yyvsp[(yyi + 1) - (yynrhs)])
984                                        );
985       fprintf (stderr, "\n");
986     }
987 }
988
989 # define YY_REDUCE_PRINT(Rule)          \
990 do {                                    \
991   if (yydebug)                          \
992     yy_reduce_print (yyvsp, Rule); \
993 } while (YYID (0))
994
995 /* Nonzero means print parse trace.  It is left uninitialized so that
996    multiple parsers can coexist.  */
997 int yydebug;
998 #else /* !YYDEBUG */
999 # define YYDPRINTF(Args)
1000 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1001 # define YY_STACK_PRINT(Bottom, Top)
1002 # define YY_REDUCE_PRINT(Rule)
1003 #endif /* !YYDEBUG */
1004
1005
1006 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1007 #ifndef YYINITDEPTH
1008 # define YYINITDEPTH 200
1009 #endif
1010
1011 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1012    if the built-in stack extension method is used).
1013
1014    Do not make this value too large; the results are undefined if
1015    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1016    evaluated with infinite-precision integer arithmetic.  */
1017
1018 #ifndef YYMAXDEPTH
1019 # define YYMAXDEPTH 10000
1020 #endif
1021
1022 \f
1023
1024 #if YYERROR_VERBOSE
1025
1026 # ifndef yystrlen
1027 #  if defined __GLIBC__ && defined _STRING_H
1028 #   define yystrlen strlen
1029 #  else
1030 /* Return the length of YYSTR.  */
1031 #if (defined __STDC__ || defined __C99__FUNC__ \
1032      || defined __cplusplus || defined _MSC_VER)
1033 static YYSIZE_T
1034 yystrlen (const char *yystr)
1035 #else
1036 static YYSIZE_T
1037 yystrlen (yystr)
1038     const char *yystr;
1039 #endif
1040 {
1041   YYSIZE_T yylen;
1042   for (yylen = 0; yystr[yylen]; yylen++)
1043     continue;
1044   return yylen;
1045 }
1046 #  endif
1047 # endif
1048
1049 # ifndef yystpcpy
1050 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1051 #   define yystpcpy stpcpy
1052 #  else
1053 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1054    YYDEST.  */
1055 #if (defined __STDC__ || defined __C99__FUNC__ \
1056      || defined __cplusplus || defined _MSC_VER)
1057 static char *
1058 yystpcpy (char *yydest, const char *yysrc)
1059 #else
1060 static char *
1061 yystpcpy (yydest, yysrc)
1062     char *yydest;
1063     const char *yysrc;
1064 #endif
1065 {
1066   char *yyd = yydest;
1067   const char *yys = yysrc;
1068
1069   while ((*yyd++ = *yys++) != '\0')
1070     continue;
1071
1072   return yyd - 1;
1073 }
1074 #  endif
1075 # endif
1076
1077 # ifndef yytnamerr
1078 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1079    quotes and backslashes, so that it's suitable for yyerror.  The
1080    heuristic is that double-quoting is unnecessary unless the string
1081    contains an apostrophe, a comma, or backslash (other than
1082    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1083    null, do not copy; instead, return the length of what the result
1084    would have been.  */
1085 static YYSIZE_T
1086 yytnamerr (char *yyres, const char *yystr)
1087 {
1088   if (*yystr == '"')
1089     {
1090       YYSIZE_T yyn = 0;
1091       char const *yyp = yystr;
1092
1093       for (;;)
1094         switch (*++yyp)
1095           {
1096           case '\'':
1097           case ',':
1098             goto do_not_strip_quotes;
1099
1100           case '\\':
1101             if (*++yyp != '\\') {
1102               goto do_not_strip_quotes;
1103             }
1104             FALL_THROUGH;
1105           default:
1106             if (yyres)
1107               yyres[yyn] = *yyp;
1108             yyn++;
1109             break;
1110
1111           case '"':
1112             if (yyres)
1113               yyres[yyn] = '\0';
1114             return yyn;
1115           }
1116     do_not_strip_quotes: ;
1117     }
1118
1119   if (! yyres)
1120     return yystrlen (yystr);
1121
1122   return yystpcpy (yyres, yystr) - yyres;
1123 }
1124 # endif
1125
1126 /* Copy into YYRESULT an error message about the unexpected token
1127    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1128    including the terminating null byte.  If YYRESULT is null, do not
1129    copy anything; just return the number of bytes that would be
1130    copied.  As a special case, return 0 if an ordinary "syntax error"
1131    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1132    size calculation.  */
1133 static YYSIZE_T
1134 yysyntax_error (char *yyresult, int yystate, int yychar)
1135 {
1136   int yyn = yypact[yystate];
1137
1138   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1139     return 0;
1140   else
1141     {
1142       int yytype = YYTRANSLATE (yychar);
1143       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1144       YYSIZE_T yysize = yysize0;
1145       YYSIZE_T yysize1;
1146       int yysize_overflow = 0;
1147       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1148       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1149       int yyx;
1150
1151 # if 0
1152       /* This is so xgettext sees the translatable formats that are
1153          constructed on the fly.  */
1154       YY_("syntax error, unexpected %s");
1155       YY_("syntax error, unexpected %s, expecting %s");
1156       YY_("syntax error, unexpected %s, expecting %s or %s");
1157       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1158       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1159 # endif
1160       char *yyfmt;
1161       char const *yyf;
1162       static char const yyunexpected[] = "syntax error, unexpected %s";
1163       static char const yyexpecting[] = ", expecting %s";
1164       static char const yyor[] = " or %s";
1165       char yyformat[sizeof yyunexpected
1166                     + sizeof yyexpecting - 1
1167                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1168                        * (sizeof yyor - 1))];
1169       char const *yyprefix = yyexpecting;
1170
1171       /* Start YYX at -YYN if negative to avoid negative indexes in
1172          YYCHECK.  */
1173       int yyxbegin = yyn < 0 ? -yyn : 0;
1174
1175       /* Stay within bounds of both yycheck and yytname.  */
1176       int yychecklim = YYLAST - yyn + 1;
1177       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1178       int yycount = 1;
1179
1180       yyarg[0] = yytname[yytype];
1181       yyfmt = yystpcpy (yyformat, yyunexpected);
1182
1183       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1184         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1185           {
1186             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1187               {
1188                 yycount = 1;
1189                 yysize = yysize0;
1190                 yyformat[sizeof yyunexpected - 1] = '\0';
1191                 break;
1192               }
1193             yyarg[yycount++] = yytname[yyx];
1194             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1195             yysize_overflow |= (yysize1 < yysize);
1196             yysize = yysize1;
1197             yyfmt = yystpcpy (yyfmt, yyprefix);
1198             yyprefix = yyor;
1199           }
1200
1201       yyf = YY_(yyformat);
1202       yysize1 = yysize + yystrlen (yyf);
1203       yysize_overflow |= (yysize1 < yysize);
1204       yysize = yysize1;
1205
1206       if (yysize_overflow)
1207         return YYSIZE_MAXIMUM;
1208
1209       if (yyresult)
1210         {
1211           /* Avoid sprintf, as that infringes on the user's name space.
1212              Don't have undefined behavior even if the translation
1213              produced a string with the wrong number of "%s"s.  */
1214           char *yyp = yyresult;
1215           int yyi = 0;
1216           while ((*yyp = *yyf) != '\0')
1217             {
1218               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1219                 {
1220                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1221                   yyf += 2;
1222                 }
1223               else
1224                 {
1225                   yyp++;
1226                   yyf++;
1227                 }
1228             }
1229         }
1230       return yysize;
1231     }
1232 }
1233 #endif /* YYERROR_VERBOSE */
1234 \f
1235
1236 /*-----------------------------------------------.
1237 | Release the memory associated to this symbol.  |
1238 `-----------------------------------------------*/
1239
1240 /*ARGSUSED*/
1241 #if (defined __STDC__ || defined __C99__FUNC__ \
1242      || defined __cplusplus || defined _MSC_VER)
1243 static void
1244 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1245 #else
1246 static void
1247 yydestruct (yymsg, yytype, yyvaluep)
1248     const char *yymsg;
1249     int yytype;
1250     YYSTYPE *yyvaluep;
1251 #endif
1252 {
1253   YYUSE (yyvaluep);
1254
1255   if (!yymsg)
1256     yymsg = "Deleting";
1257   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1258
1259   switch (yytype)
1260     {
1261
1262       default:
1263         break;
1264     }
1265 }
1266 \f
1267
1268 /* Prevent warnings from -Wmissing-prototypes.  */
1269
1270 #ifdef YYPARSE_PARAM
1271 #if defined __STDC__ || defined __cplusplus
1272 int yyparse (void *YYPARSE_PARAM);
1273 #else
1274 int yyparse ();
1275 #endif
1276 #else /* ! YYPARSE_PARAM */
1277 #if defined __STDC__ || defined __cplusplus
1278 int yyparse (void);
1279 #else
1280 int yyparse ();
1281 #endif
1282 #endif /* ! YYPARSE_PARAM */
1283
1284
1285
1286
1287
1288
1289 /*----------.
1290 | yyparse.  |
1291 `----------*/
1292
1293 #ifdef YYPARSE_PARAM
1294 #if (defined __STDC__ || defined __C99__FUNC__ \
1295      || defined __cplusplus || defined _MSC_VER)
1296 int
1297 yyparse (void *YYPARSE_PARAM)
1298 #else
1299 int
1300 yyparse (YYPARSE_PARAM)
1301     void *YYPARSE_PARAM;
1302 #endif
1303 #else /* ! YYPARSE_PARAM */
1304 #if (defined __STDC__ || defined __C99__FUNC__ \
1305      || defined __cplusplus || defined _MSC_VER)
1306 int
1307 yyparse (void)
1308 #else
1309 int
1310 yyparse ()
1311
1312 #endif
1313 #endif
1314 {
1315   /* The look-ahead symbol.  */
1316 int yychar;
1317
1318 /* The semantic value of the look-ahead symbol.  */
1319 YYSTYPE yylval;
1320
1321 /* Number of syntax errors so far.  */
1322 int yynerrs;
1323
1324   int yystate;
1325   int yyn;
1326   int yyresult;
1327   /* Number of tokens to shift before error messages enabled.  */
1328   int yyerrstatus;
1329   /* Look-ahead token as an internal (translated) token number.  */
1330   int yytoken = 0;
1331 #if YYERROR_VERBOSE
1332   /* Buffer for error messages, and its allocated size.  */
1333   char yymsgbuf[128];
1334   char *yymsg = yymsgbuf;
1335   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1336 #endif
1337
1338   /* Three stacks and their tools:
1339      `yyss': related to states,
1340      `yyvs': related to semantic values,
1341      `yyls': related to locations.
1342
1343      Refer to the stacks thru separate pointers, to allow yyoverflow
1344      to reallocate them elsewhere.  */
1345
1346   /* The state stack.  */
1347   yytype_int16 yyssa[YYINITDEPTH];
1348   yytype_int16 *yyss = yyssa;
1349   yytype_int16 *yyssp;
1350
1351   /* The semantic value stack.  */
1352   YYSTYPE yyvsa[YYINITDEPTH];
1353   YYSTYPE *yyvs = yyvsa;
1354   YYSTYPE *yyvsp;
1355
1356
1357
1358 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1359
1360   YYSIZE_T yystacksize = YYINITDEPTH;
1361
1362   /* The variables used to return semantic value and location from the
1363      action routines.  */
1364   YYSTYPE yyval;
1365
1366
1367   /* The number of symbols on the RHS of the reduced rule.
1368      Keep to zero when no symbol should be popped.  */
1369   int yylen = 0;
1370
1371   YYDPRINTF ((stderr, "Starting parse\n"));
1372
1373   yystate = 0;
1374   yyerrstatus = 0;
1375   yynerrs = 0;
1376   yychar = YYEMPTY;             /* Cause a token to be read.  */
1377
1378   /* Initialize stack pointers.
1379      Waste one element of value and location stack
1380      so that they stay on the same level as the state stack.
1381      The wasted elements are never initialized.  */
1382
1383   yyssp = yyss;
1384   yyvsp = yyvs;
1385
1386   goto yysetstate;
1387
1388 /*------------------------------------------------------------.
1389 | yynewstate -- Push a new state, which is found in yystate.  |
1390 `------------------------------------------------------------*/
1391  yynewstate:
1392   /* In all cases, when you get here, the value and location stacks
1393      have just been pushed.  So pushing a state here evens the stacks.  */
1394   yyssp++;
1395
1396  yysetstate:
1397   *yyssp = yystate;
1398
1399   if (yyss + yystacksize - 1 <= yyssp)
1400     {
1401       /* Get the current used size of the three stacks, in elements.  */
1402       YYSIZE_T yysize = yyssp - yyss + 1;
1403
1404 #ifdef yyoverflow
1405       {
1406         /* Give user a chance to reallocate the stack.  Use copies of
1407            these so that the &'s don't force the real ones into
1408            memory.  */
1409         YYSTYPE *yyvs1 = yyvs;
1410         yytype_int16 *yyss1 = yyss;
1411
1412
1413         /* Each stack pointer address is followed by the size of the
1414            data in use in that stack, in bytes.  This used to be a
1415            conditional around just the two extra args, but that might
1416            be undefined if yyoverflow is a macro.  */
1417         yyoverflow (YY_("memory exhausted"),
1418                     &yyss1, yysize * sizeof (*yyssp),
1419                     &yyvs1, yysize * sizeof (*yyvsp),
1420
1421                     &yystacksize);
1422
1423         yyss = yyss1;
1424         yyvs = yyvs1;
1425       }
1426 #else /* no yyoverflow */
1427 # ifndef YYSTACK_RELOCATE
1428       goto yyexhaustedlab;
1429 # else
1430       /* Extend the stack our own way.  */
1431       if (YYMAXDEPTH <= yystacksize)
1432         goto yyexhaustedlab;
1433       yystacksize *= 2;
1434       if (YYMAXDEPTH < yystacksize)
1435         yystacksize = YYMAXDEPTH;
1436
1437       {
1438         yytype_int16 *yyss1 = yyss;
1439         union yyalloc *yyptr =
1440           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1441         if (! yyptr)
1442           goto yyexhaustedlab;
1443         YYSTACK_RELOCATE (yyss);
1444         YYSTACK_RELOCATE (yyvs);
1445
1446 #  undef YYSTACK_RELOCATE
1447         if (yyss1 != yyssa)
1448           YYSTACK_FREE (yyss1);
1449       }
1450 # endif
1451 #endif /* no yyoverflow */
1452
1453       yyssp = yyss + yysize - 1;
1454       yyvsp = yyvs + yysize - 1;
1455
1456
1457       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1458                   (unsigned long int) yystacksize));
1459
1460       if (yyss + yystacksize - 1 <= yyssp)
1461         YYABORT;
1462     }
1463
1464   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1465
1466   goto yybackup;
1467
1468 /*-----------.
1469 | yybackup.  |
1470 `-----------*/
1471 yybackup:
1472
1473   /* Do appropriate processing given the current state.  Read a
1474      look-ahead token if we need one and don't already have one.  */
1475
1476   /* First try to decide what to do without reference to look-ahead token.  */
1477   yyn = yypact[yystate];
1478   if (yyn == YYPACT_NINF)
1479     goto yydefault;
1480
1481   /* Not known => get a look-ahead token if don't already have one.  */
1482
1483   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1484   if (yychar == YYEMPTY)
1485     {
1486       YYDPRINTF ((stderr, "Reading a token: "));
1487       yychar = YYLEX;
1488     }
1489
1490   if (yychar <= YYEOF)
1491     {
1492       yychar = yytoken = YYEOF;
1493       YYDPRINTF ((stderr, "Now at end of input.\n"));
1494     }
1495   else
1496     {
1497       yytoken = YYTRANSLATE (yychar);
1498       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1499     }
1500
1501   /* If the proper action on seeing token YYTOKEN is to reduce or to
1502      detect an error, take that action.  */
1503   yyn += yytoken;
1504   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1505     goto yydefault;
1506   yyn = yytable[yyn];
1507   if (yyn <= 0)
1508     {
1509       if (yyn == 0 || yyn == YYTABLE_NINF)
1510         goto yyerrlab;
1511       yyn = -yyn;
1512       goto yyreduce;
1513     }
1514
1515   if (yyn == YYFINAL)
1516     YYACCEPT;
1517
1518   /* Count tokens shifted since error; after three, turn off error
1519      status.  */
1520   if (yyerrstatus)
1521     yyerrstatus--;
1522
1523   /* Shift the look-ahead token.  */
1524   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1525
1526   /* Discard the shifted token unless it is eof.  */
1527   if (yychar != YYEOF)
1528     yychar = YYEMPTY;
1529
1530   yystate = yyn;
1531   *++yyvsp = yylval;
1532
1533   goto yynewstate;
1534
1535
1536 /*-----------------------------------------------------------.
1537 | yydefault -- do the default action for the current state.  |
1538 `-----------------------------------------------------------*/
1539 yydefault:
1540   yyn = yydefact[yystate];
1541   if (yyn == 0)
1542     goto yyerrlab;
1543   goto yyreduce;
1544
1545
1546 /*-----------------------------.
1547 | yyreduce -- Do a reduction.  |
1548 `-----------------------------*/
1549 yyreduce:
1550   /* yyn is the number of a rule to reduce with.  */
1551   yylen = yyr2[yyn];
1552
1553   /* If YYLEN is nonzero, implement the default value of the action:
1554      `$$ = $1'.
1555
1556      Otherwise, the following line sets YYVAL to garbage.
1557      This behavior is undocumented and Bison
1558      users should not rely upon it.  Assigning to YYVAL
1559      unconditionally makes the parser a bit smaller, and it avoids a
1560      GCC warning that YYVAL may be used uninitialized.  */
1561   yyval = yyvsp[1-yylen];
1562
1563
1564   YY_REDUCE_PRINT (yyn);
1565   switch (yyn)
1566     {
1567         case 4:
1568 #line 199 "getdate.y"
1569     { PC.times_seen++; ;}
1570     break;
1571
1572   case 5:
1573 #line 201 "getdate.y"
1574     { PC.local_zones_seen++; ;}
1575     break;
1576
1577   case 6:
1578 #line 203 "getdate.y"
1579     { PC.zones_seen++; ;}
1580     break;
1581
1582   case 7:
1583 #line 205 "getdate.y"
1584     { PC.dates_seen++; ;}
1585     break;
1586
1587   case 8:
1588 #line 207 "getdate.y"
1589     { PC.days_seen++; ;}
1590     break;
1591
1592   case 9:
1593 #line 209 "getdate.y"
1594     { PC.rels_seen++; ;}
1595     break;
1596
1597   case 11:
1598 #line 215 "getdate.y"
1599     {
1600         PC.hour = (yyvsp[(1) - (2)].textintval).value;
1601         PC.minutes = 0;
1602         PC.seconds = 0;
1603         PC.meridian = (yyvsp[(2) - (2)].intval);
1604       ;}
1605     break;
1606
1607   case 12:
1608 #line 222 "getdate.y"
1609     {
1610         PC.hour = (yyvsp[(1) - (4)].textintval).value;
1611         PC.minutes = (yyvsp[(3) - (4)].textintval).value;
1612         PC.seconds = 0;
1613         PC.meridian = (yyvsp[(4) - (4)].intval);
1614       ;}
1615     break;
1616
1617   case 13:
1618 #line 229 "getdate.y"
1619     {
1620         PC.hour = (yyvsp[(1) - (4)].textintval).value;
1621         PC.minutes = (yyvsp[(3) - (4)].textintval).value;
1622         PC.meridian = MER24;
1623         PC.zones_seen++;
1624         PC.time_zone = (yyvsp[(4) - (4)].textintval).value % 100 + ((yyvsp[(4) - (4)].textintval).value / 100) * 60;
1625       ;}
1626     break;
1627
1628   case 14:
1629 #line 237 "getdate.y"
1630     {
1631         PC.hour = (yyvsp[(1) - (6)].textintval).value;
1632         PC.minutes = (yyvsp[(3) - (6)].textintval).value;
1633         PC.seconds = (yyvsp[(5) - (6)].textintval).value;
1634         PC.meridian = (yyvsp[(6) - (6)].intval);
1635       ;}
1636     break;
1637
1638   case 15:
1639 #line 244 "getdate.y"
1640     {
1641         PC.hour = (yyvsp[(1) - (6)].textintval).value;
1642         PC.minutes = (yyvsp[(3) - (6)].textintval).value;
1643         PC.seconds = (yyvsp[(5) - (6)].textintval).value;
1644         PC.meridian = MER24;
1645         PC.zones_seen++;
1646         PC.time_zone = (yyvsp[(6) - (6)].textintval).value % 100 + ((yyvsp[(6) - (6)].textintval).value / 100) * 60;
1647       ;}
1648     break;
1649
1650   case 16:
1651 #line 256 "getdate.y"
1652     { PC.local_isdst = (yyvsp[(1) - (1)].intval); ;}
1653     break;
1654
1655   case 17:
1656 #line 258 "getdate.y"
1657     { PC.local_isdst = (yyvsp[(1) - (2)].intval) < 0 ? 1 : (yyvsp[(1) - (2)].intval) + 1; ;}
1658     break;
1659
1660   case 18:
1661 #line 263 "getdate.y"
1662     { PC.time_zone = (yyvsp[(1) - (1)].intval); ;}
1663     break;
1664
1665   case 19:
1666 #line 265 "getdate.y"
1667     { PC.time_zone = (yyvsp[(1) - (1)].intval) + 60; ;}
1668     break;
1669
1670   case 20:
1671 #line 267 "getdate.y"
1672     { PC.time_zone = (yyvsp[(1) - (2)].intval) + 60; ;}
1673     break;
1674
1675   case 21:
1676 #line 272 "getdate.y"
1677     {
1678         PC.day_ordinal = 1;
1679         PC.day_number = (yyvsp[(1) - (1)].intval);
1680       ;}
1681     break;
1682
1683   case 22:
1684 #line 277 "getdate.y"
1685     {
1686         PC.day_ordinal = 1;
1687         PC.day_number = (yyvsp[(1) - (2)].intval);
1688       ;}
1689     break;
1690
1691   case 23:
1692 #line 282 "getdate.y"
1693     {
1694         PC.day_ordinal = (yyvsp[(1) - (2)].textintval).value;
1695         PC.day_number = (yyvsp[(2) - (2)].intval);
1696       ;}
1697     break;
1698
1699   case 24:
1700 #line 290 "getdate.y"
1701     {
1702         PC.month = (yyvsp[(1) - (3)].textintval).value;
1703         PC.day = (yyvsp[(3) - (3)].textintval).value;
1704       ;}
1705     break;
1706
1707   case 25:
1708 #line 295 "getdate.y"
1709     {
1710         /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1711            otherwise as MM/DD/YY.
1712            The goal in recognizing YYYY/MM/DD is solely to support legacy
1713            machine-generated dates like those in an RCS log listing.  If
1714            you want portability, use the ISO 8601 format.  */
1715         if (4 <= (yyvsp[(1) - (5)].textintval).digits)
1716           {
1717             PC.year = (yyvsp[(1) - (5)].textintval);
1718             PC.month = (yyvsp[(3) - (5)].textintval).value;
1719             PC.day = (yyvsp[(5) - (5)].textintval).value;
1720           }
1721         else
1722           {
1723             PC.month = (yyvsp[(1) - (5)].textintval).value;
1724             PC.day = (yyvsp[(3) - (5)].textintval).value;
1725             PC.year = (yyvsp[(5) - (5)].textintval);
1726           }
1727       ;}
1728     break;
1729
1730   case 26:
1731 #line 315 "getdate.y"
1732     {
1733         /* ISO 8601 format.  YYYY-MM-DD.  */
1734         PC.year = (yyvsp[(1) - (3)].textintval);
1735         PC.month = -(yyvsp[(2) - (3)].textintval).value;
1736         PC.day = -(yyvsp[(3) - (3)].textintval).value;
1737       ;}
1738     break;
1739
1740   case 27:
1741 #line 322 "getdate.y"
1742     {
1743         /* e.g. 17-JUN-1992.  */
1744         PC.day = (yyvsp[(1) - (3)].textintval).value;
1745         PC.month = (yyvsp[(2) - (3)].intval);
1746         PC.year.value = -(yyvsp[(3) - (3)].textintval).value;
1747         PC.year.digits = (yyvsp[(3) - (3)].textintval).digits;
1748       ;}
1749     break;
1750
1751   case 28:
1752 #line 330 "getdate.y"
1753     {
1754         PC.month = (yyvsp[(1) - (2)].intval);
1755         PC.day = (yyvsp[(2) - (2)].textintval).value;
1756       ;}
1757     break;
1758
1759   case 29:
1760 #line 335 "getdate.y"
1761     {
1762         PC.month = (yyvsp[(1) - (4)].intval);
1763         PC.day = (yyvsp[(2) - (4)].textintval).value;
1764         PC.year = (yyvsp[(4) - (4)].textintval);
1765       ;}
1766     break;
1767
1768   case 30:
1769 #line 341 "getdate.y"
1770     {
1771         PC.day = (yyvsp[(1) - (2)].textintval).value;
1772         PC.month = (yyvsp[(2) - (2)].intval);
1773       ;}
1774     break;
1775
1776   case 31:
1777 #line 346 "getdate.y"
1778     {
1779         PC.day = (yyvsp[(1) - (3)].textintval).value;
1780         PC.month = (yyvsp[(2) - (3)].intval);
1781         PC.year = (yyvsp[(3) - (3)].textintval);
1782       ;}
1783     break;
1784
1785   case 32:
1786 #line 355 "getdate.y"
1787     {
1788         PC.rel_seconds = -PC.rel_seconds;
1789         PC.rel_minutes = -PC.rel_minutes;
1790         PC.rel_hour = -PC.rel_hour;
1791         PC.rel_day = -PC.rel_day;
1792         PC.rel_month = -PC.rel_month;
1793         PC.rel_year = -PC.rel_year;
1794       ;}
1795     break;
1796
1797   case 34:
1798 #line 368 "getdate.y"
1799     { PC.rel_year += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1800     break;
1801
1802   case 35:
1803 #line 370 "getdate.y"
1804     { PC.rel_year += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1805     break;
1806
1807   case 36:
1808 #line 372 "getdate.y"
1809     { PC.rel_year += (yyvsp[(1) - (1)].intval); ;}
1810     break;
1811
1812   case 37:
1813 #line 374 "getdate.y"
1814     { PC.rel_month += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1815     break;
1816
1817   case 38:
1818 #line 376 "getdate.y"
1819     { PC.rel_month += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1820     break;
1821
1822   case 39:
1823 #line 378 "getdate.y"
1824     { PC.rel_month += (yyvsp[(1) - (1)].intval); ;}
1825     break;
1826
1827   case 40:
1828 #line 380 "getdate.y"
1829     { PC.rel_day += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1830     break;
1831
1832   case 41:
1833 #line 382 "getdate.y"
1834     { PC.rel_day += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1835     break;
1836
1837   case 42:
1838 #line 384 "getdate.y"
1839     { PC.rel_day += (yyvsp[(1) - (1)].intval); ;}
1840     break;
1841
1842   case 43:
1843 #line 386 "getdate.y"
1844     { PC.rel_hour += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1845     break;
1846
1847   case 44:
1848 #line 388 "getdate.y"
1849     { PC.rel_hour += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1850     break;
1851
1852   case 45:
1853 #line 390 "getdate.y"
1854     { PC.rel_hour += (yyvsp[(1) - (1)].intval); ;}
1855     break;
1856
1857   case 46:
1858 #line 392 "getdate.y"
1859     { PC.rel_minutes += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1860     break;
1861
1862   case 47:
1863 #line 394 "getdate.y"
1864     { PC.rel_minutes += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1865     break;
1866
1867   case 48:
1868 #line 396 "getdate.y"
1869     { PC.rel_minutes += (yyvsp[(1) - (1)].intval); ;}
1870     break;
1871
1872   case 49:
1873 #line 398 "getdate.y"
1874     { PC.rel_seconds += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1875     break;
1876
1877   case 50:
1878 #line 400 "getdate.y"
1879     { PC.rel_seconds += (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); ;}
1880     break;
1881
1882   case 51:
1883 #line 402 "getdate.y"
1884     { PC.rel_seconds += (yyvsp[(1) - (1)].intval); ;}
1885     break;
1886
1887   case 52:
1888 #line 407 "getdate.y"
1889     {
1890         if (PC.dates_seen
1891             && ! PC.rels_seen && (PC.times_seen || 2 < (yyvsp[(1) - (1)].textintval).digits))
1892           PC.year = (yyvsp[(1) - (1)].textintval);
1893         else
1894           {
1895             if (4 < (yyvsp[(1) - (1)].textintval).digits)
1896               {
1897                 PC.dates_seen++;
1898                 PC.day = (yyvsp[(1) - (1)].textintval).value % 100;
1899                 PC.month = ((yyvsp[(1) - (1)].textintval).value / 100) % 100;
1900                 PC.year.value = (yyvsp[(1) - (1)].textintval).value / 10000;
1901                 PC.year.digits = (yyvsp[(1) - (1)].textintval).digits - 4;
1902               }
1903             else
1904               {
1905                 PC.times_seen++;
1906                 if ((yyvsp[(1) - (1)].textintval).digits <= 2)
1907                   {
1908                     PC.hour = (yyvsp[(1) - (1)].textintval).value;
1909                     PC.minutes = 0;
1910                   }
1911                 else
1912                   {
1913                     PC.hour = (yyvsp[(1) - (1)].textintval).value / 100;
1914                     PC.minutes = (yyvsp[(1) - (1)].textintval).value % 100;
1915                   }
1916                 PC.seconds = 0;
1917                 PC.meridian = MER24;
1918               }
1919           }
1920       ;}
1921     break;
1922
1923   case 53:
1924 #line 443 "getdate.y"
1925     { (yyval.intval) = MER24; ;}
1926     break;
1927
1928   case 54:
1929 #line 445 "getdate.y"
1930     { (yyval.intval) = (yyvsp[(1) - (1)].intval); ;}
1931     break;
1932
1933
1934 /* Line 1267 of yacc.c.  */
1935 #line 1935 "getdate.c"
1936       default: break;
1937     }
1938   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1939
1940   YYPOPSTACK (yylen);
1941   yylen = 0;
1942   YY_STACK_PRINT (yyss, yyssp);
1943
1944   *++yyvsp = yyval;
1945
1946
1947   /* Now `shift' the result of the reduction.  Determine what state
1948      that goes to, based on the state we popped back to and the rule
1949      number reduced by.  */
1950
1951   yyn = yyr1[yyn];
1952
1953   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1954   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1955     yystate = yytable[yystate];
1956   else
1957     yystate = yydefgoto[yyn - YYNTOKENS];
1958
1959   goto yynewstate;
1960
1961
1962 /*------------------------------------.
1963 | yyerrlab -- here on detecting error |
1964 `------------------------------------*/
1965 yyerrlab:
1966   /* If not already recovering from an error, report this error.  */
1967   if (!yyerrstatus)
1968     {
1969       ++yynerrs;
1970 #if ! YYERROR_VERBOSE
1971       yyerror (YY_("syntax error"));
1972 #else
1973       {
1974         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1975         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1976           {
1977             YYSIZE_T yyalloc = 2 * yysize;
1978             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1979               yyalloc = YYSTACK_ALLOC_MAXIMUM;
1980             if (yymsg != yymsgbuf)
1981               YYSTACK_FREE (yymsg);
1982             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1983             if (yymsg)
1984               yymsg_alloc = yyalloc;
1985             else
1986               {
1987                 yymsg = yymsgbuf;
1988                 yymsg_alloc = sizeof yymsgbuf;
1989               }
1990           }
1991
1992         if (0 < yysize && yysize <= yymsg_alloc)
1993           {
1994             (void) yysyntax_error (yymsg, yystate, yychar);
1995             yyerror (yymsg);
1996           }
1997         else
1998           {
1999             yyerror (YY_("syntax error"));
2000             if (yysize != 0)
2001               goto yyexhaustedlab;
2002           }
2003       }
2004 #endif
2005     }
2006
2007
2008
2009   if (yyerrstatus == 3)
2010     {
2011       /* If just tried and failed to reuse look-ahead token after an
2012          error, discard it.  */
2013
2014       if (yychar <= YYEOF)
2015         {
2016           /* Return failure if at end of input.  */
2017           if (yychar == YYEOF)
2018             YYABORT;
2019         }
2020       else
2021         {
2022           yydestruct ("Error: discarding",
2023                       yytoken, &yylval);
2024           yychar = YYEMPTY;
2025         }
2026     }
2027
2028   /* Else will try to reuse look-ahead token after shifting the error
2029      token.  */
2030   goto yyerrlab1;
2031
2032
2033 /*---------------------------------------------------.
2034 | yyerrorlab -- error raised explicitly by YYERROR.  |
2035 `---------------------------------------------------*/
2036 yyerrorlab:
2037
2038   /* Pacify compilers like GCC when the user code never invokes
2039      YYERROR and the label yyerrorlab therefore never appears in user
2040      code.  */
2041   if (/*CONSTCOND*/ 0)
2042      goto yyerrorlab;
2043
2044   /* Do not reclaim the symbols of the rule which action triggered
2045      this YYERROR.  */
2046   YYPOPSTACK (yylen);
2047   yylen = 0;
2048   YY_STACK_PRINT (yyss, yyssp);
2049   yystate = *yyssp;
2050   goto yyerrlab1;
2051
2052
2053 /*-------------------------------------------------------------.
2054 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2055 `-------------------------------------------------------------*/
2056 yyerrlab1:
2057   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2058
2059   for (;;)
2060     {
2061       yyn = yypact[yystate];
2062       if (yyn != YYPACT_NINF)
2063         {
2064           yyn += YYTERROR;
2065           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2066             {
2067               yyn = yytable[yyn];
2068               if (0 < yyn)
2069                 break;
2070             }
2071         }
2072
2073       /* Pop the current state because it cannot handle the error token.  */
2074       if (yyssp == yyss)
2075         YYABORT;
2076
2077
2078       yydestruct ("Error: popping",
2079                   yystos[yystate], yyvsp);
2080       YYPOPSTACK (1);
2081       yystate = *yyssp;
2082       YY_STACK_PRINT (yyss, yyssp);
2083     }
2084
2085   if (yyn == YYFINAL)
2086     YYACCEPT;
2087
2088   *++yyvsp = yylval;
2089
2090
2091   /* Shift the error token.  */
2092   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2093
2094   yystate = yyn;
2095   goto yynewstate;
2096
2097
2098 /*-------------------------------------.
2099 | yyacceptlab -- YYACCEPT comes here.  |
2100 `-------------------------------------*/
2101 yyacceptlab:
2102   yyresult = 0;
2103   goto yyreturn;
2104
2105 /*-----------------------------------.
2106 | yyabortlab -- YYABORT comes here.  |
2107 `-----------------------------------*/
2108 yyabortlab:
2109   yyresult = 1;
2110   goto yyreturn;
2111
2112 #ifndef yyoverflow
2113 /*-------------------------------------------------.
2114 | yyexhaustedlab -- memory exhaustion comes here.  |
2115 `-------------------------------------------------*/
2116 yyexhaustedlab:
2117   yyerror (YY_("memory exhausted"));
2118   yyresult = 2;
2119   /* Fall through.  */
2120 #endif
2121
2122 yyreturn:
2123   if (yychar != YYEOF && yychar != YYEMPTY)
2124      yydestruct ("Cleanup: discarding lookahead",
2125                  yytoken, &yylval);
2126   /* Do not reclaim the symbols of the rule which action triggered
2127      this YYABORT or YYACCEPT.  */
2128   YYPOPSTACK (yylen);
2129   YY_STACK_PRINT (yyss, yyssp);
2130   while (yyssp != yyss)
2131     {
2132       yydestruct ("Cleanup: popping",
2133                   yystos[*yyssp], yyvsp);
2134       YYPOPSTACK (1);
2135     }
2136 #ifndef yyoverflow
2137   if (yyss != yyssa)
2138     YYSTACK_FREE (yyss);
2139 #endif
2140 #if YYERROR_VERBOSE
2141   if (yymsg != yymsgbuf)
2142     YYSTACK_FREE (yymsg);
2143 #endif
2144   /* Make sure YYID is used.  */
2145   return YYID (yyresult);
2146 }
2147
2148
2149 #line 448 "getdate.y"
2150
2151
2152 /* Include this file down here because bison inserts code above which
2153    may define-away `const'.  We want the prototype for get_date to have
2154    the same signature as the function definition.  */
2155 #include "modules/getdate.h"
2156
2157 #ifndef gmtime
2158 struct tm *gmtime (const time_t *);
2159 #endif
2160 #ifndef localtime
2161 struct tm *localtime (const time_t *);
2162 #endif
2163 #ifndef mktime
2164 time_t mktime (struct tm *);
2165 #endif
2166
2167 static table const meridian_table[] =
2168 {
2169   { "AM",   tMERIDIAN, MERam },
2170   { "A.M.", tMERIDIAN, MERam },
2171   { "PM",   tMERIDIAN, MERpm },
2172   { "P.M.", tMERIDIAN, MERpm },
2173   { 0, 0, 0 }
2174 };
2175
2176 static table const dst_table[] =
2177 {
2178   { "DST", tDST, 0 }
2179 };
2180
2181 static table const month_and_day_table[] =
2182 {
2183   { "JANUARY",  tMONTH,  1 },
2184   { "FEBRUARY", tMONTH,  2 },
2185   { "MARCH",    tMONTH,  3 },
2186   { "APRIL",    tMONTH,  4 },
2187   { "MAY",      tMONTH,  5 },
2188   { "JUNE",     tMONTH,  6 },
2189   { "JULY",     tMONTH,  7 },
2190   { "AUGUST",   tMONTH,  8 },
2191   { "SEPTEMBER",tMONTH,  9 },
2192   { "SEPT",     tMONTH,  9 },
2193   { "OCTOBER",  tMONTH, 10 },
2194   { "NOVEMBER", tMONTH, 11 },
2195   { "DECEMBER", tMONTH, 12 },
2196   { "SUNDAY",   tDAY,    0 },
2197   { "MONDAY",   tDAY,    1 },
2198   { "TUESDAY",  tDAY,    2 },
2199   { "TUES",     tDAY,    2 },
2200   { "WEDNESDAY",tDAY,    3 },
2201   { "WEDNES",   tDAY,    3 },
2202   { "THURSDAY", tDAY,    4 },
2203   { "THUR",     tDAY,    4 },
2204   { "THURS",    tDAY,    4 },
2205   { "FRIDAY",   tDAY,    5 },
2206   { "SATURDAY", tDAY,    6 },
2207   { 0, 0, 0 }
2208 };
2209
2210 static table const time_units_table[] =
2211 {
2212   { "YEAR",     tYEAR_UNIT,      1 },
2213   { "MONTH",    tMONTH_UNIT,     1 },
2214   { "FORTNIGHT",tDAY_UNIT,      14 },
2215   { "WEEK",     tDAY_UNIT,       7 },
2216   { "DAY",      tDAY_UNIT,       1 },
2217   { "HOUR",     tHOUR_UNIT,      1 },
2218   { "MINUTE",   tMINUTE_UNIT,    1 },
2219   { "MIN",      tMINUTE_UNIT,    1 },
2220   { "SECOND",   tSEC_UNIT,       1 },
2221   { "SEC",      tSEC_UNIT,       1 },
2222   { 0, 0, 0 }
2223 };
2224
2225 /* Assorted relative-time words. */
2226 static table const relative_time_table[] =
2227 {
2228   { "TOMORROW", tMINUTE_UNIT,   24 * 60 },
2229   { "YESTERDAY",tMINUTE_UNIT,   - (24 * 60) },
2230   { "TODAY",    tMINUTE_UNIT,    0 },
2231   { "NOW",      tMINUTE_UNIT,    0 },
2232   { "LAST",     tUNUMBER,       -1 },
2233   { "THIS",     tUNUMBER,        0 },
2234   { "NEXT",     tUNUMBER,        1 },
2235   { "FIRST",    tUNUMBER,        1 },
2236 /*{ "SECOND",   tUNUMBER,        2 }, */
2237   { "THIRD",    tUNUMBER,        3 },
2238   { "FOURTH",   tUNUMBER,        4 },
2239   { "FIFTH",    tUNUMBER,        5 },
2240   { "SIXTH",    tUNUMBER,        6 },
2241   { "SEVENTH",  tUNUMBER,        7 },
2242   { "EIGHTH",   tUNUMBER,        8 },
2243   { "NINTH",    tUNUMBER,        9 },
2244   { "TENTH",    tUNUMBER,       10 },
2245   { "ELEVENTH", tUNUMBER,       11 },
2246   { "TWELFTH",  tUNUMBER,       12 },
2247   { "AGO",      tAGO,            1 },
2248   { 0, 0, 0 }
2249 };
2250
2251 /* The time zone table.  This table is necessarily incomplete, as time
2252    zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2253    as Eastern time in Australia, not as US Eastern Standard Time.
2254    You cannot rely on getdate to handle arbitrary time zone
2255    abbreviations; use numeric abbreviations like `-0500' instead.  */
2256 static table const time_zone_table[] =
2257 {
2258   { "GMT",      tZONE,     HOUR ( 0) }, /* Greenwich Mean */
2259   { "UT",       tZONE,     HOUR ( 0) }, /* Universal (Coordinated) */
2260   { "UTC",      tZONE,     HOUR ( 0) },
2261   { "WET",      tZONE,     HOUR ( 0) }, /* Western European */
2262   { "WEST",     tDAYZONE,  HOUR ( 0) }, /* Western European Summer */
2263   { "BST",      tDAYZONE,  HOUR ( 0) }, /* British Summer */
2264   { "ART",      tZONE,    -HOUR ( 3) }, /* Argentina */
2265   { "BRT",      tZONE,    -HOUR ( 3) }, /* Brazil */
2266   { "BRST",     tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2267   { "NST",      tZONE,   -(HOUR ( 3) + 30) },   /* Newfoundland Standard */
2268   { "NDT",      tDAYZONE,-(HOUR ( 3) + 30) },   /* Newfoundland Daylight */
2269   { "AST",      tZONE,    -HOUR ( 4) }, /* Atlantic Standard */
2270   { "ADT",      tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2271   { "CLT",      tZONE,    -HOUR ( 4) }, /* Chile */
2272   { "CLST",     tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2273   { "EST",      tZONE,    -HOUR ( 5) }, /* Eastern Standard */
2274   { "EDT",      tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2275   { "CST",      tZONE,    -HOUR ( 6) }, /* Central Standard */
2276   { "CDT",      tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2277   { "MST",      tZONE,    -HOUR ( 7) }, /* Mountain Standard */
2278   { "MDT",      tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2279   { "PST",      tZONE,    -HOUR ( 8) }, /* Pacific Standard */
2280   { "PDT",      tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2281   { "AKST",     tZONE,    -HOUR ( 9) }, /* Alaska Standard */
2282   { "AKDT",     tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2283   { "HST",      tZONE,    -HOUR (10) }, /* Hawaii Standard */
2284   { "HAST",     tZONE,    -HOUR (10) }, /* Hawaii-Aleutian Standard */
2285   { "HADT",     tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2286   { "SST",      tZONE,    -HOUR (12) }, /* Samoa Standard */
2287   { "WAT",      tZONE,     HOUR ( 1) }, /* West Africa */
2288   { "CET",      tZONE,     HOUR ( 1) }, /* Central European */
2289   { "CEST",     tDAYZONE,  HOUR ( 1) }, /* Central European Summer */
2290   { "MET",      tZONE,     HOUR ( 1) }, /* Middle European */
2291   { "MEZ",      tZONE,     HOUR ( 1) }, /* Middle European */
2292   { "MEST",     tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
2293   { "MESZ",     tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
2294   { "EET",      tZONE,     HOUR ( 2) }, /* Eastern European */
2295   { "EEST",     tDAYZONE,  HOUR ( 2) }, /* Eastern European Summer */
2296   { "CAT",      tZONE,     HOUR ( 2) }, /* Central Africa */
2297   { "SAST",     tZONE,     HOUR ( 2) }, /* South Africa Standard */
2298   { "EAT",      tZONE,     HOUR ( 3) }, /* East Africa */
2299   { "MSK",      tZONE,     HOUR ( 3) }, /* Moscow */
2300   { "MSD",      tDAYZONE,  HOUR ( 3) }, /* Moscow Daylight */
2301   { "IST",      tZONE,    (HOUR ( 5) + 30) },   /* India Standard */
2302   { "SGT",      tZONE,     HOUR ( 8) }, /* Singapore */
2303   { "KST",      tZONE,     HOUR ( 9) }, /* Korea Standard */
2304   { "JST",      tZONE,     HOUR ( 9) }, /* Japan Standard */
2305   { "GST",      tZONE,     HOUR (10) }, /* Guam Standard */
2306   { "NZST",     tZONE,     HOUR (12) }, /* New Zealand Standard */
2307   { "NZDT",     tDAYZONE,  HOUR (12) }, /* New Zealand Daylight */
2308   { 0, 0, 0  }
2309 };
2310
2311 /* Military time zone table. */
2312 static table const military_table[] =
2313 {
2314   { "A", tZONE, -HOUR ( 1) },
2315   { "B", tZONE, -HOUR ( 2) },
2316   { "C", tZONE, -HOUR ( 3) },
2317   { "D", tZONE, -HOUR ( 4) },
2318   { "E", tZONE, -HOUR ( 5) },
2319   { "F", tZONE, -HOUR ( 6) },
2320   { "G", tZONE, -HOUR ( 7) },
2321   { "H", tZONE, -HOUR ( 8) },
2322   { "I", tZONE, -HOUR ( 9) },
2323   { "K", tZONE, -HOUR (10) },
2324   { "L", tZONE, -HOUR (11) },
2325   { "M", tZONE, -HOUR (12) },
2326   { "N", tZONE,  HOUR ( 1) },
2327   { "O", tZONE,  HOUR ( 2) },
2328   { "P", tZONE,  HOUR ( 3) },
2329   { "Q", tZONE,  HOUR ( 4) },
2330   { "R", tZONE,  HOUR ( 5) },
2331   { "S", tZONE,  HOUR ( 6) },
2332   { "T", tZONE,  HOUR ( 7) },
2333   { "U", tZONE,  HOUR ( 8) },
2334   { "V", tZONE,  HOUR ( 9) },
2335   { "W", tZONE,  HOUR (10) },
2336   { "X", tZONE,  HOUR (11) },
2337   { "Y", tZONE,  HOUR (12) },
2338   { "Z", tZONE,  HOUR ( 0) },
2339   { 0, 0, 0 }
2340 };
2341
2342 \f
2343
2344 static int
2345 to_hour (int hours, int meridian)
2346 {
2347   switch (meridian)
2348     {
2349     case MER24:
2350       return 0 <= hours && hours < 24 ? hours : -1;
2351     case MERam:
2352       return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2353     case MERpm:
2354       return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2355     default:
2356       abort ();
2357     }
2358   /* NOTREACHED */
2359     return 0;
2360 }
2361
2362 static int
2363 to_year (textint textyear)
2364 {
2365   int year = textyear.value;
2366
2367   if (year < 0)
2368     year = -year;
2369
2370   /* XPG4 suggests that years 00-68 map to 2000-2068, and
2371      years 69-99 map to 1969-1999.  */
2372   if (textyear.digits == 2)
2373     year += year < 69 ? 2000 : 1900;
2374
2375   return year;
2376 }
2377
2378 static table const *
2379 lookup_zone (parser_control const *pc, char const *name)
2380 {
2381   table const *tp;
2382
2383   /* Try local zone abbreviations first; they're more likely to be right.  */
2384   for (tp = pc->local_time_zone_table; tp->name; tp++)
2385     if (strcmp (name, tp->name) == 0)
2386       return tp;
2387
2388   for (tp = time_zone_table; tp->name; tp++)
2389     if (strcmp (name, tp->name) == 0)
2390       return tp;
2391
2392   return 0;
2393 }
2394
2395 #if ! HAVE_TM_GMTOFF
2396 /* Yield the difference between *A and *B,
2397    measured in seconds, ignoring leap seconds.
2398    The body of this function is taken directly from the GNU C Library;
2399    see src/strftime.c.  */
2400 static int
2401 tm_diff (struct tm const *a, struct tm const *b)
2402 {
2403   /* Compute intervening leap days correctly even if year is negative.
2404      Take care to avoid int overflow in leap day calculations,
2405      but it's OK to assume that A and B are close to each other.  */
2406   int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
2407   int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
2408   int a100 = a4 / 25 - (a4 % 25 < 0);
2409   int b100 = b4 / 25 - (b4 % 25 < 0);
2410   int a400 = a100 >> 2;
2411   int b400 = b100 >> 2;
2412   int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2413   int years = a->tm_year - b->tm_year;
2414   int days = (365 * years + intervening_leap_days
2415               + (a->tm_yday - b->tm_yday));
2416   return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2417                 + (a->tm_min - b->tm_min))
2418           + (a->tm_sec - b->tm_sec));
2419 }
2420 #endif /* ! HAVE_TM_GMTOFF */
2421
2422 static table const *
2423 lookup_word (parser_control const *pc, char *word)
2424 {
2425   char *p;
2426   char *q;
2427   size_t wordlen;
2428   table const *tp;
2429   int i;
2430   int abbrev;
2431
2432   /* Make it uppercase.  */
2433   for (p = word; *p; p++)
2434     if (ISLOWER ((unsigned char) *p))
2435       *p = toupper ((unsigned char) *p);
2436
2437   for (tp = meridian_table; tp->name; tp++)
2438     if (strcmp (word, tp->name) == 0)
2439       return tp;
2440
2441   /* See if we have an abbreviation for a month. */
2442   wordlen = strlen (word);
2443   abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2444
2445   for (tp = month_and_day_table; tp->name; tp++)
2446     if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2447       return tp;
2448
2449   if ((tp = lookup_zone (pc, word)))
2450     return tp;
2451
2452   if (strcmp (word, dst_table[0].name) == 0)
2453     return dst_table;
2454
2455   for (tp = time_units_table; tp->name; tp++)
2456     if (strcmp (word, tp->name) == 0)
2457       return tp;
2458
2459   /* Strip off any plural and try the units table again. */
2460   if (word[wordlen - 1] == 'S')
2461     {
2462       word[wordlen - 1] = '\0';
2463       for (tp = time_units_table; tp->name; tp++)
2464         if (strcmp (word, tp->name) == 0)
2465           return tp;
2466       word[wordlen - 1] = 'S';  /* For "this" in relative_time_table.  */
2467     }
2468
2469   for (tp = relative_time_table; tp->name; tp++)
2470     if (strcmp (word, tp->name) == 0)
2471       return tp;
2472
2473   /* Military time zones. */
2474   if (wordlen == 1)
2475     for (tp = military_table; tp->name; tp++)
2476       if (word[0] == tp->name[0])
2477         return tp;
2478
2479   /* Drop out any periods and try the time zone table again. */
2480   for (i = 0, p = q = word; (*p = *q); q++)
2481     if (*q == '.')
2482       i = 1;
2483     else
2484       p++;
2485   if (i && (tp = lookup_zone (pc, word)))
2486     return tp;
2487
2488   return 0;
2489 }
2490
2491 static int
2492 yylex (YYSTYPE *lvalp, parser_control *pc)
2493 {
2494   unsigned char c;
2495   size_t count;
2496
2497   for (;;)
2498     {
2499       while (c = *pc->input, ISSPACE (c))
2500         pc->input++;
2501
2502       if (ISDIGIT (c) || c == '-' || c == '+')
2503         {
2504           char const *p;
2505           int sign;
2506           int value;
2507           if (c == '-' || c == '+')
2508             {
2509               sign = c == '-' ? -1 : 1;
2510               c = *++pc->input;
2511               if (! ISDIGIT (c))
2512                 /* skip the '-' sign */
2513                 continue;
2514             }
2515           else
2516             sign = 0;
2517           p = pc->input;
2518           value = 0;
2519           do
2520             {
2521               value = 10 * value + c - '0';
2522               c = *++p;
2523             }
2524           while (ISDIGIT (c));
2525           lvalp->textintval.value = sign < 0 ? -value : value;
2526           lvalp->textintval.digits = p - pc->input;
2527           pc->input = p;
2528           return sign ? tSNUMBER : tUNUMBER;
2529         }
2530
2531       if (ISALPHA (c))
2532         {
2533           char buff[20];
2534           char *p = buff;
2535           table const *tp;
2536
2537           do
2538             {
2539               if (p < buff + sizeof buff - 1)
2540                 *p++ = c;
2541               c = *++pc->input;
2542             }
2543           while (ISALPHA (c) || c == '.');
2544
2545           *p = '\0';
2546           tp = lookup_word (pc, buff);
2547           if (! tp)
2548             return '?';
2549           lvalp->intval = tp->value;
2550           return tp->type;
2551         }
2552
2553       if (c != '(')
2554         return *pc->input++;
2555       count = 0;
2556       do
2557         {
2558           c = *pc->input++;
2559           if (c == '\0')
2560             return c;
2561           if (c == '(')
2562             count++;
2563           else if (c == ')')
2564             count--;
2565         }
2566       while (count > 0);
2567     }
2568 }
2569
2570 /* Do nothing if the parser reports an error.  */
2571 static int
2572 yyerror (const char *s ATTRIBUTE_UNUSED)
2573 {
2574   return 0;
2575 }
2576
2577 /* Parse a date/time string P.  Return the corresponding time_t value,
2578    or (time_t) -1 if there is an error.  P can be an incomplete or
2579    relative time specification; if so, use *NOW as the basis for the
2580    returned time.  */
2581 time_t
2582 get_date (const char *p, const time_t *now)
2583 {
2584   time_t Start = now ? *now : time (0);
2585   struct tm *tmp = localtime (&Start);
2586   struct tm tm;
2587   struct tm tm0;
2588   parser_control pc;
2589
2590   if (! tmp)
2591     return -1;
2592
2593   pc.input = p;
2594   pc.year.value = tmp->tm_year + TM_YEAR_BASE;
2595   pc.year.digits = 4;
2596   pc.month = tmp->tm_mon + 1;
2597   pc.day = tmp->tm_mday;
2598   pc.hour = tmp->tm_hour;
2599   pc.minutes = tmp->tm_min;
2600   pc.seconds = tmp->tm_sec;
2601   tm.tm_isdst = tmp->tm_isdst;
2602
2603   pc.meridian = MER24;
2604   pc.rel_seconds = 0;
2605   pc.rel_minutes = 0;
2606   pc.rel_hour = 0;
2607   pc.rel_day = 0;
2608   pc.rel_month = 0;
2609   pc.rel_year = 0;
2610   pc.dates_seen = 0;
2611   pc.days_seen = 0;
2612   pc.rels_seen = 0;
2613   pc.times_seen = 0;
2614   pc.local_zones_seen = 0;
2615   pc.zones_seen = 0;
2616
2617 #if HAVE_STRUCT_TM_TM_ZONE
2618   pc.local_time_zone_table[0].name = tmp->tm_zone;
2619   pc.local_time_zone_table[0].type = tLOCAL_ZONE;
2620   pc.local_time_zone_table[0].value = tmp->tm_isdst;
2621   pc.local_time_zone_table[1].name = 0;
2622
2623   /* Probe the names used in the next three calendar quarters, looking
2624      for a tm_isdst different from the one we already have.  */
2625   {
2626     int quarter;
2627     for (quarter = 1; quarter <= 3; quarter++)
2628       {
2629         time_t probe = Start + quarter * (90 * 24 * 60 * 60);
2630         struct tm *probe_tm = localtime (&probe);
2631         if (probe_tm && probe_tm->tm_zone
2632             && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
2633           {
2634               {
2635                 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
2636                 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
2637                 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
2638                 pc.local_time_zone_table[2].name = 0;
2639               }
2640             break;
2641           }
2642       }
2643   }
2644 #else
2645 #if HAVE_TZNAME
2646   {
2647 # ifndef tzname
2648     extern char *tzname[];
2649 # endif
2650     int i;
2651     for (i = 0; i < 2; i++)
2652       {
2653         pc.local_time_zone_table[i].name = tzname[i];
2654         pc.local_time_zone_table[i].type = tLOCAL_ZONE;
2655         pc.local_time_zone_table[i].value = i;
2656       }
2657     pc.local_time_zone_table[i].name = 0;
2658   }
2659 #else
2660   pc.local_time_zone_table[0].name = 0;
2661 #endif
2662 #endif
2663
2664   if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
2665       && ! strcmp (pc.local_time_zone_table[0].name,
2666                    pc.local_time_zone_table[1].name))
2667     {
2668       /* This locale uses the same abbrevation for standard and
2669          daylight times.  So if we see that abbreviation, we don't
2670          know whether it's daylight time.  */
2671       pc.local_time_zone_table[0].value = -1;
2672       pc.local_time_zone_table[1].name = 0;
2673     }
2674
2675   if (yyparse (&pc) != 0
2676       || 1 < pc.times_seen || 1 < pc.dates_seen || 1 < pc.days_seen
2677       || 1 < (pc.local_zones_seen + pc.zones_seen)
2678       || (pc.local_zones_seen && 1 < pc.local_isdst))
2679     return -1;
2680
2681   tm.tm_year = to_year (pc.year) - TM_YEAR_BASE + pc.rel_year;
2682   tm.tm_mon = pc.month - 1 + pc.rel_month;
2683   tm.tm_mday = pc.day + pc.rel_day;
2684   if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
2685     {
2686       tm.tm_hour = to_hour (pc.hour, pc.meridian);
2687       if (tm.tm_hour < 0)
2688         return -1;
2689       tm.tm_min = pc.minutes;
2690       tm.tm_sec = pc.seconds;
2691     }
2692   else
2693     {
2694       tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
2695     }
2696
2697   /* Let mktime deduce tm_isdst if we have an absolute time stamp,
2698      or if the relative time stamp mentions days, months, or years.  */
2699   if (pc.dates_seen | pc.days_seen | pc.times_seen | pc.rel_day
2700       | pc.rel_month | pc.rel_year)
2701     tm.tm_isdst = -1;
2702
2703   /* But if the input explicitly specifies local time with or without
2704      DST, give mktime that information.  */
2705   if (pc.local_zones_seen)
2706     tm.tm_isdst = pc.local_isdst;
2707
2708   tm0 = tm;
2709
2710   Start = mktime (&tm);
2711
2712   if (Start == (time_t) -1)
2713     {
2714
2715       /* Guard against falsely reporting errors near the time_t boundaries
2716          when parsing times in other time zones.  For example, if the min
2717          time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
2718          of UTC, then the min localtime value is 1970-01-01 08:00:00; if
2719          we apply mktime to 1970-01-01 00:00:00 we will get an error, so
2720          we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
2721          zone by 24 hours to compensate.  This algorithm assumes that
2722          there is no DST transition within a day of the time_t boundaries.  */
2723       if (pc.zones_seen)
2724         {
2725           tm = tm0;
2726           if (tm.tm_year <= EPOCH_YEAR - TM_YEAR_BASE)
2727             {
2728               tm.tm_mday++;
2729               pc.time_zone += 24 * 60;
2730             }
2731           else
2732             {
2733               tm.tm_mday--;
2734               pc.time_zone -= 24 * 60;
2735             }
2736           Start = mktime (&tm);
2737         }
2738
2739       if (Start == (time_t) -1)
2740         return Start;
2741     }
2742
2743   if (pc.days_seen && ! pc.dates_seen)
2744     {
2745       tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
2746                      + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
2747       tm.tm_isdst = -1;
2748       Start = mktime (&tm);
2749       if (Start == (time_t) -1)
2750         return Start;
2751     }
2752
2753   if (pc.zones_seen)
2754     {
2755       int delta = pc.time_zone * 60;
2756 #ifdef HAVE_TM_GMTOFF
2757       delta -= tm.tm_gmtoff;
2758 #else
2759       struct tm *gmt = gmtime (&Start);
2760       if (! gmt)
2761         return -1;
2762       delta -= tm_diff (&tm, gmt);
2763 #endif
2764       if ((Start < Start - delta) != (delta < 0))
2765         return -1;      /* time_t overflow */
2766       Start -= delta;
2767     }
2768
2769   /* Add relative hours, minutes, and seconds.  Ignore leap seconds;
2770      i.e. "+ 10 minutes" means 600 seconds, even if one of them is a
2771      leap second.  Typically this is not what the user wants, but it's
2772      too hard to do it the other way, because the time zone indicator
2773      must be applied before relative times, and if mktime is applied
2774      again the time zone will be lost.  */
2775   {
2776     time_t t0 = Start;
2777     long d1 = 60 * 60 * (long) pc.rel_hour;
2778     time_t t1 = t0 + d1;
2779     long d2 = 60 * (long) pc.rel_minutes;
2780     time_t t2 = t1 + d2;
2781     int d3 = pc.rel_seconds;
2782     time_t t3 = t2 + d3;
2783     if ((d1 / (60 * 60) ^ pc.rel_hour)
2784         | (d2 / 60 ^ pc.rel_minutes)
2785         | ((t0 + d1 < t0) ^ (d1 < 0))
2786         | ((t1 + d2 < t1) ^ (d2 < 0))
2787         | ((t2 + d3 < t2) ^ (d3 < 0)))
2788       return -1;
2789     Start = t3;
2790   }
2791
2792   return Start;
2793 }
2794
2795 #if TEST
2796
2797 #include <stdio.h>
2798
2799 int
2800 main (int ac, char **av)
2801 {
2802   char buff[BUFSIZ];
2803   time_t d;
2804
2805   printf ("Enter date, or blank line to exit.\n\t> ");
2806   fflush (stdout);
2807
2808   buff[BUFSIZ - 1] = 0;
2809   while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
2810     {
2811       d = get_date (buff, 0);
2812       if (d == (time_t) -1)
2813         printf ("Bad format - couldn't convert.\n");
2814       else
2815         printf ("%s", ctime (&d));
2816       printf ("\t> ");
2817       fflush (stdout);
2818     }
2819   return 0;
2820 }
2821 #endif /* defined TEST */
2822