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