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