Bug Summary

File:src/gnu/usr.bin/cvs/obj/lib/getdate.c
Warning:line 1130, column 18
Use of zero-allocated memory

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name getdate.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/cvs/obj/lib -resource-dir /usr/local/lib/clang/13.0.0 -D HAVE_CONFIG_H -I . -I /usr/src/gnu/usr.bin/cvs/lib -I .. -I ../src -I /usr/src/gnu/usr.bin/cvs/src -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/cvs/obj/lib -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c getdate.c
1#include <stdlib.h>
2#include <string.h>
3#define YYBYACC1 1
4#define YYMAJOR1 1
5#define YYMINOR9 9
6#define YYLEXgetdate_yylex() yylexgetdate_yylex()
7#define YYEMPTY-1 -1
8#define yyclearin(yychar=(-1)) (yychar=(YYEMPTY-1))
9#define yyerrok(yyerrflag=0) (yyerrflag=0)
10#define YYRECOVERING()(yyerrflag!=0) (yyerrflag!=0)
11#define YYPREFIX"yy" "yy"
12#line 2 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
13/*
14** Originally written by Steven M. Bellovin <smb@research.att.com> while
15** at the University of North Carolina at Chapel Hill. Later tweaked by
16** a couple of people on Usenet. Completely overhauled by Rich $alz
17** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
18**
19** This grammar has 10 shift/reduce conflicts.
20**
21** This code is in the public domain and has no copyright.
22*/
23/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
24/* SUPPRESS 288 on yyerrlab *//* Label unused */
25
26#ifdef HAVE_CONFIG_H1
27#if defined (emacs) || defined (CONFIG_BROKETS)
28#include <config.h>
29#else
30#include "config.h"
31#endif
32#endif
33
34/* Since the code of getdate.y is not included in the Emacs executable
35 itself, there is no need to #define static in this file. Even if
36 the code were included in the Emacs executable, it probably
37 wouldn't do any harm to #undef it here; this will only cause
38 problems if we try to write to a static variable, which I don't
39 think this code needs to do. */
40#ifdef emacs
41#undef static
42#endif
43
44#include <stdio.h>
45#include <ctype.h>
46
47/* The code at the top of get_date which figures out the offset of the
48 current time zone checks various CPP symbols to see if special
49 tricks are need, but defaults to using the gettimeofday system call.
50 Include <sys/time.h> if that will be used. */
51
52#if defined(vms)
53# include <types.h>
54#else /* defined(vms) */
55# include <sys/types.h>
56# include "xtime.h"
57#endif /* !defined(vms) */
58
59#if defined (STDC_HEADERS1) || defined (USG)
60#include <string.h>
61#endif
62
63/* Some old versions of bison generate parsers that use bcopy.
64 That loses on systems that don't provide the function, so we have
65 to redefine it here. */
66#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
67#define bcopy(from, to, len) memcpy ((to), (from), (len))
68#endif
69
70#if defined (STDC_HEADERS1)
71#include <stdlib.h>
72#endif
73
74/* NOTES on rebuilding getdate.c (particularly for inclusion in CVS
75 releases):
76
77 We don't want to mess with all the portability hassles of alloca.
78 In particular, most (all?) versions of bison will use alloca in
79 their parser. If bison works on your system (e.g. it should work
80 with gcc), then go ahead and use it, but the more general solution
81 is to use byacc instead of bison, which should generate a portable
82 parser. I played with adding "#define alloca dont_use_alloca", to
83 give an error if the parser generator uses alloca (and thus detect
84 unportable getdate.c's), but that seems to cause as many problems
85 as it solves. */
86
87extern struct tm *gmtime();
88extern struct tm *localtime();
89
90#define yyparsegetdate_yyparse getdate_yyparse
91#define yylexgetdate_yylex getdate_yylex
92#define yyerrorgetdate_yyerror getdate_yyerror
93
94static int yyparsegetdate_yyparse ();
95static int yylexgetdate_yylex ();
96static int yyerrorgetdate_yyerror ();
97
98#define EPOCH1970 1970
99#define HOUR(x)((time_t)(x) * 60) ((time_t)(x) * 60)
100#define SECSPERDAY(24L * 60L * 60L) (24L * 60L * 60L)
101
102
103/*
104** An entry in the lexical lookup table.
105*/
106typedef struct _TABLE {
107 char *name;
108 int type;
109 time_t value;
110} TABLE;
111
112
113/*
114** Daylight-savings mode: on, off, or not yet known.
115*/
116typedef enum _DSTMODE {
117 DSTon, DSToff, DSTmaybe
118} DSTMODE;
119
120/*
121** Meridian: am, pm, or 24-hour style.
122*/
123typedef enum _MERIDIAN {
124 MERam, MERpm, MER24
125} MERIDIAN;
126
127
128/*
129** Global variables. We could get rid of most of these by using a good
130** union as the yacc stack. (This routine was originally written before
131** yacc had the %union construct.) Maybe someday; right now we only use
132** the %union very rarely.
133*/
134static char *yyInput;
135static DSTMODE yyDSTmode;
136static time_t yyDayOrdinal;
137static time_t yyDayNumber;
138static int yyHaveDate;
139static int yyHaveDay;
140static int yyHaveRel;
141static int yyHaveTime;
142static int yyHaveZone;
143static time_t yyTimezone;
144static time_t yyDay;
145static time_t yyHour;
146static time_t yyMinutes;
147static time_t yyMonth;
148static time_t yySeconds;
149static time_t yyYear;
150static MERIDIAN yyMeridian;
151static time_t yyRelMonth;
152static time_t yyRelSeconds;
153
154#line 145 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
155#ifndef YYSTYPE_DEFINED
156#define YYSTYPE_DEFINED
157typedef union {
158 time_t Number;
159 enum _MERIDIAN Meridian;
160} YYSTYPE;
161#endif /* YYSTYPE_DEFINED */
162#line 163 "y.tab.c"
163#define tAGO257 257
164#define tDAY258 258
165#define tDAYZONE259 259
166#define tID260 260
167#define tMERIDIAN261 261
168#define tMINUTE_UNIT262 262
169#define tMONTH263 263
170#define tMONTH_UNIT264 264
171#define tSEC_UNIT265 265
172#define tSNUMBER266 266
173#define tUNUMBER267 267
174#define tZONE268 268
175#define tDST269 269
176#define YYERRCODE256 256
177const short yylhs[] =
178 { -1,
179 0, 0, 2, 2, 2, 2, 2, 2, 3, 3,
180 3, 3, 3, 4, 4, 4, 6, 6, 6, 5,
181 5, 5, 5, 5, 5, 5, 5, 7, 7, 9,
182 9, 9, 9, 9, 9, 9, 9, 9, 8, 1,
183 1,
184};
185const short yylen[] =
186 { 2,
187 0, 2, 1, 1, 1, 1, 1, 1, 2, 4,
188 4, 6, 6, 1, 1, 2, 1, 2, 2, 3,
189 5, 3, 3, 2, 4, 2, 3, 2, 1, 2,
190 2, 1, 2, 2, 1, 2, 2, 1, 1, 0,
191 1,
192};
193const short yydefred[] =
194 { 1,
195 0, 0, 15, 32, 0, 38, 35, 0, 0, 0,
196 2, 3, 4, 5, 6, 7, 8, 0, 18, 0,
197 31, 36, 33, 19, 9, 30, 0, 37, 34, 0,
198 0, 0, 16, 28, 0, 23, 27, 22, 0, 0,
199 25, 41, 11, 0, 10, 0, 0, 21, 13, 12,
200};
201const short yydgoto[] =
202 { 1,
203 45, 11, 12, 13, 14, 15, 16, 17, 18,
204};
205const short yysindex[] =
206 { 0,
207 -249, -38, 0, 0, -260, 0, 0, -240, -47, -248,
208 0, 0, 0, 0, 0, 0, 0, -237, 0, -18,
209 0, 0, 0, 0, 0, 0, -262, 0, 0, -239,
210 -238, -236, 0, 0, -235, 0, 0, 0, -56, -19,
211 0, 0, 0, -234, 0, -232, -258, 0, 0, 0,};
212const short yyrindex[] =
213 { 0,
214 0, 1, 0, 0, 0, 0, 0, 0, 69, 12,
215 0, 0, 0, 0, 0, 0, 0, 23, 0, 34,
216 0, 0, 0, 0, 0, 0, 67, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 56, 45,
218 0, 0, 0, 0, 0, 0, 56, 0, 0, 0,};
219const short yygindex[] =
220 { 0,
221 -17, 0, 0, 0, 0, 0, 0, 0, 0,
222};
223#define YYTABLESIZE337 337
224const short yytable[] =
225 { 32,
226 17, 44, 42, 36, 37, 19, 20, 49, 2, 3,
227 31, 14, 4, 5, 6, 7, 8, 9, 10, 34,
228 33, 21, 29, 22, 23, 35, 38, 46, 39, 50,
229 40, 41, 47, 24, 48, 0, 0, 0, 0, 0,
230 0, 0, 0, 0, 20, 0, 0, 0, 0, 0,
231 0, 0, 0, 0, 0, 40, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 0, 26, 0, 39, 0,
233 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
234 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
235 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 42, 0, 0, 0, 0, 43,
247 24, 0, 0, 25, 26, 27, 28, 29, 30, 0,
248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
251 0, 0, 0, 0, 0, 0, 0, 0, 17, 17,
252 0, 0, 17, 17, 17, 17, 17, 17, 17, 14,
253 14, 0, 0, 14, 14, 14, 14, 14, 14, 14,
254 29, 29, 0, 0, 29, 29, 29, 29, 29, 29,
255 29, 24, 24, 0, 0, 24, 24, 24, 24, 24,
256 24, 24, 20, 20, 0, 0, 20, 20, 20, 20,
257 20, 20, 20, 40, 40, 0, 0, 40, 40, 40,
258 40, 0, 40, 40, 26, 26, 0, 39, 26, 26,
259 26, 26, 0, 0, 26, 39, 39,
260};
261const short yycheck[] =
262 { 47,
263 0, 58, 261, 266, 267, 44, 267, 266, 258, 259,
264 58, 0, 262, 263, 264, 265, 266, 267, 268, 257,
265 269, 262, 0, 264, 265, 44, 266, 47, 267, 47,
266 267, 267, 267, 0, 267, -1, -1, -1, -1, -1,
267 -1, -1, -1, -1, 0, -1, -1, -1, -1, -1,
268 -1, -1, -1, -1, -1, 0, -1, -1, -1, -1,
269 -1, -1, -1, -1, -1, -1, 0, -1, 0, -1,
270 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
271 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
272 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
273 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
274 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
275 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
276 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
282 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
283 -1, -1, -1, -1, 261, -1, -1, -1, -1, 266,
284 258, -1, -1, 261, 262, 263, 264, 265, 266, -1,
285 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
286 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
287 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
288 -1, -1, -1, -1, -1, -1, -1, -1, 258, 259,
289 -1, -1, 262, 263, 264, 265, 266, 267, 268, 258,
290 259, -1, -1, 262, 263, 264, 265, 266, 267, 268,
291 258, 259, -1, -1, 262, 263, 264, 265, 266, 267,
292 268, 258, 259, -1, -1, 262, 263, 264, 265, 266,
293 267, 268, 258, 259, -1, -1, 262, 263, 264, 265,
294 266, 267, 268, 258, 259, -1, -1, 262, 263, 264,
295 265, -1, 267, 268, 258, 259, -1, 259, 262, 263,
296 264, 265, -1, -1, 268, 267, 268,
297};
298#define YYFINAL1 1
299#ifndef YYDEBUG0
300#define YYDEBUG0 0
301#endif
302#define YYMAXTOKEN269 269
303#if YYDEBUG0
304const char * const yyname[] =
305 {
306"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3070,0,0,0,0,0,0,0,0,0,"','",0,0,"'/'",0,0,0,0,0,0,0,0,0,0,"':'",0,0,0,0,0,0,0,0,0,
3080,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3090,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3110,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"tAGO","tDAY",
313"tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
314"tSNUMBER","tUNUMBER","tZONE","tDST",
315};
316const char * const yyrule[] =
317 {"$accept : spec",
318"spec :",
319"spec : spec item",
320"item : time",
321"item : zone",
322"item : date",
323"item : day",
324"item : rel",
325"item : number",
326"time : tUNUMBER tMERIDIAN",
327"time : tUNUMBER ':' tUNUMBER o_merid",
328"time : tUNUMBER ':' tUNUMBER tSNUMBER",
329"time : tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid",
330"time : tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER",
331"zone : tZONE",
332"zone : tDAYZONE",
333"zone : tZONE tDST",
334"day : tDAY",
335"day : tDAY ','",
336"day : tUNUMBER tDAY",
337"date : tUNUMBER '/' tUNUMBER",
338"date : tUNUMBER '/' tUNUMBER '/' tUNUMBER",
339"date : tUNUMBER tSNUMBER tSNUMBER",
340"date : tUNUMBER tMONTH tSNUMBER",
341"date : tMONTH tUNUMBER",
342"date : tMONTH tUNUMBER ',' tUNUMBER",
343"date : tUNUMBER tMONTH",
344"date : tUNUMBER tMONTH tUNUMBER",
345"rel : relunit tAGO",
346"rel : relunit",
347"relunit : tUNUMBER tMINUTE_UNIT",
348"relunit : tSNUMBER tMINUTE_UNIT",
349"relunit : tMINUTE_UNIT",
350"relunit : tSNUMBER tSEC_UNIT",
351"relunit : tUNUMBER tSEC_UNIT",
352"relunit : tSEC_UNIT",
353"relunit : tSNUMBER tMONTH_UNIT",
354"relunit : tUNUMBER tMONTH_UNIT",
355"relunit : tMONTH_UNIT",
356"number : tUNUMBER",
357"o_merid :",
358"o_merid : tMERIDIAN",
359};
360#endif
361#ifdef YYSTACKSIZE10000
362#undef YYMAXDEPTH10000
363#define YYMAXDEPTH10000 YYSTACKSIZE10000
364#else
365#ifdef YYMAXDEPTH10000
366#define YYSTACKSIZE10000 YYMAXDEPTH10000
367#else
368#define YYSTACKSIZE10000 10000
369#define YYMAXDEPTH10000 10000
370#endif
371#endif
372#define YYINITSTACKSIZE200 200
373/* LINTUSED */
374int yydebug;
375int yynerrs;
376int yyerrflag;
377int yychar;
378short *yyssp;
379YYSTYPE *yyvsp;
380YYSTYPE yyval;
381YYSTYPE yylval;
382short *yyss;
383short *yysslim;
384YYSTYPE *yyvs;
385unsigned int yystacksize;
386int yyparsegetdate_yyparse(void);
387#line 364 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
388
389/* Month and day table. */
390static TABLE const MonthDayTable[] = {
391 { "january", tMONTH263, 1 },
392 { "february", tMONTH263, 2 },
393 { "march", tMONTH263, 3 },
394 { "april", tMONTH263, 4 },
395 { "may", tMONTH263, 5 },
396 { "june", tMONTH263, 6 },
397 { "july", tMONTH263, 7 },
398 { "august", tMONTH263, 8 },
399 { "september", tMONTH263, 9 },
400 { "sept", tMONTH263, 9 },
401 { "october", tMONTH263, 10 },
402 { "november", tMONTH263, 11 },
403 { "december", tMONTH263, 12 },
404 { "sunday", tDAY258, 0 },
405 { "monday", tDAY258, 1 },
406 { "tuesday", tDAY258, 2 },
407 { "tues", tDAY258, 2 },
408 { "wednesday", tDAY258, 3 },
409 { "wednes", tDAY258, 3 },
410 { "thursday", tDAY258, 4 },
411 { "thur", tDAY258, 4 },
412 { "thurs", tDAY258, 4 },
413 { "friday", tDAY258, 5 },
414 { "saturday", tDAY258, 6 },
415 { NULL((void *)0) }
416};
417
418/* Time units table. */
419static TABLE const UnitsTable[] = {
420 { "year", tMONTH_UNIT264, 12 },
421 { "month", tMONTH_UNIT264, 1 },
422 { "fortnight", tMINUTE_UNIT262, 14 * 24 * 60 },
423 { "week", tMINUTE_UNIT262, 7 * 24 * 60 },
424 { "day", tMINUTE_UNIT262, 1 * 24 * 60 },
425 { "hour", tMINUTE_UNIT262, 60 },
426 { "minute", tMINUTE_UNIT262, 1 },
427 { "min", tMINUTE_UNIT262, 1 },
428 { "second", tSEC_UNIT265, 1 },
429 { "sec", tSEC_UNIT265, 1 },
430 { NULL((void *)0) }
431};
432
433/* Assorted relative-time words. */
434static TABLE const OtherTable[] = {
435 { "tomorrow", tMINUTE_UNIT262, 1 * 24 * 60 },
436 { "yesterday", tMINUTE_UNIT262, -1 * 24 * 60 },
437 { "today", tMINUTE_UNIT262, 0 },
438 { "now", tMINUTE_UNIT262, 0 },
439 { "last", tUNUMBER267, -1 },
440 { "this", tMINUTE_UNIT262, 0 },
441 { "next", tUNUMBER267, 2 },
442 { "first", tUNUMBER267, 1 },
443/* { "second", tUNUMBER, 2 }, */
444 { "third", tUNUMBER267, 3 },
445 { "fourth", tUNUMBER267, 4 },
446 { "fifth", tUNUMBER267, 5 },
447 { "sixth", tUNUMBER267, 6 },
448 { "seventh", tUNUMBER267, 7 },
449 { "eighth", tUNUMBER267, 8 },
450 { "ninth", tUNUMBER267, 9 },
451 { "tenth", tUNUMBER267, 10 },
452 { "eleventh", tUNUMBER267, 11 },
453 { "twelfth", tUNUMBER267, 12 },
454 { "ago", tAGO257, 1 },
455 { NULL((void *)0) }
456};
457
458/* The timezone table. */
459/* Some of these are commented out because a time_t can't store a float. */
460static TABLE const TimezoneTable[] = {
461 { "gmt", tZONE268, HOUR( 0)((time_t)(0) * 60) }, /* Greenwich Mean */
462 { "ut", tZONE268, HOUR( 0)((time_t)(0) * 60) }, /* Universal (Coordinated) */
463 { "utc", tZONE268, HOUR( 0)((time_t)(0) * 60) },
464 { "wet", tZONE268, HOUR( 0)((time_t)(0) * 60) }, /* Western European */
465 { "bst", tDAYZONE259, HOUR( 0)((time_t)(0) * 60) }, /* British Summer */
466 { "wat", tZONE268, HOUR( 1)((time_t)(1) * 60) }, /* West Africa */
467 { "at", tZONE268, HOUR( 2)((time_t)(2) * 60) }, /* Azores */
468#if 0
469 /* For completeness. BST is also British Summer, and GST is
470 * also Guam Standard. */
471 { "bst", tZONE268, HOUR( 3)((time_t)(3) * 60) }, /* Brazil Standard */
472 { "gst", tZONE268, HOUR( 3)((time_t)(3) * 60) }, /* Greenland Standard */
473#endif
474#if 0
475 { "nft", tZONE268, HOUR(3.5)((time_t)(3.5) * 60) }, /* Newfoundland */
476 { "nst", tZONE268, HOUR(3.5)((time_t)(3.5) * 60) }, /* Newfoundland Standard */
477 { "ndt", tDAYZONE259, HOUR(3.5)((time_t)(3.5) * 60) }, /* Newfoundland Daylight */
478#endif
479 { "ast", tZONE268, HOUR( 4)((time_t)(4) * 60) }, /* Atlantic Standard */
480 { "adt", tDAYZONE259, HOUR( 4)((time_t)(4) * 60) }, /* Atlantic Daylight */
481 { "est", tZONE268, HOUR( 5)((time_t)(5) * 60) }, /* Eastern Standard */
482 { "edt", tDAYZONE259, HOUR( 5)((time_t)(5) * 60) }, /* Eastern Daylight */
483 { "cst", tZONE268, HOUR( 6)((time_t)(6) * 60) }, /* Central Standard */
484 { "cdt", tDAYZONE259, HOUR( 6)((time_t)(6) * 60) }, /* Central Daylight */
485 { "mst", tZONE268, HOUR( 7)((time_t)(7) * 60) }, /* Mountain Standard */
486 { "mdt", tDAYZONE259, HOUR( 7)((time_t)(7) * 60) }, /* Mountain Daylight */
487 { "pst", tZONE268, HOUR( 8)((time_t)(8) * 60) }, /* Pacific Standard */
488 { "pdt", tDAYZONE259, HOUR( 8)((time_t)(8) * 60) }, /* Pacific Daylight */
489 { "yst", tZONE268, HOUR( 9)((time_t)(9) * 60) }, /* Yukon Standard */
490 { "ydt", tDAYZONE259, HOUR( 9)((time_t)(9) * 60) }, /* Yukon Daylight */
491 { "hst", tZONE268, HOUR(10)((time_t)(10) * 60) }, /* Hawaii Standard */
492 { "hdt", tDAYZONE259, HOUR(10)((time_t)(10) * 60) }, /* Hawaii Daylight */
493 { "cat", tZONE268, HOUR(10)((time_t)(10) * 60) }, /* Central Alaska */
494 { "ahst", tZONE268, HOUR(10)((time_t)(10) * 60) }, /* Alaska-Hawaii Standard */
495 { "nt", tZONE268, HOUR(11)((time_t)(11) * 60) }, /* Nome */
496 { "idlw", tZONE268, HOUR(12)((time_t)(12) * 60) }, /* International Date Line West */
497 { "cet", tZONE268, -HOUR(1)((time_t)(1) * 60) }, /* Central European */
498 { "met", tZONE268, -HOUR(1)((time_t)(1) * 60) }, /* Middle European */
499 { "mewt", tZONE268, -HOUR(1)((time_t)(1) * 60) }, /* Middle European Winter */
500 { "mest", tDAYZONE259, -HOUR(1)((time_t)(1) * 60) }, /* Middle European Summer */
501 { "swt", tZONE268, -HOUR(1)((time_t)(1) * 60) }, /* Swedish Winter */
502 { "sst", tDAYZONE259, -HOUR(1)((time_t)(1) * 60) }, /* Swedish Summer */
503 { "fwt", tZONE268, -HOUR(1)((time_t)(1) * 60) }, /* French Winter */
504 { "fst", tDAYZONE259, -HOUR(1)((time_t)(1) * 60) }, /* French Summer */
505 { "eet", tZONE268, -HOUR(2)((time_t)(2) * 60) }, /* Eastern Europe, USSR Zone 1 */
506 { "bt", tZONE268, -HOUR(3)((time_t)(3) * 60) }, /* Baghdad, USSR Zone 2 */
507#if 0
508 { "it", tZONE268, -HOUR(3.5)((time_t)(3.5) * 60) },/* Iran */
509#endif
510 { "zp4", tZONE268, -HOUR(4)((time_t)(4) * 60) }, /* USSR Zone 3 */
511 { "zp5", tZONE268, -HOUR(5)((time_t)(5) * 60) }, /* USSR Zone 4 */
512#if 0
513 { "ist", tZONE268, -HOUR(5.5)((time_t)(5.5) * 60) },/* Indian Standard */
514#endif
515 { "zp6", tZONE268, -HOUR(6)((time_t)(6) * 60) }, /* USSR Zone 5 */
516#if 0
517 /* For completeness. NST is also Newfoundland Stanard, and SST is
518 * also Swedish Summer. */
519 { "nst", tZONE268, -HOUR(6.5)((time_t)(6.5) * 60) },/* North Sumatra */
520 { "sst", tZONE268, -HOUR(7)((time_t)(7) * 60) }, /* South Sumatra, USSR Zone 6 */
521#endif /* 0 */
522 { "wast", tZONE268, -HOUR(7)((time_t)(7) * 60) }, /* West Australian Standard */
523 { "wadt", tDAYZONE259, -HOUR(7)((time_t)(7) * 60) }, /* West Australian Daylight */
524#if 0
525 { "jt", tZONE268, -HOUR(7.5)((time_t)(7.5) * 60) },/* Java (3pm in Cronusland!) */
526#endif
527 { "cct", tZONE268, -HOUR(8)((time_t)(8) * 60) }, /* China Coast, USSR Zone 7 */
528 { "jst", tZONE268, -HOUR(9)((time_t)(9) * 60) }, /* Japan Standard, USSR Zone 8 */
529#if 0
530 { "cast", tZONE268, -HOUR(9.5)((time_t)(9.5) * 60) },/* Central Australian Standard */
531 { "cadt", tDAYZONE259, -HOUR(9.5)((time_t)(9.5) * 60) },/* Central Australian Daylight */
532#endif
533 { "east", tZONE268, -HOUR(10)((time_t)(10) * 60) }, /* Eastern Australian Standard */
534 { "eadt", tDAYZONE259, -HOUR(10)((time_t)(10) * 60) }, /* Eastern Australian Daylight */
535 { "gst", tZONE268, -HOUR(10)((time_t)(10) * 60) }, /* Guam Standard, USSR Zone 9 */
536 { "nzt", tZONE268, -HOUR(12)((time_t)(12) * 60) }, /* New Zealand */
537 { "nzst", tZONE268, -HOUR(12)((time_t)(12) * 60) }, /* New Zealand Standard */
538 { "nzdt", tDAYZONE259, -HOUR(12)((time_t)(12) * 60) }, /* New Zealand Daylight */
539 { "idle", tZONE268, -HOUR(12)((time_t)(12) * 60) }, /* International Date Line East */
540 { NULL((void *)0) }
541};
542
543/* Military timezone table. */
544static TABLE const MilitaryTable[] = {
545 { "a", tZONE268, HOUR( 1)((time_t)(1) * 60) },
546 { "b", tZONE268, HOUR( 2)((time_t)(2) * 60) },
547 { "c", tZONE268, HOUR( 3)((time_t)(3) * 60) },
548 { "d", tZONE268, HOUR( 4)((time_t)(4) * 60) },
549 { "e", tZONE268, HOUR( 5)((time_t)(5) * 60) },
550 { "f", tZONE268, HOUR( 6)((time_t)(6) * 60) },
551 { "g", tZONE268, HOUR( 7)((time_t)(7) * 60) },
552 { "h", tZONE268, HOUR( 8)((time_t)(8) * 60) },
553 { "i", tZONE268, HOUR( 9)((time_t)(9) * 60) },
554 { "k", tZONE268, HOUR( 10)((time_t)(10) * 60) },
555 { "l", tZONE268, HOUR( 11)((time_t)(11) * 60) },
556 { "m", tZONE268, HOUR( 12)((time_t)(12) * 60) },
557 { "n", tZONE268, HOUR(- 1)((time_t)(- 1) * 60) },
558 { "o", tZONE268, HOUR(- 2)((time_t)(- 2) * 60) },
559 { "p", tZONE268, HOUR(- 3)((time_t)(- 3) * 60) },
560 { "q", tZONE268, HOUR(- 4)((time_t)(- 4) * 60) },
561 { "r", tZONE268, HOUR(- 5)((time_t)(- 5) * 60) },
562 { "s", tZONE268, HOUR(- 6)((time_t)(- 6) * 60) },
563 { "t", tZONE268, HOUR(- 7)((time_t)(- 7) * 60) },
564 { "u", tZONE268, HOUR(- 8)((time_t)(- 8) * 60) },
565 { "v", tZONE268, HOUR(- 9)((time_t)(- 9) * 60) },
566 { "w", tZONE268, HOUR(-10)((time_t)(-10) * 60) },
567 { "x", tZONE268, HOUR(-11)((time_t)(-11) * 60) },
568 { "y", tZONE268, HOUR(-12)((time_t)(-12) * 60) },
569 { "z", tZONE268, HOUR( 0)((time_t)(0) * 60) },
570 { NULL((void *)0) }
571};
572
573
574
575
576/* ARGSUSED */
577static int
578yyerrorgetdate_yyerror(s)
579 char *s;
580{
581 return 0;
582}
583
584
585static time_t
586ToSeconds(Hours, Minutes, Seconds, Meridian)
587 time_t Hours;
588 time_t Minutes;
589 time_t Seconds;
590 MERIDIAN Meridian;
591{
592 if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
593 return -1;
594 switch (Meridian) {
595 case MER24:
596 if (Hours < 0 || Hours > 23)
597 return -1;
598 return (Hours * 60L + Minutes) * 60L + Seconds;
599 case MERam:
600 if (Hours < 1 || Hours > 12)
601 return -1;
602 if (Hours == 12)
603 Hours = 0;
604 return (Hours * 60L + Minutes) * 60L + Seconds;
605 case MERpm:
606 if (Hours < 1 || Hours > 12)
607 return -1;
608 if (Hours == 12)
609 Hours = 0;
610 return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
611 default:
612 abort ();
613 }
614 /* NOTREACHED */
615}
616
617
618/* Year is either
619 * A negative number, which means to use its absolute value (why?)
620 * A number from 0 to 99, which means a year from 1900 to 1999, or
621 * The actual year (>=100). */
622static time_t
623Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
624 time_t Month;
625 time_t Day;
626 time_t Year;
627 time_t Hours;
628 time_t Minutes;
629 time_t Seconds;
630 MERIDIAN Meridian;
631 DSTMODE DSTmode;
632{
633 static int DaysInMonth[12] = {
634 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
635 };
636 time_t tod;
637 time_t Julian;
638 int i;
639
640 if (Year < 0)
641 Year = -Year;
642 if (Year < 69)
643 Year += 2000;
644 else if (Year < 100) {
645 Year += 1900;
646 if (Year < EPOCH1970)
647 Year += 100;
648 }
649 DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
650 ? 29 : 28;
651 /* XXX Sloppily check for 2038 if time_t is 32 bits */
652 if (Year < EPOCH1970
653 || (sizeof(time_t) == sizeof(int) && Year > 2038)
654 || Month < 1 || Month > 12
655 /* Lint fluff: "conversion from long may lose accuracy" */
656 || Day < 1 || Day > DaysInMonth[(int)--Month])
657 return -1;
658
659 for (Julian = Day - 1, i = 0; i < Month; i++)
660 Julian += DaysInMonth[i];
661 for (i = EPOCH1970; i < Year; i++)
662 Julian += 365 + (i % 4 == 0);
663 Julian *= SECSPERDAY(24L * 60L * 60L);
664 Julian += yyTimezone * 60L;
665 if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
666 return -1;
667 Julian += tod;
668 if (DSTmode == DSTon
669 || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
670 Julian -= 60 * 60;
671 return Julian;
672}
673
674
675static time_t
676DSTcorrect(Start, Future)
677 time_t Start;
678 time_t Future;
679{
680 time_t StartDay;
681 time_t FutureDay;
682
683 StartDay = (localtime(&Start)->tm_hour + 1) % 24;
684 FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
685 return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
686}
687
688
689static time_t
690RelativeDate(Start, DayOrdinal, DayNumber)
691 time_t Start;
692 time_t DayOrdinal;
693 time_t DayNumber;
694{
695 struct tm *tm;
696 time_t now;
697
698 now = Start;
699 tm = localtime(&now);
700 now += SECSPERDAY(24L * 60L * 60L) * ((DayNumber - tm->tm_wday + 7) % 7);
701 now += 7 * SECSPERDAY(24L * 60L * 60L) * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
702 return DSTcorrect(Start, now);
703}
704
705
706static time_t
707RelativeMonth(Start, RelMonth)
708 time_t Start;
709 time_t RelMonth;
710{
711 struct tm *tm;
712 time_t Month;
713 time_t Year;
714
715 if (RelMonth == 0)
716 return 0;
717 tm = localtime(&Start);
718 Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
719 Year = Month / 12;
720 Month = Month % 12 + 1;
721 return DSTcorrect(Start,
722 Convert(Month, (time_t)tm->tm_mday, Year,
723 (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
724 MER24, DSTmaybe));
725}
726
727
728static int
729LookupWord(buff)
730 char *buff;
731{
732 register char *p;
733 register char *q;
734 register const TABLE *tp;
735 int i;
736 int abbrev;
737
738 /* Make it lowercase. */
739 for (p = buff; *p; p++)
740 if (isupper(*p))
741 *p = tolower(*p);
742
743 if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
744 yylval.Meridian = MERam;
745 return tMERIDIAN261;
746 }
747 if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
748 yylval.Meridian = MERpm;
749 return tMERIDIAN261;
750 }
751
752 /* See if we have an abbreviation for a month. */
753 if (strlen(buff) == 3)
754 abbrev = 1;
755 else if (strlen(buff) == 4 && buff[3] == '.') {
756 abbrev = 1;
757 buff[3] = '\0';
758 }
759 else
760 abbrev = 0;
761
762 for (tp = MonthDayTable; tp->name; tp++) {
763 if (abbrev) {
764 if (strncmp(buff, tp->name, 3) == 0) {
765 yylval.Number = tp->value;
766 return tp->type;
767 }
768 }
769 else if (strcmp(buff, tp->name) == 0) {
770 yylval.Number = tp->value;
771 return tp->type;
772 }
773 }
774
775 for (tp = TimezoneTable; tp->name; tp++)
776 if (strcmp(buff, tp->name) == 0) {
777 yylval.Number = tp->value;
778 return tp->type;
779 }
780
781 if (strcmp(buff, "dst") == 0)
782 return tDST269;
783
784 for (tp = UnitsTable; tp->name; tp++)
785 if (strcmp(buff, tp->name) == 0) {
786 yylval.Number = tp->value;
787 return tp->type;
788 }
789
790 /* Strip off any plural and try the units table again. */
791 i = strlen(buff) - 1;
792 if (buff[i] == 's') {
793 buff[i] = '\0';
794 for (tp = UnitsTable; tp->name; tp++)
795 if (strcmp(buff, tp->name) == 0) {
796 yylval.Number = tp->value;
797 return tp->type;
798 }
799 buff[i] = 's'; /* Put back for "this" in OtherTable. */
800 }
801
802 for (tp = OtherTable; tp->name; tp++)
803 if (strcmp(buff, tp->name) == 0) {
804 yylval.Number = tp->value;
805 return tp->type;
806 }
807
808 /* Military timezones. */
809 if (buff[1] == '\0' && isalpha(*buff)) {
810 for (tp = MilitaryTable; tp->name; tp++)
811 if (strcmp(buff, tp->name) == 0) {
812 yylval.Number = tp->value;
813 return tp->type;
814 }
815 }
816
817 /* Drop out any periods and try the timezone table again. */
818 for (i = 0, p = q = buff; *q; q++)
819 if (*q != '.')
820 *p++ = *q;
821 else
822 i++;
823 *p = '\0';
824 if (i)
825 for (tp = TimezoneTable; tp->name; tp++)
826 if (strcmp(buff, tp->name) == 0) {
827 yylval.Number = tp->value;
828 return tp->type;
829 }
830
831 return tID260;
832}
833
834
835static int
836yylexgetdate_yylex()
837{
838 register char c;
839 register char *p;
840 char buff[20];
841 int Count;
842 int sign;
843
844 for ( ; ; ) {
845 while (isspace(*yyInput))
846 yyInput++;
847
848 if (isdigit(c = *yyInput) || c == '-' || c == '+') {
849 if (c == '-' || c == '+') {
850 sign = c == '-' ? -1 : 1;
851 if (!isdigit(*++yyInput))
852 /* skip the '-' sign */
853 continue;
854 }
855 else
856 sign = 0;
857 for (yylval.Number = 0; isdigit(c = *yyInput++); )
858 yylval.Number = 10 * yylval.Number + c - '0';
859 yyInput--;
860 if (sign < 0)
861 yylval.Number = -yylval.Number;
862 return sign ? tSNUMBER266 : tUNUMBER267;
863 }
864 if (isalpha(c)) {
865 for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
866 if (p < &buff[sizeof buff - 1])
867 *p++ = c;
868 *p = '\0';
869 yyInput--;
870 return LookupWord(buff);
871 }
872 if (c != '(')
873 return *yyInput++;
874 Count = 0;
875 do {
876 c = *yyInput++;
877 if (c == '\0')
878 return c;
879 if (c == '(')
880 Count++;
881 else if (c == ')')
882 Count--;
883 } while (Count > 0);
884 }
885}
886
887#define TM_YEAR_ORIGIN1900 1900
888
889/* Yield A - B, measured in seconds. */
890static long
891difftm (a, b)
892 struct tm *a, *b;
893{
894 int ay = a->tm_year + (TM_YEAR_ORIGIN1900 - 1);
895 int by = b->tm_year + (TM_YEAR_ORIGIN1900 - 1);
896 int days = (
897 /* difference in day of year */
898 a->tm_yday - b->tm_yday
899 /* + intervening leap days */
900 + ((ay >> 2) - (by >> 2))
901 - (ay/100 - by/100)
902 + ((ay/100 >> 2) - (by/100 >> 2))
903 /* + difference in years * 365 */
904 + (long)(ay-by) * 365
905 );
906 return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
907 + (a->tm_min - b->tm_min))
908 + (a->tm_sec - b->tm_sec));
909}
910
911time_t
912get_date(p)
913 char *p;
914{
915 struct tm *tm, *gmt, gmtbuf;
916 time_t Start;
917 time_t tod;
918 time_t now;
919 time_t timezone;
920
921 yyInput = p;
922 (void)time (&now);
923
924 gmt = gmtime (&now);
925 if (gmt != NULL((void *)0))
926 {
927 /* Make a copy, in case localtime modifies *tm (I think
928 that comment now applies to *gmt, but I am too
929 lazy to dig into how gmtime and locatime allocate the
930 structures they return pointers to). */
931 gmtbuf = *gmt;
932 gmt = &gmtbuf;
933 }
934
935 if (! (tm = localtime (&now)))
936 return -1;
937
938 if (gmt != NULL((void *)0))
939 timezone = difftm (gmt, tm) / 60;
940 else
941 /* We are on a system like VMS, where the system clock is
942 in local time and the system has no concept of timezones.
943 Hopefully we can fake this out (for the case in which the
944 user specifies no timezone) by just saying the timezone
945 is zero. */
946 timezone = 0;
947
948 if(tm->tm_isdst)
949 timezone += 60;
950
951 tm = localtime(&now);
952 yyYear = tm->tm_year + 1900;
953 yyMonth = tm->tm_mon + 1;
954 yyDay = tm->tm_mday;
955 yyTimezone = timezone;
956 yyDSTmode = DSTmaybe;
957 yyHour = 0;
958 yyMinutes = 0;
959 yySeconds = 0;
960 yyMeridian = MER24;
961 yyRelSeconds = 0;
962 yyRelMonth = 0;
963 yyHaveDate = 0;
964 yyHaveDay = 0;
965 yyHaveRel = 0;
966 yyHaveTime = 0;
967 yyHaveZone = 0;
968
969 if (yyparsegetdate_yyparse()
970 || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
971 return -1;
972
973 if (yyHaveDate || yyHaveTime || yyHaveDay) {
974 Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
975 yyMeridian, yyDSTmode);
976 if (Start < 0)
977 return -1;
978 }
979 else {
980 Start = now;
981 if (!yyHaveRel)
982 Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
983 }
984
985 Start += yyRelSeconds;
986 Start += RelativeMonth(Start, yyRelMonth);
987
988 if (yyHaveDay && !yyHaveDate) {
989 tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
990 Start += tod;
991 }
992
993 /* Have to do *something* with a legitimate -1 so it's distinguishable
994 * from the error return value. (Alternately could set errno on error.) */
995 return Start == -1 ? 0 : Start;
996}
997
998
999#if defined(TEST)
1000
1001/* ARGSUSED */
1002int
1003main(ac, av)
1004 int ac;
1005 char *av[];
1006{
1007 char buff[128];
1008 time_t d;
1009
1010 (void)printf("Enter date, or blank line to exit.\n\t> ");
1011 (void)fflush(stdout(&__sF[1]));
1012 while (gets(buff) && buff[0]) {
1013 d = get_date(buff);
1014 if (d == -1)
1015 (void)printf("Bad format - couldn't convert.\n");
1016 else
1017 (void)printf("%s", ctime(&d));
1018 (void)printf("\t> ");
1019 (void)fflush(stdout(&__sF[1]));
1020 }
1021 exit(0);
1022 /* NOTREACHED */
1023}
1024#endif /* defined(TEST) */
1025#line 1018 "y.tab.c"
1026/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1027static int yygrowstack(void)
1028{
1029 unsigned int newsize;
1030 long sslen;
1031 short *newss;
1032 YYSTYPE *newvs;
1033
1034 if ((newsize = yystacksize) == 0)
17
Assuming the condition is false
18
Taking false branch
1035 newsize = YYINITSTACKSIZE200;
1036 else if (newsize >= YYMAXDEPTH10000)
19
Assuming 'newsize' is < YYMAXDEPTH
20
Taking false branch
1037 return -1;
1038 else if ((newsize *= 2) > YYMAXDEPTH10000)
21
Assuming the condition is false
22
Taking false branch
1039 newsize = YYMAXDEPTH10000;
1040 sslen = yyssp - yyss;
1041#ifdef SIZE_MAX
1042#define YY_SIZE_MAX0xffffffffU SIZE_MAX
1043#else
1044#define YY_SIZE_MAX0xffffffffU 0xffffffffU
1045#endif
1046 if (newsize && YY_SIZE_MAX0xffffffffU / newsize < sizeof *newss)
23
Assuming 'newsize' is 0
1047 goto bail;
1048 newss = (short *)realloc(yyss, newsize * sizeof *newss);
1049 if (newss == NULL((void *)0))
24
Assuming 'newss' is not equal to NULL
25
Taking false branch
1050 goto bail;
1051 yyss = newss;
1052 yyssp = newss + sslen;
1053 if (newsize
25.1
'newsize' is 0
&& YY_SIZE_MAX0xffffffffU / newsize < sizeof *newvs)
1054 goto bail;
1055 newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs);
1056 if (newvs == NULL((void *)0))
26
Assuming 'newvs' is not equal to NULL
27
Taking false branch
1057 goto bail;
1058 yyvs = newvs;
1059 yyvsp = newvs + sslen;
1060 yystacksize = newsize;
1061 yysslim = yyss + newsize - 1;
1062 return 0;
1063bail:
1064 if (yyss)
1065 free(yyss);
1066 if (yyvs)
1067 free(yyvs);
1068 yyss = yyssp = NULL((void *)0);
1069 yyvs = yyvsp = NULL((void *)0);
1070 yystacksize = 0;
1071 return -1;
1072}
1073
1074#define YYABORTgoto yyabort goto yyabort
1075#define YYREJECTgoto yyabort goto yyabort
1076#define YYACCEPTgoto yyaccept goto yyaccept
1077#define YYERRORgoto yyerrlab goto yyerrlab
1078int
1079yyparsegetdate_yyparse(void)
1080{
1081 int yym, yyn, yystate;
1082#if YYDEBUG0
1083 const char *yys;
1084
1085 if ((yys = getenv("YYDEBUG")))
1086 {
1087 yyn = *yys;
1088 if (yyn >= '0' && yyn <= '9')
1089 yydebug = yyn - '0';
1090 }
1091#endif /* YYDEBUG */
1092
1093 yynerrs = 0;
1094 yyerrflag = 0;
1095 yychar = (-1);
1096
1097 if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow;
1
Assuming 'yyss' is not equal to NULL
1098 yyssp = yyss;
1099 yyvsp = yyvs;
1100 *yyssp = yystate = 0;
1101
1102yyloop:
1103 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
2
Taking true branch
3
Control jumps to line 1210
11
Taking false branch
1104 if (yychar
11.1
'yychar' is >= 0
< 0)
12
Taking false branch
1105 {
1106 if ((yychar = yylexgetdate_yylex()) < 0) yychar = 0;
1107#if YYDEBUG0
1108 if (yydebug)
1109 {
1110 yys = 0;
1111 if (yychar <= YYMAXTOKEN269) yys = yyname[yychar];
1112 if (!yys) yys = "illegal-symbol";
1113 printf("%sdebug: state %d, reading %d (%s)\n",
1114 YYPREFIX"yy", yystate, yychar, yys);
1115 }
1116#endif
1117 }
1118 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
13
Assuming 'yyn' is not equal to 0
14
Taking true branch
1119 yyn
13.1
'yyn' is <= YYTABLESIZE
<= YYTABLESIZE337 && yycheck[yyn] == yychar)
1120 {
1121#if YYDEBUG0
1122 if (yydebug)
1123 printf("%sdebug: state %d, shifting to state %d\n",
1124 YYPREFIX"yy", yystate, yytable[yyn]);
1125#endif
1126 if (yyssp >= yysslim && yygrowstack())
15
Assuming 'yyssp' is >= 'yysslim'
16
Calling 'yygrowstack'
28
Returning from 'yygrowstack'
29
Taking false branch
1127 {
1128 goto yyoverflow;
1129 }
1130 *++yyssp = yystate = yytable[yyn];
30
Use of zero-allocated memory
1131 *++yyvsp = yylval;
1132 yychar = (-1);
1133 if (yyerrflag > 0) --yyerrflag;
1134 goto yyloop;
1135 }
1136 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1137 yyn <= YYTABLESIZE337 && yycheck[yyn] == yychar)
1138 {
1139 yyn = yytable[yyn];
1140 goto yyreduce;
1141 }
1142 if (yyerrflag) goto yyinrecovery;
1143#if defined(__GNUC__4)
1144 goto yynewerror;
1145#endif
1146yynewerror:
1147 yyerrorgetdate_yyerror("syntax error");
1148#if defined(__GNUC__4)
1149 goto yyerrlab;
1150#endif
1151yyerrlab:
1152 ++yynerrs;
1153yyinrecovery:
1154 if (yyerrflag < 3)
1155 {
1156 yyerrflag = 3;
1157 for (;;)
1158 {
1159 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 &&
1160 yyn <= YYTABLESIZE337 && yycheck[yyn] == YYERRCODE256)
1161 {
1162#if YYDEBUG0
1163 if (yydebug)
1164 printf("%sdebug: state %d, error recovery shifting\
1165 to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]);
1166#endif
1167 if (yyssp >= yysslim && yygrowstack())
1168 {
1169 goto yyoverflow;
1170 }
1171 *++yyssp = yystate = yytable[yyn];
1172 *++yyvsp = yylval;
1173 goto yyloop;
1174 }
1175 else
1176 {
1177#if YYDEBUG0
1178 if (yydebug)
1179 printf("%sdebug: error recovery discarding state %d\n",
1180 YYPREFIX"yy", *yyssp);
1181#endif
1182 if (yyssp <= yyss) goto yyabort;
1183 --yyssp;
1184 --yyvsp;
1185 }
1186 }
1187 }
1188 else
1189 {
1190 if (yychar == 0) goto yyabort;
1191#if YYDEBUG0
1192 if (yydebug)
1193 {
1194 yys = 0;
1195 if (yychar <= YYMAXTOKEN269) yys = yyname[yychar];
1196 if (!yys) yys = "illegal-symbol";
1197 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1198 YYPREFIX"yy", yystate, yychar, yys);
1199 }
1200#endif
1201 yychar = (-1);
1202 goto yyloop;
1203 }
1204yyreduce:
1205#if YYDEBUG0
1206 if (yydebug)
1207 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1208 YYPREFIX"yy", yystate, yyn, yyrule[yyn]);
1209#endif
1210 yym = yylen[yyn];
1211 if (yym
3.1
'yym' is 0
)
4
Taking false branch
1212 yyval = yyvsp[1-yym];
1213 else
1214 memset(&yyval, 0, sizeof yyval);
1215 switch (yyn)
5
'Default' branch taken. Execution continues on line 1509
1216 {
1217case 3:
1218#line 163 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1219{
1220 yyHaveTime++;
1221 }
1222break;
1223case 4:
1224#line 166 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1225{
1226 yyHaveZone++;
1227 }
1228break;
1229case 5:
1230#line 169 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1231{
1232 yyHaveDate++;
1233 }
1234break;
1235case 6:
1236#line 172 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1237{
1238 yyHaveDay++;
1239 }
1240break;
1241case 7:
1242#line 175 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1243{
1244 yyHaveRel++;
1245 }
1246break;
1247case 9:
1248#line 181 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1249{
1250 yyHour = yyvsp[-1].Number;
1251 yyMinutes = 0;
1252 yySeconds = 0;
1253 yyMeridian = yyvsp[0].Meridian;
1254 }
1255break;
1256case 10:
1257#line 187 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1258{
1259 yyHour = yyvsp[-3].Number;
1260 yyMinutes = yyvsp[-1].Number;
1261 yySeconds = 0;
1262 yyMeridian = yyvsp[0].Meridian;
1263 }
1264break;
1265case 11:
1266#line 193 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1267{
1268 yyHour = yyvsp[-3].Number;
1269 yyMinutes = yyvsp[-1].Number;
1270 yyMeridian = MER24;
1271 yyDSTmode = DSToff;
1272 yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1273 }
1274break;
1275case 12:
1276#line 200 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1277{
1278 yyHour = yyvsp[-5].Number;
1279 yyMinutes = yyvsp[-3].Number;
1280 yySeconds = yyvsp[-1].Number;
1281 yyMeridian = yyvsp[0].Meridian;
1282 }
1283break;
1284case 13:
1285#line 206 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1286{
1287 yyHour = yyvsp[-5].Number;
1288 yyMinutes = yyvsp[-3].Number;
1289 yySeconds = yyvsp[-1].Number;
1290 yyMeridian = MER24;
1291 yyDSTmode = DSToff;
1292 yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1293 }
1294break;
1295case 14:
1296#line 216 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1297{
1298 yyTimezone = yyvsp[0].Number;
1299 yyDSTmode = DSToff;
1300 }
1301break;
1302case 15:
1303#line 220 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1304{
1305 yyTimezone = yyvsp[0].Number;
1306 yyDSTmode = DSTon;
1307 }
1308break;
1309case 16:
1310#line 225 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1311{
1312 yyTimezone = yyvsp[-1].Number;
1313 yyDSTmode = DSTon;
1314 }
1315break;
1316case 17:
1317#line 231 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1318{
1319 yyDayOrdinal = 1;
1320 yyDayNumber = yyvsp[0].Number;
1321 }
1322break;
1323case 18:
1324#line 235 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1325{
1326 yyDayOrdinal = 1;
1327 yyDayNumber = yyvsp[-1].Number;
1328 }
1329break;
1330case 19:
1331#line 239 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1332{
1333 yyDayOrdinal = yyvsp[-1].Number;
1334 yyDayNumber = yyvsp[0].Number;
1335 }
1336break;
1337case 20:
1338#line 245 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1339{
1340 yyMonth = yyvsp[-2].Number;
1341 yyDay = yyvsp[0].Number;
1342 }
1343break;
1344case 21:
1345#line 249 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1346{
1347 if (yyvsp[-4].Number >= 100) {
1348 yyYear = yyvsp[-4].Number;
1349 yyMonth = yyvsp[-2].Number;
1350 yyDay = yyvsp[0].Number;
1351 } else {
1352 yyMonth = yyvsp[-4].Number;
1353 yyDay = yyvsp[-2].Number;
1354 yyYear = yyvsp[0].Number;
1355 }
1356 }
1357break;
1358case 22:
1359#line 260 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1360{
1361 /* ISO 8601 format. yyyy-mm-dd. */
1362 yyYear = yyvsp[-2].Number;
1363 yyMonth = -yyvsp[-1].Number;
1364 yyDay = -yyvsp[0].Number;
1365 }
1366break;
1367case 23:
1368#line 266 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1369{
1370 /* e.g. 17-JUN-1992. */
1371 yyDay = yyvsp[-2].Number;
1372 yyMonth = yyvsp[-1].Number;
1373 yyYear = -yyvsp[0].Number;
1374 }
1375break;
1376case 24:
1377#line 272 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1378{
1379 yyMonth = yyvsp[-1].Number;
1380 yyDay = yyvsp[0].Number;
1381 }
1382break;
1383case 25:
1384#line 276 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1385{
1386 yyMonth = yyvsp[-3].Number;
1387 yyDay = yyvsp[-2].Number;
1388 yyYear = yyvsp[0].Number;
1389 }
1390break;
1391case 26:
1392#line 281 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1393{
1394 yyMonth = yyvsp[0].Number;
1395 yyDay = yyvsp[-1].Number;
1396 }
1397break;
1398case 27:
1399#line 285 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1400{
1401 yyMonth = yyvsp[-1].Number;
1402 yyDay = yyvsp[-2].Number;
1403 yyYear = yyvsp[0].Number;
1404 }
1405break;
1406case 28:
1407#line 292 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1408{
1409 yyRelSeconds = -yyRelSeconds;
1410 yyRelMonth = -yyRelMonth;
1411 }
1412break;
1413case 30:
1414#line 299 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1415{
1416 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1417 }
1418break;
1419case 31:
1420#line 302 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1421{
1422 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1423 }
1424break;
1425case 32:
1426#line 305 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1427{
1428 yyRelSeconds += yyvsp[0].Number * 60L;
1429 }
1430break;
1431case 33:
1432#line 308 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1433{
1434 yyRelSeconds += yyvsp[-1].Number;
1435 }
1436break;
1437case 34:
1438#line 311 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1439{
1440 yyRelSeconds += yyvsp[-1].Number;
1441 }
1442break;
1443case 35:
1444#line 314 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1445{
1446 yyRelSeconds++;
1447 }
1448break;
1449case 36:
1450#line 317 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1451{
1452 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1453 }
1454break;
1455case 37:
1456#line 320 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1457{
1458 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1459 }
1460break;
1461case 38:
1462#line 323 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1463{
1464 yyRelMonth += yyvsp[0].Number;
1465 }
1466break;
1467case 39:
1468#line 328 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1469{
1470 if (yyHaveTime && yyHaveDate && !yyHaveRel)
1471 yyYear = yyvsp[0].Number;
1472 else {
1473 if(yyvsp[0].Number>10000) {
1474 yyHaveDate++;
1475 yyDay= (yyvsp[0].Number)%100;
1476 yyMonth= (yyvsp[0].Number/100)%100;
1477 yyYear = yyvsp[0].Number/10000;
1478 }
1479 else {
1480 yyHaveTime++;
1481 if (yyvsp[0].Number < 100) {
1482 yyHour = yyvsp[0].Number;
1483 yyMinutes = 0;
1484 }
1485 else {
1486 yyHour = yyvsp[0].Number / 100;
1487 yyMinutes = yyvsp[0].Number % 100;
1488 }
1489 yySeconds = 0;
1490 yyMeridian = MER24;
1491 }
1492 }
1493 }
1494break;
1495case 40:
1496#line 355 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1497{
1498 yyval.Meridian = MER24;
1499 }
1500break;
1501case 41:
1502#line 358 "/usr/src/gnu/usr.bin/cvs/lib/getdate.y"
1503{
1504 yyval.Meridian = yyvsp[0].Meridian;
1505 }
1506break;
1507#line 1500 "y.tab.c"
1508 }
1509 yyssp -= yym;
1510 yystate = *yyssp;
1511 yyvsp -= yym;
1512 yym = yylhs[yyn];
1513 if (yystate
5.1
'yystate' is equal to 0
== 0 && yym
5.2
'yym' is equal to 0
== 0)
6
Taking true branch
1514 {
1515#if YYDEBUG0
1516 if (yydebug)
1517 printf("%sdebug: after reduction, shifting from state 0 to\
1518 state %d\n", YYPREFIX"yy", YYFINAL1);
1519#endif
1520 yystate = YYFINAL1;
1521 *++yyssp = YYFINAL1;
1522 *++yyvsp = yyval;
1523 if (yychar
6.1
'yychar' is < 0
< 0)
7
Taking true branch
1524 {
1525 if ((yychar = yylexgetdate_yylex()) < 0) yychar = 0;
8
Taking false branch
1526#if YYDEBUG0
1527 if (yydebug)
1528 {
1529 yys = 0;
1530 if (yychar <= YYMAXTOKEN269) yys = yyname[yychar];
1531 if (!yys) yys = "illegal-symbol";
1532 printf("%sdebug: state %d, reading %d (%s)\n",
1533 YYPREFIX"yy", YYFINAL1, yychar, yys);
1534 }
1535#endif
1536 }
1537 if (yychar
8.1
'yychar' is not equal to 0
== 0) goto yyaccept;
9
Taking false branch
1538 goto yyloop;
10
Control jumps to line 1103
1539 }
1540 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1541 yyn <= YYTABLESIZE337 && yycheck[yyn] == yystate)
1542 yystate = yytable[yyn];
1543 else
1544 yystate = yydgoto[yym];
1545#if YYDEBUG0
1546 if (yydebug)
1547 printf("%sdebug: after reduction, shifting from state %d \
1548to state %d\n", YYPREFIX"yy", *yyssp, yystate);
1549#endif
1550 if (yyssp >= yysslim && yygrowstack())
1551 {
1552 goto yyoverflow;
1553 }
1554 *++yyssp = yystate;
1555 *++yyvsp = yyval;
1556 goto yyloop;
1557yyoverflow:
1558 yyerrorgetdate_yyerror("yacc stack overflow");
1559yyabort:
1560 if (yyss)
1561 free(yyss);
1562 if (yyvs)
1563 free(yyvs);
1564 yyss = yyssp = NULL((void *)0);
1565 yyvs = yyvsp = NULL((void *)0);
1566 yystacksize = 0;
1567 return (1);
1568yyaccept:
1569 if (yyss)
1570 free(yyss);
1571 if (yyvs)
1572 free(yyvs);
1573 yyss = yyssp = NULL((void *)0);
1574 yyvs = yyvsp = NULL((void *)0);
1575 yystacksize = 0;
1576 return (0);
1577}