1 | #include <stdlib.h> |
2 | #include <string.h> |
3 | #define YYBYACC 1 |
4 | #define YYMAJOR 1 |
5 | #define YYMINOR 9 |
6 | #define YYLEX yylex() |
7 | #define YYEMPTY -1 |
8 | #define yyclearin (yychar=(YYEMPTY)) |
9 | #define yyerrok (yyerrflag=0) |
10 | #define YYRECOVERING() (yyerrflag!=0) |
11 | #define YYPREFIX "yy" |
12 | #line 2 "/usr/src/usr.bin/cvs/date.y" |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | #include <ctype.h> |
29 | #include <string.h> |
30 | #include <time.h> |
31 | |
32 | #include "cvs.h" |
33 | |
34 | #define YEAR_EPOCH 1970 |
35 | #define YEAR_TMORIGIN 1900 |
36 | #define HOUR(x) ((time_t)(x) * 60) |
37 | #define SECSPERDAY (24L * 60L * 60L) |
38 | |
39 | |
40 | |
41 | typedef struct _TABLE { |
42 | char *name; |
43 | int type; |
44 | time_t value; |
45 | } TABLE; |
46 | |
47 | |
48 | |
49 | typedef enum _DSTMODE { |
50 | DSTon, DSToff, DSTmaybe |
51 | } DSTMODE; |
52 | |
53 | |
54 | typedef enum _MERIDIAN { |
55 | MERam, MERpm, MER24 |
56 | } MERIDIAN; |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | static const char *yyInput; |
66 | static DSTMODE yyDSTmode; |
67 | static time_t yyDayOrdinal; |
68 | static time_t yyDayNumber; |
69 | static int yyHaveDate; |
70 | static int yyHaveDay; |
71 | static int yyHaveRel; |
72 | static int yyHaveTime; |
73 | static int yyHaveZone; |
74 | static time_t yyTimezone; |
75 | static time_t yyDay; |
76 | static time_t yyHour; |
77 | static time_t yyMinutes; |
78 | static time_t yyMonth; |
79 | static time_t yySeconds; |
80 | static time_t yyYear; |
81 | static MERIDIAN yyMeridian; |
82 | static time_t yyRelMonth; |
83 | static time_t yyRelSeconds; |
84 | |
85 | |
86 | static int yyerror(const char *); |
87 | static int yylex(void); |
88 | static int yyparse(void); |
89 | static int lookup(char *); |
90 | |
91 | #line 82 "/usr/src/usr.bin/cvs/date.y" |
92 | #ifndef YYSTYPE_DEFINED |
93 | #define YYSTYPE_DEFINED |
94 | typedef union { |
95 | time_t Number; |
96 | enum _MERIDIAN Meridian; |
97 | } YYSTYPE; |
98 | #endif /* YYSTYPE_DEFINED */ |
99 | #line 100 "date.c" |
100 | #define tAGO 257 |
101 | #define tDAY 258 |
102 | #define tDAYZONE 259 |
103 | #define tID 260 |
104 | #define tMERIDIAN 261 |
105 | #define tMINUTE_UNIT 262 |
106 | #define tMONTH 263 |
107 | #define tMONTH_UNIT 264 |
108 | #define tSEC_UNIT 265 |
109 | #define tSNUMBER 266 |
110 | #define tUNUMBER 267 |
111 | #define tZONE 268 |
112 | #define tDST 269 |
113 | #define YYERRCODE 256 |
114 | const 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 | }; |
122 | const 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 | }; |
130 | const 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 | }; |
138 | const short yydgoto[] = |
139 | { 1, |
140 | 45, 11, 12, 13, 14, 15, 16, 17, 18, |
141 | }; |
142 | const 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,}; |
149 | const 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,}; |
156 | const short yygindex[] = |
157 | { 0, |
158 | -17, 0, 0, 0, 0, 0, 0, 0, 0, |
159 | }; |
160 | #define YYTABLESIZE 337 |
161 | const 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 | }; |
198 | const 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 YYFINAL 1 |
236 | #ifndef YYDEBUG |
237 | #define YYDEBUG 0 |
238 | #endif |
239 | #define YYMAXTOKEN 269 |
240 | #if YYDEBUG |
241 | const 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, |
244 | 0,0,0,0,0,0,0,0,0,0,"','",0,0,"'/'",0,0,0,0,0,0,0,0,0,0,"':'",0,0,0,0,0,0,0,0,0, |
245 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
246 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
247 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
248 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
249 | 0,0,0,0,0,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 | }; |
253 | const 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 YYSTACKSIZE |
299 | #undef YYMAXDEPTH |
300 | #define YYMAXDEPTH YYSTACKSIZE |
301 | #else |
302 | #ifdef YYMAXDEPTH |
303 | #define YYSTACKSIZE YYMAXDEPTH |
304 | #else |
305 | #define YYSTACKSIZE 10000 |
306 | #define YYMAXDEPTH 10000 |
307 | #endif |
308 | #endif |
309 | #define YYINITSTACKSIZE 200 |
310 | |
311 | int yydebug; |
312 | int yynerrs; |
313 | int yyerrflag; |
314 | int yychar; |
315 | short *yyssp; |
316 | YYSTYPE *yyvsp; |
317 | YYSTYPE yyval; |
318 | YYSTYPE yylval; |
319 | short *yyss; |
320 | short *yysslim; |
321 | YYSTYPE *yyvs; |
322 | unsigned int yystacksize; |
323 | int yyparse(void); |
324 | #line 298 "/usr/src/usr.bin/cvs/date.y" |
325 | |
326 | |
327 | static TABLE const MonthDayTable[] = { |
328 | { "january", tMONTH, 1 }, |
329 | { "february", tMONTH, 2 }, |
330 | { "march", tMONTH, 3 }, |
331 | { "april", tMONTH, 4 }, |
332 | { "may", tMONTH, 5 }, |
333 | { "june", tMONTH, 6 }, |
334 | { "july", tMONTH, 7 }, |
335 | { "august", tMONTH, 8 }, |
336 | { "september", tMONTH, 9 }, |
337 | { "sept", tMONTH, 9 }, |
338 | { "october", tMONTH, 10 }, |
339 | { "november", tMONTH, 11 }, |
340 | { "december", tMONTH, 12 }, |
341 | { "sunday", tDAY, 0 }, |
342 | { "monday", tDAY, 1 }, |
343 | { "tuesday", tDAY, 2 }, |
344 | { "tues", tDAY, 2 }, |
345 | { "wednesday", tDAY, 3 }, |
346 | { "wednes", tDAY, 3 }, |
347 | { "thursday", tDAY, 4 }, |
348 | { "thur", tDAY, 4 }, |
349 | { "thurs", tDAY, 4 }, |
350 | { "friday", tDAY, 5 }, |
351 | { "saturday", tDAY, 6 }, |
352 | { NULL } |
353 | }; |
354 | |
355 | |
356 | static TABLE const UnitsTable[] = { |
357 | { "year", tMONTH_UNIT, 12 }, |
358 | { "month", tMONTH_UNIT, 1 }, |
359 | { "fortnight", tMINUTE_UNIT, 14 * 24 * 60 }, |
360 | { "week", tMINUTE_UNIT, 7 * 24 * 60 }, |
361 | { "day", tMINUTE_UNIT, 1 * 24 * 60 }, |
362 | { "hour", tMINUTE_UNIT, 60 }, |
363 | { "minute", tMINUTE_UNIT, 1 }, |
364 | { "min", tMINUTE_UNIT, 1 }, |
365 | { "second", tSEC_UNIT, 1 }, |
366 | { "sec", tSEC_UNIT, 1 }, |
367 | { NULL } |
368 | }; |
369 | |
370 | |
371 | static TABLE const OtherTable[] = { |
372 | { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 }, |
373 | { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 }, |
374 | { "today", tMINUTE_UNIT, 0 }, |
375 | { "now", tMINUTE_UNIT, 0 }, |
376 | { "last", tUNUMBER, -1 }, |
377 | { "this", tMINUTE_UNIT, 0 }, |
378 | { "next", tUNUMBER, 2 }, |
379 | { "first", tUNUMBER, 1 }, |
380 | |
381 | { "third", tUNUMBER, 3 }, |
382 | { "fourth", tUNUMBER, 4 }, |
383 | { "fifth", tUNUMBER, 5 }, |
384 | { "sixth", tUNUMBER, 6 }, |
385 | { "seventh", tUNUMBER, 7 }, |
386 | { "eighth", tUNUMBER, 8 }, |
387 | { "ninth", tUNUMBER, 9 }, |
388 | { "tenth", tUNUMBER, 10 }, |
389 | { "eleventh", tUNUMBER, 11 }, |
390 | { "twelfth", tUNUMBER, 12 }, |
391 | { "ago", tAGO, 1 }, |
392 | { NULL } |
393 | }; |
394 | |
395 | |
396 | |
397 | static TABLE const TimezoneTable[] = { |
398 | { "gmt", tZONE, HOUR( 0) }, |
399 | { "ut", tZONE, HOUR( 0) }, |
400 | { "utc", tZONE, HOUR( 0) }, |
401 | { "wet", tZONE, HOUR( 0) }, |
402 | { "bst", tDAYZONE, HOUR( 0) }, |
403 | { "wat", tZONE, HOUR( 1) }, |
404 | { "at", tZONE, HOUR( 2) }, |
405 | #if 0 |
406 | |
407 | |
408 | { "bst", tZONE, HOUR( 3) }, |
409 | { "gst", tZONE, HOUR( 3) }, |
410 | #endif |
411 | #if 0 |
412 | { "nft", tZONE, HOUR(3.5) }, |
413 | { "nst", tZONE, HOUR(3.5) }, |
414 | { "ndt", tDAYZONE, HOUR(3.5) }, |
415 | #endif |
416 | { "ast", tZONE, HOUR( 4) }, |
417 | { "adt", tDAYZONE, HOUR( 4) }, |
418 | { "est", tZONE, HOUR( 5) }, |
419 | { "edt", tDAYZONE, HOUR( 5) }, |
420 | { "cst", tZONE, HOUR( 6) }, |
421 | { "cdt", tDAYZONE, HOUR( 6) }, |
422 | { "mst", tZONE, HOUR( 7) }, |
423 | { "mdt", tDAYZONE, HOUR( 7) }, |
424 | { "pst", tZONE, HOUR( 8) }, |
425 | { "pdt", tDAYZONE, HOUR( 8) }, |
426 | { "yst", tZONE, HOUR( 9) }, |
427 | { "ydt", tDAYZONE, HOUR( 9) }, |
428 | { "hst", tZONE, HOUR(10) }, |
429 | { "hdt", tDAYZONE, HOUR(10) }, |
430 | { "cat", tZONE, HOUR(10) }, |
431 | { "ahst", tZONE, HOUR(10) }, |
432 | { "nt", tZONE, HOUR(11) }, |
433 | { "idlw", tZONE, HOUR(12) }, |
434 | { "cet", tZONE, -HOUR(1) }, |
435 | { "met", tZONE, -HOUR(1) }, |
436 | { "mewt", tZONE, -HOUR(1) }, |
437 | { "mest", tDAYZONE, -HOUR(1) }, |
438 | { "swt", tZONE, -HOUR(1) }, |
439 | { "sst", tDAYZONE, -HOUR(1) }, |
440 | { "fwt", tZONE, -HOUR(1) }, |
441 | { "fst", tDAYZONE, -HOUR(1) }, |
442 | { "eet", tZONE, -HOUR(2) }, |
443 | { "bt", tZONE, -HOUR(3) }, |
444 | #if 0 |
445 | { "it", tZONE, -HOUR(3.5) }, |
446 | #endif |
447 | { "zp4", tZONE, -HOUR(4) }, |
448 | { "zp5", tZONE, -HOUR(5) }, |
449 | #if 0 |
450 | { "ist", tZONE, -HOUR(5.5) }, |
451 | #endif |
452 | { "zp6", tZONE, -HOUR(6) }, |
453 | #if 0 |
454 | |
455 | |
456 | { "nst", tZONE, -HOUR(6.5) }, |
457 | { "sst", tZONE, -HOUR(7) }, |
458 | #endif /* 0 */ |
459 | { "wast", tZONE, -HOUR(7) }, |
460 | { "wadt", tDAYZONE, -HOUR(7) }, |
461 | #if 0 |
462 | { "jt", tZONE, -HOUR(7.5) }, |
463 | #endif |
464 | { "cct", tZONE, -HOUR(8) }, |
465 | { "jst", tZONE, -HOUR(9) }, |
466 | #if 0 |
467 | { "cast", tZONE, -HOUR(9.5) }, |
468 | { "cadt", tDAYZONE, -HOUR(9.5) }, |
469 | #endif |
470 | { "east", tZONE, -HOUR(10) }, |
471 | { "eadt", tDAYZONE, -HOUR(10) }, |
472 | { "gst", tZONE, -HOUR(10) }, |
473 | { "nzt", tZONE, -HOUR(12) }, |
474 | { "nzst", tZONE, -HOUR(12) }, |
475 | { "nzdt", tDAYZONE, -HOUR(12) }, |
476 | { "idle", tZONE, -HOUR(12) }, |
477 | { NULL } |
478 | }; |
479 | |
480 | |
481 | static TABLE const MilitaryTable[] = { |
482 | { "a", tZONE, HOUR( 1) }, |
483 | { "b", tZONE, HOUR( 2) }, |
484 | { "c", tZONE, HOUR( 3) }, |
485 | { "d", tZONE, HOUR( 4) }, |
486 | { "e", tZONE, HOUR( 5) }, |
487 | { "f", tZONE, HOUR( 6) }, |
488 | { "g", tZONE, HOUR( 7) }, |
489 | { "h", tZONE, HOUR( 8) }, |
490 | { "i", tZONE, HOUR( 9) }, |
491 | { "k", tZONE, HOUR( 10) }, |
492 | { "l", tZONE, HOUR( 11) }, |
493 | { "m", tZONE, HOUR( 12) }, |
494 | { "n", tZONE, HOUR(- 1) }, |
495 | { "o", tZONE, HOUR(- 2) }, |
496 | { "p", tZONE, HOUR(- 3) }, |
497 | { "q", tZONE, HOUR(- 4) }, |
498 | { "r", tZONE, HOUR(- 5) }, |
499 | { "s", tZONE, HOUR(- 6) }, |
500 | { "t", tZONE, HOUR(- 7) }, |
501 | { "u", tZONE, HOUR(- 8) }, |
502 | { "v", tZONE, HOUR(- 9) }, |
503 | { "w", tZONE, HOUR(-10) }, |
504 | { "x", tZONE, HOUR(-11) }, |
505 | { "y", tZONE, HOUR(-12) }, |
506 | { "z", tZONE, HOUR( 0) }, |
507 | { NULL } |
508 | }; |
509 | |
510 | |
511 | static int |
512 | yyerror(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_ERR, "%s", str); |
519 | free(str); |
520 | #endif |
521 | return (0); |
522 | } |
523 | |
524 | |
525 | static time_t |
526 | ToSeconds(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 | |
552 | } |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | static time_t |
561 | Convert(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_EPOCH) |
578 | Year += 100; |
579 | } |
580 | DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) |
581 | ? 29 : 28; |
582 | |
583 | if (Year < YEAR_EPOCH || |
584 | (sizeof(time_t) == sizeof(int) && Year > 2038) || |
585 | Month < 1 || Month > 12 || |
586 | |
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_EPOCH; i < Year; i++) |
594 | julian += 365 + (i % 4 == 0); |
595 | julian *= SECSPERDAY; |
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 | |
608 | static time_t |
609 | DSTcorrect(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 | |
620 | static time_t |
621 | RelativeDate(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 * ((DayNumber - tm->tm_wday + 7) % 7); |
629 | now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); |
630 | return DSTcorrect(Start, now); |
631 | } |
632 | |
633 | |
634 | static time_t |
635 | RelativeMonth(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 | |
654 | static int |
655 | lookup(char *buff) |
656 | { |
657 | size_t len; |
658 | char *p, *q; |
659 | int i, abbrev; |
660 | const TABLE *tp; |
661 | |
662 | |
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 (tMERIDIAN); |
670 | } |
671 | if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { |
672 | yylval.Meridian = MERpm; |
673 | return (tMERIDIAN); |
674 | } |
675 | |
676 | len = strlen(buff); |
677 | |
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 (tDST); |
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 | |
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'; |
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 | |
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 | |
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 (tID); |
755 | } |
756 | |
757 | |
758 | static int |
759 | yylex(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 | |
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 ? tSNUMBER : tUNUMBER; |
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 | |
811 | static long |
812 | difftm(struct tm *a, struct tm *b) |
813 | { |
814 | int ay = a->tm_year + (YEAR_TMORIGIN - 1); |
815 | int by = b->tm_year + (YEAR_TMORIGIN - 1); |
816 | int days = ( |
817 | |
818 | a->tm_yday - b->tm_yday |
819 | |
820 | + ((ay >> 2) - (by >> 2)) |
821 | - (ay/100 - by/100) |
822 | + ((ay/100 >> 2) - (by/100 >> 2)) |
823 | |
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 | |
831 | |
832 | |
833 | |
834 | time_t |
835 | date_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 | |
897 | int |
898 | main(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); |
905 | while (fgets(buff, sizeof(buff), stdin) && 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); |
913 | } |
914 | |
915 | return (0); |
916 | } |
917 | #endif /* defined(TEST) */ |
918 | #line 911 "date.c" |
919 | |
920 | static int yygrowstack(void) |
921 | { |
922 | unsigned int newsize; |
923 | long sslen; |
924 | short *newss; |
925 | YYSTYPE *newvs; |
926 | |
927 | if ((newsize = yystacksize) == 0) |
| 32 | | Assuming the condition is false | |
|
| |
928 | newsize = YYINITSTACKSIZE; |
929 | else if (newsize >= YYMAXDEPTH) |
| 34 | | Assuming 'newsize' is < YYMAXDEPTH | |
|
| |
930 | return -1; |
931 | else if ((newsize *= 2) > YYMAXDEPTH) |
| 36 | | Assuming the condition is false | |
|
| |
932 | newsize = YYMAXDEPTH; |
933 | sslen = yyssp - yyss; |
934 | #ifdef SIZE_MAX |
935 | #define YY_SIZE_MAX SIZE_MAX |
936 | #else |
937 | #define YY_SIZE_MAX 0xffffffffU |
938 | #endif |
939 | if (newsize && YY_SIZE_MAX / newsize < sizeof *newss) |
| 38 | | Assuming 'newsize' is 0 | |
|
940 | goto bail; |
941 | newss = (short *)realloc(yyss, newsize * sizeof *newss); |
942 | if (newss == NULL) |
| 39 | | Assuming 'newss' is not equal to NULL | |
|
| |
943 | goto bail; |
944 | yyss = newss; |
945 | yyssp = newss + sslen; |
946 | if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs) |
947 | goto bail; |
948 | newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs); |
949 | if (newvs == NULL) |
| 41 | | Assuming 'newvs' is not equal to NULL | |
|
| |
950 | goto bail; |
951 | yyvs = newvs; |
952 | yyvsp = newvs + sslen; |
953 | yystacksize = newsize; |
954 | yysslim = yyss + newsize - 1; |
955 | return 0; |
956 | bail: |
957 | if (yyss) |
958 | free(yyss); |
959 | if (yyvs) |
960 | free(yyvs); |
961 | yyss = yyssp = NULL; |
962 | yyvs = yyvsp = NULL; |
963 | yystacksize = 0; |
964 | return -1; |
965 | } |
966 | |
967 | #define YYABORT goto yyabort |
968 | #define YYREJECT goto yyabort |
969 | #define YYACCEPT goto yyaccept |
970 | #define YYERROR goto yyerrlab |
971 | int |
972 | yyparse(void) |
973 | { |
974 | int yym, yyn, yystate; |
975 | #if YYDEBUG |
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 && yygrowstack()) goto yyoverflow; |
| 1 | Assuming 'yyss' is not equal to NULL | |
|
991 | yyssp = yyss; |
992 | yyvsp = yyvs; |
993 | *yyssp = yystate = 0; |
994 | |
995 | yyloop: |
996 | if ((yyn = yydefred[yystate]) != 0) goto yyreduce; |
| |
| 3 | | Control jumps to line 1103 | |
|
| |
| |
997 | if (yychar < 0) |
| |
| |
998 | { |
999 | if ((yychar = yylex()) < 0) yychar = 0; |
| |
1000 | #if YYDEBUG |
1001 | if (yydebug) |
1002 | { |
1003 | yys = 0; |
1004 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
1005 | if (!yys) yys = "illegal-symbol"; |
1006 | printf("%sdebug: state %d, reading %d (%s)\n", |
1007 | YYPREFIX, yystate, yychar, yys); |
1008 | } |
1009 | #endif |
1010 | } |
1011 | if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && |
| 15 | | Assuming 'yyn' is not equal to 0 | |
|
| 28 | | Assuming 'yyn' is not equal to 0 | |
|
| |
1012 | yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
1013 | { |
1014 | #if YYDEBUG |
1015 | if (yydebug) |
1016 | printf("%sdebug: state %d, shifting to state %d\n", |
1017 | YYPREFIX, yystate, yytable[yyn]); |
1018 | #endif |
1019 | if (yyssp >= yysslim && yygrowstack()) |
| 30 | | Assuming 'yyssp' is >= 'yysslim' | |
|
| |
| 43 | | Returning from 'yygrowstack' | |
|
| |
1020 | { |
1021 | goto yyoverflow; |
1022 | } |
1023 | *++yyssp = yystate = yytable[yyn]; |
| 45 | | Use of zero-allocated memory |
|
1024 | *++yyvsp = yylval; |
1025 | yychar = (-1); |
1026 | if (yyerrflag > 0) --yyerrflag; |
1027 | goto yyloop; |
1028 | } |
1029 | if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && |
| |
1030 | yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
1031 | { |
1032 | yyn = yytable[yyn]; |
1033 | goto yyreduce; |
1034 | } |
1035 | if (yyerrflag) goto yyinrecovery; |
| |
1036 | #if defined(__GNUC__) |
1037 | goto yynewerror; |
| 18 | | Control jumps to line 1040 | |
|
1038 | #endif |
1039 | yynewerror: |
1040 | yyerror("syntax error"); |
1041 | #if defined(__GNUC__) |
1042 | goto yyerrlab; |
| 19 | | Control jumps to line 1045 | |
|
1043 | #endif |
1044 | yyerrlab: |
1045 | ++yynerrs; |
1046 | yyinrecovery: |
1047 | if (yyerrflag < 3) |
| 20 | | Assuming 'yyerrflag' is >= 3 | |
|
| |
1048 | { |
1049 | yyerrflag = 3; |
1050 | for (;;) |
1051 | { |
1052 | if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && |
1053 | yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) |
1054 | { |
1055 | #if YYDEBUG |
1056 | if (yydebug) |
1057 | printf("%sdebug: state %d, error recovery shifting\ |
1058 | to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); |
1059 | #endif |
1060 | if (yyssp >= yysslim && yygrowstack()) |
1061 | { |
1062 | goto yyoverflow; |
1063 | } |
1064 | *++yyssp = yystate = yytable[yyn]; |
1065 | *++yyvsp = yylval; |
1066 | goto yyloop; |
1067 | } |
1068 | else |
1069 | { |
1070 | #if YYDEBUG |
1071 | if (yydebug) |
1072 | printf("%sdebug: error recovery discarding state %d\n", |
1073 | YYPREFIX, *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; |
| 22 | | Assuming 'yychar' is not equal to 0 | |
|
| |
1084 | #if YYDEBUG |
1085 | if (yydebug) |
1086 | { |
1087 | yys = 0; |
1088 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
1089 | if (!yys) yys = "illegal-symbol"; |
1090 | printf("%sdebug: state %d, error recovery discards token %d (%s)\n", |
1091 | YYPREFIX, yystate, yychar, yys); |
1092 | } |
1093 | #endif |
1094 | yychar = (-1); |
1095 | goto yyloop; |
| 24 | | Control jumps to line 996 | |
|
1096 | } |
1097 | yyreduce: |
1098 | #if YYDEBUG |
1099 | if (yydebug) |
1100 | printf("%sdebug: state %d, reducing by rule %d (%s)\n", |
1101 | YYPREFIX, yystate, yyn, yyrule[yyn]); |
1102 | #endif |
1103 | yym = yylen[yyn]; |
1104 | if (yym) |
| |
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 | { |
1110 | case 3: |
1111 | #line 100 "/usr/src/usr.bin/cvs/date.y" |
1112 | { |
1113 | yyHaveTime++; |
1114 | } |
1115 | break; |
1116 | case 4: |
1117 | #line 103 "/usr/src/usr.bin/cvs/date.y" |
1118 | { |
1119 | yyHaveZone++; |
1120 | } |
1121 | break; |
1122 | case 5: |
1123 | #line 106 "/usr/src/usr.bin/cvs/date.y" |
1124 | { |
1125 | yyHaveDate++; |
1126 | } |
1127 | break; |
1128 | case 6: |
1129 | #line 109 "/usr/src/usr.bin/cvs/date.y" |
1130 | { |
1131 | yyHaveDay++; |
1132 | } |
1133 | break; |
1134 | case 7: |
1135 | #line 112 "/usr/src/usr.bin/cvs/date.y" |
1136 | { |
1137 | yyHaveRel++; |
1138 | } |
1139 | break; |
1140 | case 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 | } |
1148 | break; |
1149 | case 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 | } |
1157 | break; |
1158 | case 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 | } |
1167 | break; |
1168 | case 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 | } |
1176 | break; |
1177 | case 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 | } |
1187 | break; |
1188 | case 14: |
1189 | #line 153 "/usr/src/usr.bin/cvs/date.y" |
1190 | { |
1191 | yyTimezone = yyvsp[0].Number; |
1192 | yyDSTmode = DSToff; |
1193 | } |
1194 | break; |
1195 | case 15: |
1196 | #line 157 "/usr/src/usr.bin/cvs/date.y" |
1197 | { |
1198 | yyTimezone = yyvsp[0].Number; |
1199 | yyDSTmode = DSTon; |
1200 | } |
1201 | break; |
1202 | case 16: |
1203 | #line 161 "/usr/src/usr.bin/cvs/date.y" |
1204 | { |
1205 | yyTimezone = yyvsp[-1].Number; |
1206 | yyDSTmode = DSTon; |
1207 | } |
1208 | break; |
1209 | case 17: |
1210 | #line 167 "/usr/src/usr.bin/cvs/date.y" |
1211 | { |
1212 | yyDayOrdinal = 1; |
1213 | yyDayNumber = yyvsp[0].Number; |
1214 | } |
1215 | break; |
1216 | case 18: |
1217 | #line 171 "/usr/src/usr.bin/cvs/date.y" |
1218 | { |
1219 | yyDayOrdinal = 1; |
1220 | yyDayNumber = yyvsp[-1].Number; |
1221 | } |
1222 | break; |
1223 | case 19: |
1224 | #line 175 "/usr/src/usr.bin/cvs/date.y" |
1225 | { |
1226 | yyDayOrdinal = yyvsp[-1].Number; |
1227 | yyDayNumber = yyvsp[0].Number; |
1228 | } |
1229 | break; |
1230 | case 20: |
1231 | #line 181 "/usr/src/usr.bin/cvs/date.y" |
1232 | { |
1233 | yyMonth = yyvsp[-2].Number; |
1234 | yyDay = yyvsp[0].Number; |
1235 | } |
1236 | break; |
1237 | case 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 | } |
1250 | break; |
1251 | case 22: |
1252 | #line 196 "/usr/src/usr.bin/cvs/date.y" |
1253 | { |
1254 | |
1255 | yyYear = yyvsp[-2].Number; |
1256 | yyMonth = -yyvsp[-1].Number; |
1257 | yyDay = -yyvsp[0].Number; |
1258 | } |
1259 | break; |
1260 | case 23: |
1261 | #line 202 "/usr/src/usr.bin/cvs/date.y" |
1262 | { |
1263 | |
1264 | yyDay = yyvsp[-2].Number; |
1265 | yyMonth = yyvsp[-1].Number; |
1266 | yyYear = -yyvsp[0].Number; |
1267 | } |
1268 | break; |
1269 | case 24: |
1270 | #line 208 "/usr/src/usr.bin/cvs/date.y" |
1271 | { |
1272 | yyMonth = yyvsp[-1].Number; |
1273 | yyDay = yyvsp[0].Number; |
1274 | } |
1275 | break; |
1276 | case 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 | } |
1283 | break; |
1284 | case 26: |
1285 | #line 217 "/usr/src/usr.bin/cvs/date.y" |
1286 | { |
1287 | yyMonth = yyvsp[0].Number; |
1288 | yyDay = yyvsp[-1].Number; |
1289 | } |
1290 | break; |
1291 | case 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 | } |
1298 | break; |
1299 | case 28: |
1300 | #line 228 "/usr/src/usr.bin/cvs/date.y" |
1301 | { |
1302 | yyRelSeconds = -yyRelSeconds; |
1303 | yyRelMonth = -yyRelMonth; |
1304 | } |
1305 | break; |
1306 | case 30: |
1307 | #line 235 "/usr/src/usr.bin/cvs/date.y" |
1308 | { |
1309 | yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L; |
1310 | } |
1311 | break; |
1312 | case 31: |
1313 | #line 238 "/usr/src/usr.bin/cvs/date.y" |
1314 | { |
1315 | yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L; |
1316 | } |
1317 | break; |
1318 | case 32: |
1319 | #line 241 "/usr/src/usr.bin/cvs/date.y" |
1320 | { |
1321 | yyRelSeconds += yyvsp[0].Number * 60L; |
1322 | } |
1323 | break; |
1324 | case 33: |
1325 | #line 244 "/usr/src/usr.bin/cvs/date.y" |
1326 | { |
1327 | yyRelSeconds += yyvsp[-1].Number; |
1328 | } |
1329 | break; |
1330 | case 34: |
1331 | #line 247 "/usr/src/usr.bin/cvs/date.y" |
1332 | { |
1333 | yyRelSeconds += yyvsp[-1].Number; |
1334 | } |
1335 | break; |
1336 | case 35: |
1337 | #line 250 "/usr/src/usr.bin/cvs/date.y" |
1338 | { |
1339 | yyRelSeconds++; |
1340 | } |
1341 | break; |
1342 | case 36: |
1343 | #line 253 "/usr/src/usr.bin/cvs/date.y" |
1344 | { |
1345 | yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number; |
1346 | } |
1347 | break; |
1348 | case 37: |
1349 | #line 256 "/usr/src/usr.bin/cvs/date.y" |
1350 | { |
1351 | yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number; |
1352 | } |
1353 | break; |
1354 | case 38: |
1355 | #line 259 "/usr/src/usr.bin/cvs/date.y" |
1356 | { |
1357 | yyRelMonth += yyvsp[0].Number; |
1358 | } |
1359 | break; |
1360 | case 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 | } |
1385 | break; |
1386 | case 40: |
1387 | #line 289 "/usr/src/usr.bin/cvs/date.y" |
1388 | { |
1389 | yyval.Meridian = MER24; |
1390 | } |
1391 | break; |
1392 | case 41: |
1393 | #line 292 "/usr/src/usr.bin/cvs/date.y" |
1394 | { |
1395 | yyval.Meridian = yyvsp[0].Meridian; |
1396 | } |
1397 | break; |
1398 | #line 1391 "date.c" |
1399 | } |
1400 | yyssp -= yym; |
1401 | yystate = *yyssp; |
1402 | yyvsp -= yym; |
1403 | yym = yylhs[yyn]; |
1404 | if (yystate == 0 && yym == 0) |
| |
1405 | { |
1406 | #if YYDEBUG |
1407 | if (yydebug) |
1408 | printf("%sdebug: after reduction, shifting from state 0 to\ |
1409 | state %d\n", YYPREFIX, YYFINAL); |
1410 | #endif |
1411 | yystate = YYFINAL; |
1412 | *++yyssp = YYFINAL; |
1413 | *++yyvsp = yyval; |
1414 | if (yychar < 0) |
| |
1415 | { |
1416 | if ((yychar = yylex()) < 0) yychar = 0; |
| 8 | | Assuming the condition is false | |
|
| |
1417 | #if YYDEBUG |
1418 | if (yydebug) |
1419 | { |
1420 | yys = 0; |
1421 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
1422 | if (!yys) yys = "illegal-symbol"; |
1423 | printf("%sdebug: state %d, reading %d (%s)\n", |
1424 | YYPREFIX, YYFINAL, yychar, yys); |
1425 | } |
1426 | #endif |
1427 | } |
1428 | if (yychar == 0) goto yyaccept; |
| 10 | | Assuming 'yychar' is not equal to 0 | |
|
| |
1429 | goto yyloop; |
| 12 | | Control jumps to line 996 | |
|
1430 | } |
1431 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && |
1432 | yyn <= YYTABLESIZE && yycheck[yyn] == yystate) |
1433 | yystate = yytable[yyn]; |
1434 | else |
1435 | yystate = yydgoto[yym]; |
1436 | #if YYDEBUG |
1437 | if (yydebug) |
1438 | printf("%sdebug: after reduction, shifting from state %d \ |
1439 | to state %d\n", YYPREFIX, *yyssp, yystate); |
1440 | #endif |
1441 | if (yyssp >= yysslim && yygrowstack()) |
1442 | { |
1443 | goto yyoverflow; |
1444 | } |
1445 | *++yyssp = yystate; |
1446 | *++yyvsp = yyval; |
1447 | goto yyloop; |
1448 | yyoverflow: |
1449 | yyerror("yacc stack overflow"); |
1450 | yyabort: |
1451 | if (yyss) |
1452 | free(yyss); |
1453 | if (yyvs) |
1454 | free(yyvs); |
1455 | yyss = yyssp = NULL; |
1456 | yyvs = yyvsp = NULL; |
1457 | yystacksize = 0; |
1458 | return (1); |
1459 | yyaccept: |
1460 | if (yyss) |
1461 | free(yyss); |
1462 | if (yyvs) |
1463 | free(yyvs); |
1464 | yyss = yyssp = NULL; |
1465 | yyvs = yyvsp = NULL; |
1466 | yystacksize = 0; |
1467 | return (0); |
1468 | } |