Bug Summary

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