~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/CTest/Curl/getdate.c

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2005-03-02 09:22:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050302092244-y6o9j8wr27vqcqvx
Tags: 2.0.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*  A Bison parser, made from getdate.y
 
3
    by GNU Bison version 1.28  */
 
4
 
 
5
#define YYBISON 1  /* Identify Bison output.  */
 
6
 
 
7
#define tAGO    257
 
8
#define tDAY    258
 
9
#define tDAY_UNIT       259
 
10
#define tDAYZONE        260
 
11
#define tDST    261
 
12
#define tHOUR_UNIT      262
 
13
#define tID     263
 
14
#define tMERIDIAN       264
 
15
#define tMINUTE_UNIT    265
 
16
#define tMONTH  266
 
17
#define tMONTH_UNIT     267
 
18
#define tSEC_UNIT       268
 
19
#define tSNUMBER        269
 
20
#define tUNUMBER        270
 
21
#define tYEAR_UNIT      271
 
22
#define tZONE   272
 
23
 
 
24
#line 1 "getdate.y"
 
25
 
 
26
/*
 
27
**  Originally written by Steven M. Bellovin <smb@research.att.com> while
 
28
**  at the University of North Carolina at Chapel Hill.  Later tweaked by
 
29
**  a couple of people on Usenet.  Completely overhauled by Rich $alz
 
30
**  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
 
31
**
 
32
**  This code is in the public domain and has no copyright.
 
33
*/
 
34
 
 
35
#include "setup.h"
 
36
 
 
37
# ifdef HAVE_ALLOCA_H
 
38
#  include <alloca.h>
 
39
# endif
 
40
 
 
41
# ifdef HAVE_TIME_H
 
42
#  include <time.h>
 
43
# endif
 
44
 
 
45
#ifndef YYDEBUG
 
46
  /* to satisfy gcc -Wundef, we set this to 0 */
 
47
#define YYDEBUG 0
 
48
#endif
 
49
 
 
50
/* Since the code of getdate.y is not included in the Emacs executable
 
51
   itself, there is no need to #define static in this file.  Even if
 
52
   the code were included in the Emacs executable, it probably
 
53
   wouldn't do any harm to #undef it here; this will only cause
 
54
   problems if we try to write to a static variable, which I don't
 
55
   think this code needs to do.  */
 
56
#ifdef emacs
 
57
# undef static
 
58
#endif
 
59
 
 
60
#ifdef __APPLE__
 
61
#include <sys/types.h>
 
62
#include <sys/malloc.h>
 
63
#else
 
64
 
 
65
#endif
 
66
#include <string.h>
 
67
#include <stdio.h>
 
68
#include <ctype.h>
 
69
 
 
70
#if HAVE_STDLIB_H
 
71
# include <stdlib.h> /* for `free'; used by Bison 1.27 */
 
72
#else
 
73
 
 
74
#ifdef HAVE_MALLOC_H
 
75
#include <malloc.h>
 
76
#endif
 
77
 
 
78
#endif
 
79
 
 
80
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
 
81
# define IN_CTYPE_DOMAIN(c) 1
 
82
#else
 
83
# define IN_CTYPE_DOMAIN(c) isascii((int)(c))
 
84
#endif
 
85
 
 
86
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace ((int)(c)))
 
87
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((int)(c)))
 
88
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((int)(c)))
 
89
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit ((int)(c)))
 
90
 
 
91
/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
 
92
   - Its arg may be any int or unsigned int; it need not be an unsigned char.
 
93
   - It's guaranteed to evaluate its argument exactly once.
 
94
   - It's typically faster.
 
95
   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
 
96
   only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
 
97
   it's important to use the locale's definition of `digit' even when the
 
98
   host does not conform to Posix.  */
 
99
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
 
100
 
 
101
#if defined (STDC_HEADERS) || defined (USG)
 
102
# include <string.h>
 
103
#endif
 
104
 
 
105
/* The last #include file should be: */
 
106
#ifdef MALLOCDEBUG
 
107
#include "memdebug.h"
 
108
#endif
 
109
 
 
110
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
 
111
# define __attribute__(x)
 
112
#endif
 
113
 
 
114
#ifndef ATTRIBUTE_UNUSED
 
115
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
 
116
#endif
 
117
 
 
118
/* Some old versions of bison generate parsers that use bcopy.
 
119
   That loses on systems that don't provide the function, so we have
 
120
   to redefine it here.  */
 
121
#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
 
122
# define bcopy(from, to, len) memcpy ((to), (from), (len))
 
123
#endif
 
124
 
 
125
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
 
126
   as well as gratuitiously global symbol names, so we can have multiple
 
127
   yacc generated parsers in the same program.  Note that these are only
 
128
   the variables produced by yacc.  If other parser generators (bison,
 
129
   byacc, etc) produce additional global names that conflict at link time,
 
130
   then those parser generators need to be fixed instead of adding those
 
131
   names to this list. */
 
132
 
 
133
#define yymaxdepth Curl_gd_maxdepth
 
134
#define yyparse Curl_gd_parse
 
135
#define yylex   Curl_gd_lex
 
136
#define yyerror Curl_gd_error
 
137
#define yylval  Curl_gd_lval
 
138
#define yychar  Curl_gd_char
 
139
#define yydebug Curl_gd_debug
 
140
#define yypact  Curl_gd_pact
 
141
#define yyr1    Curl_gd_r1
 
142
#define yyr2    Curl_gd_r2
 
143
#define yydef   Curl_gd_def
 
144
#define yychk   Curl_gd_chk
 
145
#define yypgo   Curl_gd_pgo
 
146
#define yyact   Curl_gd_act
 
147
#define yyexca  Curl_gd_exca
 
148
#define yyerrflag Curl_gd_errflag
 
149
#define yynerrs Curl_gd_nerrs
 
150
#define yyps    Curl_gd_ps
 
151
#define yypv    Curl_gd_pv
 
152
#define yys     Curl_gd_s
 
153
#define yy_yys  Curl_gd_yys
 
154
#define yystate Curl_gd_state
 
155
#define yytmp   Curl_gd_tmp
 
156
#define yyv     Curl_gd_v
 
157
#define yy_yyv  Curl_gd_yyv
 
158
#define yyval   Curl_gd_val
 
159
#define yylloc  Curl_gd_lloc
 
160
#define yyreds  Curl_gd_reds          /* With YYDEBUG defined */
 
161
#define yytoks  Curl_gd_toks          /* With YYDEBUG defined */
 
162
#define yylhs   Curl_gd_yylhs
 
163
#define yylen   Curl_gd_yylen
 
164
#define yydefred Curl_gd_yydefred
 
165
#define yydgoto Curl_gd_yydgoto
 
166
#define yysindex Curl_gd_yysindex
 
167
#define yyrindex Curl_gd_yyrindex
 
168
#define yygindex Curl_gd_yygindex
 
169
#define yytable  Curl_gd_yytable
 
170
#define yycheck  Curl_gd_yycheck
 
171
 
 
172
static int yylex ();
 
173
static int yyerror ();
 
174
 
 
175
#define EPOCH           1970
 
176
#define HOUR(x)         ((x) * 60)
 
177
 
 
178
#define MAX_BUFF_LEN    128   /* size of buffer to read the date into */
 
179
 
 
180
/*
 
181
**  An entry in the lexical lookup table.
 
182
*/
 
183
typedef struct _TABLE {
 
184
    const char  *name;
 
185
    int         type;
 
186
    int         value;
 
187
} TABLE;
 
188
 
 
189
 
 
190
/*
 
191
**  Meridian:  am, pm, or 24-hour style.
 
192
*/
 
193
typedef enum _MERIDIAN {
 
194
    MERam, MERpm, MER24
 
195
} MERIDIAN;
 
196
 
 
197
/* parse results and input string */
 
198
typedef struct _CONTEXT {
 
199
    const char  *yyInput;
 
200
    int         yyDayOrdinal;
 
201
    int         yyDayNumber;
 
202
    int         yyHaveDate;
 
203
    int         yyHaveDay;
 
204
    int         yyHaveRel;
 
205
    int         yyHaveTime;
 
206
    int         yyHaveZone;
 
207
    int         yyTimezone;
 
208
    int         yyDay;
 
209
    int         yyHour;
 
210
    int         yyMinutes;
 
211
    int         yyMonth;
 
212
    int         yySeconds;
 
213
    int         yyYear;
 
214
    MERIDIAN    yyMeridian;
 
215
    int         yyRelDay;
 
216
    int         yyRelHour;
 
217
    int         yyRelMinutes;
 
218
    int         yyRelMonth;
 
219
    int         yyRelSeconds;
 
220
    int         yyRelYear;
 
221
} CONTEXT;
 
222
 
 
223
/* enable use of extra argument to yyparse and yylex which can be used to pass
 
224
**  in a user defined value (CONTEXT struct in our case)
 
225
*/
 
226
#define YYPARSE_PARAM cookie
 
227
#define YYLEX_PARAM cookie
 
228
#define context ((CONTEXT *) cookie)
 
229
 
 
230
#line 215 "getdate.y"
 
231
typedef union {
 
232
    int                 Number;
 
233
    enum _MERIDIAN      Meridian;
 
234
} YYSTYPE;
 
235
#include <stdio.h>
 
236
 
 
237
#ifndef __cplusplus
 
238
#ifndef __STDC__
 
239
#define const
 
240
#endif
 
241
#endif
 
242
 
 
243
 
 
244
 
 
245
#define YYFINAL         61
 
246
#define YYFLAG          -32768
 
247
#define YYNTBASE        22
 
248
 
 
249
#define YYTRANSLATE(x) ((unsigned)(x) <= 272 ? yytranslate[x] : 32)
 
250
 
 
251
static const char yytranslate[] = {     0,
 
252
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
253
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
254
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
255
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
256
     2,     2,     2,    20,     2,     2,    21,     2,     2,     2,
 
257
     2,     2,     2,     2,     2,     2,     2,    19,     2,     2,
 
258
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
259
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
260
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
261
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
262
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
263
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
264
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
265
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
266
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
267
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
268
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
269
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
270
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
271
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
272
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
273
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
274
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
275
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
276
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
 
277
     2,     2,     2,     2,     2,     1,     3,     4,     5,     6,
 
278
     7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
 
279
    17,    18
 
280
};
 
281
 
 
282
#if YYDEBUG != 0
 
283
static const short yyprhs[] = {     0,
 
284
     0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
 
285
    24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
 
286
    62,    68,    72,    76,    79,    84,    87,    91,    94,    96,
 
287
    99,   102,   104,   107,   110,   112,   115,   118,   120,   123,
 
288
   126,   128,   131,   134,   136,   139,   142,   144,   146,   147
 
289
};
 
290
 
 
291
static const short yyrhs[] = {    -1,
 
292
    22,    23,     0,    24,     0,    25,     0,    27,     0,    26,
 
293
     0,    28,     0,    30,     0,    16,    10,     0,    16,    19,
 
294
    16,    31,     0,    16,    19,    16,    15,     0,    16,    19,
 
295
    16,    19,    16,    31,     0,    16,    19,    16,    19,    16,
 
296
    15,     0,    18,     0,     6,     0,    18,     7,     0,     4,
 
297
     0,     4,    20,     0,    16,     4,     0,    16,    21,    16,
 
298
     0,    16,    21,    16,    21,    16,     0,    16,    15,    15,
 
299
     0,    16,    12,    15,     0,    12,    16,     0,    12,    16,
 
300
    20,    16,     0,    16,    12,     0,    16,    12,    16,     0,
 
301
    29,     3,     0,    29,     0,    16,    17,     0,    15,    17,
 
302
     0,    17,     0,    16,    13,     0,    15,    13,     0,    13,
 
303
     0,    16,     5,     0,    15,     5,     0,     5,     0,    16,
 
304
     8,     0,    15,     8,     0,     8,     0,    16,    11,     0,
 
305
    15,    11,     0,    11,     0,    16,    14,     0,    15,    14,
 
306
     0,    14,     0,    16,     0,     0,    10,     0
 
307
};
 
308
 
 
309
#endif
 
310
 
 
311
#if YYDEBUG != 0
 
312
static const short yyrline[] = { 0,
 
313
   231,   232,   235,   238,   241,   244,   247,   250,   253,   259,
 
314
   265,   274,   280,   292,   295,   298,   304,   308,   312,   318,
 
315
   322,   340,   346,   352,   356,   361,   365,   372,   380,   383,
 
316
   386,   389,   392,   395,   398,   401,   404,   407,   410,   413,
 
317
   416,   419,   422,   425,   428,   431,   434,   439,   473,   477
 
318
};
 
319
#endif
 
320
 
 
321
 
 
322
#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
 
323
 
 
324
static const char * const yytname[] = {   "$","error","$undefined.","tAGO","tDAY",
 
325
"tDAY_UNIT","tDAYZONE","tDST","tHOUR_UNIT","tID","tMERIDIAN","tMINUTE_UNIT",
 
326
"tMONTH","tMONTH_UNIT","tSEC_UNIT","tSNUMBER","tUNUMBER","tYEAR_UNIT","tZONE",
 
327
"':'","','","'/'","spec","item","time","zone","day","date","rel","relunit","number",
 
328
"o_merid", NULL
 
329
};
 
330
#endif
 
331
 
 
332
static const short yyr1[] = {     0,
 
333
    22,    22,    23,    23,    23,    23,    23,    23,    24,    24,
 
334
    24,    24,    24,    25,    25,    25,    26,    26,    26,    27,
 
335
    27,    27,    27,    27,    27,    27,    27,    28,    28,    29,
 
336
    29,    29,    29,    29,    29,    29,    29,    29,    29,    29,
 
337
    29,    29,    29,    29,    29,    29,    29,    30,    31,    31
 
338
};
 
339
 
 
340
static const short yyr2[] = {     0,
 
341
     0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
 
342
     4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
 
343
     5,     3,     3,     2,     4,     2,     3,     2,     1,     2,
 
344
     2,     1,     2,     2,     1,     2,     2,     1,     2,     2,
 
345
     1,     2,     2,     1,     2,     2,     1,     1,     0,     1
 
346
};
 
347
 
 
348
static const short yydefact[] = {     1,
 
349
     0,    17,    38,    15,    41,    44,     0,    35,    47,     0,
 
350
    48,    32,    14,     2,     3,     4,     6,     5,     7,    29,
 
351
     8,    18,    24,    37,    40,    43,    34,    46,    31,    19,
 
352
    36,    39,     9,    42,    26,    33,    45,     0,    30,     0,
 
353
     0,    16,    28,     0,    23,    27,    22,    49,    20,    25,
 
354
    50,    11,     0,    10,     0,    49,    21,    13,    12,     0,
 
355
     0
 
356
};
 
357
 
 
358
static const short yydefgoto[] = {     1,
 
359
    14,    15,    16,    17,    18,    19,    20,    21,    54
 
360
};
 
361
 
 
362
static const short yypact[] = {-32768,
 
363
     0,   -19,-32768,-32768,-32768,-32768,   -13,-32768,-32768,    30,
 
364
    15,-32768,    14,-32768,-32768,-32768,-32768,-32768,-32768,    19,
 
365
-32768,-32768,     4,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
 
366
-32768,-32768,-32768,-32768,    -6,-32768,-32768,    16,-32768,    17,
 
367
    23,-32768,-32768,    24,-32768,-32768,-32768,    27,    28,-32768,
 
368
-32768,-32768,    29,-32768,    32,    -8,-32768,-32768,-32768,    50,
 
369
-32768
 
370
};
 
371
 
 
372
static const short yypgoto[] = {-32768,
 
373
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
 
374
};
 
375
 
 
376
 
 
377
#define YYLAST          51
 
378
 
 
379
 
 
380
static const short yytable[] = {    60,
 
381
    22,    51,    23,     2,     3,     4,    58,     5,    45,    46,
 
382
     6,     7,     8,     9,    10,    11,    12,    13,    30,    31,
 
383
    42,    43,    32,    44,    33,    34,    35,    36,    37,    38,
 
384
    47,    39,    48,    40,    24,    41,    51,    25,    49,    50,
 
385
    26,    52,    27,    28,    56,    53,    29,    57,    55,    61,
 
386
    59
 
387
};
 
388
 
 
389
static const short yycheck[] = {     0,
 
390
    20,    10,    16,     4,     5,     6,    15,     8,    15,    16,
 
391
    11,    12,    13,    14,    15,    16,    17,    18,     4,     5,
 
392
     7,     3,     8,    20,    10,    11,    12,    13,    14,    15,
 
393
    15,    17,    16,    19,     5,    21,    10,     8,    16,    16,
 
394
    11,    15,    13,    14,    16,    19,    17,    16,    21,     0,
 
395
    56
 
396
};
 
397
#define YYPURE 1
 
398
 
 
399
/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
 
400
#line 3 "/usr/local/share/bison.simple"
 
401
/* This file comes from bison-1.28.  */
 
402
 
 
403
/* Skeleton output parser for bison,
 
404
   Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
 
405
 
 
406
   This program is free software; you can redistribute it and/or modify
 
407
   it under the terms of the GNU General Public License as published by
 
408
   the Free Software Foundation; either version 2, or (at your option)
 
409
   any later version.
 
410
 
 
411
   This program is distributed in the hope that it will be useful,
 
412
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
413
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
414
   GNU General Public License for more details.
 
415
 
 
416
   You should have received a copy of the GNU General Public License
 
417
   along with this program; if not, write to the Free Software
 
418
   Foundation, Inc., 59 Temple Place - Suite 330,
 
419
   Boston, MA 02111-1307, USA.  */
 
420
 
 
421
/* As a special exception, when this file is copied by Bison into a
 
422
   Bison output file, you may use that output file without restriction.
 
423
   This special exception was added by the Free Software Foundation
 
424
   in version 1.24 of Bison.  */
 
425
 
 
426
/* This is the parser code that is written into each bison parser
 
427
  when the %semantic_parser declaration is not specified in the grammar.
 
428
  It was written by Richard Stallman by simplifying the hairy parser
 
429
  used when %semantic_parser is specified.  */
 
430
 
 
431
#ifndef YYSTACK_USE_ALLOCA
 
432
#ifdef alloca
 
433
#define YYSTACK_USE_ALLOCA
 
434
#else /* alloca not defined */
 
435
#ifdef __GNUC__
 
436
#define YYSTACK_USE_ALLOCA
 
437
#define alloca __builtin_alloca
 
438
#else /* not GNU C.  */
 
439
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
 
440
#define YYSTACK_USE_ALLOCA
 
441
#include <alloca.h>
 
442
#else /* not sparc */
 
443
/* We think this test detects Watcom and Microsoft C.  */
 
444
/* This used to test MSDOS, but that is a bad idea
 
445
   since that symbol is in the user namespace.  */
 
446
#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
 
447
#if 0 /* No need for malloc.h, which pollutes the namespace;
 
448
         instead, just don't use alloca.  */
 
449
#include <malloc.h>
 
450
#endif
 
451
#else /* not MSDOS, or __TURBOC__ */
 
452
#if defined(_AIX)
 
453
/* I don't know what this was needed for, but it pollutes the namespace.
 
454
   So I turned it off.   rms, 2 May 1997.  */
 
455
/* #include <malloc.h>  */
 
456
 #pragma alloca
 
457
#define YYSTACK_USE_ALLOCA
 
458
#else /* not MSDOS, or __TURBOC__, or _AIX */
 
459
#if 0
 
460
#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
 
461
                 and on HPUX 10.  Eventually we can turn this on.  */
 
462
#define YYSTACK_USE_ALLOCA
 
463
#define alloca __builtin_alloca
 
464
#endif /* __hpux */
 
465
#endif
 
466
#endif /* not _AIX */
 
467
#endif /* not MSDOS, or __TURBOC__ */
 
468
#endif /* not sparc */
 
469
#endif /* not GNU C */
 
470
#endif /* alloca not defined */
 
471
#endif /* YYSTACK_USE_ALLOCA not defined */
 
472
 
 
473
#ifdef YYSTACK_USE_ALLOCA
 
474
#define YYSTACK_ALLOC alloca
 
475
#else
 
476
#define YYSTACK_ALLOC malloc
 
477
#endif
 
478
 
 
479
/* Note: there must be only one dollar sign in this file.
 
480
   It is replaced by the list of actions, each action
 
481
   as one case of the switch.  */
 
482
 
 
483
#define yyerrok         (yyerrstatus = 0)
 
484
#define yyclearin       (yychar = YYEMPTY)
 
485
#define YYEMPTY         -2
 
486
#define YYEOF           0
 
487
#define YYACCEPT        goto yyacceptlab
 
488
#define YYABORT         goto yyabortlab
 
489
#define YYERROR         goto yyerrlab1
 
490
/* Like YYERROR except do call yyerror.
 
491
   This remains here temporarily to ease the
 
492
   transition to the new meaning of YYERROR, for GCC.
 
493
   Once GCC version 2 has supplanted version 1, this can go.  */
 
494
#define YYFAIL          goto yyerrlab
 
495
#define YYRECOVERING()  (!!yyerrstatus)
 
496
#define YYBACKUP(token, value) \
 
497
do                                                              \
 
498
  if (yychar == YYEMPTY && yylen == 1)                          \
 
499
    { yychar = (token), yylval = (value);                       \
 
500
      yychar1 = YYTRANSLATE (yychar);                           \
 
501
      YYPOPSTACK;                                               \
 
502
      goto yybackup;                                            \
 
503
    }                                                           \
 
504
  else                                                          \
 
505
    { yyerror ("syntax error: cannot back up"); YYERROR; }      \
 
506
while (0)
 
507
 
 
508
#define YYTERROR        1
 
509
#define YYERRCODE       256
 
510
 
 
511
#ifndef YYPURE
 
512
#define YYLEX           yylex()
 
513
#endif
 
514
 
 
515
#ifdef YYPURE
 
516
#ifdef YYLSP_NEEDED
 
517
#ifdef YYLEX_PARAM
 
518
#define YYLEX           yylex(&yylval, &yylloc, YYLEX_PARAM)
 
519
#else
 
520
#define YYLEX           yylex(&yylval, &yylloc)
 
521
#endif
 
522
#else /* not YYLSP_NEEDED */
 
523
#ifdef YYLEX_PARAM
 
524
#define YYLEX           yylex(&yylval, YYLEX_PARAM)
 
525
#else
 
526
#define YYLEX           yylex(&yylval)
 
527
#endif
 
528
#endif /* not YYLSP_NEEDED */
 
529
#endif
 
530
 
 
531
/* If nonreentrant, generate the variables here */
 
532
 
 
533
#ifndef YYPURE
 
534
 
 
535
int     yychar;                 /*  the lookahead symbol                */
 
536
YYSTYPE yylval;                 /*  the semantic value of the           */
 
537
                                /*  lookahead symbol                    */
 
538
 
 
539
#ifdef YYLSP_NEEDED
 
540
YYLTYPE yylloc;                 /*  location data for the lookahead     */
 
541
                                /*  symbol                              */
 
542
#endif
 
543
 
 
544
int yynerrs;                    /*  number of parse errors so far       */
 
545
#endif  /* not YYPURE */
 
546
 
 
547
#if YYDEBUG != 0
 
548
int yydebug;                    /*  nonzero means print parse trace     */
 
549
/* Since this is uninitialized, it does not stop multiple parsers
 
550
   from coexisting.  */
 
551
#endif
 
552
 
 
553
/*  YYINITDEPTH indicates the initial size of the parser's stacks       */
 
554
 
 
555
#ifndef YYINITDEPTH
 
556
#define YYINITDEPTH 200
 
557
#endif
 
558
 
 
559
/*  YYMAXDEPTH is the maximum size the stacks can grow to
 
560
    (effective only if the built-in stack extension method is used).  */
 
561
 
 
562
#if YYMAXDEPTH == 0
 
563
#undef YYMAXDEPTH
 
564
#endif
 
565
 
 
566
#ifndef YYMAXDEPTH
 
567
#define YYMAXDEPTH 10000
 
568
#endif
 
569
 
 
570
/* Define __yy_memcpy.  Note that the size argument
 
571
   should be passed with type unsigned int, because that is what the non-GCC
 
572
   definitions require.  With GCC, __builtin_memcpy takes an arg
 
573
   of type size_t, but it can handle unsigned int.  */
 
574
 
 
575
#if __GNUC__ > 1                /* GNU C and GNU C++ define this.  */
 
576
#define __yy_memcpy(TO,FROM,COUNT)      __builtin_memcpy(TO,FROM,COUNT)
 
577
#else                           /* not GNU C or C++ */
 
578
#ifndef __cplusplus
 
579
 
 
580
/* This is the most reliable way to avoid incompatibilities
 
581
   in available built-in functions on various systems.  */
 
582
static void
 
583
__yy_memcpy (to, from, count)
 
584
     char *to;
 
585
     char *from;
 
586
     unsigned int count;
 
587
{
 
588
  register char *f = from;
 
589
  register char *t = to;
 
590
  register int i = count;
 
591
 
 
592
  while (i-- > 0)
 
593
    *t++ = *f++;
 
594
}
 
595
 
 
596
#else /* __cplusplus */
 
597
 
 
598
/* This is the most reliable way to avoid incompatibilities
 
599
   in available built-in functions on various systems.  */
 
600
static void
 
601
__yy_memcpy (char *to, char *from, unsigned int count)
 
602
{
 
603
  register char *t = to;
 
604
  register char *f = from;
 
605
  register int i = count;
 
606
 
 
607
  while (i-- > 0)
 
608
    *t++ = *f++;
 
609
}
 
610
 
 
611
#endif
 
612
#endif
 
613
 
 
614
#line 217 "/usr/local/share/bison.simple"
 
615
 
 
616
/* The user can define YYPARSE_PARAM as the name of an argument to be passed
 
617
   into yyparse.  The argument should have type void *.
 
618
   It should actually point to an object.
 
619
   Grammar actions can access the variable by casting it
 
620
   to the proper pointer type.  */
 
621
 
 
622
#ifdef YYPARSE_PARAM
 
623
#ifdef __cplusplus
 
624
#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
 
625
#define YYPARSE_PARAM_DECL
 
626
#else /* not __cplusplus */
 
627
#define YYPARSE_PARAM_ARG YYPARSE_PARAM
 
628
#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
 
629
#endif /* not __cplusplus */
 
630
#else /* not YYPARSE_PARAM */
 
631
#define YYPARSE_PARAM_ARG
 
632
#define YYPARSE_PARAM_DECL
 
633
#endif /* not YYPARSE_PARAM */
 
634
 
 
635
/* Prevent warning if -Wstrict-prototypes.  */
 
636
#ifdef __GNUC__
 
637
#ifdef YYPARSE_PARAM
 
638
int yyparse (void *);
 
639
#else
 
640
int yyparse (void);
 
641
#endif
 
642
#endif
 
643
 
 
644
int
 
645
yyparse(YYPARSE_PARAM_ARG)
 
646
     YYPARSE_PARAM_DECL
 
647
{
 
648
  register int yystate;
 
649
  register int yyn;
 
650
  register short *yyssp;
 
651
  register YYSTYPE *yyvsp;
 
652
  int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
 
653
  int yychar1 = 0;              /*  lookahead token as an internal (translated) token number */
 
654
 
 
655
  short yyssa[YYINITDEPTH];     /*  the state stack                     */
 
656
  YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
 
657
 
 
658
  short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
 
659
  YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
 
660
 
 
661
#ifdef YYLSP_NEEDED
 
662
  YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
 
663
  YYLTYPE *yyls = yylsa;
 
664
  YYLTYPE *yylsp;
 
665
 
 
666
#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
 
667
#else
 
668
#define YYPOPSTACK   (yyvsp--, yyssp--)
 
669
#endif
 
670
 
 
671
  int yystacksize = YYINITDEPTH;
 
672
  int yyfree_stacks = 0;
 
673
 
 
674
#ifdef YYPURE
 
675
  int yychar;
 
676
  YYSTYPE yylval;
 
677
  int yynerrs;
 
678
#ifdef YYLSP_NEEDED
 
679
  YYLTYPE yylloc;
 
680
#endif
 
681
#endif
 
682
 
 
683
  YYSTYPE yyval;                /*  the variable used to return         */
 
684
                                /*  semantic values from the action     */
 
685
                                /*  routines                            */
 
686
 
 
687
  int yylen;
 
688
 
 
689
#if YYDEBUG != 0
 
690
  if (yydebug)
 
691
    fprintf(stderr, "Starting parse\n");
 
692
#endif
 
693
 
 
694
  yylval.Number = 0;
 
695
  yyval.Number = 0;
 
696
   
 
697
  yystate = 0;
 
698
  yyerrstatus = 0;
 
699
  yynerrs = 0;
 
700
  yychar = YYEMPTY;             /* Cause a token to be read.  */
 
701
 
 
702
  /* Initialize stack pointers.
 
703
     Waste one element of value and location stack
 
704
     so that they stay on the same level as the state stack.
 
705
     The wasted elements are never initialized.  */
 
706
 
 
707
  yyssp = yyss - 1;
 
708
  yyvsp = yyvs;
 
709
#ifdef YYLSP_NEEDED
 
710
  yylsp = yyls;
 
711
#endif
 
712
 
 
713
/* Push a new state, which is found in  yystate  .  */
 
714
/* In all cases, when you get here, the value and location stacks
 
715
   have just been pushed. so pushing a state here evens the stacks.  */
 
716
yynewstate:
 
717
 
 
718
  *++yyssp = (short)yystate;
 
719
 
 
720
  if (yyssp >= yyss + yystacksize - 1)
 
721
    {
 
722
      /* Give user a chance to reallocate the stack */
 
723
      /* Use copies of these so that the &'s don't force the real ones into memory. */
 
724
      YYSTYPE *yyvs1 = yyvs;
 
725
      short *yyss1 = yyss;
 
726
#ifdef YYLSP_NEEDED
 
727
      YYLTYPE *yyls1 = yyls;
 
728
#endif
 
729
 
 
730
      /* Get the current used size of the three stacks, in elements.  */
 
731
      int size = (int)(yyssp - yyss + 1);
 
732
 
 
733
#ifdef yyoverflow
 
734
      /* Each stack pointer address is followed by the size of
 
735
         the data in use in that stack, in bytes.  */
 
736
#ifdef YYLSP_NEEDED
 
737
      /* This used to be a conditional around just the two extra args,
 
738
         but that might be undefined if yyoverflow is a macro.  */
 
739
      yyoverflow("parser stack overflow",
 
740
                 &yyss1, size * sizeof (*yyssp),
 
741
                 &yyvs1, size * sizeof (*yyvsp),
 
742
                 &yyls1, size * sizeof (*yylsp),
 
743
                 &yystacksize);
 
744
#else
 
745
      yyoverflow("parser stack overflow",
 
746
                 &yyss1, size * sizeof (*yyssp),
 
747
                 &yyvs1, size * sizeof (*yyvsp),
 
748
                 &yystacksize);
 
749
#endif
 
750
 
 
751
      yyss = yyss1; yyvs = yyvs1;
 
752
#ifdef YYLSP_NEEDED
 
753
      yyls = yyls1;
 
754
#endif
 
755
#else /* no yyoverflow */
 
756
      /* Extend the stack our own way.  */
 
757
      if (yystacksize >= YYMAXDEPTH)
 
758
        {
 
759
          yyerror("parser stack overflow");
 
760
          if (yyfree_stacks)
 
761
            {
 
762
              free (yyss);
 
763
              free (yyvs);
 
764
#ifdef YYLSP_NEEDED
 
765
              free (yyls);
 
766
#endif
 
767
            }
 
768
          return 2;
 
769
        }
 
770
      yystacksize *= 2;
 
771
      if (yystacksize > YYMAXDEPTH)
 
772
        yystacksize = YYMAXDEPTH;
 
773
#ifndef YYSTACK_USE_ALLOCA
 
774
      yyfree_stacks = 1;
 
775
#endif
 
776
      yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
 
777
      __yy_memcpy ((char *)yyss, (char *)yyss1,
 
778
                   size * (unsigned int) sizeof (*yyssp));
 
779
      yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
 
780
      __yy_memcpy ((char *)yyvs, (char *)yyvs1,
 
781
                   size * (unsigned int) sizeof (*yyvsp));
 
782
#ifdef YYLSP_NEEDED
 
783
      yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
 
784
      __yy_memcpy ((char *)yyls, (char *)yyls1,
 
785
                   size * (unsigned int) sizeof (*yylsp));
 
786
#endif
 
787
#endif /* no yyoverflow */
 
788
 
 
789
      yyssp = yyss + size - 1;
 
790
      yyvsp = yyvs + size - 1;
 
791
#ifdef YYLSP_NEEDED
 
792
      yylsp = yyls + size - 1;
 
793
#endif
 
794
 
 
795
#if YYDEBUG != 0
 
796
      if (yydebug)
 
797
        fprintf(stderr, "Stack size increased to %d\n", yystacksize);
 
798
#endif
 
799
 
 
800
      if (yyssp >= yyss + yystacksize - 1)
 
801
        YYABORT;
 
802
    }
 
803
 
 
804
#if YYDEBUG != 0
 
805
  if (yydebug)
 
806
    fprintf(stderr, "Entering state %d\n", yystate);
 
807
#endif
 
808
 
 
809
  goto yybackup;
 
810
 yybackup:
 
811
 
 
812
/* Do appropriate processing given the current state.  */
 
813
/* Read a lookahead token if we need one and don't already have one.  */
 
814
/* yyresume: */
 
815
 
 
816
  /* First try to decide what to do without reference to lookahead token.  */
 
817
 
 
818
  yyn = yypact[yystate];
 
819
  if (yyn == YYFLAG)
 
820
    goto yydefault;
 
821
 
 
822
  /* Not known => get a lookahead token if don't already have one.  */
 
823
 
 
824
  /* yychar is either YYEMPTY or YYEOF
 
825
     or a valid token in external form.  */
 
826
 
 
827
  if (yychar == YYEMPTY)
 
828
    {
 
829
#if YYDEBUG != 0
 
830
      if (yydebug)
 
831
        fprintf(stderr, "Reading a token: ");
 
832
#endif
 
833
      yychar = YYLEX;
 
834
    }
 
835
 
 
836
  /* Convert token to internal form (in yychar1) for indexing tables with */
 
837
 
 
838
  if (yychar <= 0)              /* This means end of input. */
 
839
    {
 
840
      yychar1 = 0;
 
841
      yychar = YYEOF;           /* Don't call YYLEX any more */
 
842
 
 
843
#if YYDEBUG != 0
 
844
      if (yydebug)
 
845
        fprintf(stderr, "Now at end of input.\n");
 
846
#endif
 
847
    }
 
848
  else
 
849
    {
 
850
      yychar1 = YYTRANSLATE(yychar);
 
851
 
 
852
#if YYDEBUG != 0
 
853
      if (yydebug)
 
854
        {
 
855
          fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
 
856
          /* Give the individual parser a way to print the precise meaning
 
857
             of a token, for further debugging info.  */
 
858
#ifdef YYPRINT
 
859
          YYPRINT (stderr, yychar, yylval);
 
860
#endif
 
861
          fprintf (stderr, ")\n");
 
862
        }
 
863
#endif
 
864
    }
 
865
 
 
866
  yyn += yychar1;
 
867
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
 
868
    goto yydefault;
 
869
 
 
870
  yyn = yytable[yyn];
 
871
 
 
872
  /* yyn is what to do for this token type in this state.
 
873
     Negative => reduce, -yyn is rule number.
 
874
     Positive => shift, yyn is new state.
 
875
       New state is final state => don't bother to shift,
 
876
       just return success.
 
877
     0, or most negative number => error.  */
 
878
 
 
879
  if (yyn < 0)
 
880
    {
 
881
      if (yyn == YYFLAG)
 
882
        goto yyerrlab;
 
883
      yyn = -yyn;
 
884
      goto yyreduce;
 
885
    }
 
886
  else if (yyn == 0)
 
887
    goto yyerrlab;
 
888
 
 
889
  if (yyn == YYFINAL)
 
890
    YYACCEPT;
 
891
 
 
892
  /* Shift the lookahead token.  */
 
893
 
 
894
#if YYDEBUG != 0
 
895
  if (yydebug)
 
896
    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
 
897
#endif
 
898
 
 
899
  /* Discard the token being shifted unless it is eof.  */
 
900
  if (yychar != YYEOF)
 
901
    yychar = YYEMPTY;
 
902
 
 
903
  *++yyvsp = yylval;
 
904
#ifdef YYLSP_NEEDED
 
905
  *++yylsp = yylloc;
 
906
#endif
 
907
 
 
908
  /* count tokens shifted since error; after three, turn off error status.  */
 
909
  if (yyerrstatus) yyerrstatus--;
 
910
 
 
911
  yystate = yyn;
 
912
  goto yynewstate;
 
913
 
 
914
/* Do the default action for the current state.  */
 
915
yydefault:
 
916
 
 
917
  yyn = yydefact[yystate];
 
918
  if (yyn == 0)
 
919
    goto yyerrlab;
 
920
 
 
921
/* Do a reduction.  yyn is the number of a rule to reduce with.  */
 
922
yyreduce:
 
923
  yylen = yyr2[yyn];
 
924
  if (yylen > 0)
 
925
    yyval = yyvsp[1-yylen]; /* implement default value of the action */
 
926
 
 
927
#if YYDEBUG != 0
 
928
  if (yydebug)
 
929
    {
 
930
      int i;
 
931
 
 
932
      fprintf (stderr, "Reducing via rule %d (line %d), ",
 
933
               yyn, yyrline[yyn]);
 
934
 
 
935
      /* Print the symbols being reduced, and their result.  */
 
936
      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
 
937
        fprintf (stderr, "%s ", yytname[yyrhs[i]]);
 
938
      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
 
939
    }
 
940
#endif
 
941
 
 
942
 
 
943
  switch (yyn) {
 
944
 
 
945
case 3:
 
946
#line 235 "getdate.y"
 
947
{
 
948
            context->yyHaveTime++;
 
949
        ;
 
950
    break;}
 
951
case 4:
 
952
#line 238 "getdate.y"
 
953
{
 
954
            context->yyHaveZone++;
 
955
        ;
 
956
    break;}
 
957
case 5:
 
958
#line 241 "getdate.y"
 
959
{
 
960
            context->yyHaveDate++;
 
961
        ;
 
962
    break;}
 
963
case 6:
 
964
#line 244 "getdate.y"
 
965
{
 
966
            context->yyHaveDay++;
 
967
        ;
 
968
    break;}
 
969
case 7:
 
970
#line 247 "getdate.y"
 
971
{
 
972
            context->yyHaveRel++;
 
973
        ;
 
974
    break;}
 
975
case 9:
 
976
#line 253 "getdate.y"
 
977
{
 
978
            context->yyHour = yyvsp[-1].Number;
 
979
            context->yyMinutes = 0;
 
980
            context->yySeconds = 0;
 
981
            context->yyMeridian = yyvsp[0].Meridian;
 
982
        ;
 
983
    break;}
 
984
case 10:
 
985
#line 259 "getdate.y"
 
986
{
 
987
            context->yyHour = yyvsp[-3].Number;
 
988
            context->yyMinutes = yyvsp[-1].Number;
 
989
            context->yySeconds = 0;
 
990
            context->yyMeridian = yyvsp[0].Meridian;
 
991
        ;
 
992
    break;}
 
993
case 11:
 
994
#line 265 "getdate.y"
 
995
{
 
996
            context->yyHour = yyvsp[-3].Number;
 
997
            context->yyMinutes = yyvsp[-1].Number;
 
998
            context->yyMeridian = MER24;
 
999
            context->yyHaveZone++;
 
1000
            context->yyTimezone = (yyvsp[0].Number < 0
 
1001
                                   ? -yyvsp[0].Number % 100 + (-yyvsp[0].Number / 100) * 60
 
1002
                                   : - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60));
 
1003
        ;
 
1004
    break;}
 
1005
case 12:
 
1006
#line 274 "getdate.y"
 
1007
{
 
1008
            context->yyHour = yyvsp[-5].Number;
 
1009
            context->yyMinutes = yyvsp[-3].Number;
 
1010
            context->yySeconds = yyvsp[-1].Number;
 
1011
            context->yyMeridian = yyvsp[0].Meridian;
 
1012
        ;
 
1013
    break;}
 
1014
case 13:
 
1015
#line 280 "getdate.y"
 
1016
{
 
1017
            context->yyHour = yyvsp[-5].Number;
 
1018
            context->yyMinutes = yyvsp[-3].Number;
 
1019
            context->yySeconds = yyvsp[-1].Number;
 
1020
            context->yyMeridian = MER24;
 
1021
            context->yyHaveZone++;
 
1022
            context->yyTimezone = (yyvsp[0].Number < 0
 
1023
                                   ? -yyvsp[0].Number % 100 + (-yyvsp[0].Number / 100) * 60
 
1024
                                   : - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60));
 
1025
        ;
 
1026
    break;}
 
1027
case 14:
 
1028
#line 292 "getdate.y"
 
1029
{
 
1030
            context->yyTimezone = yyvsp[0].Number;
 
1031
        ;
 
1032
    break;}
 
1033
case 15:
 
1034
#line 295 "getdate.y"
 
1035
{
 
1036
            context->yyTimezone = yyvsp[0].Number - 60;
 
1037
        ;
 
1038
    break;}
 
1039
case 16:
 
1040
#line 299 "getdate.y"
 
1041
{
 
1042
            context->yyTimezone = yyvsp[-1].Number - 60;
 
1043
        ;
 
1044
    break;}
 
1045
case 17:
 
1046
#line 304 "getdate.y"
 
1047
{
 
1048
            context->yyDayOrdinal = 1;
 
1049
            context->yyDayNumber = yyvsp[0].Number;
 
1050
        ;
 
1051
    break;}
 
1052
case 18:
 
1053
#line 308 "getdate.y"
 
1054
{
 
1055
            context->yyDayOrdinal = 1;
 
1056
            context->yyDayNumber = yyvsp[-1].Number;
 
1057
        ;
 
1058
    break;}
 
1059
case 19:
 
1060
#line 312 "getdate.y"
 
1061
{
 
1062
            context->yyDayOrdinal = yyvsp[-1].Number;
 
1063
            context->yyDayNumber = yyvsp[0].Number;
 
1064
        ;
 
1065
    break;}
 
1066
case 20:
 
1067
#line 318 "getdate.y"
 
1068
{
 
1069
            context->yyMonth = yyvsp[-2].Number;
 
1070
            context->yyDay = yyvsp[0].Number;
 
1071
        ;
 
1072
    break;}
 
1073
case 21:
 
1074
#line 322 "getdate.y"
 
1075
{
 
1076
          /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
 
1077
             The goal in recognizing YYYY/MM/DD is solely to support legacy
 
1078
             machine-generated dates like those in an RCS log listing.  If
 
1079
             you want portability, use the ISO 8601 format.  */
 
1080
          if (yyvsp[-4].Number >= 1000)
 
1081
            {
 
1082
              context->yyYear = yyvsp[-4].Number;
 
1083
              context->yyMonth = yyvsp[-2].Number;
 
1084
              context->yyDay = yyvsp[0].Number;
 
1085
            }
 
1086
          else
 
1087
            {
 
1088
              context->yyMonth = yyvsp[-4].Number;
 
1089
              context->yyDay = yyvsp[-2].Number;
 
1090
              context->yyYear = yyvsp[0].Number;
 
1091
            }
 
1092
        ;
 
1093
    break;}
 
1094
case 22:
 
1095
#line 340 "getdate.y"
 
1096
{
 
1097
            /* ISO 8601 format.  yyyy-mm-dd.  */
 
1098
            context->yyYear = yyvsp[-2].Number;
 
1099
            context->yyMonth = -yyvsp[-1].Number;
 
1100
            context->yyDay = -yyvsp[0].Number;
 
1101
        ;
 
1102
    break;}
 
1103
case 23:
 
1104
#line 346 "getdate.y"
 
1105
{
 
1106
            /* e.g. 17-JUN-1992.  */
 
1107
            context->yyDay = yyvsp[-2].Number;
 
1108
            context->yyMonth = yyvsp[-1].Number;
 
1109
            context->yyYear = -yyvsp[0].Number;
 
1110
        ;
 
1111
    break;}
 
1112
case 24:
 
1113
#line 352 "getdate.y"
 
1114
{
 
1115
            context->yyMonth = yyvsp[-1].Number;
 
1116
            context->yyDay = yyvsp[0].Number;
 
1117
        ;
 
1118
    break;}
 
1119
case 25:
 
1120
#line 356 "getdate.y"
 
1121
{
 
1122
            context->yyMonth = yyvsp[-3].Number;
 
1123
            context->yyDay = yyvsp[-2].Number;
 
1124
            context->yyYear = yyvsp[0].Number;
 
1125
        ;
 
1126
    break;}
 
1127
case 26:
 
1128
#line 361 "getdate.y"
 
1129
{
 
1130
            context->yyMonth = yyvsp[0].Number;
 
1131
            context->yyDay = yyvsp[-1].Number;
 
1132
        ;
 
1133
    break;}
 
1134
case 27:
 
1135
#line 365 "getdate.y"
 
1136
{
 
1137
            context->yyMonth = yyvsp[-1].Number;
 
1138
            context->yyDay = yyvsp[-2].Number;
 
1139
            context->yyYear = yyvsp[0].Number;
 
1140
        ;
 
1141
    break;}
 
1142
case 28:
 
1143
#line 372 "getdate.y"
 
1144
{
 
1145
            context->yyRelSeconds = -context->yyRelSeconds;
 
1146
            context->yyRelMinutes = -context->yyRelMinutes;
 
1147
            context->yyRelHour = -context->yyRelHour;
 
1148
            context->yyRelDay = -context->yyRelDay;
 
1149
            context->yyRelMonth = -context->yyRelMonth;
 
1150
            context->yyRelYear = -context->yyRelYear;
 
1151
        ;
 
1152
    break;}
 
1153
case 30:
 
1154
#line 383 "getdate.y"
 
1155
{
 
1156
            context->yyRelYear += yyvsp[-1].Number * yyvsp[0].Number;
 
1157
        ;
 
1158
    break;}
 
1159
case 31:
 
1160
#line 386 "getdate.y"
 
1161
{
 
1162
            context->yyRelYear += yyvsp[-1].Number * yyvsp[0].Number;
 
1163
        ;
 
1164
    break;}
 
1165
case 32:
 
1166
#line 389 "getdate.y"
 
1167
{
 
1168
            context->yyRelYear += yyvsp[0].Number;
 
1169
        ;
 
1170
    break;}
 
1171
case 33:
 
1172
#line 392 "getdate.y"
 
1173
{
 
1174
            context->yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
 
1175
        ;
 
1176
    break;}
 
1177
case 34:
 
1178
#line 395 "getdate.y"
 
1179
{
 
1180
            context->yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
 
1181
        ;
 
1182
    break;}
 
1183
case 35:
 
1184
#line 398 "getdate.y"
 
1185
{
 
1186
            context->yyRelMonth += yyvsp[0].Number;
 
1187
        ;
 
1188
    break;}
 
1189
case 36:
 
1190
#line 401 "getdate.y"
 
1191
{
 
1192
            context->yyRelDay += yyvsp[-1].Number * yyvsp[0].Number;
 
1193
        ;
 
1194
    break;}
 
1195
case 37:
 
1196
#line 404 "getdate.y"
 
1197
{
 
1198
            context->yyRelDay += yyvsp[-1].Number * yyvsp[0].Number;
 
1199
        ;
 
1200
    break;}
 
1201
case 38:
 
1202
#line 407 "getdate.y"
 
1203
{
 
1204
            context->yyRelDay += yyvsp[0].Number;
 
1205
        ;
 
1206
    break;}
 
1207
case 39:
 
1208
#line 410 "getdate.y"
 
1209
{
 
1210
            context->yyRelHour += yyvsp[-1].Number * yyvsp[0].Number;
 
1211
        ;
 
1212
    break;}
 
1213
case 40:
 
1214
#line 413 "getdate.y"
 
1215
{
 
1216
            context->yyRelHour += yyvsp[-1].Number * yyvsp[0].Number;
 
1217
        ;
 
1218
    break;}
 
1219
case 41:
 
1220
#line 416 "getdate.y"
 
1221
{
 
1222
            context->yyRelHour += yyvsp[0].Number;
 
1223
        ;
 
1224
    break;}
 
1225
case 42:
 
1226
#line 419 "getdate.y"
 
1227
{
 
1228
            context->yyRelMinutes += yyvsp[-1].Number * yyvsp[0].Number;
 
1229
        ;
 
1230
    break;}
 
1231
case 43:
 
1232
#line 422 "getdate.y"
 
1233
{
 
1234
            context->yyRelMinutes += yyvsp[-1].Number * yyvsp[0].Number;
 
1235
        ;
 
1236
    break;}
 
1237
case 44:
 
1238
#line 425 "getdate.y"
 
1239
{
 
1240
            context->yyRelMinutes += yyvsp[0].Number;
 
1241
        ;
 
1242
    break;}
 
1243
case 45:
 
1244
#line 428 "getdate.y"
 
1245
{
 
1246
            context->yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
 
1247
        ;
 
1248
    break;}
 
1249
case 46:
 
1250
#line 431 "getdate.y"
 
1251
{
 
1252
            context->yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
 
1253
        ;
 
1254
    break;}
 
1255
case 47:
 
1256
#line 434 "getdate.y"
 
1257
{
 
1258
            context->yyRelSeconds += yyvsp[0].Number;
 
1259
        ;
 
1260
    break;}
 
1261
case 48:
 
1262
#line 440 "getdate.y"
 
1263
{
 
1264
            if (context->yyHaveTime && context->yyHaveDate &&
 
1265
                !context->yyHaveRel)
 
1266
              context->yyYear = yyvsp[0].Number;
 
1267
            else
 
1268
              {
 
1269
                if (yyvsp[0].Number>10000)
 
1270
                  {
 
1271
                    context->yyHaveDate++;
 
1272
                    context->yyDay= (yyvsp[0].Number)%100;
 
1273
                    context->yyMonth= (yyvsp[0].Number/100)%100;
 
1274
                    context->yyYear = yyvsp[0].Number/10000;
 
1275
                  }
 
1276
                else
 
1277
                  {
 
1278
                    context->yyHaveTime++;
 
1279
                    if (yyvsp[0].Number < 100)
 
1280
                      {
 
1281
                        context->yyHour = yyvsp[0].Number;
 
1282
                        context->yyMinutes = 0;
 
1283
                      }
 
1284
                    else
 
1285
                      {
 
1286
                        context->yyHour = yyvsp[0].Number / 100;
 
1287
                        context->yyMinutes = yyvsp[0].Number % 100;
 
1288
                      }
 
1289
                    context->yySeconds = 0;
 
1290
                    context->yyMeridian = MER24;
 
1291
                  }
 
1292
              }
 
1293
          ;
 
1294
    break;}
 
1295
case 49:
 
1296
#line 474 "getdate.y"
 
1297
{
 
1298
            yyval.Meridian = MER24;
 
1299
          ;
 
1300
    break;}
 
1301
case 50:
 
1302
#line 478 "getdate.y"
 
1303
{
 
1304
            yyval.Meridian = yyvsp[0].Meridian;
 
1305
          ;
 
1306
    break;}
 
1307
}
 
1308
   /* the action file gets copied in in place of this dollarsign */
 
1309
#line 543 "/usr/local/share/bison.simple"
 
1310
 
 
1311
  yyvsp -= yylen;
 
1312
  yyssp -= yylen;
 
1313
#ifdef YYLSP_NEEDED
 
1314
  yylsp -= yylen;
 
1315
#endif
 
1316
 
 
1317
#if YYDEBUG != 0
 
1318
  if (yydebug)
 
1319
    {
 
1320
      short *ssp1 = yyss - 1;
 
1321
      fprintf (stderr, "state stack now");
 
1322
      while (ssp1 != yyssp)
 
1323
        fprintf (stderr, " %d", *++ssp1);
 
1324
      fprintf (stderr, "\n");
 
1325
    }
 
1326
#endif
 
1327
 
 
1328
  *++yyvsp = yyval;
 
1329
 
 
1330
#ifdef YYLSP_NEEDED
 
1331
  yylsp++;
 
1332
  if (yylen == 0)
 
1333
    {
 
1334
      yylsp->first_line = yylloc.first_line;
 
1335
      yylsp->first_column = yylloc.first_column;
 
1336
      yylsp->last_line = (yylsp-1)->last_line;
 
1337
      yylsp->last_column = (yylsp-1)->last_column;
 
1338
      yylsp->text = 0;
 
1339
    }
 
1340
  else
 
1341
    {
 
1342
      yylsp->last_line = (yylsp+yylen-1)->last_line;
 
1343
      yylsp->last_column = (yylsp+yylen-1)->last_column;
 
1344
    }
 
1345
#endif
 
1346
 
 
1347
  /* Now "shift" the result of the reduction.
 
1348
     Determine what state that goes to,
 
1349
     based on the state we popped back to
 
1350
     and the rule number reduced by.  */
 
1351
 
 
1352
  yyn = yyr1[yyn];
 
1353
 
 
1354
  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
 
1355
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
 
1356
    yystate = yytable[yystate];
 
1357
  else
 
1358
    yystate = yydefgoto[yyn - YYNTBASE];
 
1359
 
 
1360
  goto yynewstate;
 
1361
 
 
1362
yyerrlab:   /* here on detecting error */
 
1363
 
 
1364
  if (! yyerrstatus)
 
1365
    /* If not already recovering from an error, report this error.  */
 
1366
    {
 
1367
      ++yynerrs;
 
1368
 
 
1369
#ifdef YYERROR_VERBOSE
 
1370
      yyn = yypact[yystate];
 
1371
 
 
1372
      if (yyn > YYFLAG && yyn < YYLAST)
 
1373
        {
 
1374
          int size = 0;
 
1375
          char *msg;
 
1376
          int x, count;
 
1377
 
 
1378
          count = 0;
 
1379
          /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
 
1380
          for (x = (yyn < 0 ? -yyn : 0);
 
1381
               x < (sizeof(yytname) / sizeof(char *)); x++)
 
1382
            if (yycheck[x + yyn] == x)
 
1383
              size += strlen(yytname[x]) + 15, count++;
 
1384
          msg = (char *) malloc(size + 15);
 
1385
          if (msg != 0)
 
1386
            {
 
1387
              strcpy(msg, "parse error");
 
1388
 
 
1389
              if (count < 5)
 
1390
                {
 
1391
                  count = 0;
 
1392
                  for (x = (yyn < 0 ? -yyn : 0);
 
1393
                       x < (sizeof(yytname) / sizeof(char *)); x++)
 
1394
                    if (yycheck[x + yyn] == x)
 
1395
                      {
 
1396
                        strcat(msg, count == 0 ? ", expecting `" : " or `");
 
1397
                        strcat(msg, yytname[x]);
 
1398
                        strcat(msg, "'");
 
1399
                        count++;
 
1400
                      }
 
1401
                }
 
1402
              yyerror(msg);
 
1403
              free(msg);
 
1404
            }
 
1405
          else
 
1406
            yyerror ("parse error; also virtual memory exceeded");
 
1407
        }
 
1408
      else
 
1409
#endif /* YYERROR_VERBOSE */
 
1410
        yyerror("parse error");
 
1411
    }
 
1412
 
 
1413
  goto yyerrlab1;
 
1414
yyerrlab1:   /* here on error raised explicitly by an action */
 
1415
 
 
1416
  if (yyerrstatus == 3)
 
1417
    {
 
1418
      /* if just tried and failed to reuse lookahead token after an error, discard it.  */
 
1419
 
 
1420
      /* return failure if at end of input */
 
1421
      if (yychar == YYEOF)
 
1422
        YYABORT;
 
1423
 
 
1424
#if YYDEBUG != 0
 
1425
      if (yydebug)
 
1426
        fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
 
1427
#endif
 
1428
 
 
1429
      yychar = YYEMPTY;
 
1430
    }
 
1431
 
 
1432
  /* Else will try to reuse lookahead token
 
1433
     after shifting the error token.  */
 
1434
 
 
1435
  yyerrstatus = 3;              /* Each real token shifted decrements this */
 
1436
 
 
1437
  goto yyerrhandle;
 
1438
 
 
1439
yyerrdefault:  /* current state does not do anything special for the error token. */
 
1440
 
 
1441
#if 0
 
1442
  /* This is wrong; only states that explicitly want error tokens
 
1443
     should shift them.  */
 
1444
  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
 
1445
  if (yyn) goto yydefault;
 
1446
#endif
 
1447
 
 
1448
yyerrpop:   /* pop the current state because it cannot handle the error token */
 
1449
 
 
1450
  if (yyssp == yyss) YYABORT;
 
1451
  yyvsp--;
 
1452
  yystate = *--yyssp;
 
1453
#ifdef YYLSP_NEEDED
 
1454
  yylsp--;
 
1455
#endif
 
1456
 
 
1457
#if YYDEBUG != 0
 
1458
  if (yydebug)
 
1459
    {
 
1460
      short *ssp1 = yyss - 1;
 
1461
      fprintf (stderr, "Error: state stack now");
 
1462
      while (ssp1 != yyssp)
 
1463
        fprintf (stderr, " %d", *++ssp1);
 
1464
      fprintf (stderr, "\n");
 
1465
    }
 
1466
#endif
 
1467
 
 
1468
yyerrhandle:
 
1469
 
 
1470
  yyn = yypact[yystate];
 
1471
  if (yyn == YYFLAG)
 
1472
    goto yyerrdefault;
 
1473
 
 
1474
  yyn += YYTERROR;
 
1475
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
 
1476
    goto yyerrdefault;
 
1477
 
 
1478
  yyn = yytable[yyn];
 
1479
  if (yyn < 0)
 
1480
    {
 
1481
      if (yyn == YYFLAG)
 
1482
        goto yyerrpop;
 
1483
      yyn = -yyn;
 
1484
      goto yyreduce;
 
1485
    }
 
1486
  else if (yyn == 0)
 
1487
    goto yyerrpop;
 
1488
 
 
1489
  if (yyn == YYFINAL)
 
1490
    YYACCEPT;
 
1491
 
 
1492
#if YYDEBUG != 0
 
1493
  if (yydebug)
 
1494
    fprintf(stderr, "Shifting error token, ");
 
1495
#endif
 
1496
 
 
1497
  *++yyvsp = yylval;
 
1498
#ifdef YYLSP_NEEDED
 
1499
  *++yylsp = yylloc;
 
1500
#endif
 
1501
 
 
1502
  yystate = yyn;
 
1503
  goto yynewstate;
 
1504
 
 
1505
 yyacceptlab:
 
1506
  /* YYACCEPT comes here.  */
 
1507
  if (yyfree_stacks)
 
1508
    {
 
1509
      free (yyss);
 
1510
      free (yyvs);
 
1511
#ifdef YYLSP_NEEDED
 
1512
      free (yyls);
 
1513
#endif
 
1514
    }
 
1515
  return 0;
 
1516
 
 
1517
 yyabortlab:
 
1518
  /* YYABORT comes here.  */
 
1519
  if (yyfree_stacks)
 
1520
    {
 
1521
      free (yyss);
 
1522
      free (yyvs);
 
1523
#ifdef YYLSP_NEEDED
 
1524
      free (yyls);
 
1525
#endif
 
1526
    }
 
1527
  return 1;
 
1528
}
 
1529
#line 483 "getdate.y"
 
1530
 
 
1531
 
 
1532
/* Include this file down here because bison inserts code above which
 
1533
   may define-away `const'.  We want the prototype for get_date to have
 
1534
   the same signature as the function definition does. */
 
1535
#include "getdate.h"
 
1536
 
 
1537
#ifndef WIN32 /* the windows dudes don't need these, does anyone really? */
 
1538
extern struct tm        *gmtime (const time_t *timer);
 
1539
extern struct tm        *localtime (const time_t *timer);
 
1540
extern time_t           mktime (struct tm *timeptr);
 
1541
#endif
 
1542
 
 
1543
/* Month and day table. */
 
1544
static TABLE const MonthDayTable[] = {
 
1545
    { "january",        tMONTH,  1 },
 
1546
    { "february",       tMONTH,  2 },
 
1547
    { "march",          tMONTH,  3 },
 
1548
    { "april",          tMONTH,  4 },
 
1549
    { "may",            tMONTH,  5 },
 
1550
    { "june",           tMONTH,  6 },
 
1551
    { "july",           tMONTH,  7 },
 
1552
    { "august",         tMONTH,  8 },
 
1553
    { "september",      tMONTH,  9 },
 
1554
    { "sept",           tMONTH,  9 },
 
1555
    { "october",        tMONTH, 10 },
 
1556
    { "november",       tMONTH, 11 },
 
1557
    { "december",       tMONTH, 12 },
 
1558
    { "sunday",         tDAY, 0 },
 
1559
    { "monday",         tDAY, 1 },
 
1560
    { "tuesday",        tDAY, 2 },
 
1561
    { "tues",           tDAY, 2 },
 
1562
    { "wednesday",      tDAY, 3 },
 
1563
    { "wednes",         tDAY, 3 },
 
1564
    { "thursday",       tDAY, 4 },
 
1565
    { "thur",           tDAY, 4 },
 
1566
    { "thurs",          tDAY, 4 },
 
1567
    { "friday",         tDAY, 5 },
 
1568
    { "saturday",       tDAY, 6 },
 
1569
    { NULL, 0, 0 }
 
1570
};
 
1571
 
 
1572
/* Time units table. */
 
1573
static TABLE const UnitsTable[] = {
 
1574
    { "year",           tYEAR_UNIT,     1 },
 
1575
    { "month",          tMONTH_UNIT,    1 },
 
1576
    { "fortnight",      tDAY_UNIT,      14 },
 
1577
    { "week",           tDAY_UNIT,      7 },
 
1578
    { "day",            tDAY_UNIT,      1 },
 
1579
    { "hour",           tHOUR_UNIT,     1 },
 
1580
    { "minute",         tMINUTE_UNIT,   1 },
 
1581
    { "min",            tMINUTE_UNIT,   1 },
 
1582
    { "second",         tSEC_UNIT,      1 },
 
1583
    { "sec",            tSEC_UNIT,      1 },
 
1584
    { NULL, 0, 0 }
 
1585
};
 
1586
 
 
1587
/* Assorted relative-time words. */
 
1588
static TABLE const OtherTable[] = {
 
1589
    { "tomorrow",       tMINUTE_UNIT,   1 * 24 * 60 },
 
1590
    { "yesterday",      tMINUTE_UNIT,   -1 * 24 * 60 },
 
1591
    { "today",          tMINUTE_UNIT,   0 },
 
1592
    { "now",            tMINUTE_UNIT,   0 },
 
1593
    { "last",           tUNUMBER,       -1 },
 
1594
    { "this",           tMINUTE_UNIT,   0 },
 
1595
    { "next",           tUNUMBER,       1 },
 
1596
    { "first",          tUNUMBER,       1 },
 
1597
/*  { "second",         tUNUMBER,       2 }, */
 
1598
    { "third",          tUNUMBER,       3 },
 
1599
    { "fourth",         tUNUMBER,       4 },
 
1600
    { "fifth",          tUNUMBER,       5 },
 
1601
    { "sixth",          tUNUMBER,       6 },
 
1602
    { "seventh",        tUNUMBER,       7 },
 
1603
    { "eighth",         tUNUMBER,       8 },
 
1604
    { "ninth",          tUNUMBER,       9 },
 
1605
    { "tenth",          tUNUMBER,       10 },
 
1606
    { "eleventh",       tUNUMBER,       11 },
 
1607
    { "twelfth",        tUNUMBER,       12 },
 
1608
    { "ago",            tAGO,   1 },
 
1609
    { NULL, 0, 0 }
 
1610
};
 
1611
 
 
1612
/* The timezone table. */
 
1613
static TABLE const TimezoneTable[] = {
 
1614
    { "gmt",    tZONE,     HOUR ( 0) }, /* Greenwich Mean */
 
1615
    { "ut",     tZONE,     HOUR ( 0) }, /* Universal (Coordinated) */
 
1616
    { "utc",    tZONE,     HOUR ( 0) },
 
1617
    { "wet",    tZONE,     HOUR ( 0) }, /* Western European */
 
1618
    { "bst",    tDAYZONE,  HOUR ( 0) }, /* British Summer */
 
1619
    { "wat",    tZONE,     HOUR ( 1) }, /* West Africa */
 
1620
    { "at",     tZONE,     HOUR ( 2) }, /* Azores */
 
1621
#if     0
 
1622
    /* For completeness.  BST is also British Summer, and GST is
 
1623
     * also Guam Standard. */
 
1624
    { "bst",    tZONE,     HOUR ( 3) }, /* Brazil Standard */
 
1625
    { "gst",    tZONE,     HOUR ( 3) }, /* Greenland Standard */
 
1626
#endif
 
1627
#if 0
 
1628
    { "nft",    tZONE,     HOUR (3.5) },        /* Newfoundland */
 
1629
    { "nst",    tZONE,     HOUR (3.5) },        /* Newfoundland Standard */
 
1630
    { "ndt",    tDAYZONE,  HOUR (3.5) },        /* Newfoundland Daylight */
 
1631
#endif
 
1632
    { "ast",    tZONE,     HOUR ( 4) }, /* Atlantic Standard */
 
1633
    { "adt",    tDAYZONE,  HOUR ( 4) }, /* Atlantic Daylight */
 
1634
    { "est",    tZONE,     HOUR ( 5) }, /* Eastern Standard */
 
1635
    { "edt",    tDAYZONE,  HOUR ( 5) }, /* Eastern Daylight */
 
1636
    { "cst",    tZONE,     HOUR ( 6) }, /* Central Standard */
 
1637
    { "cdt",    tDAYZONE,  HOUR ( 6) }, /* Central Daylight */
 
1638
    { "mst",    tZONE,     HOUR ( 7) }, /* Mountain Standard */
 
1639
    { "mdt",    tDAYZONE,  HOUR ( 7) }, /* Mountain Daylight */
 
1640
    { "pst",    tZONE,     HOUR ( 8) }, /* Pacific Standard */
 
1641
    { "pdt",    tDAYZONE,  HOUR ( 8) }, /* Pacific Daylight */
 
1642
    { "yst",    tZONE,     HOUR ( 9) }, /* Yukon Standard */
 
1643
    { "ydt",    tDAYZONE,  HOUR ( 9) }, /* Yukon Daylight */
 
1644
    { "hst",    tZONE,     HOUR (10) }, /* Hawaii Standard */
 
1645
    { "hdt",    tDAYZONE,  HOUR (10) }, /* Hawaii Daylight */
 
1646
    { "cat",    tZONE,     HOUR (10) }, /* Central Alaska */
 
1647
    { "ahst",   tZONE,     HOUR (10) }, /* Alaska-Hawaii Standard */
 
1648
    { "nt",     tZONE,     HOUR (11) }, /* Nome */
 
1649
    { "idlw",   tZONE,     HOUR (12) }, /* International Date Line West */
 
1650
    { "cet",    tZONE,     -HOUR (1) }, /* Central European */
 
1651
    { "met",    tZONE,     -HOUR (1) }, /* Middle European */
 
1652
    { "mewt",   tZONE,     -HOUR (1) }, /* Middle European Winter */
 
1653
    { "mest",   tDAYZONE,  -HOUR (1) }, /* Middle European Summer */
 
1654
    { "mesz",   tDAYZONE,  -HOUR (1) }, /* Middle European Summer */
 
1655
    { "swt",    tZONE,     -HOUR (1) }, /* Swedish Winter */
 
1656
    { "sst",    tDAYZONE,  -HOUR (1) }, /* Swedish Summer */
 
1657
    { "fwt",    tZONE,     -HOUR (1) }, /* French Winter */
 
1658
    { "fst",    tDAYZONE,  -HOUR (1) }, /* French Summer */
 
1659
    { "eet",    tZONE,     -HOUR (2) }, /* Eastern Europe, USSR Zone 1 */
 
1660
    { "bt",     tZONE,     -HOUR (3) }, /* Baghdad, USSR Zone 2 */
 
1661
#if 0
 
1662
    { "it",     tZONE,     -HOUR (3.5) },/* Iran */
 
1663
#endif
 
1664
    { "zp4",    tZONE,     -HOUR (4) }, /* USSR Zone 3 */
 
1665
    { "zp5",    tZONE,     -HOUR (5) }, /* USSR Zone 4 */
 
1666
#if 0
 
1667
    { "ist",    tZONE,     -HOUR (5.5) },/* Indian Standard */
 
1668
#endif
 
1669
    { "zp6",    tZONE,     -HOUR (6) }, /* USSR Zone 5 */
 
1670
#if     0
 
1671
    /* For completeness.  NST is also Newfoundland Standard, and SST is
 
1672
     * also Swedish Summer. */
 
1673
    { "nst",    tZONE,     -HOUR (6.5) },/* North Sumatra */
 
1674
    { "sst",    tZONE,     -HOUR (7) }, /* South Sumatra, USSR Zone 6 */
 
1675
#endif  /* 0 */
 
1676
    { "wast",   tZONE,     -HOUR (7) }, /* West Australian Standard */
 
1677
    { "wadt",   tDAYZONE,  -HOUR (7) }, /* West Australian Daylight */
 
1678
#if 0
 
1679
    { "jt",     tZONE,     -HOUR (7.5) },/* Java (3pm in Cronusland!) */
 
1680
#endif
 
1681
    { "cct",    tZONE,     -HOUR (8) }, /* China Coast, USSR Zone 7 */
 
1682
    { "jst",    tZONE,     -HOUR (9) }, /* Japan Standard, USSR Zone 8 */
 
1683
#if 0
 
1684
    { "cast",   tZONE,     -HOUR (9.5) },/* Central Australian Standard */
 
1685
    { "cadt",   tDAYZONE,  -HOUR (9.5) },/* Central Australian Daylight */
 
1686
#endif
 
1687
    { "east",   tZONE,     -HOUR (10) },        /* Eastern Australian Standard */
 
1688
    { "eadt",   tDAYZONE,  -HOUR (10) },        /* Eastern Australian Daylight */
 
1689
    { "gst",    tZONE,     -HOUR (10) },        /* Guam Standard, USSR Zone 9 */
 
1690
    { "nzt",    tZONE,     -HOUR (12) },        /* New Zealand */
 
1691
    { "nzst",   tZONE,     -HOUR (12) },        /* New Zealand Standard */
 
1692
    { "nzdt",   tDAYZONE,  -HOUR (12) },        /* New Zealand Daylight */
 
1693
    { "idle",   tZONE,     -HOUR (12) },        /* International Date Line East */
 
1694
    {  NULL, 0, 0  }
 
1695
};
 
1696
 
 
1697
/* Military timezone table. */
 
1698
static TABLE const MilitaryTable[] = {
 
1699
    { "a",      tZONE,  HOUR (  1) },
 
1700
    { "b",      tZONE,  HOUR (  2) },
 
1701
    { "c",      tZONE,  HOUR (  3) },
 
1702
    { "d",      tZONE,  HOUR (  4) },
 
1703
    { "e",      tZONE,  HOUR (  5) },
 
1704
    { "f",      tZONE,  HOUR (  6) },
 
1705
    { "g",      tZONE,  HOUR (  7) },
 
1706
    { "h",      tZONE,  HOUR (  8) },
 
1707
    { "i",      tZONE,  HOUR (  9) },
 
1708
    { "k",      tZONE,  HOUR ( 10) },
 
1709
    { "l",      tZONE,  HOUR ( 11) },
 
1710
    { "m",      tZONE,  HOUR ( 12) },
 
1711
    { "n",      tZONE,  HOUR (- 1) },
 
1712
    { "o",      tZONE,  HOUR (- 2) },
 
1713
    { "p",      tZONE,  HOUR (- 3) },
 
1714
    { "q",      tZONE,  HOUR (- 4) },
 
1715
    { "r",      tZONE,  HOUR (- 5) },
 
1716
    { "s",      tZONE,  HOUR (- 6) },
 
1717
    { "t",      tZONE,  HOUR (- 7) },
 
1718
    { "u",      tZONE,  HOUR (- 8) },
 
1719
    { "v",      tZONE,  HOUR (- 9) },
 
1720
    { "w",      tZONE,  HOUR (-10) },
 
1721
    { "x",      tZONE,  HOUR (-11) },
 
1722
    { "y",      tZONE,  HOUR (-12) },
 
1723
    { "z",      tZONE,  HOUR (  0) },
 
1724
    { NULL, 0, 0 }
 
1725
};
 
1726
 
 
1727
 
 
1728
 
 
1729
 
 
1730
/* ARGSUSED */
 
1731
static int
 
1732
yyerror (s)
 
1733
     char *s ATTRIBUTE_UNUSED;
 
1734
{
 
1735
  (void)s;
 
1736
  return 0;
 
1737
}
 
1738
 
 
1739
static int
 
1740
ToHour (Hours, Meridian)
 
1741
     int Hours;
 
1742
     MERIDIAN Meridian;
 
1743
{
 
1744
  switch (Meridian)
 
1745
    {
 
1746
    case MER24:
 
1747
      if (Hours < 0 || Hours > 23)
 
1748
        return -1;
 
1749
      return Hours;
 
1750
    case MERam:
 
1751
      if (Hours < 1 || Hours > 12)
 
1752
        return -1;
 
1753
      if (Hours == 12)
 
1754
        Hours = 0;
 
1755
      return Hours;
 
1756
    case MERpm:
 
1757
      if (Hours < 1 || Hours > 12)
 
1758
        return -1;
 
1759
      if (Hours == 12)
 
1760
        Hours = 0;
 
1761
      return Hours + 12;
 
1762
    default:
 
1763
      abort ();
 
1764
    }
 
1765
  /* NOTREACHED */
 
1766
}
 
1767
 
 
1768
static int
 
1769
ToYear (Year)
 
1770
     int Year;
 
1771
{
 
1772
  if (Year < 0)
 
1773
    Year = -Year;
 
1774
 
 
1775
  /* XPG4 suggests that years 00-68 map to 2000-2068, and
 
1776
     years 69-99 map to 1969-1999.  */
 
1777
  if (Year < 69)
 
1778
    Year += 2000;
 
1779
  else if (Year < 100)
 
1780
    Year += 1900;
 
1781
 
 
1782
  return Year;
 
1783
}
 
1784
 
 
1785
static int
 
1786
LookupWord (yylval, buff)
 
1787
     YYSTYPE *yylval;
 
1788
     char *buff;
 
1789
{
 
1790
  register char *p;
 
1791
  register char *q;
 
1792
  register const TABLE *tp;
 
1793
  int i;
 
1794
  int abbrev;
 
1795
 
 
1796
  /* Make it lowercase. */
 
1797
  for (p = buff; *p; p++)
 
1798
    if (ISUPPER ((unsigned int)(*p)))
 
1799
      *p = (char)tolower ((unsigned int)(*p));
 
1800
 
 
1801
  if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
 
1802
    {
 
1803
      yylval->Meridian = MERam;
 
1804
      return tMERIDIAN;
 
1805
    }
 
1806
  if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
 
1807
    {
 
1808
      yylval->Meridian = MERpm;
 
1809
      return tMERIDIAN;
 
1810
    }
 
1811
 
 
1812
  /* See if we have an abbreviation for a month. */
 
1813
  if (strlen (buff) == 3)
 
1814
    abbrev = 1;
 
1815
  else if (strlen (buff) == 4 && buff[3] == '.')
 
1816
    {
 
1817
      abbrev = 1;
 
1818
      buff[3] = '\0';
 
1819
    }
 
1820
  else
 
1821
    abbrev = 0;
 
1822
 
 
1823
  for (tp = MonthDayTable; tp->name; tp++)
 
1824
    {
 
1825
      if (abbrev)
 
1826
        {
 
1827
          if (strncmp (buff, tp->name, 3) == 0)
 
1828
            {
 
1829
              yylval->Number = tp->value;
 
1830
              return tp->type;
 
1831
            }
 
1832
        }
 
1833
      else if (strcmp (buff, tp->name) == 0)
 
1834
        {
 
1835
          yylval->Number = tp->value;
 
1836
          return tp->type;
 
1837
        }
 
1838
    }
 
1839
 
 
1840
  for (tp = TimezoneTable; tp->name; tp++)
 
1841
    if (strcmp (buff, tp->name) == 0)
 
1842
      {
 
1843
        yylval->Number = tp->value;
 
1844
        return tp->type;
 
1845
      }
 
1846
 
 
1847
  if (strcmp (buff, "dst") == 0)
 
1848
    return tDST;
 
1849
 
 
1850
  for (tp = UnitsTable; tp->name; tp++)
 
1851
    if (strcmp (buff, tp->name) == 0)
 
1852
      {
 
1853
        yylval->Number = tp->value;
 
1854
        return tp->type;
 
1855
      }
 
1856
 
 
1857
  /* Strip off any plural and try the units table again. */
 
1858
  i = (int)strlen (buff) - 1;
 
1859
  if (buff[i] == 's')
 
1860
    {
 
1861
      buff[i] = '\0';
 
1862
      for (tp = UnitsTable; tp->name; tp++)
 
1863
        if (strcmp (buff, tp->name) == 0)
 
1864
          {
 
1865
            yylval->Number = tp->value;
 
1866
            return tp->type;
 
1867
          }
 
1868
      buff[i] = 's';            /* Put back for "this" in OtherTable. */
 
1869
    }
 
1870
 
 
1871
  for (tp = OtherTable; tp->name; tp++)
 
1872
    if (strcmp (buff, tp->name) == 0)
 
1873
      {
 
1874
        yylval->Number = tp->value;
 
1875
        return tp->type;
 
1876
      }
 
1877
 
 
1878
  /* Military timezones. */
 
1879
  if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff))
 
1880
    {
 
1881
      for (tp = MilitaryTable; tp->name; tp++)
 
1882
        if (strcmp (buff, tp->name) == 0)
 
1883
          {
 
1884
            yylval->Number = tp->value;
 
1885
            return tp->type;
 
1886
          }
 
1887
    }
 
1888
 
 
1889
  /* Drop out any periods and try the timezone table again. */
 
1890
  for (i = 0, p = q = buff; *q; q++)
 
1891
    if (*q != '.')
 
1892
      *p++ = *q;
 
1893
    else
 
1894
      i++;
 
1895
  *p = '\0';
 
1896
  if (i)
 
1897
    for (tp = TimezoneTable; tp->name; tp++)
 
1898
      if (strcmp (buff, tp->name) == 0)
 
1899
        {
 
1900
          yylval->Number = tp->value;
 
1901
          return tp->type;
 
1902
        }
 
1903
 
 
1904
  return tID;
 
1905
}
 
1906
 
 
1907
static int
 
1908
yylex (yylval, cookie)
 
1909
     YYSTYPE *yylval;
 
1910
     void *cookie;
 
1911
{
 
1912
  register unsigned char c;
 
1913
  register char *p;
 
1914
  char buff[20];
 
1915
  int Count;
 
1916
  int sign;
 
1917
 
 
1918
  for (;;)
 
1919
    {
 
1920
      while (ISSPACE ((unsigned char) *context->yyInput))
 
1921
        context->yyInput++;
 
1922
 
 
1923
      if (ISDIGIT (c = *context->yyInput) || c == '-' || c == '+')
 
1924
        {
 
1925
          if (c == '-' || c == '+')
 
1926
            {
 
1927
              sign = c == '-' ? -1 : 1;
 
1928
              if (!ISDIGIT (*++context->yyInput))
 
1929
                /* skip the '-' sign */
 
1930
                continue;
 
1931
            }
 
1932
          else
 
1933
            sign = 0;
 
1934
          for (yylval->Number = 0; ISDIGIT (c = *context->yyInput++);)
 
1935
            yylval->Number = 10 * yylval->Number + c - '0';
 
1936
          context->yyInput--;
 
1937
          if (sign < 0)
 
1938
            yylval->Number = -yylval->Number;
 
1939
          return sign ? tSNUMBER : tUNUMBER;
 
1940
        }
 
1941
      if (ISALPHA (c))
 
1942
        {
 
1943
          for (p = buff; (c = *context->yyInput++, ISALPHA (c)) || c == '.';)
 
1944
            if (p < &buff[sizeof buff - 1])
 
1945
              *p++ = c;
 
1946
          *p = '\0';
 
1947
          context->yyInput--;
 
1948
          return LookupWord (yylval, buff);
 
1949
        }
 
1950
      if (c != '(')
 
1951
        return *context->yyInput++;
 
1952
      Count = 0;
 
1953
      do
 
1954
        {
 
1955
          c = *context->yyInput++;
 
1956
          if (c == '\0')
 
1957
            return c;
 
1958
          if (c == '(')
 
1959
            Count++;
 
1960
          else if (c == ')')
 
1961
            Count--;
 
1962
        }
 
1963
      while (Count > 0);
 
1964
    }
 
1965
}
 
1966
 
 
1967
#define TM_YEAR_ORIGIN 1900
 
1968
 
 
1969
/* Yield A - B, measured in seconds.  */
 
1970
static long
 
1971
difftm (struct tm *a, struct tm *b)
 
1972
{
 
1973
  int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
 
1974
  int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
 
1975
  long days = (
 
1976
  /* difference in day of year */
 
1977
                a->tm_yday - b->tm_yday
 
1978
  /* + intervening leap days */
 
1979
                + ((ay >> 2) - (by >> 2))
 
1980
                - (ay / 100 - by / 100)
 
1981
                + ((ay / 100 >> 2) - (by / 100 >> 2))
 
1982
  /* + difference in years * 365 */
 
1983
                + (long) (ay - by) * 365
 
1984
  );
 
1985
  return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
 
1986
                + (a->tm_min - b->tm_min))
 
1987
          + (a->tm_sec - b->tm_sec));
 
1988
}
 
1989
 
 
1990
time_t
 
1991
curl_getdate (const char *p, const time_t *now)
 
1992
{
 
1993
  struct tm tm, tm0, *tmp;
 
1994
  time_t Start;
 
1995
  CONTEXT cookie;
 
1996
#ifdef HAVE_LOCALTIME_R
 
1997
  struct tm keeptime;
 
1998
#endif
 
1999
  cookie.yyInput = p;
 
2000
  Start = now ? *now : time ((time_t *) NULL);
 
2001
#ifdef HAVE_LOCALTIME_R
 
2002
  tmp = (struct tm *)localtime_r(&Start, &keeptime);
 
2003
#else
 
2004
  tmp = localtime (&Start);
 
2005
#endif
 
2006
  if (!tmp)
 
2007
    return -1;
 
2008
  cookie.yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
 
2009
  cookie.yyMonth = tmp->tm_mon + 1;
 
2010
  cookie.yyDay = tmp->tm_mday;
 
2011
  cookie.yyHour = tmp->tm_hour;
 
2012
  cookie.yyMinutes = tmp->tm_min;
 
2013
  cookie.yySeconds = tmp->tm_sec;
 
2014
  tm.tm_isdst = tmp->tm_isdst;
 
2015
  cookie.yyMeridian = MER24;
 
2016
  cookie.yyRelSeconds = 0;
 
2017
  cookie.yyRelMinutes = 0;
 
2018
  cookie.yyRelHour = 0;
 
2019
  cookie.yyRelDay = 0;
 
2020
  cookie.yyRelMonth = 0;
 
2021
  cookie.yyRelYear = 0;
 
2022
  cookie.yyHaveDate = 0;
 
2023
  cookie.yyHaveDay = 0;
 
2024
  cookie.yyHaveRel = 0;
 
2025
  cookie.yyHaveTime = 0;
 
2026
  cookie.yyHaveZone = 0;
 
2027
 
 
2028
  if (yyparse ((void*)&cookie)
 
2029
      || cookie.yyHaveTime > 1 || cookie.yyHaveZone > 1 ||
 
2030
      cookie.yyHaveDate > 1 || cookie.yyHaveDay > 1)
 
2031
    return -1;
 
2032
 
 
2033
  tm.tm_year = ToYear (cookie.yyYear) - TM_YEAR_ORIGIN + cookie.yyRelYear;
 
2034
  tm.tm_mon = cookie.yyMonth - 1 + cookie.yyRelMonth;
 
2035
  tm.tm_mday = cookie.yyDay + cookie.yyRelDay;
 
2036
  if (cookie.yyHaveTime ||
 
2037
      (cookie.yyHaveRel && !cookie.yyHaveDate && !cookie.yyHaveDay))
 
2038
    {
 
2039
      tm.tm_hour = ToHour (cookie.yyHour, cookie.yyMeridian);
 
2040
      if (tm.tm_hour < 0)
 
2041
        return -1;
 
2042
      tm.tm_min = cookie.yyMinutes;
 
2043
      tm.tm_sec = cookie.yySeconds;
 
2044
    }
 
2045
  else
 
2046
    {
 
2047
      tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
 
2048
    }
 
2049
  tm.tm_hour += cookie.yyRelHour;
 
2050
  tm.tm_min += cookie.yyRelMinutes;
 
2051
  tm.tm_sec += cookie.yyRelSeconds;
 
2052
 
 
2053
  /* Let mktime deduce tm_isdst if we have an absolute timestamp,
 
2054
     or if the relative timestamp mentions days, months, or years.  */
 
2055
  if (cookie.yyHaveDate | cookie.yyHaveDay | cookie.yyHaveTime |
 
2056
      cookie.yyRelDay | cookie.yyRelMonth | cookie.yyRelYear)
 
2057
    tm.tm_isdst = -1;
 
2058
 
 
2059
  tm0 = tm;
 
2060
 
 
2061
  Start = mktime (&tm);
 
2062
 
 
2063
  if (Start == (time_t) -1)
 
2064
    {
 
2065
 
 
2066
      /* Guard against falsely reporting errors near the time_t boundaries
 
2067
         when parsing times in other time zones.  For example, if the min
 
2068
         time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
 
2069
         of UTC, then the min localtime value is 1970-01-01 08:00:00; if
 
2070
         we apply mktime to 1970-01-01 00:00:00 we will get an error, so
 
2071
         we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
 
2072
         zone by 24 hours to compensate.  This algorithm assumes that
 
2073
         there is no DST transition within a day of the time_t boundaries.  */
 
2074
      if (cookie.yyHaveZone)
 
2075
        {
 
2076
          tm = tm0;
 
2077
          if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
 
2078
            {
 
2079
              tm.tm_mday++;
 
2080
              cookie.yyTimezone -= 24 * 60;
 
2081
            }
 
2082
          else
 
2083
            {
 
2084
              tm.tm_mday--;
 
2085
              cookie.yyTimezone += 24 * 60;
 
2086
            }
 
2087
          Start = mktime (&tm);
 
2088
        }
 
2089
 
 
2090
      if (Start == (time_t) -1)
 
2091
        return Start;
 
2092
    }
 
2093
 
 
2094
  if (cookie.yyHaveDay && !cookie.yyHaveDate)
 
2095
    {
 
2096
      tm.tm_mday += ((cookie.yyDayNumber - tm.tm_wday + 7) % 7
 
2097
                     + 7 * (cookie.yyDayOrdinal - (0 < cookie.yyDayOrdinal)));
 
2098
      Start = mktime (&tm);
 
2099
      if (Start == (time_t) -1)
 
2100
        return Start;
 
2101
    }
 
2102
 
 
2103
  if (cookie.yyHaveZone)
 
2104
    {
 
2105
      long delta;
 
2106
      struct tm *gmt;
 
2107
#ifdef HAVE_GMTIME_R
 
2108
      /* thread-safe version */
 
2109
      struct tm keeptime;
 
2110
      gmt = (struct tm *)gmtime_r(&Start, &keeptime);
 
2111
#else
 
2112
      gmt = gmtime(&Start);
 
2113
#endif
 
2114
      if (!gmt)
 
2115
        return -1;
 
2116
      delta = cookie.yyTimezone * 60L + difftm (&tm, gmt);
 
2117
      if ((Start + delta < Start) != (delta < 0))
 
2118
        return -1;              /* time_t overflow */
 
2119
      Start += delta;
 
2120
    }
 
2121
 
 
2122
  return Start;
 
2123
}
 
2124
 
 
2125
#if     defined (TEST)
 
2126
 
 
2127
/* ARGSUSED */
 
2128
int
 
2129
main (ac, av)
 
2130
     int ac;
 
2131
     char *av[];
 
2132
{
 
2133
  char buff[MAX_BUFF_LEN + 1];
 
2134
  time_t d;
 
2135
 
 
2136
  (void) printf ("Enter date, or blank line to exit.\n\t> ");
 
2137
  (void) fflush (stdout);
 
2138
 
 
2139
  buff[MAX_BUFF_LEN] = 0;
 
2140
  while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
 
2141
    {
 
2142
      d = curl_getdate (buff, (time_t *) NULL);
 
2143
      if (d == -1)
 
2144
        (void) printf ("Bad format - couldn't convert.\n");
 
2145
      else
 
2146
        (void) printf ("%s", ctime (&d));
 
2147
      (void) printf ("\t> ");
 
2148
      (void) fflush (stdout);
 
2149
    }
 
2150
  exit (0);
 
2151
  /* NOTREACHED */
 
2152
}
 
2153
#endif /* defined (TEST) */