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