Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/sudoers/getdate.c
1532 views
1
#include <config.h>
2
/* A Bison parser, made by GNU Bison 3.8.2. */
3
4
/* Bison implementation for Yacc-like parsers in C
5
6
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
7
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 <https://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
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
39
especially those whose name start with YY_ or yy_. They are
40
private implementation details that can be changed or removed. */
41
42
/* All symbols defined below should begin with yy or YY, to avoid
43
infringing on user name space. This should be done even for local
44
variables, as they might otherwise be expanded by user macros.
45
There are some unavoidable exceptions within include files to
46
define necessary library symbols; they are noted "INFRINGES ON
47
USER NAME SPACE" below. */
48
49
/* Identify Bison output, and Bison version. */
50
#define YYBISON 30802
51
52
/* Bison version string. */
53
#define YYBISON_VERSION "3.8.2"
54
55
/* Skeleton name. */
56
#define YYSKELETON_NAME "yacc.c"
57
58
/* Pure parsers. */
59
#define YYPURE 0
60
61
/* Push parsers. */
62
#define YYPUSH 0
63
64
/* Pull parsers. */
65
#define YYPULL 1
66
67
68
69
70
/* First part of user prologue. */
71
#line 1 "getdate.y"
72
73
/*
74
** Originally written by Steven M. Bellovin <[email protected]> while
75
** at the University of North Carolina at Chapel Hill. Later tweaked by
76
** a couple of people on Usenet. Completely overhauled by Rich $alz
77
** <[email protected]> and Jim Berets <[email protected]> in August, 1990;
78
**
79
** This grammar has 10 shift/reduce conflicts.
80
**
81
** This code is in the public domain and has no copyright.
82
*/
83
/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
84
/* SUPPRESS 288 on yyerrlab *//* Label unused */
85
86
// PVS Studio suppression
87
// -V::560, 592, 1037, 1042
88
89
#include <config.h>
90
91
#include <stdio.h>
92
#include <stdlib.h>
93
#include <string.h>
94
#if defined(HAVE_STDINT_H)
95
# include <stdint.h>
96
#elif defined(HAVE_INTTYPES_H)
97
# include <inttypes.h>
98
#endif
99
#include <time.h>
100
#include <limits.h>
101
#include <ctype.h>
102
103
#include <sudo_compat.h>
104
105
106
#define EPOCH 1970
107
#define HOUR(x) ((time_t)(x) * 60)
108
#define SECSPERDAY (24L * 60L * 60L)
109
110
111
/*
112
** An entry in the lexical lookup table.
113
*/
114
typedef struct _TABLE {
115
const char *name;
116
int type;
117
time_t value;
118
} TABLE;
119
120
121
/*
122
** Daylight-savings mode: on, off, or not yet known.
123
*/
124
typedef enum _DSTMODE {
125
DSTon, DSToff, DSTmaybe
126
} DSTMODE;
127
128
/*
129
** Meridian: am, pm, or 24-hour style.
130
*/
131
typedef enum _MERIDIAN {
132
MERam, MERpm, MER24
133
} MERIDIAN;
134
135
136
/*
137
** Global variables. We could get rid of most of these by using a good
138
** union as the yacc stack. (This routine was originally written before
139
** yacc had the %union construct.) Maybe someday; right now we only use
140
** the %union very rarely.
141
*/
142
static char *yyInput;
143
static DSTMODE yyDSTmode;
144
static time_t yyDayOrdinal;
145
static time_t yyDayNumber;
146
static int yyHaveDate;
147
static int yyHaveDay;
148
static int yyHaveRel;
149
static int yyHaveTime;
150
static int yyHaveZone;
151
static time_t yyTimezone;
152
static time_t yyDay;
153
static time_t yyHour;
154
static time_t yyMinutes;
155
static time_t yyMonth;
156
static time_t yySeconds;
157
static time_t yyYear;
158
static MERIDIAN yyMeridian;
159
static time_t yyRelMonth;
160
static time_t yyRelSeconds;
161
162
static int yylex(void);
163
int yyparse(void);
164
void yyerror(const char *s);
165
166
167
#line 167 "getdate.c"
168
169
# ifndef YY_CAST
170
# ifdef __cplusplus
171
# define YY_CAST(Type, Val) static_cast<Type> (Val)
172
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
173
# else
174
# define YY_CAST(Type, Val) ((Type) (Val))
175
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
176
# endif
177
# endif
178
# ifndef YY_NULLPTR
179
# if defined __cplusplus
180
# if 201103L <= __cplusplus
181
# define YY_NULLPTR nullptr
182
# else
183
# define YY_NULLPTR 0
184
# endif
185
# else
186
# define YY_NULLPTR ((void*)0)
187
# endif
188
# endif
189
190
191
/* Debug traces. */
192
#ifndef YYDEBUG
193
# define YYDEBUG 0
194
#endif
195
#if YYDEBUG
196
extern int yydebug;
197
#endif
198
199
/* Token kinds. */
200
#ifndef YYTOKENTYPE
201
# define YYTOKENTYPE
202
enum yytokentype
203
{
204
YYEMPTY = -2,
205
YYEOF = 0, /* "end of file" */
206
YYerror = 256, /* error */
207
YYUNDEF = 257, /* "invalid token" */
208
tAGO = 258, /* tAGO */
209
tID = 259, /* tID */
210
tDST = 260, /* tDST */
211
tDAY = 261, /* tDAY */
212
tDAYZONE = 262, /* tDAYZONE */
213
tMINUTE_UNIT = 263, /* tMINUTE_UNIT */
214
tMONTH = 264, /* tMONTH */
215
tMONTH_UNIT = 265, /* tMONTH_UNIT */
216
tSEC_UNIT = 266, /* tSEC_UNIT */
217
tSNUMBER = 267, /* tSNUMBER */
218
tUNUMBER = 268, /* tUNUMBER */
219
tZONE = 269, /* tZONE */
220
tMERIDIAN = 270 /* tMERIDIAN */
221
};
222
typedef enum yytokentype yytoken_kind_t;
223
#endif
224
/* Token kinds. */
225
#define YYEMPTY -2
226
#define YYEOF 0
227
#define YYerror 256
228
#define YYUNDEF 257
229
#define tAGO 258
230
#define tID 259
231
#define tDST 260
232
#define tDAY 261
233
#define tDAYZONE 262
234
#define tMINUTE_UNIT 263
235
#define tMONTH 264
236
#define tMONTH_UNIT 265
237
#define tSEC_UNIT 266
238
#define tSNUMBER 267
239
#define tUNUMBER 268
240
#define tZONE 269
241
#define tMERIDIAN 270
242
243
/* Value type. */
244
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
245
union YYSTYPE
246
{
247
#line 97 "getdate.y"
248
249
time_t Number;
250
enum _MERIDIAN Meridian;
251
252
#line 252 "getdate.c"
253
254
};
255
typedef union YYSTYPE YYSTYPE;
256
# define YYSTYPE_IS_TRIVIAL 1
257
# define YYSTYPE_IS_DECLARED 1
258
#endif
259
260
261
extern YYSTYPE yylval;
262
263
264
int yyparse (void);
265
266
267
268
/* Symbol kind. */
269
enum yysymbol_kind_t
270
{
271
YYSYMBOL_YYEMPTY = -2,
272
YYSYMBOL_YYEOF = 0, /* "end of file" */
273
YYSYMBOL_YYerror = 1, /* error */
274
YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
275
YYSYMBOL_tAGO = 3, /* tAGO */
276
YYSYMBOL_tID = 4, /* tID */
277
YYSYMBOL_tDST = 5, /* tDST */
278
YYSYMBOL_tDAY = 6, /* tDAY */
279
YYSYMBOL_tDAYZONE = 7, /* tDAYZONE */
280
YYSYMBOL_tMINUTE_UNIT = 8, /* tMINUTE_UNIT */
281
YYSYMBOL_tMONTH = 9, /* tMONTH */
282
YYSYMBOL_tMONTH_UNIT = 10, /* tMONTH_UNIT */
283
YYSYMBOL_tSEC_UNIT = 11, /* tSEC_UNIT */
284
YYSYMBOL_tSNUMBER = 12, /* tSNUMBER */
285
YYSYMBOL_tUNUMBER = 13, /* tUNUMBER */
286
YYSYMBOL_tZONE = 14, /* tZONE */
287
YYSYMBOL_tMERIDIAN = 15, /* tMERIDIAN */
288
YYSYMBOL_16_ = 16, /* ':' */
289
YYSYMBOL_17_ = 17, /* ',' */
290
YYSYMBOL_18_ = 18, /* '/' */
291
YYSYMBOL_YYACCEPT = 19, /* $accept */
292
YYSYMBOL_spec = 20, /* spec */
293
YYSYMBOL_item = 21, /* item */
294
YYSYMBOL_time = 22, /* time */
295
YYSYMBOL_zone = 23, /* zone */
296
YYSYMBOL_day = 24, /* day */
297
YYSYMBOL_date = 25, /* date */
298
YYSYMBOL_rel = 26, /* rel */
299
YYSYMBOL_relunit = 27, /* relunit */
300
YYSYMBOL_number = 28, /* number */
301
YYSYMBOL_o_merid = 29 /* o_merid */
302
};
303
typedef enum yysymbol_kind_t yysymbol_kind_t;
304
305
306
307
308
#ifdef short
309
# undef short
310
#endif
311
312
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
313
<limits.h> and (if available) <stdint.h> are included
314
so that the code can choose integer types of a good width. */
315
316
#ifndef __PTRDIFF_MAX__
317
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
318
# if defined HAVE_STDINT_H
319
# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
320
# define YY_STDINT_H
321
# endif
322
#endif
323
324
/* Narrow types that promote to a signed type and that can represent a
325
signed or unsigned integer of at least N bits. In tables they can
326
save space and decrease cache pressure. Promoting to a signed type
327
helps avoid bugs in integer arithmetic. */
328
329
#ifdef __INT_LEAST8_MAX__
330
typedef __INT_LEAST8_TYPE__ yytype_int8;
331
#elif defined YY_STDINT_H
332
typedef int_least8_t yytype_int8;
333
#else
334
typedef signed char yytype_int8;
335
#endif
336
337
#ifdef __INT_LEAST16_MAX__
338
typedef __INT_LEAST16_TYPE__ yytype_int16;
339
#elif defined YY_STDINT_H
340
typedef int_least16_t yytype_int16;
341
#else
342
typedef short yytype_int16;
343
#endif
344
345
/* Work around bug in HP-UX 11.23, which defines these macros
346
incorrectly for preprocessor constants. This workaround can likely
347
be removed in 2023, as HPE has promised support for HP-UX 11.23
348
(aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
349
<https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
350
#ifdef __hpux
351
# undef UINT_LEAST8_MAX
352
# undef UINT_LEAST16_MAX
353
# define UINT_LEAST8_MAX 255
354
# define UINT_LEAST16_MAX 65535
355
#endif
356
357
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
358
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
359
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
360
&& UINT_LEAST8_MAX <= INT_MAX)
361
typedef uint_least8_t yytype_uint8;
362
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
363
typedef unsigned char yytype_uint8;
364
#else
365
typedef short yytype_uint8;
366
#endif
367
368
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
369
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
370
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
371
&& UINT_LEAST16_MAX <= INT_MAX)
372
typedef uint_least16_t yytype_uint16;
373
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
374
typedef unsigned short yytype_uint16;
375
#else
376
typedef int yytype_uint16;
377
#endif
378
379
#ifndef YYPTRDIFF_T
380
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
381
# define YYPTRDIFF_T __PTRDIFF_TYPE__
382
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
383
# elif defined PTRDIFF_MAX
384
# ifndef ptrdiff_t
385
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
386
# endif
387
# define YYPTRDIFF_T ptrdiff_t
388
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
389
# else
390
# define YYPTRDIFF_T long
391
# define YYPTRDIFF_MAXIMUM LONG_MAX
392
# endif
393
#endif
394
395
#ifndef YYSIZE_T
396
# ifdef __SIZE_TYPE__
397
# define YYSIZE_T __SIZE_TYPE__
398
# elif defined size_t
399
# define YYSIZE_T size_t
400
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
401
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
402
# define YYSIZE_T size_t
403
# else
404
# define YYSIZE_T unsigned
405
# endif
406
#endif
407
408
#define YYSIZE_MAXIMUM \
409
YY_CAST (YYPTRDIFF_T, \
410
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
411
? YYPTRDIFF_MAXIMUM \
412
: YY_CAST (YYSIZE_T, -1)))
413
414
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
415
416
417
/* Stored state numbers (used for stacks). */
418
typedef yytype_int8 yy_state_t;
419
420
/* State numbers in computations. */
421
typedef int yy_state_fast_t;
422
423
#ifndef YY_
424
# if defined YYENABLE_NLS && YYENABLE_NLS
425
# if ENABLE_NLS
426
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
427
# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
428
# endif
429
# endif
430
# ifndef YY_
431
# define YY_(Msgid) Msgid
432
# endif
433
#endif
434
435
436
#ifndef YY_ATTRIBUTE_PURE
437
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
438
# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
439
# else
440
# define YY_ATTRIBUTE_PURE
441
# endif
442
#endif
443
444
#ifndef YY_ATTRIBUTE_UNUSED
445
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
446
# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
447
# else
448
# define YY_ATTRIBUTE_UNUSED
449
# endif
450
#endif
451
452
/* Suppress unused-variable warnings by "using" E. */
453
#if ! defined lint || defined __GNUC__
454
# define YY_USE(E) ((void) (E))
455
#else
456
# define YY_USE(E) /* empty */
457
#endif
458
459
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
460
#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
461
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
462
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
463
_Pragma ("GCC diagnostic push") \
464
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
465
# else
466
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
467
_Pragma ("GCC diagnostic push") \
468
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
469
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
470
# endif
471
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
472
_Pragma ("GCC diagnostic pop")
473
#else
474
# define YY_INITIAL_VALUE(Value) Value
475
#endif
476
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
477
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
478
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
479
#endif
480
#ifndef YY_INITIAL_VALUE
481
# define YY_INITIAL_VALUE(Value) /* Nothing. */
482
#endif
483
484
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
485
# define YY_IGNORE_USELESS_CAST_BEGIN \
486
_Pragma ("GCC diagnostic push") \
487
_Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
488
# define YY_IGNORE_USELESS_CAST_END \
489
_Pragma ("GCC diagnostic pop")
490
#endif
491
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
492
# define YY_IGNORE_USELESS_CAST_BEGIN
493
# define YY_IGNORE_USELESS_CAST_END
494
#endif
495
496
497
#define YY_ASSERT(E) ((void) (0 && (E)))
498
499
#if !defined yyoverflow
500
501
/* The parser invokes alloca or malloc; define the necessary symbols. */
502
503
# ifdef YYSTACK_USE_ALLOCA
504
# if YYSTACK_USE_ALLOCA
505
# ifdef __GNUC__
506
# define YYSTACK_ALLOC __builtin_alloca
507
# elif defined __BUILTIN_VA_ARG_INCR
508
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
509
# elif defined _AIX
510
# define YYSTACK_ALLOC __alloca
511
# elif defined _MSC_VER
512
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
513
# define alloca _alloca
514
# else
515
# define YYSTACK_ALLOC alloca
516
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
517
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
518
/* Use EXIT_SUCCESS as a witness for stdlib.h. */
519
# ifndef EXIT_SUCCESS
520
# define EXIT_SUCCESS 0
521
# endif
522
# endif
523
# endif
524
# endif
525
# endif
526
527
# ifdef YYSTACK_ALLOC
528
/* Pacify GCC's 'empty if-body' warning. */
529
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
530
# ifndef YYSTACK_ALLOC_MAXIMUM
531
/* The OS might guarantee only one guard page at the bottom of the stack,
532
and a page size can be as small as 4096 bytes. So we cannot safely
533
invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
534
to allow for a few compiler-allocated temporary stack slots. */
535
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
536
# endif
537
# else
538
# define YYSTACK_ALLOC YYMALLOC
539
# define YYSTACK_FREE YYFREE
540
# ifndef YYSTACK_ALLOC_MAXIMUM
541
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
542
# endif
543
# if (defined __cplusplus && ! defined EXIT_SUCCESS \
544
&& ! ((defined YYMALLOC || defined malloc) \
545
&& (defined YYFREE || defined free)))
546
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
547
# ifndef EXIT_SUCCESS
548
# define EXIT_SUCCESS 0
549
# endif
550
# endif
551
# ifndef YYMALLOC
552
# define YYMALLOC malloc
553
# if ! defined malloc && ! defined EXIT_SUCCESS
554
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
555
# endif
556
# endif
557
# ifndef YYFREE
558
# define YYFREE free
559
# if ! defined free && ! defined EXIT_SUCCESS
560
void free (void *); /* INFRINGES ON USER NAME SPACE */
561
# endif
562
# endif
563
# endif
564
#endif /* !defined yyoverflow */
565
566
#if (! defined yyoverflow \
567
&& (! defined __cplusplus \
568
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
569
570
/* A type that is properly aligned for any stack member. */
571
union yyalloc
572
{
573
yy_state_t yyss_alloc;
574
YYSTYPE yyvs_alloc;
575
};
576
577
/* The size of the maximum gap between one aligned stack and the next. */
578
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
579
580
/* The size of an array large to enough to hold all stacks, each with
581
N elements. */
582
# define YYSTACK_BYTES(N) \
583
((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
584
+ YYSTACK_GAP_MAXIMUM)
585
586
# define YYCOPY_NEEDED 1
587
588
/* Relocate STACK from its old location to the new one. The
589
local variables YYSIZE and YYSTACKSIZE give the old and new number of
590
elements in the stack, and YYPTR gives the new location of the
591
stack. Advance YYPTR to a properly aligned location for the next
592
stack. */
593
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
594
do \
595
{ \
596
YYPTRDIFF_T yynewbytes; \
597
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
598
Stack = &yyptr->Stack_alloc; \
599
yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
600
yyptr += yynewbytes / YYSIZEOF (*yyptr); \
601
} \
602
while (0)
603
604
#endif
605
606
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
607
/* Copy COUNT objects from SRC to DST. The source and destination do
608
not overlap. */
609
# ifndef YYCOPY
610
# if defined __GNUC__ && 1 < __GNUC__
611
# define YYCOPY(Dst, Src, Count) \
612
__builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
613
# else
614
# define YYCOPY(Dst, Src, Count) \
615
do \
616
{ \
617
YYPTRDIFF_T yyi; \
618
for (yyi = 0; yyi < (Count); yyi++) \
619
(Dst)[yyi] = (Src)[yyi]; \
620
} \
621
while (0)
622
# endif
623
# endif
624
#endif /* !YYCOPY_NEEDED */
625
626
/* YYFINAL -- State number of the termination state. */
627
#define YYFINAL 2
628
/* YYLAST -- Last index in YYTABLE. */
629
#define YYLAST 41
630
631
/* YYNTOKENS -- Number of terminals. */
632
#define YYNTOKENS 19
633
/* YYNNTS -- Number of nonterminals. */
634
#define YYNNTS 11
635
/* YYNRULES -- Number of rules. */
636
#define YYNRULES 42
637
/* YYNSTATES -- Number of states. */
638
#define YYNSTATES 52
639
640
/* YYMAXUTOK -- Last valid token kind. */
641
#define YYMAXUTOK 270
642
643
644
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
645
as returned by yylex, with out-of-bounds checking. */
646
#define YYTRANSLATE(YYX) \
647
(0 <= (YYX) && (YYX) <= YYMAXUTOK \
648
? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
649
: YYSYMBOL_YYUNDEF)
650
651
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
652
as returned by yylex. */
653
static const yytype_int8 yytranslate[] =
654
{
655
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
656
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
657
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
658
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
659
2, 2, 2, 2, 17, 2, 2, 18, 2, 2,
660
2, 2, 2, 2, 2, 2, 2, 2, 16, 2,
661
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
662
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
663
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
664
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
665
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
666
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
667
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
668
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
669
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
670
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
671
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
672
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
673
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
674
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
675
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
676
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
677
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
678
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
679
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
680
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
681
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
682
15
683
};
684
685
#if YYDEBUG
686
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
687
static const yytype_int16 yyrline[] =
688
{
689
0, 111, 111, 112, 115, 118, 121, 124, 127, 130,
690
133, 139, 145, 152, 158, 168, 172, 177, 183, 187,
691
191, 197, 201, 212, 218, 224, 228, 233, 237, 244,
692
248, 251, 254, 257, 260, 263, 266, 269, 272, 275,
693
280, 307, 310
694
};
695
#endif
696
697
/** Accessing symbol of state STATE. */
698
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
699
700
#if YYDEBUG || 0
701
/* The user-facing name of the symbol whose (internal) number is
702
YYSYMBOL. No bounds checking. */
703
static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
704
705
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
706
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
707
static const char *const yytname[] =
708
{
709
"\"end of file\"", "error", "\"invalid token\"", "tAGO", "tID", "tDST",
710
"tDAY", "tDAYZONE", "tMINUTE_UNIT", "tMONTH", "tMONTH_UNIT", "tSEC_UNIT",
711
"tSNUMBER", "tUNUMBER", "tZONE", "tMERIDIAN", "':'", "','", "'/'",
712
"$accept", "spec", "item", "time", "zone", "day", "date", "rel",
713
"relunit", "number", "o_merid", YY_NULLPTR
714
};
715
716
static const char *
717
yysymbol_name (yysymbol_kind_t yysymbol)
718
{
719
return yytname[yysymbol];
720
}
721
#endif
722
723
#define YYPACT_NINF (-12)
724
725
#define yypact_value_is_default(Yyn) \
726
((Yyn) == YYPACT_NINF)
727
728
#define YYTABLE_NINF (-1)
729
730
#define yytable_value_is_error(Yyn) \
731
0
732
733
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
734
STATE-NUM. */
735
static const yytype_int8 yypact[] =
736
{
737
-12, 0, -12, -1, -12, -12, 10, -12, -12, 18,
738
9, 17, -12, -12, -12, -12, -12, -12, 27, -12,
739
-12, 15, -12, -12, -12, -12, -12, -10, -12, -12,
740
21, -12, 22, 23, -12, -12, 24, -12, -12, -12,
741
-11, 20, -12, -12, -12, 26, -12, 28, 19, -12,
742
-12, -12
743
};
744
745
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
746
Performed when YYTABLE does not specify something else to do. Zero
747
means the default is an error. */
748
static const yytype_int8 yydefact[] =
749
{
750
2, 0, 1, 18, 16, 33, 0, 39, 36, 0,
751
40, 15, 3, 4, 5, 7, 6, 8, 30, 9,
752
19, 25, 32, 37, 34, 20, 31, 27, 38, 35,
753
0, 10, 0, 0, 17, 29, 0, 24, 28, 23,
754
41, 21, 26, 12, 42, 0, 11, 0, 41, 22,
755
14, 13
756
};
757
758
/* YYPGOTO[NTERM-NUM]. */
759
static const yytype_int8 yypgoto[] =
760
{
761
-12, -12, -12, -12, -12, -12, -12, -12, -12, -12,
762
-8
763
};
764
765
/* YYDEFGOTO[NTERM-NUM]. */
766
static const yytype_int8 yydefgoto[] =
767
{
768
0, 1, 12, 13, 14, 15, 16, 17, 18, 19,
769
46
770
};
771
772
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
773
positive, shift that token. If negative, reduce the rule whose
774
number is the opposite. If YYTABLE_NINF, syntax error. */
775
static const yytype_int8 yytable[] =
776
{
777
2, 43, 37, 38, 44, 45, 3, 4, 5, 6,
778
7, 8, 9, 10, 11, 25, 20, 26, 27, 28,
779
29, 30, 34, 21, 31, 32, 22, 33, 23, 24,
780
35, 50, 36, 39, 44, 40, 41, 42, 47, 48,
781
51, 49
782
};
783
784
static const yytype_int8 yycheck[] =
785
{
786
0, 12, 12, 13, 15, 16, 6, 7, 8, 9,
787
10, 11, 12, 13, 14, 6, 17, 8, 9, 10,
788
11, 12, 5, 13, 15, 16, 8, 18, 10, 11,
789
3, 12, 17, 12, 15, 13, 13, 13, 18, 13,
790
48, 13
791
};
792
793
/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
794
state STATE-NUM. */
795
static const yytype_int8 yystos[] =
796
{
797
0, 20, 0, 6, 7, 8, 9, 10, 11, 12,
798
13, 14, 21, 22, 23, 24, 25, 26, 27, 28,
799
17, 13, 8, 10, 11, 6, 8, 9, 10, 11,
800
12, 15, 16, 18, 5, 3, 17, 12, 13, 12,
801
13, 13, 13, 12, 15, 16, 29, 18, 13, 13,
802
12, 29
803
};
804
805
/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
806
static const yytype_int8 yyr1[] =
807
{
808
0, 19, 20, 20, 21, 21, 21, 21, 21, 21,
809
22, 22, 22, 22, 22, 23, 23, 23, 24, 24,
810
24, 25, 25, 25, 25, 25, 25, 25, 25, 26,
811
26, 27, 27, 27, 27, 27, 27, 27, 27, 27,
812
28, 29, 29
813
};
814
815
/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
816
static const yytype_int8 yyr2[] =
817
{
818
0, 2, 0, 2, 1, 1, 1, 1, 1, 1,
819
2, 4, 4, 6, 6, 1, 1, 2, 1, 2,
820
2, 3, 5, 3, 3, 2, 4, 2, 3, 2,
821
1, 2, 2, 1, 2, 2, 1, 2, 2, 1,
822
1, 0, 1
823
};
824
825
826
enum { YYENOMEM = -2 };
827
828
#define yyerrok (yyerrstatus = 0)
829
#define yyclearin (yychar = YYEMPTY)
830
831
#define YYACCEPT goto yyacceptlab
832
#define YYABORT goto yyabortlab
833
#define YYERROR goto yyerrorlab
834
#define YYNOMEM goto yyexhaustedlab
835
836
837
#define YYRECOVERING() (!!yyerrstatus)
838
839
#define YYBACKUP(Token, Value) \
840
do \
841
if (yychar == YYEMPTY) \
842
{ \
843
yychar = (Token); \
844
yylval = (Value); \
845
YYPOPSTACK (yylen); \
846
yystate = *yyssp; \
847
goto yybackup; \
848
} \
849
else \
850
{ \
851
yyerror (YY_("syntax error: cannot back up")); \
852
YYERROR; \
853
} \
854
while (0)
855
856
/* Backward compatibility with an undocumented macro.
857
Use YYerror or YYUNDEF. */
858
#define YYERRCODE YYUNDEF
859
860
861
/* Enable debugging if requested. */
862
#if YYDEBUG
863
864
# ifndef YYFPRINTF
865
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
866
# define YYFPRINTF fprintf
867
# endif
868
869
# define YYDPRINTF(Args) \
870
do { \
871
if (yydebug) \
872
YYFPRINTF Args; \
873
} while (0)
874
875
876
877
878
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
879
do { \
880
if (yydebug) \
881
{ \
882
YYFPRINTF (stderr, "%s ", Title); \
883
yy_symbol_print (stderr, \
884
Kind, Value); \
885
YYFPRINTF (stderr, "\n"); \
886
} \
887
} while (0)
888
889
890
/*-----------------------------------.
891
| Print this symbol's value on YYO. |
892
`-----------------------------------*/
893
894
static void
895
yy_symbol_value_print (FILE *yyo,
896
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
897
{
898
FILE *yyoutput = yyo;
899
YY_USE (yyoutput);
900
if (!yyvaluep)
901
return;
902
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
903
YY_USE (yykind);
904
YY_IGNORE_MAYBE_UNINITIALIZED_END
905
}
906
907
908
/*---------------------------.
909
| Print this symbol on YYO. |
910
`---------------------------*/
911
912
static void
913
yy_symbol_print (FILE *yyo,
914
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
915
{
916
YYFPRINTF (yyo, "%s %s (",
917
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
918
919
yy_symbol_value_print (yyo, yykind, yyvaluep);
920
YYFPRINTF (yyo, ")");
921
}
922
923
/*------------------------------------------------------------------.
924
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
925
| TOP (included). |
926
`------------------------------------------------------------------*/
927
928
static void
929
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
930
{
931
YYFPRINTF (stderr, "Stack now");
932
for (; yybottom <= yytop; yybottom++)
933
{
934
int yybot = *yybottom;
935
YYFPRINTF (stderr, " %d", yybot);
936
}
937
YYFPRINTF (stderr, "\n");
938
}
939
940
# define YY_STACK_PRINT(Bottom, Top) \
941
do { \
942
if (yydebug) \
943
yy_stack_print ((Bottom), (Top)); \
944
} while (0)
945
946
947
/*------------------------------------------------.
948
| Report that the YYRULE is going to be reduced. |
949
`------------------------------------------------*/
950
951
static void
952
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
953
int yyrule)
954
{
955
int yylno = yyrline[yyrule];
956
int yynrhs = yyr2[yyrule];
957
int yyi;
958
YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
959
yyrule - 1, yylno);
960
/* The symbols being reduced. */
961
for (yyi = 0; yyi < yynrhs; yyi++)
962
{
963
YYFPRINTF (stderr, " $%d = ", yyi + 1);
964
yy_symbol_print (stderr,
965
YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
966
&yyvsp[(yyi + 1) - (yynrhs)]);
967
YYFPRINTF (stderr, "\n");
968
}
969
}
970
971
# define YY_REDUCE_PRINT(Rule) \
972
do { \
973
if (yydebug) \
974
yy_reduce_print (yyssp, yyvsp, Rule); \
975
} while (0)
976
977
/* Nonzero means print parse trace. It is left uninitialized so that
978
multiple parsers can coexist. */
979
int yydebug;
980
#else /* !YYDEBUG */
981
# define YYDPRINTF(Args) ((void) 0)
982
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
983
# define YY_STACK_PRINT(Bottom, Top)
984
# define YY_REDUCE_PRINT(Rule)
985
#endif /* !YYDEBUG */
986
987
988
/* YYINITDEPTH -- initial size of the parser's stacks. */
989
#ifndef YYINITDEPTH
990
# define YYINITDEPTH 200
991
#endif
992
993
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
994
if the built-in stack extension method is used).
995
996
Do not make this value too large; the results are undefined if
997
YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
998
evaluated with infinite-precision integer arithmetic. */
999
1000
#ifndef YYMAXDEPTH
1001
# define YYMAXDEPTH 10000
1002
#endif
1003
1004
1005
1006
1007
1008
1009
/*-----------------------------------------------.
1010
| Release the memory associated to this symbol. |
1011
`-----------------------------------------------*/
1012
1013
static void
1014
yydestruct (const char *yymsg,
1015
yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
1016
{
1017
YY_USE (yyvaluep);
1018
if (!yymsg)
1019
yymsg = "Deleting";
1020
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1021
1022
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1023
YY_USE (yykind);
1024
YY_IGNORE_MAYBE_UNINITIALIZED_END
1025
}
1026
1027
1028
/* Lookahead token kind. */
1029
int yychar;
1030
1031
/* The semantic value of the lookahead symbol. */
1032
YYSTYPE yylval;
1033
/* Number of syntax errors so far. */
1034
int yynerrs;
1035
1036
1037
1038
1039
/*----------.
1040
| yyparse. |
1041
`----------*/
1042
1043
int
1044
yyparse (void)
1045
{
1046
yy_state_fast_t yystate = 0;
1047
/* Number of tokens to shift before error messages enabled. */
1048
int yyerrstatus = 0;
1049
1050
/* Refer to the stacks through separate pointers, to allow yyoverflow
1051
to reallocate them elsewhere. */
1052
1053
/* Their size. */
1054
YYPTRDIFF_T yystacksize = YYINITDEPTH;
1055
1056
/* The state stack: array, bottom, top. */
1057
yy_state_t yyssa[YYINITDEPTH];
1058
yy_state_t *yyss = yyssa;
1059
yy_state_t *yyssp = yyss;
1060
1061
/* The semantic value stack: array, bottom, top. */
1062
YYSTYPE yyvsa[YYINITDEPTH];
1063
YYSTYPE *yyvs = yyvsa;
1064
YYSTYPE *yyvsp = yyvs;
1065
1066
int yyn;
1067
/* The return value of yyparse. */
1068
int yyresult;
1069
/* Lookahead symbol kind. */
1070
yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1071
/* The variables used to return semantic value and location from the
1072
action routines. */
1073
YYSTYPE yyval;
1074
1075
1076
1077
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1078
1079
/* The number of symbols on the RHS of the reduced rule.
1080
Keep to zero when no symbol should be popped. */
1081
int yylen = 0;
1082
1083
YYDPRINTF ((stderr, "Starting parse\n"));
1084
1085
yychar = YYEMPTY; /* Cause a token to be read. */
1086
1087
goto yysetstate;
1088
1089
1090
/*------------------------------------------------------------.
1091
| yynewstate -- push a new state, which is found in yystate. |
1092
`------------------------------------------------------------*/
1093
yynewstate:
1094
/* In all cases, when you get here, the value and location stacks
1095
have just been pushed. So pushing a state here evens the stacks. */
1096
yyssp++;
1097
1098
1099
/*--------------------------------------------------------------------.
1100
| yysetstate -- set current state (the top of the stack) to yystate. |
1101
`--------------------------------------------------------------------*/
1102
yysetstate:
1103
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1104
YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1105
YY_IGNORE_USELESS_CAST_BEGIN
1106
*yyssp = YY_CAST (yy_state_t, yystate);
1107
YY_IGNORE_USELESS_CAST_END
1108
YY_STACK_PRINT (yyss, yyssp);
1109
1110
if (yyss + yystacksize - 1 <= yyssp)
1111
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
1112
YYNOMEM;
1113
#else
1114
{
1115
/* Get the current used size of the three stacks, in elements. */
1116
YYPTRDIFF_T yysize = yyssp - yyss + 1;
1117
1118
# if defined yyoverflow
1119
{
1120
/* Give user a chance to reallocate the stack. Use copies of
1121
these so that the &'s don't force the real ones into
1122
memory. */
1123
yy_state_t *yyss1 = yyss;
1124
YYSTYPE *yyvs1 = yyvs;
1125
1126
/* Each stack pointer address is followed by the size of the
1127
data in use in that stack, in bytes. This used to be a
1128
conditional around just the two extra args, but that might
1129
be undefined if yyoverflow is a macro. */
1130
yyoverflow (YY_("memory exhausted"),
1131
&yyss1, yysize * YYSIZEOF (*yyssp),
1132
&yyvs1, yysize * YYSIZEOF (*yyvsp),
1133
&yystacksize);
1134
yyss = yyss1;
1135
yyvs = yyvs1;
1136
}
1137
# else /* defined YYSTACK_RELOCATE */
1138
/* Extend the stack our own way. */
1139
if (YYMAXDEPTH <= yystacksize)
1140
YYNOMEM;
1141
yystacksize *= 2;
1142
if (YYMAXDEPTH < yystacksize)
1143
yystacksize = YYMAXDEPTH;
1144
1145
{
1146
yy_state_t *yyss1 = yyss;
1147
union yyalloc *yyptr =
1148
YY_CAST (union yyalloc *,
1149
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1150
if (! yyptr)
1151
YYNOMEM;
1152
YYSTACK_RELOCATE (yyss_alloc, yyss);
1153
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1154
# undef YYSTACK_RELOCATE
1155
if (yyss1 != yyssa)
1156
YYSTACK_FREE (yyss1);
1157
}
1158
# endif
1159
1160
yyssp = yyss + yysize - 1;
1161
yyvsp = yyvs + yysize - 1;
1162
1163
YY_IGNORE_USELESS_CAST_BEGIN
1164
YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1165
YY_CAST (long, yystacksize)));
1166
YY_IGNORE_USELESS_CAST_END
1167
1168
if (yyss + yystacksize - 1 <= yyssp)
1169
YYABORT;
1170
}
1171
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1172
1173
1174
if (yystate == YYFINAL)
1175
YYACCEPT;
1176
1177
goto yybackup;
1178
1179
1180
/*-----------.
1181
| yybackup. |
1182
`-----------*/
1183
yybackup:
1184
/* Do appropriate processing given the current state. Read a
1185
lookahead token if we need one and don't already have one. */
1186
1187
/* First try to decide what to do without reference to lookahead token. */
1188
yyn = yypact[yystate];
1189
if (yypact_value_is_default (yyn))
1190
goto yydefault;
1191
1192
/* Not known => get a lookahead token if don't already have one. */
1193
1194
/* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1195
if (yychar == YYEMPTY)
1196
{
1197
YYDPRINTF ((stderr, "Reading a token\n"));
1198
yychar = yylex ();
1199
}
1200
1201
if (yychar <= YYEOF)
1202
{
1203
yychar = YYEOF;
1204
yytoken = YYSYMBOL_YYEOF;
1205
YYDPRINTF ((stderr, "Now at end of input.\n"));
1206
}
1207
else if (yychar == YYerror)
1208
{
1209
/* The scanner already issued an error message, process directly
1210
to error recovery. But do not keep the error token as
1211
lookahead, it is too special and may lead us to an endless
1212
loop in error recovery. */
1213
yychar = YYUNDEF;
1214
yytoken = YYSYMBOL_YYerror;
1215
goto yyerrlab1;
1216
}
1217
else
1218
{
1219
yytoken = YYTRANSLATE (yychar);
1220
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1221
}
1222
1223
/* If the proper action on seeing token YYTOKEN is to reduce or to
1224
detect an error, take that action. */
1225
yyn += yytoken;
1226
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1227
goto yydefault;
1228
yyn = yytable[yyn];
1229
if (yyn <= 0)
1230
{
1231
if (yytable_value_is_error (yyn))
1232
goto yyerrlab;
1233
yyn = -yyn;
1234
goto yyreduce;
1235
}
1236
1237
/* Count tokens shifted since error; after three, turn off error
1238
status. */
1239
if (yyerrstatus)
1240
yyerrstatus--;
1241
1242
/* Shift the lookahead token. */
1243
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1244
yystate = yyn;
1245
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1246
*++yyvsp = yylval;
1247
YY_IGNORE_MAYBE_UNINITIALIZED_END
1248
1249
/* Discard the shifted token. */
1250
yychar = YYEMPTY;
1251
goto yynewstate;
1252
1253
1254
/*-----------------------------------------------------------.
1255
| yydefault -- do the default action for the current state. |
1256
`-----------------------------------------------------------*/
1257
yydefault:
1258
yyn = yydefact[yystate];
1259
if (yyn == 0)
1260
goto yyerrlab;
1261
goto yyreduce;
1262
1263
1264
/*-----------------------------.
1265
| yyreduce -- do a reduction. |
1266
`-----------------------------*/
1267
yyreduce:
1268
/* yyn is the number of a rule to reduce with. */
1269
yylen = yyr2[yyn];
1270
1271
/* If YYLEN is nonzero, implement the default value of the action:
1272
'$$ = $1'.
1273
1274
Otherwise, the following line sets YYVAL to garbage.
1275
This behavior is undocumented and Bison
1276
users should not rely upon it. Assigning to YYVAL
1277
unconditionally makes the parser a bit smaller, and it avoids a
1278
GCC warning that YYVAL may be used uninitialized. */
1279
yyval = yyvsp[1-yylen];
1280
1281
1282
YY_REDUCE_PRINT (yyn);
1283
switch (yyn)
1284
{
1285
case 4: /* item: time */
1286
#line 115 "getdate.y"
1287
{
1288
yyHaveTime++;
1289
}
1290
#line 1290 "getdate.c"
1291
break;
1292
1293
case 5: /* item: zone */
1294
#line 118 "getdate.y"
1295
{
1296
yyHaveZone++;
1297
}
1298
#line 1298 "getdate.c"
1299
break;
1300
1301
case 6: /* item: date */
1302
#line 121 "getdate.y"
1303
{
1304
yyHaveDate++;
1305
}
1306
#line 1306 "getdate.c"
1307
break;
1308
1309
case 7: /* item: day */
1310
#line 124 "getdate.y"
1311
{
1312
yyHaveDay++;
1313
}
1314
#line 1314 "getdate.c"
1315
break;
1316
1317
case 8: /* item: rel */
1318
#line 127 "getdate.y"
1319
{
1320
yyHaveRel++;
1321
}
1322
#line 1322 "getdate.c"
1323
break;
1324
1325
case 10: /* time: tUNUMBER tMERIDIAN */
1326
#line 133 "getdate.y"
1327
{
1328
yyHour = (yyvsp[-1].Number);
1329
yyMinutes = 0;
1330
yySeconds = 0;
1331
yyMeridian = (yyvsp[0].Meridian);
1332
}
1333
#line 1333 "getdate.c"
1334
break;
1335
1336
case 11: /* time: tUNUMBER ':' tUNUMBER o_merid */
1337
#line 139 "getdate.y"
1338
{
1339
yyHour = (yyvsp[-3].Number);
1340
yyMinutes = (yyvsp[-1].Number);
1341
yySeconds = 0;
1342
yyMeridian = (yyvsp[0].Meridian);
1343
}
1344
#line 1344 "getdate.c"
1345
break;
1346
1347
case 12: /* time: tUNUMBER ':' tUNUMBER tSNUMBER */
1348
#line 145 "getdate.y"
1349
{
1350
yyHour = (yyvsp[-3].Number);
1351
yyMinutes = (yyvsp[-1].Number);
1352
yyMeridian = MER24;
1353
yyDSTmode = DSToff;
1354
yyTimezone = - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60);
1355
}
1356
#line 1356 "getdate.c"
1357
break;
1358
1359
case 13: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid */
1360
#line 152 "getdate.y"
1361
{
1362
yyHour = (yyvsp[-5].Number);
1363
yyMinutes = (yyvsp[-3].Number);
1364
yySeconds = (yyvsp[-1].Number);
1365
yyMeridian = (yyvsp[0].Meridian);
1366
}
1367
#line 1367 "getdate.c"
1368
break;
1369
1370
case 14: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER */
1371
#line 158 "getdate.y"
1372
{
1373
yyHour = (yyvsp[-5].Number);
1374
yyMinutes = (yyvsp[-3].Number);
1375
yySeconds = (yyvsp[-1].Number);
1376
yyMeridian = MER24;
1377
yyDSTmode = DSToff;
1378
yyTimezone = - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60);
1379
}
1380
#line 1380 "getdate.c"
1381
break;
1382
1383
case 15: /* zone: tZONE */
1384
#line 168 "getdate.y"
1385
{
1386
yyTimezone = (yyvsp[0].Number);
1387
yyDSTmode = DSToff;
1388
}
1389
#line 1389 "getdate.c"
1390
break;
1391
1392
case 16: /* zone: tDAYZONE */
1393
#line 172 "getdate.y"
1394
{
1395
yyTimezone = (yyvsp[0].Number);
1396
yyDSTmode = DSTon;
1397
}
1398
#line 1398 "getdate.c"
1399
break;
1400
1401
case 17: /* zone: tZONE tDST */
1402
#line 177 "getdate.y"
1403
{
1404
yyTimezone = (yyvsp[-1].Number);
1405
yyDSTmode = DSTon;
1406
}
1407
#line 1407 "getdate.c"
1408
break;
1409
1410
case 18: /* day: tDAY */
1411
#line 183 "getdate.y"
1412
{
1413
yyDayOrdinal = 1;
1414
yyDayNumber = (yyvsp[0].Number);
1415
}
1416
#line 1416 "getdate.c"
1417
break;
1418
1419
case 19: /* day: tDAY ',' */
1420
#line 187 "getdate.y"
1421
{
1422
yyDayOrdinal = 1;
1423
yyDayNumber = (yyvsp[-1].Number);
1424
}
1425
#line 1425 "getdate.c"
1426
break;
1427
1428
case 20: /* day: tUNUMBER tDAY */
1429
#line 191 "getdate.y"
1430
{
1431
yyDayOrdinal = (yyvsp[-1].Number);
1432
yyDayNumber = (yyvsp[0].Number);
1433
}
1434
#line 1434 "getdate.c"
1435
break;
1436
1437
case 21: /* date: tUNUMBER '/' tUNUMBER */
1438
#line 197 "getdate.y"
1439
{
1440
yyMonth = (yyvsp[-2].Number);
1441
yyDay = (yyvsp[0].Number);
1442
}
1443
#line 1443 "getdate.c"
1444
break;
1445
1446
case 22: /* date: tUNUMBER '/' tUNUMBER '/' tUNUMBER */
1447
#line 201 "getdate.y"
1448
{
1449
if ((yyvsp[-4].Number) >= 100) {
1450
yyYear = (yyvsp[-4].Number);
1451
yyMonth = (yyvsp[-2].Number);
1452
yyDay = (yyvsp[0].Number);
1453
} else {
1454
yyMonth = (yyvsp[-4].Number);
1455
yyDay = (yyvsp[-2].Number);
1456
yyYear = (yyvsp[0].Number);
1457
}
1458
}
1459
#line 1459 "getdate.c"
1460
break;
1461
1462
case 23: /* date: tUNUMBER tSNUMBER tSNUMBER */
1463
#line 212 "getdate.y"
1464
{
1465
/* ISO 8601 format. yyyy-mm-dd. */
1466
yyYear = (yyvsp[-2].Number);
1467
yyMonth = -(yyvsp[-1].Number);
1468
yyDay = -(yyvsp[0].Number);
1469
}
1470
#line 1470 "getdate.c"
1471
break;
1472
1473
case 24: /* date: tUNUMBER tMONTH tSNUMBER */
1474
#line 218 "getdate.y"
1475
{
1476
/* e.g. 17-JUN-1992. */
1477
yyDay = (yyvsp[-2].Number);
1478
yyMonth = (yyvsp[-1].Number);
1479
yyYear = -(yyvsp[0].Number);
1480
}
1481
#line 1481 "getdate.c"
1482
break;
1483
1484
case 25: /* date: tMONTH tUNUMBER */
1485
#line 224 "getdate.y"
1486
{
1487
yyMonth = (yyvsp[-1].Number);
1488
yyDay = (yyvsp[0].Number);
1489
}
1490
#line 1490 "getdate.c"
1491
break;
1492
1493
case 26: /* date: tMONTH tUNUMBER ',' tUNUMBER */
1494
#line 228 "getdate.y"
1495
{
1496
yyMonth = (yyvsp[-3].Number);
1497
yyDay = (yyvsp[-2].Number);
1498
yyYear = (yyvsp[0].Number);
1499
}
1500
#line 1500 "getdate.c"
1501
break;
1502
1503
case 27: /* date: tUNUMBER tMONTH */
1504
#line 233 "getdate.y"
1505
{
1506
yyMonth = (yyvsp[0].Number);
1507
yyDay = (yyvsp[-1].Number);
1508
}
1509
#line 1509 "getdate.c"
1510
break;
1511
1512
case 28: /* date: tUNUMBER tMONTH tUNUMBER */
1513
#line 237 "getdate.y"
1514
{
1515
yyMonth = (yyvsp[-1].Number);
1516
yyDay = (yyvsp[-2].Number);
1517
yyYear = (yyvsp[0].Number);
1518
}
1519
#line 1519 "getdate.c"
1520
break;
1521
1522
case 29: /* rel: relunit tAGO */
1523
#line 244 "getdate.y"
1524
{
1525
yyRelSeconds = -yyRelSeconds;
1526
yyRelMonth = -yyRelMonth;
1527
}
1528
#line 1528 "getdate.c"
1529
break;
1530
1531
case 31: /* relunit: tUNUMBER tMINUTE_UNIT */
1532
#line 251 "getdate.y"
1533
{
1534
yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number) * 60L;
1535
}
1536
#line 1536 "getdate.c"
1537
break;
1538
1539
case 32: /* relunit: tSNUMBER tMINUTE_UNIT */
1540
#line 254 "getdate.y"
1541
{
1542
yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number) * 60L;
1543
}
1544
#line 1544 "getdate.c"
1545
break;
1546
1547
case 33: /* relunit: tMINUTE_UNIT */
1548
#line 257 "getdate.y"
1549
{
1550
yyRelSeconds += (yyvsp[0].Number) * 60L;
1551
}
1552
#line 1552 "getdate.c"
1553
break;
1554
1555
case 34: /* relunit: tSNUMBER tSEC_UNIT */
1556
#line 260 "getdate.y"
1557
{
1558
yyRelSeconds += (yyvsp[-1].Number);
1559
}
1560
#line 1560 "getdate.c"
1561
break;
1562
1563
case 35: /* relunit: tUNUMBER tSEC_UNIT */
1564
#line 263 "getdate.y"
1565
{
1566
yyRelSeconds += (yyvsp[-1].Number);
1567
}
1568
#line 1568 "getdate.c"
1569
break;
1570
1571
case 36: /* relunit: tSEC_UNIT */
1572
#line 266 "getdate.y"
1573
{
1574
yyRelSeconds++;
1575
}
1576
#line 1576 "getdate.c"
1577
break;
1578
1579
case 37: /* relunit: tSNUMBER tMONTH_UNIT */
1580
#line 269 "getdate.y"
1581
{
1582
yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
1583
}
1584
#line 1584 "getdate.c"
1585
break;
1586
1587
case 38: /* relunit: tUNUMBER tMONTH_UNIT */
1588
#line 272 "getdate.y"
1589
{
1590
yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
1591
}
1592
#line 1592 "getdate.c"
1593
break;
1594
1595
case 39: /* relunit: tMONTH_UNIT */
1596
#line 275 "getdate.y"
1597
{
1598
yyRelMonth += (yyvsp[0].Number);
1599
}
1600
#line 1600 "getdate.c"
1601
break;
1602
1603
case 40: /* number: tUNUMBER */
1604
#line 280 "getdate.y"
1605
{
1606
if (yyHaveTime && yyHaveDate && !yyHaveRel)
1607
yyYear = (yyvsp[0].Number);
1608
else {
1609
if((yyvsp[0].Number)>10000) {
1610
yyHaveDate++;
1611
yyDay= ((yyvsp[0].Number))%100;
1612
yyMonth= ((yyvsp[0].Number)/100)%100;
1613
yyYear = (yyvsp[0].Number)/10000;
1614
}
1615
else {
1616
yyHaveTime++;
1617
if ((yyvsp[0].Number) < 100) {
1618
yyHour = (yyvsp[0].Number);
1619
yyMinutes = 0;
1620
}
1621
else {
1622
yyHour = (yyvsp[0].Number) / 100;
1623
yyMinutes = (yyvsp[0].Number) % 100;
1624
}
1625
yySeconds = 0;
1626
yyMeridian = MER24;
1627
}
1628
}
1629
}
1630
#line 1630 "getdate.c"
1631
break;
1632
1633
case 41: /* o_merid: %empty */
1634
#line 307 "getdate.y"
1635
{
1636
(yyval.Meridian) = MER24;
1637
}
1638
#line 1638 "getdate.c"
1639
break;
1640
1641
case 42: /* o_merid: tMERIDIAN */
1642
#line 310 "getdate.y"
1643
{
1644
(yyval.Meridian) = (yyvsp[0].Meridian);
1645
}
1646
#line 1646 "getdate.c"
1647
break;
1648
1649
1650
#line 1650 "getdate.c"
1651
1652
default: break;
1653
}
1654
/* User semantic actions sometimes alter yychar, and that requires
1655
that yytoken be updated with the new translation. We take the
1656
approach of translating immediately before every use of yytoken.
1657
One alternative is translating here after every semantic action,
1658
but that translation would be missed if the semantic action invokes
1659
YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1660
if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1661
incorrect destructor might then be invoked immediately. In the
1662
case of YYERROR or YYBACKUP, subsequent parser actions might lead
1663
to an incorrect destructor call or verbose syntax error message
1664
before the lookahead is translated. */
1665
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1666
1667
YYPOPSTACK (yylen);
1668
yylen = 0;
1669
1670
*++yyvsp = yyval;
1671
1672
/* Now 'shift' the result of the reduction. Determine what state
1673
that goes to, based on the state we popped back to and the rule
1674
number reduced by. */
1675
{
1676
const int yylhs = yyr1[yyn] - YYNTOKENS;
1677
const int yyi = yypgoto[yylhs] + *yyssp;
1678
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1679
? yytable[yyi]
1680
: yydefgoto[yylhs]);
1681
}
1682
1683
goto yynewstate;
1684
1685
1686
/*--------------------------------------.
1687
| yyerrlab -- here on detecting error. |
1688
`--------------------------------------*/
1689
yyerrlab:
1690
/* Make sure we have latest lookahead translation. See comments at
1691
user semantic actions for why this is necessary. */
1692
yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1693
/* If not already recovering from an error, report this error. */
1694
if (!yyerrstatus)
1695
{
1696
++yynerrs;
1697
yyerror (YY_("syntax error"));
1698
}
1699
1700
if (yyerrstatus == 3)
1701
{
1702
/* If just tried and failed to reuse lookahead token after an
1703
error, discard it. */
1704
1705
if (yychar <= YYEOF)
1706
{
1707
/* Return failure if at end of input. */
1708
if (yychar == YYEOF)
1709
YYABORT;
1710
}
1711
else
1712
{
1713
yydestruct ("Error: discarding",
1714
yytoken, &yylval);
1715
yychar = YYEMPTY;
1716
}
1717
}
1718
1719
/* Else will try to reuse lookahead token after shifting the error
1720
token. */
1721
goto yyerrlab1;
1722
1723
1724
/*---------------------------------------------------.
1725
| yyerrorlab -- error raised explicitly by YYERROR. |
1726
`---------------------------------------------------*/
1727
yyerrorlab:
1728
/* Pacify compilers when the user code never invokes YYERROR and the
1729
label yyerrorlab therefore never appears in user code. */
1730
if (0)
1731
YYERROR;
1732
++yynerrs;
1733
1734
/* Do not reclaim the symbols of the rule whose action triggered
1735
this YYERROR. */
1736
YYPOPSTACK (yylen);
1737
yylen = 0;
1738
YY_STACK_PRINT (yyss, yyssp);
1739
yystate = *yyssp;
1740
goto yyerrlab1;
1741
1742
1743
/*-------------------------------------------------------------.
1744
| yyerrlab1 -- common code for both syntax error and YYERROR. |
1745
`-------------------------------------------------------------*/
1746
yyerrlab1:
1747
yyerrstatus = 3; /* Each real token shifted decrements this. */
1748
1749
/* Pop stack until we find a state that shifts the error token. */
1750
for (;;)
1751
{
1752
yyn = yypact[yystate];
1753
if (!yypact_value_is_default (yyn))
1754
{
1755
yyn += YYSYMBOL_YYerror;
1756
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1757
{
1758
yyn = yytable[yyn];
1759
if (0 < yyn)
1760
break;
1761
}
1762
}
1763
1764
/* Pop the current state because it cannot handle the error token. */
1765
if (yyssp == yyss)
1766
YYABORT;
1767
1768
1769
yydestruct ("Error: popping",
1770
YY_ACCESSING_SYMBOL (yystate), yyvsp);
1771
YYPOPSTACK (1);
1772
yystate = *yyssp;
1773
YY_STACK_PRINT (yyss, yyssp);
1774
}
1775
1776
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1777
*++yyvsp = yylval;
1778
YY_IGNORE_MAYBE_UNINITIALIZED_END
1779
1780
1781
/* Shift the error token. */
1782
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1783
1784
yystate = yyn;
1785
goto yynewstate;
1786
1787
1788
/*-------------------------------------.
1789
| yyacceptlab -- YYACCEPT comes here. |
1790
`-------------------------------------*/
1791
yyacceptlab:
1792
yyresult = 0;
1793
goto yyreturnlab;
1794
1795
1796
/*-----------------------------------.
1797
| yyabortlab -- YYABORT comes here. |
1798
`-----------------------------------*/
1799
yyabortlab:
1800
yyresult = 1;
1801
goto yyreturnlab;
1802
1803
1804
/*-----------------------------------------------------------.
1805
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
1806
`-----------------------------------------------------------*/
1807
yyexhaustedlab:
1808
yyerror (YY_("memory exhausted"));
1809
yyresult = 2;
1810
goto yyreturnlab;
1811
1812
1813
/*----------------------------------------------------------.
1814
| yyreturnlab -- parsing is finished, clean up and return. |
1815
`----------------------------------------------------------*/
1816
yyreturnlab:
1817
if (yychar != YYEMPTY)
1818
{
1819
/* Make sure we have latest lookahead translation. See comments at
1820
user semantic actions for why this is necessary. */
1821
yytoken = YYTRANSLATE (yychar);
1822
yydestruct ("Cleanup: discarding lookahead",
1823
yytoken, &yylval);
1824
}
1825
/* Do not reclaim the symbols of the rule whose action triggered
1826
this YYABORT or YYACCEPT. */
1827
YYPOPSTACK (yylen);
1828
YY_STACK_PRINT (yyss, yyssp);
1829
while (yyssp != yyss)
1830
{
1831
yydestruct ("Cleanup: popping",
1832
YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
1833
YYPOPSTACK (1);
1834
}
1835
#ifndef yyoverflow
1836
if (yyss != yyssa)
1837
YYSTACK_FREE (yyss);
1838
#endif
1839
1840
return yyresult;
1841
}
1842
1843
#line 315 "getdate.y"
1844
1845
1846
/* Month and day table. */
1847
static TABLE const MonthDayTable[] = {
1848
{ "january", tMONTH, 1 },
1849
{ "february", tMONTH, 2 },
1850
{ "march", tMONTH, 3 },
1851
{ "april", tMONTH, 4 },
1852
{ "may", tMONTH, 5 },
1853
{ "june", tMONTH, 6 },
1854
{ "july", tMONTH, 7 },
1855
{ "august", tMONTH, 8 },
1856
{ "september", tMONTH, 9 },
1857
{ "sept", tMONTH, 9 },
1858
{ "october", tMONTH, 10 },
1859
{ "november", tMONTH, 11 },
1860
{ "december", tMONTH, 12 },
1861
{ "sunday", tDAY, 0 },
1862
{ "monday", tDAY, 1 },
1863
{ "tuesday", tDAY, 2 },
1864
{ "tues", tDAY, 2 },
1865
{ "wednesday", tDAY, 3 },
1866
{ "wednes", tDAY, 3 },
1867
{ "thursday", tDAY, 4 },
1868
{ "thur", tDAY, 4 },
1869
{ "thurs", tDAY, 4 },
1870
{ "friday", tDAY, 5 },
1871
{ "saturday", tDAY, 6 },
1872
{ NULL }
1873
};
1874
1875
/* Time units table. */
1876
static TABLE const UnitsTable[] = {
1877
{ "year", tMONTH_UNIT, 12 },
1878
{ "month", tMONTH_UNIT, 1 },
1879
{ "fortnight", tMINUTE_UNIT, 14 * 24 * 60 },
1880
{ "week", tMINUTE_UNIT, 7 * 24 * 60 },
1881
{ "day", tMINUTE_UNIT, 1 * 24 * 60 },
1882
{ "hour", tMINUTE_UNIT, 60 },
1883
{ "minute", tMINUTE_UNIT, 1 },
1884
{ "min", tMINUTE_UNIT, 1 },
1885
{ "second", tSEC_UNIT, 1 },
1886
{ "sec", tSEC_UNIT, 1 },
1887
{ NULL }
1888
};
1889
1890
/* Assorted relative-time words. */
1891
static TABLE const OtherTable[] = {
1892
{ "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 },
1893
{ "yesterday", tMINUTE_UNIT, -1 * 24 * 60 },
1894
{ "today", tMINUTE_UNIT, 0 },
1895
{ "now", tMINUTE_UNIT, 0 },
1896
{ "last", tUNUMBER, -1 },
1897
{ "this", tUNUMBER, 0 },
1898
{ "next", tUNUMBER, 2 },
1899
{ "first", tUNUMBER, 1 },
1900
/* { "second", tUNUMBER, 2 }, */
1901
{ "third", tUNUMBER, 3 },
1902
{ "fourth", tUNUMBER, 4 },
1903
{ "fifth", tUNUMBER, 5 },
1904
{ "sixth", tUNUMBER, 6 },
1905
{ "seventh", tUNUMBER, 7 },
1906
{ "eighth", tUNUMBER, 8 },
1907
{ "ninth", tUNUMBER, 9 },
1908
{ "tenth", tUNUMBER, 10 },
1909
{ "eleventh", tUNUMBER, 11 },
1910
{ "twelfth", tUNUMBER, 12 },
1911
{ "ago", tAGO, 1 },
1912
{ NULL }
1913
};
1914
1915
/* The timezone table. */
1916
/* Some of these are commented out because a time_t can't store a float. */
1917
static TABLE const TimezoneTable[] = {
1918
{ "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */
1919
{ "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */
1920
{ "utc", tZONE, HOUR( 0) },
1921
{ "wet", tZONE, HOUR( 0) }, /* Western European */
1922
{ "bst", tDAYZONE, HOUR( 0) }, /* British Summer */
1923
{ "wat", tZONE, HOUR( 1) }, /* West Africa */
1924
{ "at", tZONE, HOUR( 2) }, /* Azores */
1925
#if 0
1926
/* For completeness. BST is also British Summer, and GST is
1927
* also Guam Standard. */
1928
{ "bst", tZONE, HOUR( 3) }, /* Brazil Standard */
1929
{ "gst", tZONE, HOUR( 3) }, /* Greenland Standard */
1930
#endif
1931
#if 0
1932
{ "nft", tZONE, HOUR(3.5) }, /* Newfoundland */
1933
{ "nst", tZONE, HOUR(3.5) }, /* Newfoundland Standard */
1934
{ "ndt", tDAYZONE, HOUR(3.5) }, /* Newfoundland Daylight */
1935
#endif
1936
{ "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */
1937
{ "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */
1938
{ "est", tZONE, HOUR( 5) }, /* Eastern Standard */
1939
{ "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */
1940
{ "cst", tZONE, HOUR( 6) }, /* Central Standard */
1941
{ "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */
1942
{ "mst", tZONE, HOUR( 7) }, /* Mountain Standard */
1943
{ "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */
1944
{ "pst", tZONE, HOUR( 8) }, /* Pacific Standard */
1945
{ "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */
1946
{ "yst", tZONE, HOUR( 9) }, /* Yukon Standard */
1947
{ "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */
1948
{ "hst", tZONE, HOUR(10) }, /* Hawaii Standard */
1949
{ "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */
1950
{ "cat", tZONE, HOUR(10) }, /* Central Alaska */
1951
{ "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */
1952
{ "nt", tZONE, HOUR(11) }, /* Nome */
1953
{ "idlw", tZONE, HOUR(12) }, /* International Date Line West */
1954
{ "cet", tZONE, -HOUR(1) }, /* Central European */
1955
{ "met", tZONE, -HOUR(1) }, /* Middle European */
1956
{ "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */
1957
{ "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */
1958
{ "swt", tZONE, -HOUR(1) }, /* Swedish Winter */
1959
{ "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */
1960
{ "fwt", tZONE, -HOUR(1) }, /* French Winter */
1961
{ "fst", tDAYZONE, -HOUR(1) }, /* French Summer */
1962
{ "eet", tZONE, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */
1963
{ "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
1964
#if 0
1965
{ "it", tZONE, -HOUR(3.5) },/* Iran */
1966
#endif
1967
{ "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */
1968
{ "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */
1969
#if 0
1970
{ "ist", tZONE, -HOUR(5.5) },/* Indian Standard */
1971
#endif
1972
{ "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */
1973
#if 0
1974
/* For completeness. NST is also Newfoundland Standard, and SST is
1975
* also Swedish Summer. */
1976
{ "nst", tZONE, -HOUR(6.5) },/* North Sumatra */
1977
{ "sst", tZONE, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */
1978
#endif /* 0 */
1979
{ "wast", tZONE, -HOUR(7) }, /* West Australian Standard */
1980
{ "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */
1981
#if 0
1982
{ "jt", tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */
1983
#endif
1984
{ "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */
1985
{ "jst", tZONE, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
1986
#if 0
1987
{ "cast", tZONE, -HOUR(9.5) },/* Central Australian Standard */
1988
{ "cadt", tDAYZONE, -HOUR(9.5) },/* Central Australian Daylight */
1989
#endif
1990
{ "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */
1991
{ "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */
1992
{ "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */
1993
{ "nzt", tZONE, -HOUR(12) }, /* New Zealand */
1994
{ "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */
1995
{ "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */
1996
{ "idle", tZONE, -HOUR(12) }, /* International Date Line East */
1997
{ NULL }
1998
};
1999
2000
/* Military timezone table. */
2001
static TABLE const MilitaryTable[] = {
2002
{ "a", tZONE, HOUR( 1) },
2003
{ "b", tZONE, HOUR( 2) },
2004
{ "c", tZONE, HOUR( 3) },
2005
{ "d", tZONE, HOUR( 4) },
2006
{ "e", tZONE, HOUR( 5) },
2007
{ "f", tZONE, HOUR( 6) },
2008
{ "g", tZONE, HOUR( 7) },
2009
{ "h", tZONE, HOUR( 8) },
2010
{ "i", tZONE, HOUR( 9) },
2011
{ "k", tZONE, HOUR( 10) },
2012
{ "l", tZONE, HOUR( 11) },
2013
{ "m", tZONE, HOUR( 12) },
2014
{ "n", tZONE, HOUR(- 1) },
2015
{ "o", tZONE, HOUR(- 2) },
2016
{ "p", tZONE, HOUR(- 3) },
2017
{ "q", tZONE, HOUR(- 4) },
2018
{ "r", tZONE, HOUR(- 5) },
2019
{ "s", tZONE, HOUR(- 6) },
2020
{ "t", tZONE, HOUR(- 7) },
2021
{ "u", tZONE, HOUR(- 8) },
2022
{ "v", tZONE, HOUR(- 9) },
2023
{ "w", tZONE, HOUR(-10) },
2024
{ "x", tZONE, HOUR(-11) },
2025
{ "y", tZONE, HOUR(-12) },
2026
{ "z", tZONE, HOUR( 0) },
2027
{ NULL }
2028
};
2029
2030
2031
2032
2033
/* ARGSUSED */
2034
void
2035
yyerror(const char *s)
2036
{
2037
return;
2038
}
2039
2040
2041
static time_t
2042
ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian)
2043
{
2044
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
2045
return -1;
2046
switch (Meridian) {
2047
case MER24:
2048
if (Hours < 0 || Hours > 23)
2049
return -1;
2050
return (Hours * 60L + Minutes) * 60L + Seconds;
2051
case MERam:
2052
if (Hours < 1 || Hours > 12)
2053
return -1;
2054
if (Hours == 12)
2055
Hours = 0;
2056
return (Hours * 60L + Minutes) * 60L + Seconds;
2057
case MERpm:
2058
if (Hours < 1 || Hours > 12)
2059
return -1;
2060
if (Hours == 12)
2061
Hours = 0;
2062
return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
2063
default:
2064
abort ();
2065
}
2066
/* NOTREACHED */
2067
}
2068
2069
2070
/* Year is either
2071
* A negative number, which means to use its absolute value (why?)
2072
* A number from 0 to 99, which means a year from 1900 to 1999, or
2073
* The actual year (>=100). */
2074
static time_t
2075
Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes,
2076
time_t Seconds, MERIDIAN Meridian, DSTMODE DSTmode)
2077
{
2078
static int DaysInMonth[12] = {
2079
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
2080
};
2081
struct tm tm;
2082
time_t tod;
2083
time_t Julian;
2084
int i;
2085
2086
if (Year < 0)
2087
Year = -Year;
2088
if (Year < 69)
2089
Year += 2000;
2090
else if (Year < 100) {
2091
Year += 1900;
2092
if (Year < EPOCH)
2093
Year += 100;
2094
}
2095
DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
2096
? 29 : 28;
2097
/* 32-bit time_t cannot represent years past 2038 */
2098
if (Year < EPOCH || (sizeof(time_t) == sizeof(int) && Year > 2038)
2099
|| Month < 1 || Month > 12
2100
/* Lint fluff: "conversion from long may lose accuracy" */
2101
|| Day < 1 || Day > DaysInMonth[--Month])
2102
return -1;
2103
2104
for (Julian = Day - 1, i = 0; i < Month; i++)
2105
Julian += DaysInMonth[i];
2106
for (i = EPOCH; i < Year; i++)
2107
Julian += 365 + (i % 4 == 0);
2108
Julian *= SECSPERDAY;
2109
Julian += yyTimezone * 60L;
2110
if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
2111
return -1;
2112
Julian += tod;
2113
if (DSTmode == DSTon
2114
|| (DSTmode == DSTmaybe && localtime_r(&Julian, &tm) && tm.tm_isdst))
2115
Julian -= 60 * 60;
2116
return Julian;
2117
}
2118
2119
2120
static time_t
2121
DSTcorrect(time_t Start, time_t Future)
2122
{
2123
struct tm start_tm;
2124
struct tm future_tm;
2125
time_t StartDay;
2126
time_t FutureDay;
2127
2128
if (!localtime_r(&Start, &start_tm) || !localtime_r(&Future, &future_tm))
2129
return -1;
2130
2131
StartDay = (start_tm.tm_hour + 1) % 24;
2132
FutureDay = (future_tm.tm_hour + 1) % 24;
2133
return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
2134
}
2135
2136
2137
static time_t
2138
RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber)
2139
{
2140
struct tm tm;
2141
time_t now;
2142
2143
now = Start;
2144
if (!localtime_r(&now, &tm))
2145
return -1;
2146
now += SECSPERDAY * ((DayNumber - tm.tm_wday + 7) % 7);
2147
now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
2148
return DSTcorrect(Start, now);
2149
}
2150
2151
2152
static time_t
2153
RelativeMonth(time_t Start, time_t RelMonth)
2154
{
2155
struct tm tm;
2156
time_t Month;
2157
time_t Year;
2158
2159
if (RelMonth == 0)
2160
return 0;
2161
if (!localtime_r(&Start, &tm))
2162
return -1;
2163
Month = 12 * (tm.tm_year + 1900) + tm.tm_mon + RelMonth;
2164
Year = Month / 12;
2165
Month = Month % 12 + 1;
2166
return DSTcorrect(Start,
2167
Convert(Month, (time_t)tm.tm_mday, Year,
2168
(time_t)tm.tm_hour, (time_t)tm.tm_min, (time_t)tm.tm_sec,
2169
MER24, DSTmaybe));
2170
}
2171
2172
2173
static int
2174
LookupWord(char *buff)
2175
{
2176
char *p;
2177
char *q;
2178
const TABLE *tp;
2179
int i;
2180
int abbrev;
2181
int bufflen;
2182
2183
/* Make it lowercase. */
2184
for (p = buff; *p; p++) {
2185
if (isupper((unsigned char)*p))
2186
*p = (char)tolower((unsigned char)*p);
2187
}
2188
if ((bufflen = (int)(p - buff)) == 0)
2189
return '\0';
2190
2191
if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
2192
yylval.Meridian = MERam;
2193
return tMERIDIAN;
2194
}
2195
if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
2196
yylval.Meridian = MERpm;
2197
return tMERIDIAN;
2198
}
2199
2200
/* See if we have an abbreviation for a month. */
2201
if (bufflen == 3)
2202
abbrev = 1;
2203
else if (bufflen == 4 && buff[3] == '.') {
2204
abbrev = 1;
2205
buff[bufflen = 3] = '\0';
2206
}
2207
else
2208
abbrev = 0;
2209
2210
for (tp = MonthDayTable; tp->name; tp++) {
2211
if (abbrev) {
2212
if (strncmp(buff, tp->name, 3) == 0) {
2213
yylval.Number = tp->value;
2214
return tp->type;
2215
}
2216
}
2217
else if (strcmp(buff, tp->name) == 0) {
2218
yylval.Number = tp->value;
2219
return tp->type;
2220
}
2221
}
2222
2223
for (tp = TimezoneTable; tp->name; tp++)
2224
if (strcmp(buff, tp->name) == 0) {
2225
yylval.Number = tp->value;
2226
return tp->type;
2227
}
2228
2229
if (strcmp(buff, "dst") == 0)
2230
return tDST;
2231
2232
for (tp = UnitsTable; tp->name; tp++)
2233
if (strcmp(buff, tp->name) == 0) {
2234
yylval.Number = tp->value;
2235
return tp->type;
2236
}
2237
2238
/* Strip off any plural and try the units table again. */
2239
i = bufflen - 1;
2240
if (buff[i] == 's') {
2241
buff[i] = '\0';
2242
for (tp = UnitsTable; tp->name; tp++)
2243
if (strcmp(buff, tp->name) == 0) {
2244
yylval.Number = tp->value;
2245
return tp->type;
2246
}
2247
buff[i] = 's'; /* Put back for "this" in OtherTable. */
2248
}
2249
2250
for (tp = OtherTable; tp->name; tp++)
2251
if (strcmp(buff, tp->name) == 0) {
2252
yylval.Number = tp->value;
2253
return tp->type;
2254
}
2255
2256
/* Military timezones. */
2257
if (buff[1] == '\0' && isalpha((unsigned char)*buff)) {
2258
for (tp = MilitaryTable; tp->name; tp++)
2259
if (strcmp(buff, tp->name) == 0) {
2260
yylval.Number = tp->value;
2261
return tp->type;
2262
}
2263
}
2264
2265
/* Drop out any periods and try the timezone table again. */
2266
for (i = 0, p = q = buff; *q; q++)
2267
if (*q != '.')
2268
*p++ = *q;
2269
else
2270
i++;
2271
*p = '\0';
2272
if (i)
2273
for (tp = TimezoneTable; tp->name; tp++)
2274
if (strcmp(buff, tp->name) == 0) {
2275
yylval.Number = tp->value;
2276
return tp->type;
2277
}
2278
2279
return tID;
2280
}
2281
2282
2283
static int
2284
yylex(void)
2285
{
2286
char c;
2287
char *p;
2288
char buff[20];
2289
int Count;
2290
int sign;
2291
2292
for ( ; ; ) {
2293
while (isspace((unsigned char)*yyInput))
2294
yyInput++;
2295
2296
if (isdigit((unsigned char)(c = *yyInput)) || c == '-' || c == '+') {
2297
if (c == '-' || c == '+') {
2298
sign = c == '-' ? -1 : 1;
2299
if (!isdigit((unsigned char)*++yyInput))
2300
/* skip the '-' sign */
2301
continue;
2302
}
2303
else
2304
sign = 0;
2305
for (yylval.Number = 0; isdigit((unsigned char)(c = *yyInput++)); )
2306
yylval.Number = 10 * yylval.Number + c - '0';
2307
yyInput--;
2308
if (sign < 0)
2309
yylval.Number = -yylval.Number;
2310
return sign ? tSNUMBER : tUNUMBER;
2311
}
2312
if (isalpha((unsigned char)c)) {
2313
for (p = buff; isalpha((unsigned char)(c = *yyInput++)) || c == '.'; )
2314
if (p < &buff[sizeof buff - 1])
2315
*p++ = c;
2316
*p = '\0';
2317
yyInput--;
2318
return LookupWord(buff);
2319
}
2320
if (c != '(')
2321
return *yyInput++;
2322
Count = 0;
2323
do {
2324
c = *yyInput++;
2325
if (c == '\0')
2326
return c;
2327
if (c == '(')
2328
Count++;
2329
else if (c == ')')
2330
Count--;
2331
} while (Count > 0);
2332
}
2333
}
2334
2335
#define TM_YEAR_ORIGIN 1900
2336
2337
/* Yield A - B, measured in seconds. */
2338
static long
2339
difftm(struct tm *a, struct tm *b)
2340
{
2341
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
2342
int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
2343
long days = (
2344
/* difference in day of year */
2345
a->tm_yday - b->tm_yday
2346
/* + intervening leap days */
2347
+ ((ay >> 2) - (by >> 2))
2348
- (ay/100 - by/100)
2349
+ ((ay/100 >> 2) - (by/100 >> 2))
2350
/* + difference in years * 365 */
2351
+ (long)(ay-by) * 365
2352
);
2353
return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
2354
+ (a->tm_min - b->tm_min))
2355
+ (a->tm_sec - b->tm_sec));
2356
}
2357
2358
time_t get_date(char *p);
2359
2360
time_t
2361
get_date(char *p)
2362
{
2363
struct tm tm, gmt;
2364
time_t Start;
2365
time_t tod;
2366
time_t now;
2367
time_t tz;
2368
2369
yyInput = p;
2370
(void)time (&now);
2371
2372
if (gmtime_r (&now, &gmt) == NULL)
2373
return -1;
2374
2375
if (localtime_r (&now, &tm) == NULL)
2376
return -1;
2377
2378
tz = difftm (&gmt, &tm) / 60;
2379
if (tm.tm_isdst)
2380
tz += 60;
2381
2382
yyYear = tm.tm_year + 1900;
2383
yyMonth = tm.tm_mon + 1;
2384
yyDay = tm.tm_mday;
2385
yyTimezone = tz;
2386
yyDSTmode = DSTmaybe;
2387
yyHour = 0;
2388
yyMinutes = 0;
2389
yySeconds = 0;
2390
yyMeridian = MER24;
2391
yyRelSeconds = 0;
2392
yyRelMonth = 0;
2393
yyHaveDate = 0;
2394
yyHaveDay = 0;
2395
yyHaveRel = 0;
2396
yyHaveTime = 0;
2397
yyHaveZone = 0;
2398
2399
if (yyparse()
2400
|| yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
2401
return -1;
2402
2403
if (yyHaveDate || yyHaveTime || yyHaveDay) {
2404
Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
2405
yyMeridian, yyDSTmode);
2406
if (Start < 0)
2407
return -1;
2408
}
2409
else {
2410
Start = now;
2411
if (!yyHaveRel)
2412
Start -= ((tm.tm_hour * 60L + tm.tm_min) * 60L) + tm.tm_sec;
2413
}
2414
2415
Start += yyRelSeconds;
2416
Start += RelativeMonth(Start, yyRelMonth);
2417
2418
if (yyHaveDay && !yyHaveDate) {
2419
tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
2420
Start += tod;
2421
}
2422
2423
/* Have to do *something* with a legitimate -1 so it's distinguishable
2424
* from the error return value. (Alternately could set errno on error.) */
2425
return Start == -1 ? 0 : Start;
2426
}
2427
2428
2429
#ifdef TEST
2430
2431
/* ARGSUSED */
2432
int
2433
main(int argc, char *argv[])
2434
{
2435
char buff[128];
2436
time_t d;
2437
2438
(void)fputs("Enter date, or blank line to exit.\n\t> ", stdout);
2439
(void)fflush(stdout);
2440
while (fgets(buff, sizeof(buff), stdin) && buff[0]) {
2441
d = get_date(buff);
2442
if (d == -1)
2443
(void)fputs("Bad format - couldn't convert.\n\t> ", stdout);
2444
else
2445
(void)printf("%s\t> ", ctime(&d));
2446
(void)fflush(stdout);
2447
}
2448
return 0;
2449
}
2450
#endif /* TEST */
2451
2452