Bug Summary

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