python: models: rename argument ldb to samdb
[samba.git] / source3 / modules / getdate.c
blob763ff934628e96d9936b1339a38e7d5e2ec8cc72
1 /* A Bison parser, made by GNU Bison 3.0.4. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
43 /* Identify Bison output. */
44 #define YYBISON 1
46 /* Bison version. */
47 #define YYBISON_VERSION "3.0.4"
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
52 /* Pure parsers. */
53 #define YYPURE 1
55 /* Push parsers. */
56 #define YYPUSH 0
58 /* Pull parsers. */
59 #define YYPULL 1
64 /* Copy the first part of user declarations. */
65 #line 1 "source3/modules/getdate.y" /* yacc.c:339 */
67 /* Parse a string into an internal time stamp.
68 Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
70 This program is free software; you can redistribute it and/or modify
71 it under the terms of the GNU General Public License as published by
72 the Free Software Foundation; either version 2, or (at your option)
73 any later version.
75 This program is distributed in the hope that it will be useful,
76 but WITHOUT ANY WARRANTY; without even the implied warranty of
77 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78 GNU General Public License for more details.
80 You should have received a copy of the GNU General Public License
81 along with this program; if not, see <http://www.gnu.org/licenses/>. */
83 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
84 at the University of North Carolina at Chapel Hill. Later tweaked by
85 a couple of people on Usenet. Completely overhauled by Rich $alz
86 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
88 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
89 the right thing about local DST. Unlike previous versions, this
90 version is reentrant. */
92 #ifdef HAVE_CONFIG_H
93 # include <config.h>
94 # ifdef HAVE_ALLOCA_H
95 # include <alloca.h>
96 # endif
97 #endif
99 /* Since the code of getdate.y is not included in the Emacs executable
100 itself, there is no need to #define static in this file. Even if
101 the code were included in the Emacs executable, it probably
102 wouldn't do any harm to #undef it here; this will only cause
103 problems if we try to write to a static variable, which I don't
104 think this code needs to do. */
105 #ifdef emacs
106 # undef static
107 #endif
109 #include <ctype.h>
110 #include <string.h>
112 #ifdef HAVE_STDLIB_H
113 # include <stdlib.h> /* for `free'; used by Bison 1.27 */
114 #endif
116 #if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
117 # define IN_CTYPE_DOMAIN(c) 1
118 #else
119 # define IN_CTYPE_DOMAIN(c) isascii (c)
120 #endif
122 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
123 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
124 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
125 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
127 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
128 - Its arg may be any int or unsigned int; it need not be an unsigned char.
129 - It's guaranteed to evaluate its argument exactly once.
130 - It's typically faster.
131 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
132 ISDIGIT_LOCALE unless it's important to use the locale's definition
133 of `digit' even when the host does not conform to POSIX. */
134 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
136 #if STDC_HEADERS || HAVE_STRING_H
137 # include <string.h>
138 #endif
140 #ifndef HAVE___ATTRIBUTE__
141 # define __attribute__(x)
142 #endif
144 #ifndef ATTRIBUTE_UNUSED
145 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
146 #endif
148 #define EPOCH_YEAR 1970
149 #define TM_YEAR_BASE 1900
151 #define HOUR(x) ((x) * 60)
153 /* An integer value, and the number of digits in its textual
154 representation. */
155 typedef struct
157 int value;
158 int digits;
159 } textint;
161 /* An entry in the lexical lookup table. */
162 typedef struct
164 char const *name;
165 int type;
166 int value;
167 } table;
169 /* Meridian: am, pm, or 24-hour style. */
170 enum { MERam, MERpm, MER24 };
172 /* Information passed to and from the parser. */
173 struct parser_control
175 /* The input string remaining to be parsed. */
176 const char *input;
178 /* N, if this is the Nth Tuesday. */
179 int day_ordinal;
181 /* Day of week; Sunday is 0. */
182 int day_number;
184 /* tm_isdst flag for the local zone. */
185 int local_isdst;
187 /* Time zone, in minutes east of UTC. */
188 int time_zone;
190 /* Style used for time. */
191 int meridian;
193 /* Gregorian year, month, day, hour, minutes, and seconds. */
194 textint year;
195 int month;
196 int day;
197 int hour;
198 int minutes;
199 int seconds;
201 /* Relative year, month, day, hour, minutes, and seconds. */
202 int rel_year;
203 int rel_month;
204 int rel_day;
205 int rel_hour;
206 int rel_minutes;
207 int rel_seconds;
209 /* Counts of nonterminals of various flavors parsed so far. */
210 int dates_seen;
211 int days_seen;
212 int local_zones_seen;
213 int rels_seen;
214 int times_seen;
215 int zones_seen;
217 /* Table of local time zone abbreviations, terminated by a null entry. */
218 table local_time_zone_table[3];
222 #line 223 "source3/modules/getdate.c" /* yacc.c:339 */
224 # ifndef YY_NULLPTR
225 # if defined __cplusplus && 201103L <= __cplusplus
226 # define YY_NULLPTR nullptr
227 # else
228 # define YY_NULLPTR 0
229 # endif
230 # endif
232 /* Enabling verbose error messages. */
233 #ifdef YYERROR_VERBOSE
234 # undef YYERROR_VERBOSE
235 # define YYERROR_VERBOSE 1
236 #else
237 # define YYERROR_VERBOSE 0
238 #endif
241 /* Debug traces. */
242 #ifndef YYDEBUG
243 # define YYDEBUG 0
244 #endif
245 #if YYDEBUG
246 extern int yydebug;
247 #endif
249 /* Token type. */
250 #ifndef YYTOKENTYPE
251 # define YYTOKENTYPE
252 enum yytokentype
254 tAGO = 258,
255 tDST = 259,
256 tDAY = 260,
257 tDAY_UNIT = 261,
258 tDAYZONE = 262,
259 tHOUR_UNIT = 263,
260 tLOCAL_ZONE = 264,
261 tMERIDIAN = 265,
262 tMINUTE_UNIT = 266,
263 tMONTH = 267,
264 tMONTH_UNIT = 268,
265 tSEC_UNIT = 269,
266 tYEAR_UNIT = 270,
267 tZONE = 271,
268 tSNUMBER = 272,
269 tUNUMBER = 273
271 #endif
273 /* Value type. */
274 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
276 union YYSTYPE
278 #line 168 "source3/modules/getdate.y" /* yacc.c:355 */
280 int intval;
281 textint textintval;
283 #line 284 "source3/modules/getdate.c" /* yacc.c:355 */
286 typedef union YYSTYPE YYSTYPE;
287 # define YYSTYPE_IS_TRIVIAL 1
288 # define YYSTYPE_IS_DECLARED 1
289 #endif
293 int yyparse (struct parser_control *pc);
297 /* Copy the second part of user declarations. */
298 #line 173 "source3/modules/getdate.y" /* yacc.c:358 */
301 static int yyerror(struct parser_control *, const char *);
302 static int yylex(YYSTYPE *, struct parser_control *);
305 #line 306 "source3/modules/getdate.c" /* yacc.c:358 */
307 #ifdef short
308 # undef short
309 #endif
311 #ifdef YYTYPE_UINT8
312 typedef YYTYPE_UINT8 yytype_uint8;
313 #else
314 typedef unsigned char yytype_uint8;
315 #endif
317 #ifdef YYTYPE_INT8
318 typedef YYTYPE_INT8 yytype_int8;
319 #else
320 typedef signed char yytype_int8;
321 #endif
323 #ifdef YYTYPE_UINT16
324 typedef YYTYPE_UINT16 yytype_uint16;
325 #else
326 typedef unsigned short int yytype_uint16;
327 #endif
329 #ifdef YYTYPE_INT16
330 typedef YYTYPE_INT16 yytype_int16;
331 #else
332 typedef short int yytype_int16;
333 #endif
335 #ifndef YYSIZE_T
336 # ifdef __SIZE_TYPE__
337 # define YYSIZE_T __SIZE_TYPE__
338 # elif defined size_t
339 # define YYSIZE_T size_t
340 # elif ! defined YYSIZE_T
341 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
342 # define YYSIZE_T size_t
343 # else
344 # define YYSIZE_T unsigned int
345 # endif
346 #endif
348 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
350 #ifndef YY_
351 # if defined YYENABLE_NLS && YYENABLE_NLS
352 # if ENABLE_NLS
353 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
354 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
355 # endif
356 # endif
357 # ifndef YY_
358 # define YY_(Msgid) Msgid
359 # endif
360 #endif
362 #ifndef YY_ATTRIBUTE
363 # if (defined __GNUC__ \
364 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
365 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
366 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
367 # else
368 # define YY_ATTRIBUTE(Spec) /* empty */
369 # endif
370 #endif
372 #ifndef YY_ATTRIBUTE_PURE
373 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
374 #endif
376 #ifndef YY_ATTRIBUTE_UNUSED
377 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
378 #endif
380 #if !defined _Noreturn \
381 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
382 # if defined _MSC_VER && 1200 <= _MSC_VER
383 # define _Noreturn __declspec (noreturn)
384 # else
385 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
386 # endif
387 #endif
389 /* Suppress unused-variable warnings by "using" E. */
390 #if ! defined lint || defined __GNUC__
391 # define YYUSE(E) ((void) (E))
392 #else
393 # define YYUSE(E) /* empty */
394 #endif
396 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
397 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
398 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
399 _Pragma ("GCC diagnostic push") \
400 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
401 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
402 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
403 _Pragma ("GCC diagnostic pop")
404 #else
405 # define YY_INITIAL_VALUE(Value) Value
406 #endif
407 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
408 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
409 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
410 #endif
411 #ifndef YY_INITIAL_VALUE
412 # define YY_INITIAL_VALUE(Value) /* Nothing. */
413 #endif
416 #if ! defined yyoverflow || YYERROR_VERBOSE
418 /* The parser invokes alloca or malloc; define the necessary symbols. */
420 # ifdef YYSTACK_USE_ALLOCA
421 # if YYSTACK_USE_ALLOCA
422 # ifdef __GNUC__
423 # define YYSTACK_ALLOC __builtin_alloca
424 # elif defined __BUILTIN_VA_ARG_INCR
425 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
426 # elif defined _AIX
427 # define YYSTACK_ALLOC __alloca
428 # elif defined _MSC_VER
429 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
430 # define alloca _alloca
431 # else
432 # define YYSTACK_ALLOC alloca
433 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
434 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
435 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
436 # ifndef EXIT_SUCCESS
437 # define EXIT_SUCCESS 0
438 # endif
439 # endif
440 # endif
441 # endif
442 # endif
444 # ifdef YYSTACK_ALLOC
445 /* Pacify GCC's 'empty if-body' warning. */
446 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
447 # ifndef YYSTACK_ALLOC_MAXIMUM
448 /* The OS might guarantee only one guard page at the bottom of the stack,
449 and a page size can be as small as 4096 bytes. So we cannot safely
450 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
451 to allow for a few compiler-allocated temporary stack slots. */
452 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
453 # endif
454 # else
455 # define YYSTACK_ALLOC YYMALLOC
456 # define YYSTACK_FREE YYFREE
457 # ifndef YYSTACK_ALLOC_MAXIMUM
458 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
459 # endif
460 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
461 && ! ((defined YYMALLOC || defined malloc) \
462 && (defined YYFREE || defined free)))
463 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
464 # ifndef EXIT_SUCCESS
465 # define EXIT_SUCCESS 0
466 # endif
467 # endif
468 # ifndef YYMALLOC
469 # define YYMALLOC malloc
470 # if ! defined malloc && ! defined EXIT_SUCCESS
471 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
472 # endif
473 # endif
474 # ifndef YYFREE
475 # define YYFREE free
476 # if ! defined free && ! defined EXIT_SUCCESS
477 void free (void *); /* INFRINGES ON USER NAME SPACE */
478 # endif
479 # endif
480 # endif
481 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
484 #if (! defined yyoverflow \
485 && (! defined __cplusplus \
486 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
488 /* A type that is properly aligned for any stack member. */
489 union yyalloc
491 yytype_int16 yyss_alloc;
492 YYSTYPE yyvs_alloc;
495 /* The size of the maximum gap between one aligned stack and the next. */
496 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
498 /* The size of an array large to enough to hold all stacks, each with
499 N elements. */
500 # define YYSTACK_BYTES(N) \
501 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
502 + YYSTACK_GAP_MAXIMUM)
504 # define YYCOPY_NEEDED 1
506 /* Relocate STACK from its old location to the new one. The
507 local variables YYSIZE and YYSTACKSIZE give the old and new number of
508 elements in the stack, and YYPTR gives the new location of the
509 stack. Advance YYPTR to a properly aligned location for the next
510 stack. */
511 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
512 do \
514 YYSIZE_T yynewbytes; \
515 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
516 Stack = &yyptr->Stack_alloc; \
517 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
518 yyptr += yynewbytes / sizeof (*yyptr); \
520 while (0)
522 #endif
524 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
525 /* Copy COUNT objects from SRC to DST. The source and destination do
526 not overlap. */
527 # ifndef YYCOPY
528 # if defined __GNUC__ && 1 < __GNUC__
529 # define YYCOPY(Dst, Src, Count) \
530 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
531 # else
532 # define YYCOPY(Dst, Src, Count) \
533 do \
535 YYSIZE_T yyi; \
536 for (yyi = 0; yyi < (Count); yyi++) \
537 (Dst)[yyi] = (Src)[yyi]; \
539 while (0)
540 # endif
541 # endif
542 #endif /* !YYCOPY_NEEDED */
544 /* YYFINAL -- State number of the termination state. */
545 #define YYFINAL 2
546 /* YYLAST -- Last index in YYTABLE. */
547 #define YYLAST 52
549 /* YYNTOKENS -- Number of terminals. */
550 #define YYNTOKENS 22
551 /* YYNNTS -- Number of nonterminals. */
552 #define YYNNTS 12
553 /* YYNRULES -- Number of rules. */
554 #define YYNRULES 54
555 /* YYNSTATES -- Number of states. */
556 #define YYNSTATES 64
558 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
559 by yylex, with out-of-bounds checking. */
560 #define YYUNDEFTOK 2
561 #define YYMAXUTOK 273
563 #define YYTRANSLATE(YYX) \
564 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
566 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
567 as returned by yylex, without out-of-bounds checking. */
568 static const yytype_uint8 yytranslate[] =
570 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574 2, 2, 2, 2, 20, 2, 2, 21, 2, 2,
575 2, 2, 2, 2, 2, 2, 2, 2, 19, 2,
576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
586 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
587 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
588 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
589 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
590 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
591 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
592 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
593 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
594 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
595 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
596 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
597 15, 16, 17, 18
600 #if YYDEBUG
601 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
602 static const yytype_uint16 yyrline[] =
604 0, 191, 191, 193, 197, 199, 201, 203, 205, 207,
605 209, 213, 220, 227, 235, 242, 254, 256, 261, 263,
606 265, 270, 275, 280, 288, 293, 313, 320, 328, 333,
607 339, 344, 353, 362, 366, 368, 370, 372, 374, 376,
608 378, 380, 382, 384, 386, 388, 390, 392, 394, 396,
609 398, 400, 405, 442, 443
611 #endif
613 #if YYDEBUG || YYERROR_VERBOSE || 0
614 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
615 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
616 static const char *const yytname[] =
618 "$end", "error", "$undefined", "tAGO", "tDST", "tDAY", "tDAY_UNIT",
619 "tDAYZONE", "tHOUR_UNIT", "tLOCAL_ZONE", "tMERIDIAN", "tMINUTE_UNIT",
620 "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tYEAR_UNIT", "tZONE", "tSNUMBER",
621 "tUNUMBER", "':'", "','", "'/'", "$accept", "spec", "item", "time",
622 "local_zone", "zone", "day", "date", "rel", "relunit", "number",
623 "o_merid", YY_NULLPTR
625 #endif
627 # ifdef YYPRINT
628 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
629 (internal) symbol number NUM (which must be that of a token). */
630 static const yytype_uint16 yytoknum[] =
632 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
633 265, 266, 267, 268, 269, 270, 271, 272, 273, 58,
634 44, 47
636 # endif
638 #define YYPACT_NINF -17
640 #define yypact_value_is_default(Yystate) \
641 (!!((Yystate) == (-17)))
643 #define YYTABLE_NINF -1
645 #define yytable_value_is_error(Yytable_value) \
648 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
649 STATE-NUM. */
650 static const yytype_int8 yypact[] =
652 -17, 0, -17, 1, -17, -17, -17, 19, -17, -14,
653 -17, -17, -17, 32, 26, 14, -17, -17, -17, -17,
654 -17, -17, -17, 27, -17, -17, -17, 22, -17, -17,
655 -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
656 -16, -17, -17, -17, 29, 25, 30, -17, 31, -17,
657 -17, -17, 28, 23, -17, -17, -17, 33, -17, 34,
658 -7, -17, -17, -17
661 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
662 Performed when YYTABLE does not specify something else to do. Zero
663 means the default is an error. */
664 static const yytype_uint8 yydefact[] =
666 2, 0, 1, 21, 42, 19, 45, 16, 48, 0,
667 39, 51, 36, 18, 0, 52, 3, 4, 5, 6,
668 8, 7, 9, 33, 10, 22, 17, 28, 20, 41,
669 44, 47, 38, 50, 35, 23, 40, 43, 11, 46,
670 30, 37, 49, 34, 0, 0, 0, 32, 0, 27,
671 31, 26, 53, 24, 29, 54, 13, 0, 12, 0,
672 53, 25, 15, 14
675 /* YYPGOTO[NTERM-NUM]. */
676 static const yytype_int8 yypgoto[] =
678 -17, -17, -17, -17, -17, -17, -17, -17, -17, -17,
679 -17, -10
682 /* YYDEFGOTO[NTERM-NUM]. */
683 static const yytype_int8 yydefgoto[] =
685 -1, 1, 16, 17, 18, 19, 20, 21, 22, 23,
686 24, 58
689 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
690 positive, shift that token. If negative, reduce the rule whose
691 number is the opposite. If YYTABLE_NINF, syntax error. */
692 static const yytype_uint8 yytable[] =
694 2, 49, 50, 55, 27, 3, 4, 5, 6, 7,
695 62, 8, 9, 10, 11, 12, 13, 14, 15, 35,
696 36, 25, 37, 26, 38, 39, 40, 41, 42, 43,
697 47, 44, 29, 45, 30, 46, 28, 31, 55, 32,
698 33, 34, 48, 52, 59, 56, 51, 57, 53, 54,
699 63, 60, 61
702 static const yytype_uint8 yycheck[] =
704 0, 17, 18, 10, 18, 5, 6, 7, 8, 9,
705 17, 11, 12, 13, 14, 15, 16, 17, 18, 5,
706 6, 20, 8, 4, 10, 11, 12, 13, 14, 15,
707 3, 17, 6, 19, 8, 21, 4, 11, 10, 13,
708 14, 15, 20, 18, 21, 17, 17, 19, 18, 18,
709 60, 18, 18
712 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
713 symbol of state STATE-NUM. */
714 static const yytype_uint8 yystos[] =
716 0, 23, 0, 5, 6, 7, 8, 9, 11, 12,
717 13, 14, 15, 16, 17, 18, 24, 25, 26, 27,
718 28, 29, 30, 31, 32, 20, 4, 18, 4, 6,
719 8, 11, 13, 14, 15, 5, 6, 8, 10, 11,
720 12, 13, 14, 15, 17, 19, 21, 3, 20, 17,
721 18, 17, 18, 18, 18, 10, 17, 19, 33, 21,
722 18, 18, 17, 33
725 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
726 static const yytype_uint8 yyr1[] =
728 0, 22, 23, 23, 24, 24, 24, 24, 24, 24,
729 24, 25, 25, 25, 25, 25, 26, 26, 27, 27,
730 27, 28, 28, 28, 29, 29, 29, 29, 29, 29,
731 29, 29, 30, 30, 31, 31, 31, 31, 31, 31,
732 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
733 31, 31, 32, 33, 33
736 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
737 static const yytype_uint8 yyr2[] =
739 0, 2, 0, 2, 1, 1, 1, 1, 1, 1,
740 1, 2, 4, 4, 6, 6, 1, 2, 1, 1,
741 2, 1, 2, 2, 3, 5, 3, 3, 2, 4,
742 2, 3, 2, 1, 2, 2, 1, 2, 2, 1,
743 2, 2, 1, 2, 2, 1, 2, 2, 1, 2,
744 2, 1, 1, 0, 1
748 #define yyerrok (yyerrstatus = 0)
749 #define yyclearin (yychar = YYEMPTY)
750 #define YYEMPTY (-2)
751 #define YYEOF 0
753 #define YYACCEPT goto yyacceptlab
754 #define YYABORT goto yyabortlab
755 #define YYERROR goto yyerrorlab
758 #define YYRECOVERING() (!!yyerrstatus)
760 #define YYBACKUP(Token, Value) \
761 do \
762 if (yychar == YYEMPTY) \
764 yychar = (Token); \
765 yylval = (Value); \
766 YYPOPSTACK (yylen); \
767 yystate = *yyssp; \
768 goto yybackup; \
770 else \
772 yyerror (pc, YY_("syntax error: cannot back up")); \
773 YYERROR; \
775 while (0)
777 /* Error token number */
778 #define YYTERROR 1
779 #define YYERRCODE 256
783 /* Enable debugging if requested. */
784 #if YYDEBUG
786 # ifndef YYFPRINTF
787 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
788 # define YYFPRINTF fprintf
789 # endif
791 # define YYDPRINTF(Args) \
792 do { \
793 if (yydebug) \
794 YYFPRINTF Args; \
795 } while (0)
797 /* This macro is provided for backward compatibility. */
798 #ifndef YY_LOCATION_PRINT
799 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
800 #endif
803 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
804 do { \
805 if (yydebug) \
807 YYFPRINTF (stderr, "%s ", Title); \
808 yy_symbol_print (stderr, \
809 Type, Value, pc); \
810 YYFPRINTF (stderr, "\n"); \
812 } while (0)
815 /*----------------------------------------.
816 | Print this symbol's value on YYOUTPUT. |
817 `----------------------------------------*/
819 static void
820 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, struct parser_control *pc)
822 FILE *yyo = yyoutput;
823 YYUSE (yyo);
824 YYUSE (pc);
825 if (!yyvaluep)
826 return;
827 # ifdef YYPRINT
828 if (yytype < YYNTOKENS)
829 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
830 # endif
831 YYUSE (yytype);
835 /*--------------------------------.
836 | Print this symbol on YYOUTPUT. |
837 `--------------------------------*/
839 static void
840 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, struct parser_control *pc)
842 YYFPRINTF (yyoutput, "%s %s (",
843 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
845 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
846 YYFPRINTF (yyoutput, ")");
849 /*------------------------------------------------------------------.
850 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
851 | TOP (included). |
852 `------------------------------------------------------------------*/
854 static void
855 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
857 YYFPRINTF (stderr, "Stack now");
858 for (; yybottom <= yytop; yybottom++)
860 int yybot = *yybottom;
861 YYFPRINTF (stderr, " %d", yybot);
863 YYFPRINTF (stderr, "\n");
866 # define YY_STACK_PRINT(Bottom, Top) \
867 do { \
868 if (yydebug) \
869 yy_stack_print ((Bottom), (Top)); \
870 } while (0)
873 /*------------------------------------------------.
874 | Report that the YYRULE is going to be reduced. |
875 `------------------------------------------------*/
877 static void
878 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, struct parser_control *pc)
880 unsigned long int yylno = yyrline[yyrule];
881 int yynrhs = yyr2[yyrule];
882 int yyi;
883 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
884 yyrule - 1, yylno);
885 /* The symbols being reduced. */
886 for (yyi = 0; yyi < yynrhs; yyi++)
888 YYFPRINTF (stderr, " $%d = ", yyi + 1);
889 yy_symbol_print (stderr,
890 yystos[yyssp[yyi + 1 - yynrhs]],
891 &(yyvsp[(yyi + 1) - (yynrhs)])
892 , pc);
893 YYFPRINTF (stderr, "\n");
897 # define YY_REDUCE_PRINT(Rule) \
898 do { \
899 if (yydebug) \
900 yy_reduce_print (yyssp, yyvsp, Rule, pc); \
901 } while (0)
903 /* Nonzero means print parse trace. It is left uninitialized so that
904 multiple parsers can coexist. */
905 int yydebug;
906 #else /* !YYDEBUG */
907 # define YYDPRINTF(Args)
908 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
909 # define YY_STACK_PRINT(Bottom, Top)
910 # define YY_REDUCE_PRINT(Rule)
911 #endif /* !YYDEBUG */
914 /* YYINITDEPTH -- initial size of the parser's stacks. */
915 #ifndef YYINITDEPTH
916 # define YYINITDEPTH 200
917 #endif
919 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
920 if the built-in stack extension method is used).
922 Do not make this value too large; the results are undefined if
923 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
924 evaluated with infinite-precision integer arithmetic. */
926 #ifndef YYMAXDEPTH
927 # define YYMAXDEPTH 10000
928 #endif
931 #if YYERROR_VERBOSE
933 # ifndef yystrlen
934 # if defined __GLIBC__ && defined _STRING_H
935 # define yystrlen strlen
936 # else
937 /* Return the length of YYSTR. */
938 static YYSIZE_T
939 yystrlen (const char *yystr)
941 YYSIZE_T yylen;
942 for (yylen = 0; yystr[yylen]; yylen++)
943 continue;
944 return yylen;
946 # endif
947 # endif
949 # ifndef yystpcpy
950 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
951 # define yystpcpy stpcpy
952 # else
953 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
954 YYDEST. */
955 static char *
956 yystpcpy (char *yydest, const char *yysrc)
958 char *yyd = yydest;
959 const char *yys = yysrc;
961 while ((*yyd++ = *yys++) != '\0')
962 continue;
964 return yyd - 1;
966 # endif
967 # endif
969 # ifndef yytnamerr
970 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
971 quotes and backslashes, so that it's suitable for yyerror. The
972 heuristic is that double-quoting is unnecessary unless the string
973 contains an apostrophe, a comma, or backslash (other than
974 backslash-backslash). YYSTR is taken from yytname. If YYRES is
975 null, do not copy; instead, return the length of what the result
976 would have been. */
977 static YYSIZE_T
978 yytnamerr (char *yyres, const char *yystr)
980 if (*yystr == '"')
982 YYSIZE_T yyn = 0;
983 char const *yyp = yystr;
985 for (;;)
986 switch (*++yyp)
988 case '\'':
989 case ',':
990 goto do_not_strip_quotes;
992 case '\\':
993 if (*++yyp != '\\')
994 goto do_not_strip_quotes;
995 /* Fall through. */
996 default:
997 if (yyres)
998 yyres[yyn] = *yyp;
999 yyn++;
1000 break;
1002 case '"':
1003 if (yyres)
1004 yyres[yyn] = '\0';
1005 return yyn;
1007 do_not_strip_quotes: ;
1010 if (! yyres)
1011 return yystrlen (yystr);
1013 return yystpcpy (yyres, yystr) - yyres;
1015 # endif
1017 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1018 about the unexpected token YYTOKEN for the state stack whose top is
1019 YYSSP.
1021 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1022 not large enough to hold the message. In that case, also set
1023 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1024 required number of bytes is too large to store. */
1025 static int
1026 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1027 yytype_int16 *yyssp, int yytoken)
1029 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1030 YYSIZE_T yysize = yysize0;
1031 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1032 /* Internationalized format string. */
1033 const char *yyformat = YY_NULLPTR;
1034 /* Arguments of yyformat. */
1035 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1036 /* Number of reported tokens (one for the "unexpected", one per
1037 "expected"). */
1038 int yycount = 0;
1040 /* There are many possibilities here to consider:
1041 - If this state is a consistent state with a default action, then
1042 the only way this function was invoked is if the default action
1043 is an error action. In that case, don't check for expected
1044 tokens because there are none.
1045 - The only way there can be no lookahead present (in yychar) is if
1046 this state is a consistent state with a default action. Thus,
1047 detecting the absence of a lookahead is sufficient to determine
1048 that there is no unexpected or expected token to report. In that
1049 case, just report a simple "syntax error".
1050 - Don't assume there isn't a lookahead just because this state is a
1051 consistent state with a default action. There might have been a
1052 previous inconsistent state, consistent state with a non-default
1053 action, or user semantic action that manipulated yychar.
1054 - Of course, the expected token list depends on states to have
1055 correct lookahead information, and it depends on the parser not
1056 to perform extra reductions after fetching a lookahead from the
1057 scanner and before detecting a syntax error. Thus, state merging
1058 (from LALR or IELR) and default reductions corrupt the expected
1059 token list. However, the list is correct for canonical LR with
1060 one exception: it will still contain any token that will not be
1061 accepted due to an error action in a later state.
1063 if (yytoken != YYEMPTY)
1065 int yyn = yypact[*yyssp];
1066 yyarg[yycount++] = yytname[yytoken];
1067 if (!yypact_value_is_default (yyn))
1069 /* Start YYX at -YYN if negative to avoid negative indexes in
1070 YYCHECK. In other words, skip the first -YYN actions for
1071 this state because they are default actions. */
1072 int yyxbegin = yyn < 0 ? -yyn : 0;
1073 /* Stay within bounds of both yycheck and yytname. */
1074 int yychecklim = YYLAST - yyn + 1;
1075 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1076 int yyx;
1078 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1079 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1080 && !yytable_value_is_error (yytable[yyx + yyn]))
1082 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1084 yycount = 1;
1085 yysize = yysize0;
1086 break;
1088 yyarg[yycount++] = yytname[yyx];
1090 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1091 if (! (yysize <= yysize1
1092 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1093 return 2;
1094 yysize = yysize1;
1100 switch (yycount)
1102 # define YYCASE_(N, S) \
1103 case N: \
1104 yyformat = S; \
1105 break
1106 YYCASE_(0, YY_("syntax error"));
1107 YYCASE_(1, YY_("syntax error, unexpected %s"));
1108 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1109 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1110 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1111 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1112 # undef YYCASE_
1116 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1117 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1118 return 2;
1119 yysize = yysize1;
1122 if (*yymsg_alloc < yysize)
1124 *yymsg_alloc = 2 * yysize;
1125 if (! (yysize <= *yymsg_alloc
1126 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1127 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1128 return 1;
1131 /* Avoid sprintf, as that infringes on the user's name space.
1132 Don't have undefined behavior even if the translation
1133 produced a string with the wrong number of "%s"s. */
1135 char *yyp = *yymsg;
1136 int yyi = 0;
1137 while ((*yyp = *yyformat) != '\0')
1138 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1140 yyp += yytnamerr (yyp, yyarg[yyi++]);
1141 yyformat += 2;
1143 else
1145 yyp++;
1146 yyformat++;
1149 return 0;
1151 #endif /* YYERROR_VERBOSE */
1153 /*-----------------------------------------------.
1154 | Release the memory associated to this symbol. |
1155 `-----------------------------------------------*/
1157 static void
1158 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, struct parser_control *pc)
1160 YYUSE (yyvaluep);
1161 YYUSE (pc);
1162 if (!yymsg)
1163 yymsg = "Deleting";
1164 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1166 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1167 YYUSE (yytype);
1168 YY_IGNORE_MAYBE_UNINITIALIZED_END
1174 /*----------.
1175 | yyparse. |
1176 `----------*/
1179 yyparse (struct parser_control *pc)
1181 /* The lookahead symbol. */
1182 int yychar;
1185 /* The semantic value of the lookahead symbol. */
1186 /* Default value used for initialization, for pacifying older GCCs
1187 or non-GCC compilers. */
1188 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1189 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1191 /* Number of syntax errors so far. */
1192 int yynerrs;
1194 int yystate;
1195 /* Number of tokens to shift before error messages enabled. */
1196 int yyerrstatus;
1198 /* The stacks and their tools:
1199 'yyss': related to states.
1200 'yyvs': related to semantic values.
1202 Refer to the stacks through separate pointers, to allow yyoverflow
1203 to reallocate them elsewhere. */
1205 /* The state stack. */
1206 yytype_int16 yyssa[YYINITDEPTH];
1207 yytype_int16 *yyss;
1208 yytype_int16 *yyssp;
1210 /* The semantic value stack. */
1211 YYSTYPE yyvsa[YYINITDEPTH];
1212 YYSTYPE *yyvs;
1213 YYSTYPE *yyvsp;
1215 YYSIZE_T yystacksize;
1217 int yyn;
1218 int yyresult;
1219 /* Lookahead token as an internal (translated) token number. */
1220 int yytoken = 0;
1221 /* The variables used to return semantic value and location from the
1222 action routines. */
1223 YYSTYPE yyval;
1225 #if YYERROR_VERBOSE
1226 /* Buffer for error messages, and its allocated size. */
1227 char yymsgbuf[128];
1228 char *yymsg = yymsgbuf;
1229 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1230 #endif
1232 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1234 /* The number of symbols on the RHS of the reduced rule.
1235 Keep to zero when no symbol should be popped. */
1236 int yylen = 0;
1238 yyssp = yyss = yyssa;
1239 yyvsp = yyvs = yyvsa;
1240 yystacksize = YYINITDEPTH;
1242 YYDPRINTF ((stderr, "Starting parse\n"));
1244 yystate = 0;
1245 yyerrstatus = 0;
1246 yynerrs = 0;
1247 yychar = YYEMPTY; /* Cause a token to be read. */
1248 goto yysetstate;
1250 /*------------------------------------------------------------.
1251 | yynewstate -- Push a new state, which is found in yystate. |
1252 `------------------------------------------------------------*/
1253 yynewstate:
1254 /* In all cases, when you get here, the value and location stacks
1255 have just been pushed. So pushing a state here evens the stacks. */
1256 yyssp++;
1258 yysetstate:
1259 *yyssp = yystate;
1261 if (yyss + yystacksize - 1 <= yyssp)
1263 /* Get the current used size of the three stacks, in elements. */
1264 YYSIZE_T yysize = yyssp - yyss + 1;
1266 #ifdef yyoverflow
1268 /* Give user a chance to reallocate the stack. Use copies of
1269 these so that the &'s don't force the real ones into
1270 memory. */
1271 YYSTYPE *yyvs1 = yyvs;
1272 yytype_int16 *yyss1 = yyss;
1274 /* Each stack pointer address is followed by the size of the
1275 data in use in that stack, in bytes. This used to be a
1276 conditional around just the two extra args, but that might
1277 be undefined if yyoverflow is a macro. */
1278 yyoverflow (YY_("memory exhausted"),
1279 &yyss1, yysize * sizeof (*yyssp),
1280 &yyvs1, yysize * sizeof (*yyvsp),
1281 &yystacksize);
1283 yyss = yyss1;
1284 yyvs = yyvs1;
1286 #else /* no yyoverflow */
1287 # ifndef YYSTACK_RELOCATE
1288 goto yyexhaustedlab;
1289 # else
1290 /* Extend the stack our own way. */
1291 if (YYMAXDEPTH <= yystacksize)
1292 goto yyexhaustedlab;
1293 yystacksize *= 2;
1294 if (YYMAXDEPTH < yystacksize)
1295 yystacksize = YYMAXDEPTH;
1298 yytype_int16 *yyss1 = yyss;
1299 union yyalloc *yyptr =
1300 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1301 if (! yyptr)
1302 goto yyexhaustedlab;
1303 YYSTACK_RELOCATE (yyss_alloc, yyss);
1304 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1305 # undef YYSTACK_RELOCATE
1306 if (yyss1 != yyssa)
1307 YYSTACK_FREE (yyss1);
1309 # endif
1310 #endif /* no yyoverflow */
1312 yyssp = yyss + yysize - 1;
1313 yyvsp = yyvs + yysize - 1;
1315 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1316 (unsigned long int) yystacksize));
1318 if (yyss + yystacksize - 1 <= yyssp)
1319 YYABORT;
1322 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1324 if (yystate == YYFINAL)
1325 YYACCEPT;
1327 goto yybackup;
1329 /*-----------.
1330 | yybackup. |
1331 `-----------*/
1332 yybackup:
1334 /* Do appropriate processing given the current state. Read a
1335 lookahead token if we need one and don't already have one. */
1337 /* First try to decide what to do without reference to lookahead token. */
1338 yyn = yypact[yystate];
1339 if (yypact_value_is_default (yyn))
1340 goto yydefault;
1342 /* Not known => get a lookahead token if don't already have one. */
1344 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1345 if (yychar == YYEMPTY)
1347 YYDPRINTF ((stderr, "Reading a token: "));
1348 yychar = yylex (&yylval, pc);
1351 if (yychar <= YYEOF)
1353 yychar = yytoken = YYEOF;
1354 YYDPRINTF ((stderr, "Now at end of input.\n"));
1356 else
1358 yytoken = YYTRANSLATE (yychar);
1359 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1362 /* If the proper action on seeing token YYTOKEN is to reduce or to
1363 detect an error, take that action. */
1364 yyn += yytoken;
1365 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1366 goto yydefault;
1367 yyn = yytable[yyn];
1368 if (yyn <= 0)
1370 if (yytable_value_is_error (yyn))
1371 goto yyerrlab;
1372 yyn = -yyn;
1373 goto yyreduce;
1376 /* Count tokens shifted since error; after three, turn off error
1377 status. */
1378 if (yyerrstatus)
1379 yyerrstatus--;
1381 /* Shift the lookahead token. */
1382 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1384 /* Discard the shifted token. */
1385 yychar = YYEMPTY;
1387 yystate = yyn;
1388 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1389 *++yyvsp = yylval;
1390 YY_IGNORE_MAYBE_UNINITIALIZED_END
1392 goto yynewstate;
1395 /*-----------------------------------------------------------.
1396 | yydefault -- do the default action for the current state. |
1397 `-----------------------------------------------------------*/
1398 yydefault:
1399 yyn = yydefact[yystate];
1400 if (yyn == 0)
1401 goto yyerrlab;
1402 goto yyreduce;
1405 /*-----------------------------.
1406 | yyreduce -- Do a reduction. |
1407 `-----------------------------*/
1408 yyreduce:
1409 /* yyn is the number of a rule to reduce with. */
1410 yylen = yyr2[yyn];
1412 /* If YYLEN is nonzero, implement the default value of the action:
1413 '$$ = $1'.
1415 Otherwise, the following line sets YYVAL to garbage.
1416 This behavior is undocumented and Bison
1417 users should not rely upon it. Assigning to YYVAL
1418 unconditionally makes the parser a bit smaller, and it avoids a
1419 GCC warning that YYVAL may be used uninitialized. */
1420 yyval = yyvsp[1-yylen];
1423 YY_REDUCE_PRINT (yyn);
1424 switch (yyn)
1426 case 4:
1427 #line 198 "source3/modules/getdate.y" /* yacc.c:1646 */
1428 { pc->times_seen++; }
1429 #line 1430 "source3/modules/getdate.c" /* yacc.c:1646 */
1430 break;
1432 case 5:
1433 #line 200 "source3/modules/getdate.y" /* yacc.c:1646 */
1434 { pc->local_zones_seen++; }
1435 #line 1436 "source3/modules/getdate.c" /* yacc.c:1646 */
1436 break;
1438 case 6:
1439 #line 202 "source3/modules/getdate.y" /* yacc.c:1646 */
1440 { pc->zones_seen++; }
1441 #line 1442 "source3/modules/getdate.c" /* yacc.c:1646 */
1442 break;
1444 case 7:
1445 #line 204 "source3/modules/getdate.y" /* yacc.c:1646 */
1446 { pc->dates_seen++; }
1447 #line 1448 "source3/modules/getdate.c" /* yacc.c:1646 */
1448 break;
1450 case 8:
1451 #line 206 "source3/modules/getdate.y" /* yacc.c:1646 */
1452 { pc->days_seen++; }
1453 #line 1454 "source3/modules/getdate.c" /* yacc.c:1646 */
1454 break;
1456 case 9:
1457 #line 208 "source3/modules/getdate.y" /* yacc.c:1646 */
1458 { pc->rels_seen++; }
1459 #line 1460 "source3/modules/getdate.c" /* yacc.c:1646 */
1460 break;
1462 case 11:
1463 #line 214 "source3/modules/getdate.y" /* yacc.c:1646 */
1465 pc->hour = (yyvsp[-1].textintval).value;
1466 pc->minutes = 0;
1467 pc->seconds = 0;
1468 pc->meridian = (yyvsp[0].intval);
1470 #line 1471 "source3/modules/getdate.c" /* yacc.c:1646 */
1471 break;
1473 case 12:
1474 #line 221 "source3/modules/getdate.y" /* yacc.c:1646 */
1476 pc->hour = (yyvsp[-3].textintval).value;
1477 pc->minutes = (yyvsp[-1].textintval).value;
1478 pc->seconds = 0;
1479 pc->meridian = (yyvsp[0].intval);
1481 #line 1482 "source3/modules/getdate.c" /* yacc.c:1646 */
1482 break;
1484 case 13:
1485 #line 228 "source3/modules/getdate.y" /* yacc.c:1646 */
1487 pc->hour = (yyvsp[-3].textintval).value;
1488 pc->minutes = (yyvsp[-1].textintval).value;
1489 pc->meridian = MER24;
1490 pc->zones_seen++;
1491 pc->time_zone = (yyvsp[0].textintval).value % 100 + ((yyvsp[0].textintval).value / 100) * 60;
1493 #line 1494 "source3/modules/getdate.c" /* yacc.c:1646 */
1494 break;
1496 case 14:
1497 #line 236 "source3/modules/getdate.y" /* yacc.c:1646 */
1499 pc->hour = (yyvsp[-5].textintval).value;
1500 pc->minutes = (yyvsp[-3].textintval).value;
1501 pc->seconds = (yyvsp[-1].textintval).value;
1502 pc->meridian = (yyvsp[0].intval);
1504 #line 1505 "source3/modules/getdate.c" /* yacc.c:1646 */
1505 break;
1507 case 15:
1508 #line 243 "source3/modules/getdate.y" /* yacc.c:1646 */
1510 pc->hour = (yyvsp[-5].textintval).value;
1511 pc->minutes = (yyvsp[-3].textintval).value;
1512 pc->seconds = (yyvsp[-1].textintval).value;
1513 pc->meridian = MER24;
1514 pc->zones_seen++;
1515 pc->time_zone = (yyvsp[0].textintval).value % 100 + ((yyvsp[0].textintval).value / 100) * 60;
1517 #line 1518 "source3/modules/getdate.c" /* yacc.c:1646 */
1518 break;
1520 case 16:
1521 #line 255 "source3/modules/getdate.y" /* yacc.c:1646 */
1522 { pc->local_isdst = (yyvsp[0].intval); }
1523 #line 1524 "source3/modules/getdate.c" /* yacc.c:1646 */
1524 break;
1526 case 17:
1527 #line 257 "source3/modules/getdate.y" /* yacc.c:1646 */
1528 { pc->local_isdst = (yyvsp[-1].intval) < 0 ? 1 : (yyvsp[-1].intval) + 1; }
1529 #line 1530 "source3/modules/getdate.c" /* yacc.c:1646 */
1530 break;
1532 case 18:
1533 #line 262 "source3/modules/getdate.y" /* yacc.c:1646 */
1534 { pc->time_zone = (yyvsp[0].intval); }
1535 #line 1536 "source3/modules/getdate.c" /* yacc.c:1646 */
1536 break;
1538 case 19:
1539 #line 264 "source3/modules/getdate.y" /* yacc.c:1646 */
1540 { pc->time_zone = (yyvsp[0].intval) + 60; }
1541 #line 1542 "source3/modules/getdate.c" /* yacc.c:1646 */
1542 break;
1544 case 20:
1545 #line 266 "source3/modules/getdate.y" /* yacc.c:1646 */
1546 { pc->time_zone = (yyvsp[-1].intval) + 60; }
1547 #line 1548 "source3/modules/getdate.c" /* yacc.c:1646 */
1548 break;
1550 case 21:
1551 #line 271 "source3/modules/getdate.y" /* yacc.c:1646 */
1553 pc->day_ordinal = 1;
1554 pc->day_number = (yyvsp[0].intval);
1556 #line 1557 "source3/modules/getdate.c" /* yacc.c:1646 */
1557 break;
1559 case 22:
1560 #line 276 "source3/modules/getdate.y" /* yacc.c:1646 */
1562 pc->day_ordinal = 1;
1563 pc->day_number = (yyvsp[-1].intval);
1565 #line 1566 "source3/modules/getdate.c" /* yacc.c:1646 */
1566 break;
1568 case 23:
1569 #line 281 "source3/modules/getdate.y" /* yacc.c:1646 */
1571 pc->day_ordinal = (yyvsp[-1].textintval).value;
1572 pc->day_number = (yyvsp[0].intval);
1574 #line 1575 "source3/modules/getdate.c" /* yacc.c:1646 */
1575 break;
1577 case 24:
1578 #line 289 "source3/modules/getdate.y" /* yacc.c:1646 */
1580 pc->month = (yyvsp[-2].textintval).value;
1581 pc->day = (yyvsp[0].textintval).value;
1583 #line 1584 "source3/modules/getdate.c" /* yacc.c:1646 */
1584 break;
1586 case 25:
1587 #line 294 "source3/modules/getdate.y" /* yacc.c:1646 */
1589 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1590 otherwise as MM/DD/YY.
1591 The goal in recognizing YYYY/MM/DD is solely to support legacy
1592 machine-generated dates like those in an RCS log listing. If
1593 you want portability, use the ISO 8601 format. */
1594 if (4 <= (yyvsp[-4].textintval).digits)
1596 pc->year = (yyvsp[-4].textintval);
1597 pc->month = (yyvsp[-2].textintval).value;
1598 pc->day = (yyvsp[0].textintval).value;
1600 else
1602 pc->month = (yyvsp[-4].textintval).value;
1603 pc->day = (yyvsp[-2].textintval).value;
1604 pc->year = (yyvsp[0].textintval);
1607 #line 1608 "source3/modules/getdate.c" /* yacc.c:1646 */
1608 break;
1610 case 26:
1611 #line 314 "source3/modules/getdate.y" /* yacc.c:1646 */
1613 /* ISO 8601 format. YYYY-MM-DD. */
1614 pc->year = (yyvsp[-2].textintval);
1615 pc->month = -(yyvsp[-1].textintval).value;
1616 pc->day = -(yyvsp[0].textintval).value;
1618 #line 1619 "source3/modules/getdate.c" /* yacc.c:1646 */
1619 break;
1621 case 27:
1622 #line 321 "source3/modules/getdate.y" /* yacc.c:1646 */
1624 /* e.g. 17-JUN-1992. */
1625 pc->day = (yyvsp[-2].textintval).value;
1626 pc->month = (yyvsp[-1].intval);
1627 pc->year.value = -(yyvsp[0].textintval).value;
1628 pc->year.digits = (yyvsp[0].textintval).digits;
1630 #line 1631 "source3/modules/getdate.c" /* yacc.c:1646 */
1631 break;
1633 case 28:
1634 #line 329 "source3/modules/getdate.y" /* yacc.c:1646 */
1636 pc->month = (yyvsp[-1].intval);
1637 pc->day = (yyvsp[0].textintval).value;
1639 #line 1640 "source3/modules/getdate.c" /* yacc.c:1646 */
1640 break;
1642 case 29:
1643 #line 334 "source3/modules/getdate.y" /* yacc.c:1646 */
1645 pc->month = (yyvsp[-3].intval);
1646 pc->day = (yyvsp[-2].textintval).value;
1647 pc->year = (yyvsp[0].textintval);
1649 #line 1650 "source3/modules/getdate.c" /* yacc.c:1646 */
1650 break;
1652 case 30:
1653 #line 340 "source3/modules/getdate.y" /* yacc.c:1646 */
1655 pc->day = (yyvsp[-1].textintval).value;
1656 pc->month = (yyvsp[0].intval);
1658 #line 1659 "source3/modules/getdate.c" /* yacc.c:1646 */
1659 break;
1661 case 31:
1662 #line 345 "source3/modules/getdate.y" /* yacc.c:1646 */
1664 pc->day = (yyvsp[-2].textintval).value;
1665 pc->month = (yyvsp[-1].intval);
1666 pc->year = (yyvsp[0].textintval);
1668 #line 1669 "source3/modules/getdate.c" /* yacc.c:1646 */
1669 break;
1671 case 32:
1672 #line 354 "source3/modules/getdate.y" /* yacc.c:1646 */
1674 pc->rel_seconds = -pc->rel_seconds;
1675 pc->rel_minutes = -pc->rel_minutes;
1676 pc->rel_hour = -pc->rel_hour;
1677 pc->rel_day = -pc->rel_day;
1678 pc->rel_month = -pc->rel_month;
1679 pc->rel_year = -pc->rel_year;
1681 #line 1682 "source3/modules/getdate.c" /* yacc.c:1646 */
1682 break;
1684 case 34:
1685 #line 367 "source3/modules/getdate.y" /* yacc.c:1646 */
1686 { pc->rel_year += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1687 #line 1688 "source3/modules/getdate.c" /* yacc.c:1646 */
1688 break;
1690 case 35:
1691 #line 369 "source3/modules/getdate.y" /* yacc.c:1646 */
1692 { pc->rel_year += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1693 #line 1694 "source3/modules/getdate.c" /* yacc.c:1646 */
1694 break;
1696 case 36:
1697 #line 371 "source3/modules/getdate.y" /* yacc.c:1646 */
1698 { pc->rel_year += (yyvsp[0].intval); }
1699 #line 1700 "source3/modules/getdate.c" /* yacc.c:1646 */
1700 break;
1702 case 37:
1703 #line 373 "source3/modules/getdate.y" /* yacc.c:1646 */
1704 { pc->rel_month += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1705 #line 1706 "source3/modules/getdate.c" /* yacc.c:1646 */
1706 break;
1708 case 38:
1709 #line 375 "source3/modules/getdate.y" /* yacc.c:1646 */
1710 { pc->rel_month += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1711 #line 1712 "source3/modules/getdate.c" /* yacc.c:1646 */
1712 break;
1714 case 39:
1715 #line 377 "source3/modules/getdate.y" /* yacc.c:1646 */
1716 { pc->rel_month += (yyvsp[0].intval); }
1717 #line 1718 "source3/modules/getdate.c" /* yacc.c:1646 */
1718 break;
1720 case 40:
1721 #line 379 "source3/modules/getdate.y" /* yacc.c:1646 */
1722 { pc->rel_day += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1723 #line 1724 "source3/modules/getdate.c" /* yacc.c:1646 */
1724 break;
1726 case 41:
1727 #line 381 "source3/modules/getdate.y" /* yacc.c:1646 */
1728 { pc->rel_day += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1729 #line 1730 "source3/modules/getdate.c" /* yacc.c:1646 */
1730 break;
1732 case 42:
1733 #line 383 "source3/modules/getdate.y" /* yacc.c:1646 */
1734 { pc->rel_day += (yyvsp[0].intval); }
1735 #line 1736 "source3/modules/getdate.c" /* yacc.c:1646 */
1736 break;
1738 case 43:
1739 #line 385 "source3/modules/getdate.y" /* yacc.c:1646 */
1740 { pc->rel_hour += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1741 #line 1742 "source3/modules/getdate.c" /* yacc.c:1646 */
1742 break;
1744 case 44:
1745 #line 387 "source3/modules/getdate.y" /* yacc.c:1646 */
1746 { pc->rel_hour += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1747 #line 1748 "source3/modules/getdate.c" /* yacc.c:1646 */
1748 break;
1750 case 45:
1751 #line 389 "source3/modules/getdate.y" /* yacc.c:1646 */
1752 { pc->rel_hour += (yyvsp[0].intval); }
1753 #line 1754 "source3/modules/getdate.c" /* yacc.c:1646 */
1754 break;
1756 case 46:
1757 #line 391 "source3/modules/getdate.y" /* yacc.c:1646 */
1758 { pc->rel_minutes += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1759 #line 1760 "source3/modules/getdate.c" /* yacc.c:1646 */
1760 break;
1762 case 47:
1763 #line 393 "source3/modules/getdate.y" /* yacc.c:1646 */
1764 { pc->rel_minutes += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1765 #line 1766 "source3/modules/getdate.c" /* yacc.c:1646 */
1766 break;
1768 case 48:
1769 #line 395 "source3/modules/getdate.y" /* yacc.c:1646 */
1770 { pc->rel_minutes += (yyvsp[0].intval); }
1771 #line 1772 "source3/modules/getdate.c" /* yacc.c:1646 */
1772 break;
1774 case 49:
1775 #line 397 "source3/modules/getdate.y" /* yacc.c:1646 */
1776 { pc->rel_seconds += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1777 #line 1778 "source3/modules/getdate.c" /* yacc.c:1646 */
1778 break;
1780 case 50:
1781 #line 399 "source3/modules/getdate.y" /* yacc.c:1646 */
1782 { pc->rel_seconds += (yyvsp[-1].textintval).value * (yyvsp[0].intval); }
1783 #line 1784 "source3/modules/getdate.c" /* yacc.c:1646 */
1784 break;
1786 case 51:
1787 #line 401 "source3/modules/getdate.y" /* yacc.c:1646 */
1788 { pc->rel_seconds += (yyvsp[0].intval); }
1789 #line 1790 "source3/modules/getdate.c" /* yacc.c:1646 */
1790 break;
1792 case 52:
1793 #line 406 "source3/modules/getdate.y" /* yacc.c:1646 */
1795 if (pc->dates_seen
1796 && ! pc->rels_seen && (pc->times_seen || 2 < (yyvsp[0].textintval).digits))
1797 pc->year = (yyvsp[0].textintval);
1798 else
1800 if (4 < (yyvsp[0].textintval).digits)
1802 pc->dates_seen++;
1803 pc->day = (yyvsp[0].textintval).value % 100;
1804 pc->month = ((yyvsp[0].textintval).value / 100) % 100;
1805 pc->year.value = (yyvsp[0].textintval).value / 10000;
1806 pc->year.digits = (yyvsp[0].textintval).digits - 4;
1808 else
1810 pc->times_seen++;
1811 if ((yyvsp[0].textintval).digits <= 2)
1813 pc->hour = (yyvsp[0].textintval).value;
1814 pc->minutes = 0;
1816 else
1818 pc->hour = (yyvsp[0].textintval).value / 100;
1819 pc->minutes = (yyvsp[0].textintval).value % 100;
1821 pc->seconds = 0;
1822 pc->meridian = MER24;
1826 #line 1827 "source3/modules/getdate.c" /* yacc.c:1646 */
1827 break;
1829 case 53:
1830 #line 442 "source3/modules/getdate.y" /* yacc.c:1646 */
1831 { (yyval.intval) = MER24; }
1832 #line 1833 "source3/modules/getdate.c" /* yacc.c:1646 */
1833 break;
1835 case 54:
1836 #line 444 "source3/modules/getdate.y" /* yacc.c:1646 */
1837 { (yyval.intval) = (yyvsp[0].intval); }
1838 #line 1839 "source3/modules/getdate.c" /* yacc.c:1646 */
1839 break;
1842 #line 1843 "source3/modules/getdate.c" /* yacc.c:1646 */
1843 default: break;
1845 /* User semantic actions sometimes alter yychar, and that requires
1846 that yytoken be updated with the new translation. We take the
1847 approach of translating immediately before every use of yytoken.
1848 One alternative is translating here after every semantic action,
1849 but that translation would be missed if the semantic action invokes
1850 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1851 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1852 incorrect destructor might then be invoked immediately. In the
1853 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1854 to an incorrect destructor call or verbose syntax error message
1855 before the lookahead is translated. */
1856 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1858 YYPOPSTACK (yylen);
1859 yylen = 0;
1860 YY_STACK_PRINT (yyss, yyssp);
1862 *++yyvsp = yyval;
1864 /* Now 'shift' the result of the reduction. Determine what state
1865 that goes to, based on the state we popped back to and the rule
1866 number reduced by. */
1868 yyn = yyr1[yyn];
1870 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1871 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1872 yystate = yytable[yystate];
1873 else
1874 yystate = yydefgoto[yyn - YYNTOKENS];
1876 goto yynewstate;
1879 /*--------------------------------------.
1880 | yyerrlab -- here on detecting error. |
1881 `--------------------------------------*/
1882 yyerrlab:
1883 /* Make sure we have latest lookahead translation. See comments at
1884 user semantic actions for why this is necessary. */
1885 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1887 /* If not already recovering from an error, report this error. */
1888 if (!yyerrstatus)
1890 ++yynerrs;
1891 #if ! YYERROR_VERBOSE
1892 yyerror (pc, YY_("syntax error"));
1893 #else
1894 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1895 yyssp, yytoken)
1897 char const *yymsgp = YY_("syntax error");
1898 int yysyntax_error_status;
1899 yysyntax_error_status = YYSYNTAX_ERROR;
1900 if (yysyntax_error_status == 0)
1901 yymsgp = yymsg;
1902 else if (yysyntax_error_status == 1)
1904 if (yymsg != yymsgbuf)
1905 YYSTACK_FREE (yymsg);
1906 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1907 if (!yymsg)
1909 yymsg = yymsgbuf;
1910 yymsg_alloc = sizeof yymsgbuf;
1911 yysyntax_error_status = 2;
1913 else
1915 yysyntax_error_status = YYSYNTAX_ERROR;
1916 yymsgp = yymsg;
1919 yyerror (pc, yymsgp);
1920 if (yysyntax_error_status == 2)
1921 goto yyexhaustedlab;
1923 # undef YYSYNTAX_ERROR
1924 #endif
1929 if (yyerrstatus == 3)
1931 /* If just tried and failed to reuse lookahead token after an
1932 error, discard it. */
1934 if (yychar <= YYEOF)
1936 /* Return failure if at end of input. */
1937 if (yychar == YYEOF)
1938 YYABORT;
1940 else
1942 yydestruct ("Error: discarding",
1943 yytoken, &yylval, pc);
1944 yychar = YYEMPTY;
1948 /* Else will try to reuse lookahead token after shifting the error
1949 token. */
1950 goto yyerrlab1;
1953 /*---------------------------------------------------.
1954 | yyerrorlab -- error raised explicitly by YYERROR. |
1955 `---------------------------------------------------*/
1956 yyerrorlab:
1958 /* Pacify compilers like GCC when the user code never invokes
1959 YYERROR and the label yyerrorlab therefore never appears in user
1960 code. */
1961 if (/*CONSTCOND*/ 0)
1962 goto yyerrorlab;
1964 /* Do not reclaim the symbols of the rule whose action triggered
1965 this YYERROR. */
1966 YYPOPSTACK (yylen);
1967 yylen = 0;
1968 YY_STACK_PRINT (yyss, yyssp);
1969 yystate = *yyssp;
1970 goto yyerrlab1;
1973 /*-------------------------------------------------------------.
1974 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1975 `-------------------------------------------------------------*/
1976 yyerrlab1:
1977 yyerrstatus = 3; /* Each real token shifted decrements this. */
1979 for (;;)
1981 yyn = yypact[yystate];
1982 if (!yypact_value_is_default (yyn))
1984 yyn += YYTERROR;
1985 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1987 yyn = yytable[yyn];
1988 if (0 < yyn)
1989 break;
1993 /* Pop the current state because it cannot handle the error token. */
1994 if (yyssp == yyss)
1995 YYABORT;
1998 yydestruct ("Error: popping",
1999 yystos[yystate], yyvsp, pc);
2000 YYPOPSTACK (1);
2001 yystate = *yyssp;
2002 YY_STACK_PRINT (yyss, yyssp);
2005 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2006 *++yyvsp = yylval;
2007 YY_IGNORE_MAYBE_UNINITIALIZED_END
2010 /* Shift the error token. */
2011 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2013 yystate = yyn;
2014 goto yynewstate;
2017 /*-------------------------------------.
2018 | yyacceptlab -- YYACCEPT comes here. |
2019 `-------------------------------------*/
2020 yyacceptlab:
2021 yyresult = 0;
2022 goto yyreturn;
2024 /*-----------------------------------.
2025 | yyabortlab -- YYABORT comes here. |
2026 `-----------------------------------*/
2027 yyabortlab:
2028 yyresult = 1;
2029 goto yyreturn;
2031 #if !defined yyoverflow || YYERROR_VERBOSE
2032 /*-------------------------------------------------.
2033 | yyexhaustedlab -- memory exhaustion comes here. |
2034 `-------------------------------------------------*/
2035 yyexhaustedlab:
2036 yyerror (pc, YY_("memory exhausted"));
2037 yyresult = 2;
2038 /* Fall through. */
2039 #endif
2041 yyreturn:
2042 if (yychar != YYEMPTY)
2044 /* Make sure we have latest lookahead translation. See comments at
2045 user semantic actions for why this is necessary. */
2046 yytoken = YYTRANSLATE (yychar);
2047 yydestruct ("Cleanup: discarding lookahead",
2048 yytoken, &yylval, pc);
2050 /* Do not reclaim the symbols of the rule whose action triggered
2051 this YYABORT or YYACCEPT. */
2052 YYPOPSTACK (yylen);
2053 YY_STACK_PRINT (yyss, yyssp);
2054 while (yyssp != yyss)
2056 yydestruct ("Cleanup: popping",
2057 yystos[*yyssp], yyvsp, pc);
2058 YYPOPSTACK (1);
2060 #ifndef yyoverflow
2061 if (yyss != yyssa)
2062 YYSTACK_FREE (yyss);
2063 #endif
2064 #if YYERROR_VERBOSE
2065 if (yymsg != yymsgbuf)
2066 YYSTACK_FREE (yymsg);
2067 #endif
2068 return yyresult;
2070 #line 447 "source3/modules/getdate.y" /* yacc.c:1906 */
2073 /* Include this file down here because bison inserts code above which
2074 may define-away `const'. We want the prototype for get_date to have
2075 the same signature as the function definition. */
2076 #include "modules/getdate.h"
2078 #ifndef gmtime
2079 struct tm *gmtime (const time_t *);
2080 #endif
2081 #ifndef localtime
2082 struct tm *localtime (const time_t *);
2083 #endif
2084 #ifndef mktime
2085 time_t mktime (struct tm *);
2086 #endif
2088 static table const meridian_table[] =
2090 { "AM", tMERIDIAN, MERam },
2091 { "A.M.", tMERIDIAN, MERam },
2092 { "PM", tMERIDIAN, MERpm },
2093 { "P.M.", tMERIDIAN, MERpm },
2094 { 0, 0, 0 }
2097 static table const dst_table[] =
2099 { "DST", tDST, 0 }
2102 static table const month_and_day_table[] =
2104 { "JANUARY", tMONTH, 1 },
2105 { "FEBRUARY", tMONTH, 2 },
2106 { "MARCH", tMONTH, 3 },
2107 { "APRIL", tMONTH, 4 },
2108 { "MAY", tMONTH, 5 },
2109 { "JUNE", tMONTH, 6 },
2110 { "JULY", tMONTH, 7 },
2111 { "AUGUST", tMONTH, 8 },
2112 { "SEPTEMBER",tMONTH, 9 },
2113 { "SEPT", tMONTH, 9 },
2114 { "OCTOBER", tMONTH, 10 },
2115 { "NOVEMBER", tMONTH, 11 },
2116 { "DECEMBER", tMONTH, 12 },
2117 { "SUNDAY", tDAY, 0 },
2118 { "MONDAY", tDAY, 1 },
2119 { "TUESDAY", tDAY, 2 },
2120 { "TUES", tDAY, 2 },
2121 { "WEDNESDAY",tDAY, 3 },
2122 { "WEDNES", tDAY, 3 },
2123 { "THURSDAY", tDAY, 4 },
2124 { "THUR", tDAY, 4 },
2125 { "THURS", tDAY, 4 },
2126 { "FRIDAY", tDAY, 5 },
2127 { "SATURDAY", tDAY, 6 },
2128 { 0, 0, 0 }
2131 static table const time_units_table[] =
2133 { "YEAR", tYEAR_UNIT, 1 },
2134 { "MONTH", tMONTH_UNIT, 1 },
2135 { "FORTNIGHT",tDAY_UNIT, 14 },
2136 { "WEEK", tDAY_UNIT, 7 },
2137 { "DAY", tDAY_UNIT, 1 },
2138 { "HOUR", tHOUR_UNIT, 1 },
2139 { "MINUTE", tMINUTE_UNIT, 1 },
2140 { "MIN", tMINUTE_UNIT, 1 },
2141 { "SECOND", tSEC_UNIT, 1 },
2142 { "SEC", tSEC_UNIT, 1 },
2143 { 0, 0, 0 }
2146 /* Assorted relative-time words. */
2147 static table const relative_time_table[] =
2149 { "TOMORROW", tMINUTE_UNIT, 24 * 60 },
2150 { "YESTERDAY",tMINUTE_UNIT, - (24 * 60) },
2151 { "TODAY", tMINUTE_UNIT, 0 },
2152 { "NOW", tMINUTE_UNIT, 0 },
2153 { "LAST", tUNUMBER, -1 },
2154 { "THIS", tUNUMBER, 0 },
2155 { "NEXT", tUNUMBER, 1 },
2156 { "FIRST", tUNUMBER, 1 },
2157 /*{ "SECOND", tUNUMBER, 2 }, */
2158 { "THIRD", tUNUMBER, 3 },
2159 { "FOURTH", tUNUMBER, 4 },
2160 { "FIFTH", tUNUMBER, 5 },
2161 { "SIXTH", tUNUMBER, 6 },
2162 { "SEVENTH", tUNUMBER, 7 },
2163 { "EIGHTH", tUNUMBER, 8 },
2164 { "NINTH", tUNUMBER, 9 },
2165 { "TENTH", tUNUMBER, 10 },
2166 { "ELEVENTH", tUNUMBER, 11 },
2167 { "TWELFTH", tUNUMBER, 12 },
2168 { "AGO", tAGO, 1 },
2169 { 0, 0, 0 }
2172 /* The time zone table. This table is necessarily incomplete, as time
2173 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2174 as Eastern time in Australia, not as US Eastern Standard Time.
2175 You cannot rely on getdate to handle arbitrary time zone
2176 abbreviations; use numeric abbreviations like `-0500' instead. */
2177 static table const time_zone_table[] =
2179 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2180 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2181 { "UTC", tZONE, HOUR ( 0) },
2182 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2183 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2184 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2185 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2186 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2187 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2188 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2189 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2190 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2191 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2192 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2193 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2194 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2195 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2196 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2197 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2198 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2199 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2200 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2201 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2202 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2203 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2204 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2205 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2206 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2207 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2208 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2209 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2210 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2211 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2212 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2213 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2214 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2215 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2216 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2217 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2218 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2219 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2220 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2221 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2222 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2223 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2224 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2225 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2226 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2227 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2228 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2229 { 0, 0, 0 }
2232 /* Military time zone table. */
2233 static table const military_table[] =
2235 { "A", tZONE, -HOUR ( 1) },
2236 { "B", tZONE, -HOUR ( 2) },
2237 { "C", tZONE, -HOUR ( 3) },
2238 { "D", tZONE, -HOUR ( 4) },
2239 { "E", tZONE, -HOUR ( 5) },
2240 { "F", tZONE, -HOUR ( 6) },
2241 { "G", tZONE, -HOUR ( 7) },
2242 { "H", tZONE, -HOUR ( 8) },
2243 { "I", tZONE, -HOUR ( 9) },
2244 { "K", tZONE, -HOUR (10) },
2245 { "L", tZONE, -HOUR (11) },
2246 { "M", tZONE, -HOUR (12) },
2247 { "N", tZONE, HOUR ( 1) },
2248 { "O", tZONE, HOUR ( 2) },
2249 { "P", tZONE, HOUR ( 3) },
2250 { "Q", tZONE, HOUR ( 4) },
2251 { "R", tZONE, HOUR ( 5) },
2252 { "S", tZONE, HOUR ( 6) },
2253 { "T", tZONE, HOUR ( 7) },
2254 { "U", tZONE, HOUR ( 8) },
2255 { "V", tZONE, HOUR ( 9) },
2256 { "W", tZONE, HOUR (10) },
2257 { "X", tZONE, HOUR (11) },
2258 { "Y", tZONE, HOUR (12) },
2259 { "Z", tZONE, HOUR ( 0) },
2260 { 0, 0, 0 }
2265 static int
2266 to_hour (int hours, int meridian)
2268 switch (meridian)
2270 case MER24:
2271 return 0 <= hours && hours < 24 ? hours : -1;
2272 case MERam:
2273 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2274 case MERpm:
2275 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2276 default:
2277 abort ();
2279 /* NOTREACHED */
2280 return 0;
2283 static int
2284 to_year (textint textyear)
2286 int year = textyear.value;
2288 if (year < 0)
2289 year = -year;
2291 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2292 years 69-99 map to 1969-1999. */
2293 if (textyear.digits == 2)
2294 year += year < 69 ? 2000 : 1900;
2296 return year;
2299 static table const *
2300 lookup_zone (struct parser_control const *pc, char const *name)
2302 table const *tp;
2304 /* Try local zone abbreviations first; they're more likely to be right. */
2305 for (tp = pc->local_time_zone_table; tp->name; tp++)
2306 if (strcmp (name, tp->name) == 0)
2307 return tp;
2309 for (tp = time_zone_table; tp->name; tp++)
2310 if (strcmp (name, tp->name) == 0)
2311 return tp;
2313 return 0;
2316 #if ! HAVE_TM_GMTOFF
2317 /* Yield the difference between *A and *B,
2318 measured in seconds, ignoring leap seconds.
2319 The body of this function is taken directly from the GNU C Library;
2320 see src/strftime.c. */
2321 static int
2322 tm_diff (struct tm const *a, struct tm const *b)
2324 /* Compute intervening leap days correctly even if year is negative.
2325 Take care to avoid int overflow in leap day calculations,
2326 but it's OK to assume that A and B are close to each other. */
2327 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
2328 int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
2329 int a100 = a4 / 25 - (a4 % 25 < 0);
2330 int b100 = b4 / 25 - (b4 % 25 < 0);
2331 int a400 = a100 >> 2;
2332 int b400 = b100 >> 2;
2333 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2334 int years = a->tm_year - b->tm_year;
2335 int days = (365 * years + intervening_leap_days
2336 + (a->tm_yday - b->tm_yday));
2337 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2338 + (a->tm_min - b->tm_min))
2339 + (a->tm_sec - b->tm_sec));
2341 #endif /* ! HAVE_TM_GMTOFF */
2343 static table const *
2344 lookup_word (struct parser_control const *pc, char *word)
2346 char *p;
2347 char *q;
2348 size_t wordlen;
2349 table const *tp;
2350 int i;
2351 int abbrev;
2353 /* Make it uppercase. */
2354 for (p = word; *p; p++)
2355 if (ISLOWER ((unsigned char) *p))
2356 *p = toupper ((unsigned char) *p);
2358 for (tp = meridian_table; tp->name; tp++)
2359 if (strcmp (word, tp->name) == 0)
2360 return tp;
2362 /* See if we have an abbreviation for a month. */
2363 wordlen = strlen (word);
2364 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2366 for (tp = month_and_day_table; tp->name; tp++)
2367 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2368 return tp;
2370 if ((tp = lookup_zone (pc, word)))
2371 return tp;
2373 if (strcmp (word, dst_table[0].name) == 0)
2374 return dst_table;
2376 for (tp = time_units_table; tp->name; tp++)
2377 if (strcmp (word, tp->name) == 0)
2378 return tp;
2380 /* Strip off any plural and try the units table again. */
2381 if (word[wordlen - 1] == 'S')
2383 word[wordlen - 1] = '\0';
2384 for (tp = time_units_table; tp->name; tp++)
2385 if (strcmp (word, tp->name) == 0)
2386 return tp;
2387 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
2390 for (tp = relative_time_table; tp->name; tp++)
2391 if (strcmp (word, tp->name) == 0)
2392 return tp;
2394 /* Military time zones. */
2395 if (wordlen == 1)
2396 for (tp = military_table; tp->name; tp++)
2397 if (word[0] == tp->name[0])
2398 return tp;
2400 /* Drop out any periods and try the time zone table again. */
2401 for (i = 0, p = q = word; (*p = *q); q++)
2402 if (*q == '.')
2403 i = 1;
2404 else
2405 p++;
2406 if (i && (tp = lookup_zone (pc, word)))
2407 return tp;
2409 return 0;
2412 static int
2413 yylex (YYSTYPE *lvalp, struct parser_control *pc)
2415 unsigned char c;
2416 size_t count;
2418 for (;;)
2420 while (c = *pc->input, ISSPACE (c))
2421 pc->input++;
2423 if (ISDIGIT (c) || c == '-' || c == '+')
2425 char const *p;
2426 int sign;
2427 int value;
2428 if (c == '-' || c == '+')
2430 sign = c == '-' ? -1 : 1;
2431 c = *++pc->input;
2432 if (! ISDIGIT (c))
2433 /* skip the '-' sign */
2434 continue;
2436 else
2437 sign = 0;
2438 p = pc->input;
2439 value = 0;
2442 value = 10 * value + c - '0';
2443 c = *++p;
2445 while (ISDIGIT (c));
2446 lvalp->textintval.value = sign < 0 ? -value : value;
2447 lvalp->textintval.digits = p - pc->input;
2448 pc->input = p;
2449 return sign ? tSNUMBER : tUNUMBER;
2452 if (ISALPHA (c))
2454 char buff[20];
2455 size_t i = 0;
2456 table const *tp;
2460 if (i < 20)
2461 buff[i++] = c;
2462 c = *++pc->input;
2464 while (ISALPHA (c) || c == '.');
2466 buff[i] = '\0';
2467 tp = lookup_word (pc, buff);
2468 if (! tp)
2469 return '?';
2470 lvalp->intval = tp->value;
2471 return tp->type;
2474 if (c != '(')
2475 return *pc->input++;
2476 count = 0;
2479 c = *pc->input++;
2480 if (c == '\0')
2481 return c;
2482 if (c == '(')
2483 count++;
2484 else if (c == ')')
2485 count--;
2487 while (count > 0);
2491 /* Do nothing if the parser reports an error. */
2492 static int
2493 yyerror (struct parser_control *pc ATTRIBUTE_UNUSED, const char *s ATTRIBUTE_UNUSED)
2495 return 0;
2498 /* Parse a date/time string P. Return the corresponding time_t value,
2499 or (time_t) -1 if there is an error. P can be an incomplete or
2500 relative time specification; if so, use *NOW as the basis for the
2501 returned time. */
2502 time_t
2503 get_date (const char *p, const time_t *now)
2505 time_t Start = now ? *now : time (0);
2506 struct tm *tmp = localtime (&Start);
2507 struct tm tm;
2508 struct tm tm0;
2509 struct parser_control pc;
2511 if (! tmp)
2512 return -1;
2514 pc.input = p;
2515 pc.year.value = tmp->tm_year + TM_YEAR_BASE;
2516 pc.year.digits = 4;
2517 pc.month = tmp->tm_mon + 1;
2518 pc.day = tmp->tm_mday;
2519 pc.hour = tmp->tm_hour;
2520 pc.minutes = tmp->tm_min;
2521 pc.seconds = tmp->tm_sec;
2522 tm.tm_isdst = tmp->tm_isdst;
2524 pc.meridian = MER24;
2525 pc.rel_seconds = 0;
2526 pc.rel_minutes = 0;
2527 pc.rel_hour = 0;
2528 pc.rel_day = 0;
2529 pc.rel_month = 0;
2530 pc.rel_year = 0;
2531 pc.dates_seen = 0;
2532 pc.days_seen = 0;
2533 pc.rels_seen = 0;
2534 pc.times_seen = 0;
2535 pc.local_zones_seen = 0;
2536 pc.zones_seen = 0;
2538 #ifdef HAVE_STRUCT_TM_TM_ZONE
2539 pc.local_time_zone_table[0].name = tmp->tm_zone;
2540 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
2541 pc.local_time_zone_table[0].value = tmp->tm_isdst;
2542 pc.local_time_zone_table[1].name = 0;
2544 /* Probe the names used in the next three calendar quarters, looking
2545 for a tm_isdst different from the one we already have. */
2547 int quarter;
2548 for (quarter = 1; quarter <= 3; quarter++)
2550 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
2551 struct tm *probe_tm = localtime (&probe);
2552 if (probe_tm && probe_tm->tm_zone
2553 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
2556 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
2557 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
2558 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
2559 pc.local_time_zone_table[2].name = 0;
2561 break;
2565 #else
2566 #ifdef HAVE_TZNAME
2568 # ifndef tzname
2569 extern char *tzname[];
2570 # endif
2571 int i;
2572 for (i = 0; i < 2; i++)
2574 pc.local_time_zone_table[i].name = tzname[i];
2575 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
2576 pc.local_time_zone_table[i].value = i;
2578 pc.local_time_zone_table[i].name = 0;
2580 #else
2581 pc.local_time_zone_table[0].name = 0;
2582 #endif
2583 #endif
2585 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
2586 && ! strcmp (pc.local_time_zone_table[0].name,
2587 pc.local_time_zone_table[1].name))
2589 /* This locale uses the same abbreviation for standard and
2590 daylight times. So if we see that abbreviation, we don't
2591 know whether it's daylight time. */
2592 pc.local_time_zone_table[0].value = -1;
2593 pc.local_time_zone_table[1].name = 0;
2596 if (yyparse (&pc) != 0
2597 || 1 < pc.times_seen || 1 < pc.dates_seen || 1 < pc.days_seen
2598 || 1 < (pc.local_zones_seen + pc.zones_seen)
2599 || (pc.local_zones_seen && 1 < pc.local_isdst))
2600 return -1;
2602 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE + pc.rel_year;
2603 tm.tm_mon = pc.month - 1 + pc.rel_month;
2604 tm.tm_mday = pc.day + pc.rel_day;
2605 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
2607 tm.tm_hour = to_hour (pc.hour, pc.meridian);
2608 if (tm.tm_hour < 0)
2609 return -1;
2610 tm.tm_min = pc.minutes;
2611 tm.tm_sec = pc.seconds;
2613 else
2615 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
2618 /* Let mktime deduce tm_isdst if we have an absolute time stamp,
2619 or if the relative time stamp mentions days, months, or years. */
2620 if (pc.dates_seen | pc.days_seen | pc.times_seen | pc.rel_day
2621 | pc.rel_month | pc.rel_year)
2622 tm.tm_isdst = -1;
2624 /* But if the input explicitly specifies local time with or without
2625 DST, give mktime that information. */
2626 if (pc.local_zones_seen)
2627 tm.tm_isdst = pc.local_isdst;
2629 tm0 = tm;
2631 Start = mktime (&tm);
2633 if (Start == (time_t) -1)
2636 /* Guard against falsely reporting errors near the time_t boundaries
2637 when parsing times in other time zones. For example, if the min
2638 time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
2639 of UTC, then the min localtime value is 1970-01-01 08:00:00; if
2640 we apply mktime to 1970-01-01 00:00:00 we will get an error, so
2641 we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
2642 zone by 24 hours to compensate. This algorithm assumes that
2643 there is no DST transition within a day of the time_t boundaries. */
2644 if (pc.zones_seen)
2646 tm = tm0;
2647 if (tm.tm_year <= EPOCH_YEAR - TM_YEAR_BASE)
2649 tm.tm_mday++;
2650 pc.time_zone += 24 * 60;
2652 else
2654 tm.tm_mday--;
2655 pc.time_zone -= 24 * 60;
2657 Start = mktime (&tm);
2660 if (Start == (time_t) -1)
2661 return Start;
2664 if (pc.days_seen && ! pc.dates_seen)
2666 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
2667 + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
2668 tm.tm_isdst = -1;
2669 Start = mktime (&tm);
2670 if (Start == (time_t) -1)
2671 return Start;
2674 if (pc.zones_seen)
2676 int delta = pc.time_zone * 60;
2677 #ifdef HAVE_TM_GMTOFF
2678 delta -= tm.tm_gmtoff;
2679 #else
2680 struct tm *gmt = gmtime (&Start);
2681 if (! gmt)
2682 return -1;
2683 delta -= tm_diff (&tm, gmt);
2684 #endif
2685 if ((Start < Start - delta) != (delta < 0))
2686 return -1; /* time_t overflow */
2687 Start -= delta;
2690 /* Add relative hours, minutes, and seconds. Ignore leap seconds;
2691 i.e. "+ 10 minutes" means 600 seconds, even if one of them is a
2692 leap second. Typically this is not what the user wants, but it's
2693 too hard to do it the other way, because the time zone indicator
2694 must be applied before relative times, and if mktime is applied
2695 again the time zone will be lost. */
2697 time_t t0 = Start;
2698 long d1 = 60 * 60 * (long) pc.rel_hour;
2699 time_t t1 = t0 + d1;
2700 long d2 = 60 * (long) pc.rel_minutes;
2701 time_t t2 = t1 + d2;
2702 int d3 = pc.rel_seconds;
2703 time_t t3 = t2 + d3;
2704 if ((d1 / (60 * 60) ^ pc.rel_hour)
2705 | (d2 / 60 ^ pc.rel_minutes)
2706 | ((t0 + d1 < t0) ^ (d1 < 0))
2707 | ((t1 + d2 < t1) ^ (d2 < 0))
2708 | ((t2 + d3 < t2) ^ (d3 < 0)))
2709 return -1;
2710 Start = t3;
2713 return Start;
2716 #if TEST
2718 #include <stdio.h>
2721 main (int ac, char **av)
2723 char buff[BUFSIZ];
2724 time_t d;
2726 printf ("Enter date, or blank line to exit.\n\t> ");
2727 fflush (stdout);
2729 buff[BUFSIZ - 1] = 0;
2730 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
2732 d = get_date (buff, 0);
2733 if (d == (time_t) -1)
2734 printf ("Bad format - couldn't convert.\n");
2735 else
2736 printf ("%s", ctime (&d));
2737 printf ("\t> ");
2738 fflush (stdout);
2740 return 0;
2742 #endif /* defined TEST */