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/rcs/date.y" |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
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_EPOCH 1970 |
36 | #define YEAR_TMORIGIN 1900 |
37 | #define HOUR(x) ((time_t)(x) * 60) |
38 | #define SECSPERDAY (24L * 60L * 60L) |
39 | |
40 | |
41 | |
42 | typedef struct _TABLE { |
43 | char *name; |
44 | int type; |
45 | time_t value; |
46 | } TABLE; |
47 | |
48 | |
49 | |
50 | typedef enum _DSTMODE { |
51 | DSTon, DSToff, DSTmaybe |
52 | } DSTMODE; |
53 | |
54 | |
55 | typedef enum _MERIDIAN { |
56 | MERam, MERpm, MER24 |
57 | } MERIDIAN; |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | static const char *yyInput; |
67 | static DSTMODE yyDSTmode; |
68 | static time_t yyDayOrdinal; |
69 | static time_t yyDayNumber; |
70 | static int yyHaveDate; |
71 | static int yyHaveDay; |
72 | static int yyHaveRel; |
73 | static int yyHaveTime; |
74 | static int yyHaveZone; |
75 | static time_t yyTimezone; |
76 | static time_t yyDay; |
77 | static time_t yyHour; |
78 | static time_t yyMinutes; |
79 | static time_t yyMonth; |
80 | static time_t yySeconds; |
81 | static time_t yyYear; |
82 | static MERIDIAN yyMeridian; |
83 | static time_t yyRelMonth; |
84 | static time_t yyRelSeconds; |
85 | |
86 | |
87 | static int yyerror(const char *); |
88 | static int yylex(void); |
89 | static int yyparse(void); |
90 | static int lookup(char *); |
91 | |
92 | #line 83 "/usr/src/usr.bin/rcs/date.y" |
93 | #ifndef YYSTYPE_DEFINED |
94 | #define YYSTYPE_DEFINED |
95 | typedef union { |
96 | time_t Number; |
97 | enum _MERIDIAN Meridian; |
98 | } YYSTYPE; |
99 | #endif /* YYSTYPE_DEFINED */ |
100 | #line 101 "date.c" |
101 | #define tAGO 257 |
102 | #define tDAY 258 |
103 | #define tDAYZONE 259 |
104 | #define tID 260 |
105 | #define tMERIDIAN 261 |
106 | #define tMINUTE_UNIT 262 |
107 | #define tMONTH 263 |
108 | #define tMONTH_UNIT 264 |
109 | #define tSEC_UNIT 265 |
110 | #define tSNUMBER 266 |
111 | #define tUNUMBER 267 |
112 | #define tZONE 268 |
113 | #define tDST 269 |
114 | #define YYERRCODE 256 |
115 | const 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 | }; |
123 | const 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 | }; |
131 | const 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 | }; |
139 | const short yydgoto[] = |
140 | { 1, |
141 | 45, 11, 12, 13, 14, 15, 16, 17, 18, |
142 | }; |
143 | const 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,}; |
150 | const 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,}; |
157 | const short yygindex[] = |
158 | { 0, |
159 | -17, 0, 0, 0, 0, 0, 0, 0, 0, |
160 | }; |
161 | #define YYTABLESIZE 337 |
162 | const 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 | }; |
199 | const 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 YYFINAL 1 |
237 | #ifndef YYDEBUG |
238 | #define YYDEBUG 0 |
239 | #endif |
240 | #define YYMAXTOKEN 269 |
241 | #if YYDEBUG |
242 | const 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, |
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, |
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,0,0,0,0,0,0,0,0,0,0,0, |
250 | 0,0,0,0,0,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 | }; |
254 | const 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 YYSTACKSIZE |
300 | #undef YYMAXDEPTH |
301 | #define YYMAXDEPTH YYSTACKSIZE |
302 | #else |
303 | #ifdef YYMAXDEPTH |
304 | #define YYSTACKSIZE YYMAXDEPTH |
305 | #else |
306 | #define YYSTACKSIZE 10000 |
307 | #define YYMAXDEPTH 10000 |
308 | #endif |
309 | #endif |
310 | #define YYINITSTACKSIZE 200 |
311 | |
312 | int yydebug; |
313 | int yynerrs; |
314 | int yyerrflag; |
315 | int yychar; |
316 | short *yyssp; |
317 | YYSTYPE *yyvsp; |
318 | YYSTYPE yyval; |
319 | YYSTYPE yylval; |
320 | short *yyss; |
321 | short *yysslim; |
322 | YYSTYPE *yyvs; |
323 | unsigned int yystacksize; |
324 | int yyparse(void); |
325 | #line 299 "/usr/src/usr.bin/rcs/date.y" |
326 | |
327 | |
328 | static TABLE const MonthDayTable[] = { |
329 | { "january", tMONTH, 1 }, |
330 | { "february", tMONTH, 2 }, |
331 | { "march", tMONTH, 3 }, |
332 | { "april", tMONTH, 4 }, |
333 | { "may", tMONTH, 5 }, |
334 | { "june", tMONTH, 6 }, |
335 | { "july", tMONTH, 7 }, |
336 | { "august", tMONTH, 8 }, |
337 | { "september", tMONTH, 9 }, |
338 | { "sept", tMONTH, 9 }, |
339 | { "october", tMONTH, 10 }, |
340 | { "november", tMONTH, 11 }, |
341 | { "december", tMONTH, 12 }, |
342 | { "sunday", tDAY, 0 }, |
343 | { "monday", tDAY, 1 }, |
344 | { "tuesday", tDAY, 2 }, |
345 | { "tues", tDAY, 2 }, |
346 | { "wednesday", tDAY, 3 }, |
347 | { "wednes", tDAY, 3 }, |
348 | { "thursday", tDAY, 4 }, |
349 | { "thur", tDAY, 4 }, |
350 | { "thurs", tDAY, 4 }, |
351 | { "friday", tDAY, 5 }, |
352 | { "saturday", tDAY, 6 }, |
353 | { NULL } |
354 | }; |
355 | |
356 | |
357 | static TABLE const UnitsTable[] = { |
358 | { "year", tMONTH_UNIT, 12 }, |
359 | { "month", tMONTH_UNIT, 1 }, |
360 | { "fortnight", tMINUTE_UNIT, 14 * 24 * 60 }, |
361 | { "week", tMINUTE_UNIT, 7 * 24 * 60 }, |
362 | { "day", tMINUTE_UNIT, 1 * 24 * 60 }, |
363 | { "hour", tMINUTE_UNIT, 60 }, |
364 | { "minute", tMINUTE_UNIT, 1 }, |
365 | { "min", tMINUTE_UNIT, 1 }, |
366 | { "second", tSEC_UNIT, 1 }, |
367 | { "sec", tSEC_UNIT, 1 }, |
368 | { NULL } |
369 | }; |
370 | |
371 | |
372 | static TABLE const OtherTable[] = { |
373 | { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 }, |
374 | { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 }, |
375 | { "today", tMINUTE_UNIT, 0 }, |
376 | { "now", tMINUTE_UNIT, 0 }, |
377 | { "last", tUNUMBER, -1 }, |
378 | { "this", tMINUTE_UNIT, 0 }, |
379 | { "next", tUNUMBER, 2 }, |
380 | { "first", tUNUMBER, 1 }, |
381 | |
382 | { "third", tUNUMBER, 3 }, |
383 | { "fourth", tUNUMBER, 4 }, |
384 | { "fifth", tUNUMBER, 5 }, |
385 | { "sixth", tUNUMBER, 6 }, |
386 | { "seventh", tUNUMBER, 7 }, |
387 | { "eighth", tUNUMBER, 8 }, |
388 | { "ninth", tUNUMBER, 9 }, |
389 | { "tenth", tUNUMBER, 10 }, |
390 | { "eleventh", tUNUMBER, 11 }, |
391 | { "twelfth", tUNUMBER, 12 }, |
392 | { "ago", tAGO, 1 }, |
393 | { NULL } |
394 | }; |
395 | |
396 | |
397 | |
398 | static TABLE const TimezoneTable[] = { |
399 | { "gmt", tZONE, HOUR( 0) }, |
400 | { "ut", tZONE, HOUR( 0) }, |
401 | { "utc", tZONE, HOUR( 0) }, |
402 | { "wet", tZONE, HOUR( 0) }, |
403 | { "bst", tDAYZONE, HOUR( 0) }, |
404 | { "wat", tZONE, HOUR( 1) }, |
405 | { "at", tZONE, HOUR( 2) }, |
406 | #if 0 |
407 | |
408 | |
409 | { "bst", tZONE, HOUR( 3) }, |
410 | { "gst", tZONE, HOUR( 3) }, |
411 | #endif |
412 | #if 0 |
413 | { "nft", tZONE, HOUR(3.5) }, |
414 | { "nst", tZONE, HOUR(3.5) }, |
415 | { "ndt", tDAYZONE, HOUR(3.5) }, |
416 | #endif |
417 | { "ast", tZONE, HOUR( 4) }, |
418 | { "adt", tDAYZONE, HOUR( 4) }, |
419 | { "est", tZONE, HOUR( 5) }, |
420 | { "edt", tDAYZONE, HOUR( 5) }, |
421 | { "cst", tZONE, HOUR( 6) }, |
422 | { "cdt", tDAYZONE, HOUR( 6) }, |
423 | { "mst", tZONE, HOUR( 7) }, |
424 | { "mdt", tDAYZONE, HOUR( 7) }, |
425 | { "pst", tZONE, HOUR( 8) }, |
426 | { "pdt", tDAYZONE, HOUR( 8) }, |
427 | { "yst", tZONE, HOUR( 9) }, |
428 | { "ydt", tDAYZONE, HOUR( 9) }, |
429 | { "hst", tZONE, HOUR(10) }, |
430 | { "hdt", tDAYZONE, HOUR(10) }, |
431 | { "cat", tZONE, HOUR(10) }, |
432 | { "ahst", tZONE, HOUR(10) }, |
433 | { "nt", tZONE, HOUR(11) }, |
434 | { "idlw", tZONE, HOUR(12) }, |
435 | { "cet", tZONE, -HOUR(1) }, |
436 | { "met", tZONE, -HOUR(1) }, |
437 | { "mewt", tZONE, -HOUR(1) }, |
438 | { "mest", tDAYZONE, -HOUR(1) }, |
439 | { "swt", tZONE, -HOUR(1) }, |
440 | { "sst", tDAYZONE, -HOUR(1) }, |
441 | { "fwt", tZONE, -HOUR(1) }, |
442 | { "fst", tDAYZONE, -HOUR(1) }, |
443 | { "eet", tZONE, -HOUR(2) }, |
444 | { "bt", tZONE, -HOUR(3) }, |
445 | #if 0 |
446 | { "it", tZONE, -HOUR(3.5) }, |
447 | #endif |
448 | { "zp4", tZONE, -HOUR(4) }, |
449 | { "zp5", tZONE, -HOUR(5) }, |
450 | #if 0 |
451 | { "ist", tZONE, -HOUR(5.5) }, |
452 | #endif |
453 | { "zp6", tZONE, -HOUR(6) }, |
454 | #if 0 |
455 | |
456 | |
457 | { "nst", tZONE, -HOUR(6.5) }, |
458 | { "sst", tZONE, -HOUR(7) }, |
459 | #endif /* 0 */ |
460 | { "wast", tZONE, -HOUR(7) }, |
461 | { "wadt", tDAYZONE, -HOUR(7) }, |
462 | #if 0 |
463 | { "jt", tZONE, -HOUR(7.5) }, |
464 | #endif |
465 | { "cct", tZONE, -HOUR(8) }, |
466 | { "jst", tZONE, -HOUR(9) }, |
467 | #if 0 |
468 | { "cast", tZONE, -HOUR(9.5) }, |
469 | { "cadt", tDAYZONE, -HOUR(9.5) }, |
470 | #endif |
471 | { "east", tZONE, -HOUR(10) }, |
472 | { "eadt", tDAYZONE, -HOUR(10) }, |
473 | { "gst", tZONE, -HOUR(10) }, |
474 | { "nzt", tZONE, -HOUR(12) }, |
475 | { "nzst", tZONE, -HOUR(12) }, |
476 | { "nzdt", tDAYZONE, -HOUR(12) }, |
477 | { "idle", tZONE, -HOUR(12) }, |
478 | { NULL } |
479 | }; |
480 | |
481 | |
482 | static TABLE const MilitaryTable[] = { |
483 | { "a", tZONE, HOUR( 1) }, |
484 | { "b", tZONE, HOUR( 2) }, |
485 | { "c", tZONE, HOUR( 3) }, |
486 | { "d", tZONE, HOUR( 4) }, |
487 | { "e", tZONE, HOUR( 5) }, |
488 | { "f", tZONE, HOUR( 6) }, |
489 | { "g", tZONE, HOUR( 7) }, |
490 | { "h", tZONE, HOUR( 8) }, |
491 | { "i", tZONE, HOUR( 9) }, |
492 | { "k", tZONE, HOUR( 10) }, |
493 | { "l", tZONE, HOUR( 11) }, |
494 | { "m", tZONE, HOUR( 12) }, |
495 | { "n", tZONE, HOUR(- 1) }, |
496 | { "o", tZONE, HOUR(- 2) }, |
497 | { "p", tZONE, HOUR(- 3) }, |
498 | { "q", tZONE, HOUR(- 4) }, |
499 | { "r", tZONE, HOUR(- 5) }, |
500 | { "s", tZONE, HOUR(- 6) }, |
501 | { "t", tZONE, HOUR(- 7) }, |
502 | { "u", tZONE, HOUR(- 8) }, |
503 | { "v", tZONE, HOUR(- 9) }, |
504 | { "w", tZONE, HOUR(-10) }, |
505 | { "x", tZONE, HOUR(-11) }, |
506 | { "y", tZONE, HOUR(-12) }, |
507 | { "z", tZONE, HOUR( 0) }, |
508 | { NULL } |
509 | }; |
510 | |
511 | |
512 | static int |
513 | yyerror(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 | |
530 | static time_t |
531 | ToSeconds(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 | |
557 | } |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | static time_t |
566 | Convert(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_EPOCH) |
583 | Year += 100; |
584 | } |
585 | DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) |
586 | ? 29 : 28; |
587 | |
588 | if (Year < YEAR_EPOCH || |
589 | (sizeof(time_t) == sizeof(int) && Year > 2038) || |
590 | Month < 1 || Month > 12 || |
591 | |
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_EPOCH; i < Year; i++) |
599 | julian += 365 + (i % 4 == 0); |
600 | julian *= SECSPERDAY; |
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 | |
613 | static time_t |
614 | DSTcorrect(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 | |
625 | static time_t |
626 | RelativeDate(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 * ((DayNumber - tm->tm_wday + 7) % 7); |
634 | now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); |
635 | return DSTcorrect(Start, now); |
636 | } |
637 | |
638 | |
639 | static time_t |
640 | RelativeMonth(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 | |
659 | static int |
660 | lookup(char *buff) |
661 | { |
662 | size_t len; |
663 | char *p, *q; |
664 | int i, abbrev; |
665 | const TABLE *tp; |
666 | |
667 | |
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 (tMERIDIAN); |
675 | } |
676 | if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { |
677 | yylval.Meridian = MERpm; |
678 | return (tMERIDIAN); |
679 | } |
680 | |
681 | len = strlen(buff); |
682 | |
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 (tDST); |
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 | |
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'; |
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 | |
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 | |
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 (tID); |
760 | } |
761 | |
762 | |
763 | static int |
764 | yylex(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 | |
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 ? tSNUMBER : tUNUMBER; |
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 | |
816 | static long |
817 | difftm(struct tm *a, struct tm *b) |
818 | { |
819 | int ay = a->tm_year + (YEAR_TMORIGIN - 1); |
820 | int by = b->tm_year + (YEAR_TMORIGIN - 1); |
821 | int days = ( |
822 | |
823 | a->tm_yday - b->tm_yday |
824 | |
825 | + ((ay >> 2) - (by >> 2)) |
826 | - (ay/100 - by/100) |
827 | + ((ay/100 >> 2) - (by/100 >> 2)) |
828 | |
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 | |
836 | |
837 | |
838 | |
839 | time_t |
840 | date_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 | |
902 | int |
903 | main(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); |
910 | while (fgets(buff, sizeof(buff), stdin) && 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); |
918 | } |
919 | |
920 | return (0); |
921 | } |
922 | #endif /* defined(TEST) */ |
923 | #line 916 "date.c" |
924 | |
925 | static 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 | |
|
| |
933 | newsize = YYINITSTACKSIZE; |
934 | else if (newsize >= YYMAXDEPTH) |
| 32 | | Assuming 'newsize' is < YYMAXDEPTH | |
|
| |
935 | return -1; |
936 | else if ((newsize *= 2) > YYMAXDEPTH) |
| 34 | | Assuming the condition is false | |
|
| |
937 | newsize = YYMAXDEPTH; |
938 | sslen = yyssp - yyss; |
939 | #ifdef SIZE_MAX |
940 | #define YY_SIZE_MAX SIZE_MAX |
941 | #else |
942 | #define YY_SIZE_MAX 0xffffffffU |
943 | #endif |
944 | if (newsize && YY_SIZE_MAX / newsize < sizeof *newss) |
| 36 | | Assuming 'newsize' is 0 | |
|
945 | goto bail; |
946 | newss = (short *)realloc(yyss, newsize * sizeof *newss); |
| |
947 | if (newss == NULL) |
| 38 | | Assuming 'newss' is equal to NULL | |
|
| |
948 | goto bail; |
| 40 | | Control jumps to line 962 | |
|
949 | yyss = newss; |
950 | yyssp = newss + sslen; |
951 | if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs) |
952 | goto bail; |
953 | newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs); |
954 | if (newvs == NULL) |
955 | goto bail; |
956 | yyvs = newvs; |
957 | yyvsp = newvs + sslen; |
958 | yystacksize = newsize; |
959 | yysslim = yyss + newsize - 1; |
960 | return 0; |
961 | bail: |
962 | if (yyss) |
| 41 | | Assuming 'yyss' is non-null | |
|
| |
963 | free(yyss); |
| 43 | | Attempt to free released memory |
|
964 | if (yyvs) |
965 | free(yyvs); |
966 | yyss = yyssp = NULL; |
967 | yyvs = yyvsp = NULL; |
968 | yystacksize = 0; |
969 | return -1; |
970 | } |
971 | |
972 | #define YYABORT goto yyabort |
973 | #define YYREJECT goto yyabort |
974 | #define YYACCEPT goto yyaccept |
975 | #define YYERROR goto yyerrlab |
976 | int |
977 | yyparse(void) |
978 | { |
979 | int yym, yyn, yystate; |
980 | #if YYDEBUG |
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 && yygrowstack()) goto yyoverflow; |
| 1 | Assuming 'yyss' is not equal to NULL | |
|
996 | yyssp = yyss; |
997 | yyvsp = yyvs; |
998 | *yyssp = yystate = 0; |
999 | |
1000 | yyloop: |
1001 | if ((yyn = yydefred[yystate]) != 0) goto yyreduce; |
| |
| 3 | | Control jumps to line 1108 | |
|
| |
1002 | if (yychar < 0) |
| |
1003 | { |
1004 | if ((yychar = yylex()) < 0) yychar = 0; |
1005 | #if YYDEBUG |
1006 | if (yydebug) |
1007 | { |
1008 | yys = 0; |
1009 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
1010 | if (!yys) yys = "illegal-symbol"; |
1011 | printf("%sdebug: state %d, reading %d (%s)\n", |
1012 | YYPREFIX, 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 <= YYTABLESIZE && yycheck[yyn] == yychar) |
1018 | { |
1019 | #if YYDEBUG |
1020 | if (yydebug) |
1021 | printf("%sdebug: state %d, shifting to state %d\n", |
1022 | YYPREFIX, 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 && |
| |
1035 | yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
1036 | { |
1037 | yyn = yytable[yyn]; |
1038 | goto yyreduce; |
1039 | } |
1040 | if (yyerrflag) goto yyinrecovery; |
| |
1041 | #if defined(__GNUC__) |
1042 | goto yynewerror; |
| 18 | | Control jumps to line 1045 | |
|
1043 | #endif |
1044 | yynewerror: |
1045 | yyerror("syntax error"); |
1046 | #if defined(__GNUC__) |
1047 | goto yyerrlab; |
| 19 | | Control jumps to line 1050 | |
|
1048 | #endif |
1049 | yyerrlab: |
1050 | ++yynerrs; |
1051 | yyinrecovery: |
1052 | if (yyerrflag < 3) |
| 20 | | Assuming 'yyerrflag' is < 3 | |
|
| |
1053 | { |
1054 | yyerrflag = 3; |
1055 | for (;;) |
| 22 | | Loop condition is true. Entering loop body | |
|
1056 | { |
1057 | if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && |
| 23 | | Assuming 'yyn' is not equal to 0 | |
|
| 24 | | Assuming the condition is true | |
|
| |
1058 | yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) |
| 25 | | Assuming 'yyn' is <= YYTABLESIZE | |
|
| 26 | | Assuming the condition is true | |
|
1059 | { |
1060 | #if YYDEBUG |
1061 | if (yydebug) |
1062 | printf("%sdebug: state %d, error recovery shifting\ |
1063 | to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); |
1064 | #endif |
1065 | if (yyssp >= yysslim && yygrowstack()) |
| 28 | | Assuming 'yyssp' is >= 'yysslim' | |
|
| |
1066 | { |
1067 | goto yyoverflow; |
1068 | } |
1069 | *++yyssp = yystate = yytable[yyn]; |
1070 | *++yyvsp = yylval; |
1071 | goto yyloop; |
1072 | } |
1073 | else |
1074 | { |
1075 | #if YYDEBUG |
1076 | if (yydebug) |
1077 | printf("%sdebug: error recovery discarding state %d\n", |
1078 | YYPREFIX, *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 YYDEBUG |
1090 | if (yydebug) |
1091 | { |
1092 | yys = 0; |
1093 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
1094 | if (!yys) yys = "illegal-symbol"; |
1095 | printf("%sdebug: state %d, error recovery discards token %d (%s)\n", |
1096 | YYPREFIX, yystate, yychar, yys); |
1097 | } |
1098 | #endif |
1099 | yychar = (-1); |
1100 | goto yyloop; |
1101 | } |
1102 | yyreduce: |
1103 | #if YYDEBUG |
1104 | if (yydebug) |
1105 | printf("%sdebug: state %d, reducing by rule %d (%s)\n", |
1106 | YYPREFIX, yystate, yyn, yyrule[yyn]); |
1107 | #endif |
1108 | yym = yylen[yyn]; |
1109 | if (yym) |
| |
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 | { |
1115 | case 3: |
1116 | #line 101 "/usr/src/usr.bin/rcs/date.y" |
1117 | { |
1118 | yyHaveTime++; |
1119 | } |
1120 | break; |
1121 | case 4: |
1122 | #line 104 "/usr/src/usr.bin/rcs/date.y" |
1123 | { |
1124 | yyHaveZone++; |
1125 | } |
1126 | break; |
1127 | case 5: |
1128 | #line 107 "/usr/src/usr.bin/rcs/date.y" |
1129 | { |
1130 | yyHaveDate++; |
1131 | } |
1132 | break; |
1133 | case 6: |
1134 | #line 110 "/usr/src/usr.bin/rcs/date.y" |
1135 | { |
1136 | yyHaveDay++; |
1137 | } |
1138 | break; |
1139 | case 7: |
1140 | #line 113 "/usr/src/usr.bin/rcs/date.y" |
1141 | { |
1142 | yyHaveRel++; |
1143 | } |
1144 | break; |
1145 | case 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 | } |
1153 | break; |
1154 | case 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 | } |
1162 | break; |
1163 | case 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 | } |
1172 | break; |
1173 | case 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 | } |
1181 | break; |
1182 | case 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 | } |
1192 | break; |
1193 | case 14: |
1194 | #line 154 "/usr/src/usr.bin/rcs/date.y" |
1195 | { |
1196 | yyTimezone = yyvsp[0].Number; |
1197 | yyDSTmode = DSToff; |
1198 | } |
1199 | break; |
1200 | case 15: |
1201 | #line 158 "/usr/src/usr.bin/rcs/date.y" |
1202 | { |
1203 | yyTimezone = yyvsp[0].Number; |
1204 | yyDSTmode = DSTon; |
1205 | } |
1206 | break; |
1207 | case 16: |
1208 | #line 162 "/usr/src/usr.bin/rcs/date.y" |
1209 | { |
1210 | yyTimezone = yyvsp[-1].Number; |
1211 | yyDSTmode = DSTon; |
1212 | } |
1213 | break; |
1214 | case 17: |
1215 | #line 168 "/usr/src/usr.bin/rcs/date.y" |
1216 | { |
1217 | yyDayOrdinal = 1; |
1218 | yyDayNumber = yyvsp[0].Number; |
1219 | } |
1220 | break; |
1221 | case 18: |
1222 | #line 172 "/usr/src/usr.bin/rcs/date.y" |
1223 | { |
1224 | yyDayOrdinal = 1; |
1225 | yyDayNumber = yyvsp[-1].Number; |
1226 | } |
1227 | break; |
1228 | case 19: |
1229 | #line 176 "/usr/src/usr.bin/rcs/date.y" |
1230 | { |
1231 | yyDayOrdinal = yyvsp[-1].Number; |
1232 | yyDayNumber = yyvsp[0].Number; |
1233 | } |
1234 | break; |
1235 | case 20: |
1236 | #line 182 "/usr/src/usr.bin/rcs/date.y" |
1237 | { |
1238 | yyMonth = yyvsp[-2].Number; |
1239 | yyDay = yyvsp[0].Number; |
1240 | } |
1241 | break; |
1242 | case 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 | } |
1255 | break; |
1256 | case 22: |
1257 | #line 197 "/usr/src/usr.bin/rcs/date.y" |
1258 | { |
1259 | |
1260 | yyYear = yyvsp[-2].Number; |
1261 | yyMonth = -yyvsp[-1].Number; |
1262 | yyDay = -yyvsp[0].Number; |
1263 | } |
1264 | break; |
1265 | case 23: |
1266 | #line 203 "/usr/src/usr.bin/rcs/date.y" |
1267 | { |
1268 | |
1269 | yyDay = yyvsp[-2].Number; |
1270 | yyMonth = yyvsp[-1].Number; |
1271 | yyYear = -yyvsp[0].Number; |
1272 | } |
1273 | break; |
1274 | case 24: |
1275 | #line 209 "/usr/src/usr.bin/rcs/date.y" |
1276 | { |
1277 | yyMonth = yyvsp[-1].Number; |
1278 | yyDay = yyvsp[0].Number; |
1279 | } |
1280 | break; |
1281 | case 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 | } |
1288 | break; |
1289 | case 26: |
1290 | #line 218 "/usr/src/usr.bin/rcs/date.y" |
1291 | { |
1292 | yyMonth = yyvsp[0].Number; |
1293 | yyDay = yyvsp[-1].Number; |
1294 | } |
1295 | break; |
1296 | case 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 | } |
1303 | break; |
1304 | case 28: |
1305 | #line 229 "/usr/src/usr.bin/rcs/date.y" |
1306 | { |
1307 | yyRelSeconds = -yyRelSeconds; |
1308 | yyRelMonth = -yyRelMonth; |
1309 | } |
1310 | break; |
1311 | case 30: |
1312 | #line 236 "/usr/src/usr.bin/rcs/date.y" |
1313 | { |
1314 | yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L; |
1315 | } |
1316 | break; |
1317 | case 31: |
1318 | #line 239 "/usr/src/usr.bin/rcs/date.y" |
1319 | { |
1320 | yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L; |
1321 | } |
1322 | break; |
1323 | case 32: |
1324 | #line 242 "/usr/src/usr.bin/rcs/date.y" |
1325 | { |
1326 | yyRelSeconds += yyvsp[0].Number * 60L; |
1327 | } |
1328 | break; |
1329 | case 33: |
1330 | #line 245 "/usr/src/usr.bin/rcs/date.y" |
1331 | { |
1332 | yyRelSeconds += yyvsp[-1].Number; |
1333 | } |
1334 | break; |
1335 | case 34: |
1336 | #line 248 "/usr/src/usr.bin/rcs/date.y" |
1337 | { |
1338 | yyRelSeconds += yyvsp[-1].Number; |
1339 | } |
1340 | break; |
1341 | case 35: |
1342 | #line 251 "/usr/src/usr.bin/rcs/date.y" |
1343 | { |
1344 | yyRelSeconds++; |
1345 | } |
1346 | break; |
1347 | case 36: |
1348 | #line 254 "/usr/src/usr.bin/rcs/date.y" |
1349 | { |
1350 | yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number; |
1351 | } |
1352 | break; |
1353 | case 37: |
1354 | #line 257 "/usr/src/usr.bin/rcs/date.y" |
1355 | { |
1356 | yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number; |
1357 | } |
1358 | break; |
1359 | case 38: |
1360 | #line 260 "/usr/src/usr.bin/rcs/date.y" |
1361 | { |
1362 | yyRelMonth += yyvsp[0].Number; |
1363 | } |
1364 | break; |
1365 | case 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 | } |
1390 | break; |
1391 | case 40: |
1392 | #line 290 "/usr/src/usr.bin/rcs/date.y" |
1393 | { |
1394 | yyval.Meridian = MER24; |
1395 | } |
1396 | break; |
1397 | case 41: |
1398 | #line 293 "/usr/src/usr.bin/rcs/date.y" |
1399 | { |
1400 | yyval.Meridian = yyvsp[0].Meridian; |
1401 | } |
1402 | break; |
1403 | #line 1396 "date.c" |
1404 | } |
1405 | yyssp -= yym; |
1406 | yystate = *yyssp; |
1407 | yyvsp -= yym; |
1408 | yym = yylhs[yyn]; |
1409 | if (yystate == 0 && yym == 0) |
| |
1410 | { |
1411 | #if YYDEBUG |
1412 | if (yydebug) |
1413 | printf("%sdebug: after reduction, shifting from state 0 to\ |
1414 | state %d\n", YYPREFIX, YYFINAL); |
1415 | #endif |
1416 | yystate = YYFINAL; |
1417 | *++yyssp = YYFINAL; |
1418 | *++yyvsp = yyval; |
1419 | if (yychar < 0) |
| |
1420 | { |
1421 | if ((yychar = yylex()) < 0) yychar = 0; |
| 8 | | Assuming the condition is false | |
|
| |
1422 | #if YYDEBUG |
1423 | if (yydebug) |
1424 | { |
1425 | yys = 0; |
1426 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
1427 | if (!yys) yys = "illegal-symbol"; |
1428 | printf("%sdebug: state %d, reading %d (%s)\n", |
1429 | YYPREFIX, YYFINAL, yychar, yys); |
1430 | } |
1431 | #endif |
1432 | } |
1433 | if (yychar == 0) goto yyaccept; |
| 10 | | Assuming 'yychar' is not equal to 0 | |
|
| |
1434 | goto yyloop; |
| 12 | | Control jumps to line 1001 | |
|
1435 | } |
1436 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && |
1437 | yyn <= YYTABLESIZE && yycheck[yyn] == yystate) |
1438 | yystate = yytable[yyn]; |
1439 | else |
1440 | yystate = yydgoto[yym]; |
1441 | #if YYDEBUG |
1442 | if (yydebug) |
1443 | printf("%sdebug: after reduction, shifting from state %d \ |
1444 | to state %d\n", YYPREFIX, *yyssp, yystate); |
1445 | #endif |
1446 | if (yyssp >= yysslim && yygrowstack()) |
1447 | { |
1448 | goto yyoverflow; |
1449 | } |
1450 | *++yyssp = yystate; |
1451 | *++yyvsp = yyval; |
1452 | goto yyloop; |
1453 | yyoverflow: |
1454 | yyerror("yacc stack overflow"); |
1455 | yyabort: |
1456 | if (yyss) |
1457 | free(yyss); |
1458 | if (yyvs) |
1459 | free(yyvs); |
1460 | yyss = yyssp = NULL; |
1461 | yyvs = yyvsp = NULL; |
1462 | yystacksize = 0; |
1463 | return (1); |
1464 | yyaccept: |
1465 | if (yyss) |
1466 | free(yyss); |
1467 | if (yyvs) |
1468 | free(yyvs); |
1469 | yyss = yyssp = NULL; |
1470 | yyvs = yyvsp = NULL; |
1471 | yystacksize = 0; |
1472 | return (0); |
1473 | } |