Bug Summary

File:src/usr.bin/cvs/obj/date.c
Warning:line 715, column 32
The left operand of '==' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name date.c -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 -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -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/llvm16/lib/clang/16 -I /usr/src/usr.bin/cvs -internal-isystem /usr/local/llvm16/lib/clang/16/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 -fcf-protection=branch -fno-jump-tables -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/scan/2024-01-11-140451-98009-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.27 2023/03/08 04:43:10 guenther 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++)
22
Loop condition is true. Entering loop body
664 if (isupper(*p))
23
Assuming the character is not an uppercase letter
24
Taking false branch
665 *p = tolower(*p);
666
667 if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
25
Assuming the condition is false
26
Assuming the condition is false
668 yylval.Meridian = MERam;
669 return (tMERIDIAN261);
670 }
671 if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
27
Assuming the condition is false
28
Assuming the condition is false
29
Taking false branch
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)
30
Assuming 'len' is equal to 3
31
Taking true branch
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++) {
32
Loop condition is false. Execution continues on line 699
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++)
33
Loop condition is false. Execution continues on line 705
700 if (strcmp(buff, tp->name) == 0) {
701 yylval.Number = tp->value;
702 return (tp->type);
703 }
704
705 if (strcmp(buff, "dst") == 0)
34
Assuming the condition is false
35
Taking false branch
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
35.1
'len' is not equal to 0
!= 0 && buff[len - 1] == 's') {
36
The left operand of '==' is a garbage value
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 (;;) {
9
Loop condition is true. Entering loop body
765 while (isspace(*yyInput))
10
Assuming the character is not a whitespace character
766 yyInput++;
767
768 if (isdigit(c = *yyInput) || c == '-' || c == '+') {
11
Assuming the character is not a digit
12
Assuming the condition is false
13
Assuming the condition is false
14
Taking false branch
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)) {
15
Assuming the character is alphabetical
16
Taking true branch
787 for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
18
Assuming the character is non-alphabetical
19
Assuming the condition is false
20
Loop condition is false. Execution continues on line 790
788 if (p < &buff[sizeof buff - 1])
17
Taking true branch
789 *p++ = c;
790 *p = '\0';
791 yyInput--;
792 return lookup(buff);
21
Calling 'lookup'
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)
896int
897main(int argc, char **argv)
898{
899 char buff[128];
900 time_t d;
901
902 (void)printf("Enter date, or blank line to exit.\n\t> ");
903 (void)fflush(stdout(&__sF[1]));
904 while (fgets(buff, sizeof(buff), stdin(&__sF[0])) && buff[0]) {
905 d = date_parse(buff);
906 if (d == -1)
907 (void)printf("Bad format - couldn't convert.\n");
908 else
909 (void)printf("%s", ctime(&d));
910 (void)printf("\t> ");
911 (void)fflush(stdout(&__sF[1]));
912 }
913
914 return (0);
915}
916#endif /* defined(TEST) */
917#line 910 "date.c"
918/* allocate initial stack or double stack size, up to YYMAXDEPTH */
919static int yygrowstack(void)
920{
921 unsigned int newsize;
922 long sslen;
923 short *newss;
924 YYSTYPE *newvs;
925
926 if ((newsize = yystacksize) == 0)
927 newsize = YYINITSTACKSIZE200;
928 else if (newsize >= YYMAXDEPTH10000)
929 return -1;
930 else if ((newsize *= 2) > YYMAXDEPTH10000)
931 newsize = YYMAXDEPTH10000;
932 sslen = yyssp - yyss;
933#ifdef SIZE_MAX
934#define YY_SIZE_MAX0xffffffffU SIZE_MAX
935#else
936#define YY_SIZE_MAX0xffffffffU 0xffffffffU
937#endif
938 if (newsize && YY_SIZE_MAX0xffffffffU / newsize < sizeof *newss)
939 goto bail;
940 newss = (short *)realloc(yyss, newsize * sizeof *newss);
941 if (newss == NULL((void *)0))
942 goto bail;
943 yyss = newss;
944 yyssp = newss + sslen;
945 if (newsize && YY_SIZE_MAX0xffffffffU / newsize < sizeof *newvs)
946 goto bail;
947 newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs);
948 if (newvs == NULL((void *)0))
949 goto bail;
950 yyvs = newvs;
951 yyvsp = newvs + sslen;
952 yystacksize = newsize;
953 yysslim = yyss + newsize - 1;
954 return 0;
955bail:
956 if (yyss)
957 free(yyss);
958 if (yyvs)
959 free(yyvs);
960 yyss = yyssp = NULL((void *)0);
961 yyvs = yyvsp = NULL((void *)0);
962 yystacksize = 0;
963 return -1;
964}
965
966#define YYABORTgoto yyabort goto yyabort
967#define YYREJECTgoto yyabort goto yyabort
968#define YYACCEPTgoto yyaccept goto yyaccept
969#define YYERRORgoto yyerrlab goto yyerrlab
970int
971yyparse(void)
972{
973 int yym, yyn, yystate;
974#if YYDEBUG0
975 const char *yys;
976
977 if ((yys = getenv("YYDEBUG")))
978 {
979 yyn = *yys;
980 if (yyn >= '0' && yyn <= '9')
981 yydebug = yyn - '0';
982 }
983#endif /* YYDEBUG */
984
985 yynerrs = 0;
986 yyerrflag = 0;
987 yychar = (-1);
988
989 if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow;
1
Assuming 'yyss' is not equal to NULL
990 yyssp = yyss;
991 yyvsp = yyvs;
992 *yyssp = yystate = 0;
993
994yyloop:
995 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
2
Taking true branch
3
Control jumps to line 1102
996 if (yychar < 0)
997 {
998 if ((yychar = yylex()) < 0) yychar = 0;
999#if YYDEBUG0
1000 if (yydebug)
1001 {
1002 yys = 0;
1003 if (yychar <= YYMAXTOKEN269) yys = yyname[yychar];
1004 if (!yys) yys = "illegal-symbol";
1005 printf("%sdebug: state %d, reading %d (%s)\n",
1006 YYPREFIX"yy", yystate, yychar, yys);
1007 }
1008#endif
1009 }
1010 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1011 yyn <= YYTABLESIZE337 && yycheck[yyn] == yychar)
1012 {
1013#if YYDEBUG0
1014 if (yydebug)
1015 printf("%sdebug: state %d, shifting to state %d\n",
1016 YYPREFIX"yy", yystate, yytable[yyn]);
1017#endif
1018 if (yyssp >= yysslim && yygrowstack())
1019 {
1020 goto yyoverflow;
1021 }
1022 *++yyssp = yystate = yytable[yyn];
1023 *++yyvsp = yylval;
1024 yychar = (-1);
1025 if (yyerrflag > 0) --yyerrflag;
1026 goto yyloop;
1027 }
1028 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1029 yyn <= YYTABLESIZE337 && yycheck[yyn] == yychar)
1030 {
1031 yyn = yytable[yyn];
1032 goto yyreduce;
1033 }
1034 if (yyerrflag) goto yyinrecovery;
1035#if defined(__GNUC__4)
1036 goto yynewerror;
1037#endif
1038yynewerror:
1039 yyerror("syntax error");
1040#if defined(__GNUC__4)
1041 goto yyerrlab;
1042#endif
1043yyerrlab:
1044 ++yynerrs;
1045yyinrecovery:
1046 if (yyerrflag < 3)
1047 {
1048 yyerrflag = 3;
1049 for (;;)
1050 {
1051 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 &&
1052 yyn <= YYTABLESIZE337 && yycheck[yyn] == YYERRCODE256)
1053 {
1054#if YYDEBUG0
1055 if (yydebug)
1056 printf("%sdebug: state %d, error recovery shifting\
1057 to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]);
1058#endif
1059 if (yyssp >= yysslim && yygrowstack())
1060 {
1061 goto yyoverflow;
1062 }
1063 *++yyssp = yystate = yytable[yyn];
1064 *++yyvsp = yylval;
1065 goto yyloop;
1066 }
1067 else
1068 {
1069#if YYDEBUG0
1070 if (yydebug)
1071 printf("%sdebug: error recovery discarding state %d\n",
1072 YYPREFIX"yy", *yyssp);
1073#endif
1074 if (yyssp <= yyss) goto yyabort;
1075 --yyssp;
1076 --yyvsp;
1077 }
1078 }
1079 }
1080 else
1081 {
1082 if (yychar == 0) goto yyabort;
1083#if YYDEBUG0
1084 if (yydebug)
1085 {
1086 yys = 0;
1087 if (yychar <= YYMAXTOKEN269) yys = yyname[yychar];
1088 if (!yys) yys = "illegal-symbol";
1089 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1090 YYPREFIX"yy", yystate, yychar, yys);
1091 }
1092#endif
1093 yychar = (-1);
1094 goto yyloop;
1095 }
1096yyreduce:
1097#if YYDEBUG0
1098 if (yydebug)
1099 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1100 YYPREFIX"yy", yystate, yyn, yyrule[yyn]);
1101#endif
1102 yym = yylen[yyn];
1103 if (yym
3.1
'yym' is 0
)
4
Taking false branch
1104 yyval = yyvsp[1-yym];
1105 else
1106 memset(&yyval, 0, sizeof yyval);
1107 switch (yyn)
5
'Default' branch taken. Execution continues on line 1399
1108 {
1109case 3:
1110#line 100 "/usr/src/usr.bin/cvs/date.y"
1111{
1112 yyHaveTime++;
1113 }
1114break;
1115case 4:
1116#line 103 "/usr/src/usr.bin/cvs/date.y"
1117{
1118 yyHaveZone++;
1119 }
1120break;
1121case 5:
1122#line 106 "/usr/src/usr.bin/cvs/date.y"
1123{
1124 yyHaveDate++;
1125 }
1126break;
1127case 6:
1128#line 109 "/usr/src/usr.bin/cvs/date.y"
1129{
1130 yyHaveDay++;
1131 }
1132break;
1133case 7:
1134#line 112 "/usr/src/usr.bin/cvs/date.y"
1135{
1136 yyHaveRel++;
1137 }
1138break;
1139case 9:
1140#line 118 "/usr/src/usr.bin/cvs/date.y"
1141{
1142 yyHour = yyvsp[-1].Number;
1143 yyMinutes = 0;
1144 yySeconds = 0;
1145 yyMeridian = yyvsp[0].Meridian;
1146 }
1147break;
1148case 10:
1149#line 124 "/usr/src/usr.bin/cvs/date.y"
1150{
1151 yyHour = yyvsp[-3].Number;
1152 yyMinutes = yyvsp[-1].Number;
1153 yySeconds = 0;
1154 yyMeridian = yyvsp[0].Meridian;
1155 }
1156break;
1157case 11:
1158#line 130 "/usr/src/usr.bin/cvs/date.y"
1159{
1160 yyHour = yyvsp[-3].Number;
1161 yyMinutes = yyvsp[-1].Number;
1162 yyMeridian = MER24;
1163 yyDSTmode = DSToff;
1164 yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1165 }
1166break;
1167case 12:
1168#line 137 "/usr/src/usr.bin/cvs/date.y"
1169{
1170 yyHour = yyvsp[-5].Number;
1171 yyMinutes = yyvsp[-3].Number;
1172 yySeconds = yyvsp[-1].Number;
1173 yyMeridian = yyvsp[0].Meridian;
1174 }
1175break;
1176case 13:
1177#line 143 "/usr/src/usr.bin/cvs/date.y"
1178{
1179 yyHour = yyvsp[-5].Number;
1180 yyMinutes = yyvsp[-3].Number;
1181 yySeconds = yyvsp[-1].Number;
1182 yyMeridian = MER24;
1183 yyDSTmode = DSToff;
1184 yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
1185 }
1186break;
1187case 14:
1188#line 153 "/usr/src/usr.bin/cvs/date.y"
1189{
1190 yyTimezone = yyvsp[0].Number;
1191 yyDSTmode = DSToff;
1192 }
1193break;
1194case 15:
1195#line 157 "/usr/src/usr.bin/cvs/date.y"
1196{
1197 yyTimezone = yyvsp[0].Number;
1198 yyDSTmode = DSTon;
1199 }
1200break;
1201case 16:
1202#line 161 "/usr/src/usr.bin/cvs/date.y"
1203{
1204 yyTimezone = yyvsp[-1].Number;
1205 yyDSTmode = DSTon;
1206 }
1207break;
1208case 17:
1209#line 167 "/usr/src/usr.bin/cvs/date.y"
1210{
1211 yyDayOrdinal = 1;
1212 yyDayNumber = yyvsp[0].Number;
1213 }
1214break;
1215case 18:
1216#line 171 "/usr/src/usr.bin/cvs/date.y"
1217{
1218 yyDayOrdinal = 1;
1219 yyDayNumber = yyvsp[-1].Number;
1220 }
1221break;
1222case 19:
1223#line 175 "/usr/src/usr.bin/cvs/date.y"
1224{
1225 yyDayOrdinal = yyvsp[-1].Number;
1226 yyDayNumber = yyvsp[0].Number;
1227 }
1228break;
1229case 20:
1230#line 181 "/usr/src/usr.bin/cvs/date.y"
1231{
1232 yyMonth = yyvsp[-2].Number;
1233 yyDay = yyvsp[0].Number;
1234 }
1235break;
1236case 21:
1237#line 185 "/usr/src/usr.bin/cvs/date.y"
1238{
1239 if (yyvsp[-4].Number >= 100) {
1240 yyYear = yyvsp[-4].Number;
1241 yyMonth = yyvsp[-2].Number;
1242 yyDay = yyvsp[0].Number;
1243 } else {
1244 yyMonth = yyvsp[-4].Number;
1245 yyDay = yyvsp[-2].Number;
1246 yyYear = yyvsp[0].Number;
1247 }
1248 }
1249break;
1250case 22:
1251#line 196 "/usr/src/usr.bin/cvs/date.y"
1252{
1253 /* ISO 8601 format. yyyy-mm-dd. */
1254 yyYear = yyvsp[-2].Number;
1255 yyMonth = -yyvsp[-1].Number;
1256 yyDay = -yyvsp[0].Number;
1257 }
1258break;
1259case 23:
1260#line 202 "/usr/src/usr.bin/cvs/date.y"
1261{
1262 /* e.g. 17-JUN-1992. */
1263 yyDay = yyvsp[-2].Number;
1264 yyMonth = yyvsp[-1].Number;
1265 yyYear = -yyvsp[0].Number;
1266 }
1267break;
1268case 24:
1269#line 208 "/usr/src/usr.bin/cvs/date.y"
1270{
1271 yyMonth = yyvsp[-1].Number;
1272 yyDay = yyvsp[0].Number;
1273 }
1274break;
1275case 25:
1276#line 212 "/usr/src/usr.bin/cvs/date.y"
1277{
1278 yyMonth = yyvsp[-3].Number;
1279 yyDay = yyvsp[-2].Number;
1280 yyYear = yyvsp[0].Number;
1281 }
1282break;
1283case 26:
1284#line 217 "/usr/src/usr.bin/cvs/date.y"
1285{
1286 yyMonth = yyvsp[0].Number;
1287 yyDay = yyvsp[-1].Number;
1288 }
1289break;
1290case 27:
1291#line 221 "/usr/src/usr.bin/cvs/date.y"
1292{
1293 yyMonth = yyvsp[-1].Number;
1294 yyDay = yyvsp[-2].Number;
1295 yyYear = yyvsp[0].Number;
1296 }
1297break;
1298case 28:
1299#line 228 "/usr/src/usr.bin/cvs/date.y"
1300{
1301 yyRelSeconds = -yyRelSeconds;
1302 yyRelMonth = -yyRelMonth;
1303 }
1304break;
1305case 30:
1306#line 235 "/usr/src/usr.bin/cvs/date.y"
1307{
1308 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1309 }
1310break;
1311case 31:
1312#line 238 "/usr/src/usr.bin/cvs/date.y"
1313{
1314 yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
1315 }
1316break;
1317case 32:
1318#line 241 "/usr/src/usr.bin/cvs/date.y"
1319{
1320 yyRelSeconds += yyvsp[0].Number * 60L;
1321 }
1322break;
1323case 33:
1324#line 244 "/usr/src/usr.bin/cvs/date.y"
1325{
1326 yyRelSeconds += yyvsp[-1].Number;
1327 }
1328break;
1329case 34:
1330#line 247 "/usr/src/usr.bin/cvs/date.y"
1331{
1332 yyRelSeconds += yyvsp[-1].Number;
1333 }
1334break;
1335case 35:
1336#line 250 "/usr/src/usr.bin/cvs/date.y"
1337{
1338 yyRelSeconds++;
1339 }
1340break;
1341case 36:
1342#line 253 "/usr/src/usr.bin/cvs/date.y"
1343{
1344 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1345 }
1346break;
1347case 37:
1348#line 256 "/usr/src/usr.bin/cvs/date.y"
1349{
1350 yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
1351 }
1352break;
1353case 38:
1354#line 259 "/usr/src/usr.bin/cvs/date.y"
1355{
1356 yyRelMonth += yyvsp[0].Number;
1357 }
1358break;
1359case 39:
1360#line 264 "/usr/src/usr.bin/cvs/date.y"
1361{
1362 if (yyHaveTime && yyHaveDate && !yyHaveRel)
1363 yyYear = yyvsp[0].Number;
1364 else {
1365 if (yyvsp[0].Number > 10000) {
1366 yyHaveDate++;
1367 yyDay= (yyvsp[0].Number)%100;
1368 yyMonth= (yyvsp[0].Number/100)%100;
1369 yyYear = yyvsp[0].Number/10000;
1370 } else {
1371 yyHaveTime++;
1372 if (yyvsp[0].Number < 100) {
1373 yyHour = yyvsp[0].Number;
1374 yyMinutes = 0;
1375 } else {
1376 yyHour = yyvsp[0].Number / 100;
1377 yyMinutes = yyvsp[0].Number % 100;
1378 }
1379 yySeconds = 0;
1380 yyMeridian = MER24;
1381 }
1382 }
1383 }
1384break;
1385case 40:
1386#line 289 "/usr/src/usr.bin/cvs/date.y"
1387{
1388 yyval.Meridian = MER24;
1389 }
1390break;
1391case 41:
1392#line 292 "/usr/src/usr.bin/cvs/date.y"
1393{
1394 yyval.Meridian = yyvsp[0].Meridian;
1395 }
1396break;
1397#line 1390 "date.c"
1398 }
1399 yyssp -= yym;
1400 yystate = *yyssp;
1401 yyvsp -= yym;
1402 yym = yylhs[yyn];
1403 if (yystate
5.1
'yystate' is equal to 0
== 0 && yym
5.2
'yym' is equal to 0
== 0)
6
Taking true branch
1404 {
1405#if YYDEBUG0
1406 if (yydebug)
1407 printf("%sdebug: after reduction, shifting from state 0 to\
1408 state %d\n", YYPREFIX"yy", YYFINAL1);
1409#endif
1410 yystate = YYFINAL1;
1411 *++yyssp = YYFINAL1;
1412 *++yyvsp = yyval;
1413 if (yychar
6.1
'yychar' is < 0
< 0)
7
Taking true branch
1414 {
1415 if ((yychar = yylex()) < 0) yychar = 0;
8
Calling 'yylex'
1416#if YYDEBUG0
1417 if (yydebug)
1418 {
1419 yys = 0;
1420 if (yychar <= YYMAXTOKEN269) yys = yyname[yychar];
1421 if (!yys) yys = "illegal-symbol";
1422 printf("%sdebug: state %d, reading %d (%s)\n",
1423 YYPREFIX"yy", YYFINAL1, yychar, yys);
1424 }
1425#endif
1426 }
1427 if (yychar == 0) goto yyaccept;
1428 goto yyloop;
1429 }
1430 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1431 yyn <= YYTABLESIZE337 && yycheck[yyn] == yystate)
1432 yystate = yytable[yyn];
1433 else
1434 yystate = yydgoto[yym];
1435#if YYDEBUG0
1436 if (yydebug)
1437 printf("%sdebug: after reduction, shifting from state %d \
1438to state %d\n", YYPREFIX"yy", *yyssp, yystate);
1439#endif
1440 if (yyssp >= yysslim && yygrowstack())
1441 {
1442 goto yyoverflow;
1443 }
1444 *++yyssp = yystate;
1445 *++yyvsp = yyval;
1446 goto yyloop;
1447yyoverflow:
1448 yyerror("yacc stack overflow");
1449yyabort:
1450 if (yyss)
1451 free(yyss);
1452 if (yyvs)
1453 free(yyvs);
1454 yyss = yyssp = NULL((void *)0);
1455 yyvs = yyvsp = NULL((void *)0);
1456 yystacksize = 0;
1457 return (1);
1458yyaccept:
1459 if (yyss)
1460 free(yyss);
1461 if (yyvs)
1462 free(yyvs);
1463 yyss = yyssp = NULL((void *)0);
1464 yyvs = yyvsp = NULL((void *)0);
1465 yystacksize = 0;
1466 return (0);
1467}