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