xref: /PHP-7.1/ext/date/lib/parse_iso_intervals.c (revision 7121b8d0)
1 /* Generated by re2c 0.15.3 on Wed Aug 16 15:55:55 2017 */
2 #line 1 "ext/date/lib/parse_iso_intervals.re"
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2015 Derick Rethans
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 /* $Id$ */
28 
29 #include "timelib.h"
30 
31 #include <stdio.h>
32 #include <ctype.h>
33 
34 #ifdef HAVE_STDLIB_H
35 #include <stdlib.h>
36 #endif
37 #ifdef HAVE_STRING_H
38 #include <string.h>
39 #else
40 #include <strings.h>
41 #endif
42 
43 #if defined(_MSC_VER)
44 # define strtoll(s, f, b) _atoi64(s)
45 #elif !defined(HAVE_STRTOLL)
46 # if defined(HAVE_ATOLL)
47 #  define strtoll(s, f, b) atoll(s)
48 # else
49 #  define strtoll(s, f, b) strtol(s, f, b)
50 # endif
51 #endif
52 
53 #define TIMELIB_UNSET   -99999
54 
55 #define TIMELIB_SECOND  1
56 #define TIMELIB_MINUTE  2
57 #define TIMELIB_HOUR    3
58 #define TIMELIB_DAY     4
59 #define TIMELIB_MONTH   5
60 #define TIMELIB_YEAR    6
61 
62 #define EOI      257
63 
64 #define TIMELIB_PERIOD  260
65 #define TIMELIB_ISO_DATE 261
66 #define TIMELIB_ERROR   999
67 
68 typedef unsigned char uchar;
69 
70 #define   BSIZE	   8192
71 
72 #define   YYCTYPE      uchar
73 #define   YYCURSOR     cursor
74 #define   YYLIMIT      s->lim
75 #define   YYMARKER     s->ptr
76 #define   YYFILL(n)    return EOI;
77 
78 #define   RET(i)       {s->cur = cursor; return i;}
79 
80 #define timelib_string_free timelib_free
81 
82 #define TIMELIB_INIT  s->cur = cursor; str = timelib_string(s); ptr = str
83 #define TIMELIB_DEINIT timelib_string_free(str)
84 
85 #ifdef DEBUG_PARSER
86 #define DEBUG_OUTPUT(s) printf("%s\n", s);
87 #define YYDEBUG(s,c) { if (s != -1) { printf("state: %d ", s); printf("[%c]\n", c); } }
88 #else
89 #define DEBUG_OUTPUT(s)
90 #define YYDEBUG(s,c)
91 #endif
92 
93 #include "timelib_structs.h"
94 
95 typedef struct Scanner {
96 	int           fd;
97 	uchar        *lim, *str, *ptr, *cur, *tok, *pos;
98 	unsigned int  line, len;
99 	struct timelib_error_container *errors;
100 
101 	struct timelib_time     *begin;
102 	struct timelib_time     *end;
103 	struct timelib_rel_time *period;
104 	int                      recurrences;
105 
106 	int have_period;
107 	int have_recurrences;
108 	int have_date;
109 	int have_begin_date;
110 	int have_end_date;
111 } Scanner;
112 
add_warning(Scanner * s,char * error)113 static void add_warning(Scanner *s, char *error)
114 {
115 	s->errors->warning_count++;
116 	s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
117 	s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0;
118 	s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0;
119 	s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
120 }
121 
add_error(Scanner * s,char * error)122 static void add_error(Scanner *s, char *error)
123 {
124 	s->errors->error_count++;
125 	s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
126 	s->errors->error_messages[s->errors->error_count - 1].position = s->tok ? s->tok - s->str : 0;
127 	s->errors->error_messages[s->errors->error_count - 1].character = s->tok ? *s->tok : 0;
128 	s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error);
129 }
130 
timelib_string(Scanner * s)131 static char *timelib_string(Scanner *s)
132 {
133 	char *tmp = timelib_calloc(1, s->cur - s->tok + 1);
134 	memcpy(tmp, s->tok, s->cur - s->tok);
135 
136 	return tmp;
137 }
138 
timelib_get_nr(char ** ptr,int max_length)139 static timelib_sll timelib_get_nr(char **ptr, int max_length)
140 {
141 	char *begin, *end, *str;
142 	timelib_sll tmp_nr = TIMELIB_UNSET;
143 	int len = 0;
144 
145 	while ((**ptr < '0') || (**ptr > '9')) {
146 		if (**ptr == '\0') {
147 			return TIMELIB_UNSET;
148 		}
149 		++*ptr;
150 	}
151 	begin = *ptr;
152 	while ((**ptr >= '0') && (**ptr <= '9') && len < max_length) {
153 		++*ptr;
154 		++len;
155 	}
156 	end = *ptr;
157 	str = timelib_calloc(1, end - begin + 1);
158 	memcpy(str, begin, end - begin);
159 	tmp_nr = strtoll(str, NULL, 10);
160 	timelib_free(str);
161 	return tmp_nr;
162 }
163 
timelib_get_unsigned_nr(char ** ptr,int max_length)164 static timelib_ull timelib_get_unsigned_nr(char **ptr, int max_length)
165 {
166 	timelib_ull dir = 1;
167 
168 	while (((**ptr < '0') || (**ptr > '9')) && (**ptr != '+') && (**ptr != '-')) {
169 		if (**ptr == '\0') {
170 			return TIMELIB_UNSET;
171 		}
172 		++*ptr;
173 	}
174 
175 	while (**ptr == '+' || **ptr == '-')
176 	{
177 		if (**ptr == '-') {
178 			dir *= -1;
179 		}
180 		++*ptr;
181 	}
182 	return dir * timelib_get_nr(ptr, max_length);
183 }
184 
timelib_eat_spaces(char ** ptr)185 static void timelib_eat_spaces(char **ptr)
186 {
187 	while (**ptr == ' ' || **ptr == '\t') {
188 		++*ptr;
189 	}
190 }
191 
timelib_eat_until_separator(char ** ptr)192 static void timelib_eat_until_separator(char **ptr)
193 {
194 	while (strchr(" \t.,:;/-0123456789", **ptr) == NULL) {
195 		++*ptr;
196 	}
197 }
198 
timelib_get_zone(char ** ptr,int * dst,timelib_time * t,int * tz_not_found,const timelib_tzdb * tzdb)199 static timelib_long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb)
200 {
201 	timelib_long retval = 0;
202 
203 	*tz_not_found = 0;
204 
205 	while (**ptr == ' ' || **ptr == '\t' || **ptr == '(') {
206 		++*ptr;
207 	}
208 	if ((*ptr)[0] == 'G' && (*ptr)[1] == 'M' && (*ptr)[2] == 'T' && ((*ptr)[3] == '+' || (*ptr)[3] == '-')) {
209 		*ptr += 3;
210 	}
211 	if (**ptr == '+') {
212 		++*ptr;
213 		t->is_localtime = 1;
214 		t->zone_type = TIMELIB_ZONETYPE_OFFSET;
215 		*tz_not_found = 0;
216 		t->dst = 0;
217 
218 		retval = -1 * timelib_parse_tz_cor(ptr);
219 	} else if (**ptr == '-') {
220 		++*ptr;
221 		t->is_localtime = 1;
222 		t->zone_type = TIMELIB_ZONETYPE_OFFSET;
223 		*tz_not_found = 0;
224 		t->dst = 0;
225 
226 		retval = timelib_parse_tz_cor(ptr);
227 	}
228 	while (**ptr == ')') {
229 		++*ptr;
230 	}
231 	return retval;
232 }
233 
234 #define timelib_split_free(arg) {       \
235 	int i;                         \
236 	for (i = 0; i < arg.c; i++) {  \
237 		timelib_free(arg.v[i]);    \
238 	}                              \
239 	if (arg.v) {                   \
240 		timelib_free(arg.v);       \
241 	}                              \
242 }
243 
244 /* date parser's scan function too large for VC6 - VC7.x
245    drop the optimization solves the problem */
246 #ifdef PHP_WIN32
247 #pragma optimize( "", off )
248 #endif
scan(Scanner * s)249 static int scan(Scanner *s)
250 {
251 	uchar *cursor = s->cur;
252 	char *str, *ptr = NULL;
253 
254 std:
255 	s->tok = cursor;
256 	s->len = 0;
257 #line 282 "ext/date/lib/parse_iso_intervals.re"
258 
259 
260 
261 #line 262 "<stdout>"
262 {
263 	YYCTYPE yych;
264 	unsigned int yyaccept = 0;
265 	static const unsigned char yybm[] = {
266 		  0,   0,   0,   0,   0,   0,   0,   0,
267 		  0,   0,   0,   0,   0,   0,   0,   0,
268 		  0,   0,   0,   0,   0,   0,   0,   0,
269 		  0,   0,   0,   0,   0,   0,   0,   0,
270 		  0,   0,   0,   0,   0,   0,   0,   0,
271 		  0,   0,   0,   0,   0,   0,   0,   0,
272 		128, 128, 128, 128, 128, 128, 128, 128,
273 		128, 128,   0,   0,   0,   0,   0,   0,
274 		  0,   0,   0,   0,   0,   0,   0,   0,
275 		  0,   0,   0,   0,   0,   0,   0,   0,
276 		  0,   0,   0,   0,   0,   0,   0,   0,
277 		  0,   0,   0,   0,   0,   0,   0,   0,
278 		  0,   0,   0,   0,   0,   0,   0,   0,
279 		  0,   0,   0,   0,   0,   0,   0,   0,
280 		  0,   0,   0,   0,   0,   0,   0,   0,
281 		  0,   0,   0,   0,   0,   0,   0,   0,
282 		  0,   0,   0,   0,   0,   0,   0,   0,
283 		  0,   0,   0,   0,   0,   0,   0,   0,
284 		  0,   0,   0,   0,   0,   0,   0,   0,
285 		  0,   0,   0,   0,   0,   0,   0,   0,
286 		  0,   0,   0,   0,   0,   0,   0,   0,
287 		  0,   0,   0,   0,   0,   0,   0,   0,
288 		  0,   0,   0,   0,   0,   0,   0,   0,
289 		  0,   0,   0,   0,   0,   0,   0,   0,
290 		  0,   0,   0,   0,   0,   0,   0,   0,
291 		  0,   0,   0,   0,   0,   0,   0,   0,
292 		  0,   0,   0,   0,   0,   0,   0,   0,
293 		  0,   0,   0,   0,   0,   0,   0,   0,
294 		  0,   0,   0,   0,   0,   0,   0,   0,
295 		  0,   0,   0,   0,   0,   0,   0,   0,
296 		  0,   0,   0,   0,   0,   0,   0,   0,
297 		  0,   0,   0,   0,   0,   0,   0,   0,
298 	};
299 	YYDEBUG(0, *YYCURSOR);
300 	if ((YYLIMIT - YYCURSOR) < 20) YYFILL(20);
301 	yych = *YYCURSOR;
302 	if (yych <= ',') {
303 		if (yych <= '\n') {
304 			if (yych <= 0x00) goto yy9;
305 			if (yych <= 0x08) goto yy11;
306 			if (yych <= '\t') goto yy7;
307 			goto yy9;
308 		} else {
309 			if (yych == ' ') goto yy7;
310 			if (yych <= '+') goto yy11;
311 			goto yy7;
312 		}
313 	} else {
314 		if (yych <= 'O') {
315 			if (yych <= '-') goto yy11;
316 			if (yych <= '/') goto yy7;
317 			if (yych <= '9') goto yy4;
318 			goto yy11;
319 		} else {
320 			if (yych <= 'P') goto yy5;
321 			if (yych != 'R') goto yy11;
322 		}
323 	}
324 	YYDEBUG(2, *YYCURSOR);
325 	++YYCURSOR;
326 	if ((yych = *YYCURSOR) <= '/') goto yy3;
327 	if (yych <= '9') goto yy98;
328 yy3:
329 	YYDEBUG(3, *YYCURSOR);
330 #line 395 "ext/date/lib/parse_iso_intervals.re"
331 	{
332 		add_error(s, "Unexpected character");
333 		goto std;
334 	}
335 #line 336 "<stdout>"
336 yy4:
337 	YYDEBUG(4, *YYCURSOR);
338 	yyaccept = 0;
339 	yych = *(YYMARKER = ++YYCURSOR);
340 	if (yych <= '/') goto yy3;
341 	if (yych <= '9') goto yy59;
342 	goto yy3;
343 yy5:
344 	YYDEBUG(5, *YYCURSOR);
345 	yyaccept = 1;
346 	yych = *(YYMARKER = ++YYCURSOR);
347 	if (yych <= '/') goto yy6;
348 	if (yych <= '9') goto yy12;
349 	if (yych == 'T') goto yy14;
350 yy6:
351 	YYDEBUG(6, *YYCURSOR);
352 #line 322 "ext/date/lib/parse_iso_intervals.re"
353 	{
354 		timelib_sll nr;
355 		int         in_time = 0;
356 		DEBUG_OUTPUT("period");
357 		TIMELIB_INIT;
358 		ptr++;
359 		do {
360 			if ( *ptr == 'T' ) {
361 				in_time = 1;
362 				ptr++;
363 			}
364 			if ( *ptr == '\0' ) {
365 				add_error(s, "Missing expected time part");
366 				break;
367 			}
368 
369 			nr = timelib_get_unsigned_nr((char **) &ptr, 12);
370 			switch (*ptr) {
371 				case 'Y': s->period->y = nr; break;
372 				case 'W': s->period->d = nr * 7; break;
373 				case 'D': s->period->d = nr; break;
374 				case 'H': s->period->h = nr; break;
375 				case 'S': s->period->s = nr; break;
376 				case 'M':
377 					if (in_time) {
378 						s->period->i = nr;
379 					} else {
380 						s->period->m = nr;
381 					}
382 					break;
383 				default:
384 					add_error(s, "Undefined period specifier");
385 					break;
386 			}
387 			ptr++;
388 		} while (!s->errors->error_count && *ptr);
389 		s->have_period = 1;
390 		TIMELIB_DEINIT;
391 		return TIMELIB_PERIOD;
392 	}
393 #line 394 "<stdout>"
394 yy7:
395 	YYDEBUG(7, *YYCURSOR);
396 	++YYCURSOR;
397 	YYDEBUG(8, *YYCURSOR);
398 #line 384 "ext/date/lib/parse_iso_intervals.re"
399 	{
400 		goto std;
401 	}
402 #line 403 "<stdout>"
403 yy9:
404 	YYDEBUG(9, *YYCURSOR);
405 	++YYCURSOR;
406 	YYDEBUG(10, *YYCURSOR);
407 #line 389 "ext/date/lib/parse_iso_intervals.re"
408 	{
409 		s->pos = cursor; s->line++;
410 		goto std;
411 	}
412 #line 413 "<stdout>"
413 yy11:
414 	YYDEBUG(11, *YYCURSOR);
415 	yych = *++YYCURSOR;
416 	goto yy3;
417 yy12:
418 	YYDEBUG(12, *YYCURSOR);
419 	yych = *++YYCURSOR;
420 	if (yych <= 'L') {
421 		if (yych <= '9') {
422 			if (yych >= '0') goto yy25;
423 		} else {
424 			if (yych == 'D') goto yy24;
425 		}
426 	} else {
427 		if (yych <= 'W') {
428 			if (yych <= 'M') goto yy27;
429 			if (yych >= 'W') goto yy26;
430 		} else {
431 			if (yych == 'Y') goto yy28;
432 		}
433 	}
434 yy13:
435 	YYDEBUG(13, *YYCURSOR);
436 	YYCURSOR = YYMARKER;
437 	if (yyaccept == 0) {
438 		goto yy3;
439 	} else {
440 		goto yy6;
441 	}
442 yy14:
443 	YYDEBUG(14, *YYCURSOR);
444 	yyaccept = 1;
445 	yych = *(YYMARKER = ++YYCURSOR);
446 	if (yybm[0+yych] & 128) {
447 		goto yy15;
448 	}
449 	goto yy6;
450 yy15:
451 	YYDEBUG(15, *YYCURSOR);
452 	++YYCURSOR;
453 	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
454 	yych = *YYCURSOR;
455 	YYDEBUG(16, *YYCURSOR);
456 	if (yybm[0+yych] & 128) {
457 		goto yy15;
458 	}
459 	if (yych <= 'L') {
460 		if (yych == 'H') goto yy19;
461 		goto yy13;
462 	} else {
463 		if (yych <= 'M') goto yy18;
464 		if (yych != 'S') goto yy13;
465 	}
466 yy17:
467 	YYDEBUG(17, *YYCURSOR);
468 	yych = *++YYCURSOR;
469 	goto yy6;
470 yy18:
471 	YYDEBUG(18, *YYCURSOR);
472 	yyaccept = 1;
473 	yych = *(YYMARKER = ++YYCURSOR);
474 	if (yych <= '/') goto yy6;
475 	if (yych <= '9') goto yy22;
476 	goto yy6;
477 yy19:
478 	YYDEBUG(19, *YYCURSOR);
479 	yyaccept = 1;
480 	yych = *(YYMARKER = ++YYCURSOR);
481 	if (yych <= '/') goto yy6;
482 	if (yych >= ':') goto yy6;
483 yy20:
484 	YYDEBUG(20, *YYCURSOR);
485 	++YYCURSOR;
486 	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
487 	yych = *YYCURSOR;
488 	YYDEBUG(21, *YYCURSOR);
489 	if (yych <= 'L') {
490 		if (yych <= '/') goto yy13;
491 		if (yych <= '9') goto yy20;
492 		goto yy13;
493 	} else {
494 		if (yych <= 'M') goto yy18;
495 		if (yych == 'S') goto yy17;
496 		goto yy13;
497 	}
498 yy22:
499 	YYDEBUG(22, *YYCURSOR);
500 	++YYCURSOR;
501 	if (YYLIMIT <= YYCURSOR) YYFILL(1);
502 	yych = *YYCURSOR;
503 	YYDEBUG(23, *YYCURSOR);
504 	if (yych <= '/') goto yy13;
505 	if (yych <= '9') goto yy22;
506 	if (yych == 'S') goto yy17;
507 	goto yy13;
508 yy24:
509 	YYDEBUG(24, *YYCURSOR);
510 	yych = *++YYCURSOR;
511 	if (yych == 'T') goto yy14;
512 	goto yy6;
513 yy25:
514 	YYDEBUG(25, *YYCURSOR);
515 	yych = *++YYCURSOR;
516 	if (yych <= 'L') {
517 		if (yych <= '9') {
518 			if (yych <= '/') goto yy13;
519 			goto yy35;
520 		} else {
521 			if (yych == 'D') goto yy24;
522 			goto yy13;
523 		}
524 	} else {
525 		if (yych <= 'W') {
526 			if (yych <= 'M') goto yy27;
527 			if (yych <= 'V') goto yy13;
528 		} else {
529 			if (yych == 'Y') goto yy28;
530 			goto yy13;
531 		}
532 	}
533 yy26:
534 	YYDEBUG(26, *YYCURSOR);
535 	yyaccept = 1;
536 	yych = *(YYMARKER = ++YYCURSOR);
537 	if (yych <= '/') goto yy6;
538 	if (yych <= '9') goto yy33;
539 	if (yych == 'T') goto yy14;
540 	goto yy6;
541 yy27:
542 	YYDEBUG(27, *YYCURSOR);
543 	yyaccept = 1;
544 	yych = *(YYMARKER = ++YYCURSOR);
545 	if (yych <= '/') goto yy6;
546 	if (yych <= '9') goto yy31;
547 	if (yych == 'T') goto yy14;
548 	goto yy6;
549 yy28:
550 	YYDEBUG(28, *YYCURSOR);
551 	yyaccept = 1;
552 	yych = *(YYMARKER = ++YYCURSOR);
553 	if (yych <= '/') goto yy6;
554 	if (yych <= '9') goto yy29;
555 	if (yych == 'T') goto yy14;
556 	goto yy6;
557 yy29:
558 	YYDEBUG(29, *YYCURSOR);
559 	++YYCURSOR;
560 	if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
561 	yych = *YYCURSOR;
562 	YYDEBUG(30, *YYCURSOR);
563 	if (yych <= 'D') {
564 		if (yych <= '/') goto yy13;
565 		if (yych <= '9') goto yy29;
566 		if (yych <= 'C') goto yy13;
567 		goto yy24;
568 	} else {
569 		if (yych <= 'M') {
570 			if (yych <= 'L') goto yy13;
571 			goto yy27;
572 		} else {
573 			if (yych == 'W') goto yy26;
574 			goto yy13;
575 		}
576 	}
577 yy31:
578 	YYDEBUG(31, *YYCURSOR);
579 	++YYCURSOR;
580 	if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
581 	yych = *YYCURSOR;
582 	YYDEBUG(32, *YYCURSOR);
583 	if (yych <= 'C') {
584 		if (yych <= '/') goto yy13;
585 		if (yych <= '9') goto yy31;
586 		goto yy13;
587 	} else {
588 		if (yych <= 'D') goto yy24;
589 		if (yych == 'W') goto yy26;
590 		goto yy13;
591 	}
592 yy33:
593 	YYDEBUG(33, *YYCURSOR);
594 	++YYCURSOR;
595 	if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
596 	yych = *YYCURSOR;
597 	YYDEBUG(34, *YYCURSOR);
598 	if (yych <= '/') goto yy13;
599 	if (yych <= '9') goto yy33;
600 	if (yych == 'D') goto yy24;
601 	goto yy13;
602 yy35:
603 	YYDEBUG(35, *YYCURSOR);
604 	yych = *++YYCURSOR;
605 	if (yych <= 'L') {
606 		if (yych <= '9') {
607 			if (yych <= '/') goto yy13;
608 		} else {
609 			if (yych == 'D') goto yy24;
610 			goto yy13;
611 		}
612 	} else {
613 		if (yych <= 'W') {
614 			if (yych <= 'M') goto yy27;
615 			if (yych <= 'V') goto yy13;
616 			goto yy26;
617 		} else {
618 			if (yych == 'Y') goto yy28;
619 			goto yy13;
620 		}
621 	}
622 	YYDEBUG(36, *YYCURSOR);
623 	yych = *++YYCURSOR;
624 	if (yych != '-') goto yy39;
625 	YYDEBUG(37, *YYCURSOR);
626 	yych = *++YYCURSOR;
627 	if (yych <= '/') goto yy13;
628 	if (yych <= '0') goto yy40;
629 	if (yych <= '1') goto yy41;
630 	goto yy13;
631 yy38:
632 	YYDEBUG(38, *YYCURSOR);
633 	++YYCURSOR;
634 	if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
635 	yych = *YYCURSOR;
636 yy39:
637 	YYDEBUG(39, *YYCURSOR);
638 	if (yych <= 'L') {
639 		if (yych <= '9') {
640 			if (yych <= '/') goto yy13;
641 			goto yy38;
642 		} else {
643 			if (yych == 'D') goto yy24;
644 			goto yy13;
645 		}
646 	} else {
647 		if (yych <= 'W') {
648 			if (yych <= 'M') goto yy27;
649 			if (yych <= 'V') goto yy13;
650 			goto yy26;
651 		} else {
652 			if (yych == 'Y') goto yy28;
653 			goto yy13;
654 		}
655 	}
656 yy40:
657 	YYDEBUG(40, *YYCURSOR);
658 	yych = *++YYCURSOR;
659 	if (yych <= '/') goto yy13;
660 	if (yych <= '9') goto yy42;
661 	goto yy13;
662 yy41:
663 	YYDEBUG(41, *YYCURSOR);
664 	yych = *++YYCURSOR;
665 	if (yych <= '/') goto yy13;
666 	if (yych >= '3') goto yy13;
667 yy42:
668 	YYDEBUG(42, *YYCURSOR);
669 	yych = *++YYCURSOR;
670 	if (yych != '-') goto yy13;
671 	YYDEBUG(43, *YYCURSOR);
672 	yych = *++YYCURSOR;
673 	if (yych <= '/') goto yy13;
674 	if (yych <= '0') goto yy44;
675 	if (yych <= '2') goto yy45;
676 	if (yych <= '3') goto yy46;
677 	goto yy13;
678 yy44:
679 	YYDEBUG(44, *YYCURSOR);
680 	yych = *++YYCURSOR;
681 	if (yych <= '/') goto yy13;
682 	if (yych <= '9') goto yy47;
683 	goto yy13;
684 yy45:
685 	YYDEBUG(45, *YYCURSOR);
686 	yych = *++YYCURSOR;
687 	if (yych <= '/') goto yy13;
688 	if (yych <= '9') goto yy47;
689 	goto yy13;
690 yy46:
691 	YYDEBUG(46, *YYCURSOR);
692 	yych = *++YYCURSOR;
693 	if (yych <= '/') goto yy13;
694 	if (yych >= '2') goto yy13;
695 yy47:
696 	YYDEBUG(47, *YYCURSOR);
697 	yych = *++YYCURSOR;
698 	if (yych != 'T') goto yy13;
699 	YYDEBUG(48, *YYCURSOR);
700 	yych = *++YYCURSOR;
701 	if (yych <= '/') goto yy13;
702 	if (yych <= '1') goto yy49;
703 	if (yych <= '2') goto yy50;
704 	goto yy13;
705 yy49:
706 	YYDEBUG(49, *YYCURSOR);
707 	yych = *++YYCURSOR;
708 	if (yych <= '/') goto yy13;
709 	if (yych <= '9') goto yy51;
710 	goto yy13;
711 yy50:
712 	YYDEBUG(50, *YYCURSOR);
713 	yych = *++YYCURSOR;
714 	if (yych <= '/') goto yy13;
715 	if (yych >= '5') goto yy13;
716 yy51:
717 	YYDEBUG(51, *YYCURSOR);
718 	yych = *++YYCURSOR;
719 	if (yych != ':') goto yy13;
720 	YYDEBUG(52, *YYCURSOR);
721 	yych = *++YYCURSOR;
722 	if (yych <= '/') goto yy13;
723 	if (yych >= '6') goto yy13;
724 	YYDEBUG(53, *YYCURSOR);
725 	yych = *++YYCURSOR;
726 	if (yych <= '/') goto yy13;
727 	if (yych >= ':') goto yy13;
728 	YYDEBUG(54, *YYCURSOR);
729 	yych = *++YYCURSOR;
730 	if (yych != ':') goto yy13;
731 	YYDEBUG(55, *YYCURSOR);
732 	yych = *++YYCURSOR;
733 	if (yych <= '/') goto yy13;
734 	if (yych >= '6') goto yy13;
735 	YYDEBUG(56, *YYCURSOR);
736 	yych = *++YYCURSOR;
737 	if (yych <= '/') goto yy13;
738 	if (yych >= ':') goto yy13;
739 	YYDEBUG(57, *YYCURSOR);
740 	++YYCURSOR;
741 	YYDEBUG(58, *YYCURSOR);
742 #line 364 "ext/date/lib/parse_iso_intervals.re"
743 	{
744 		DEBUG_OUTPUT("combinedrep");
745 		TIMELIB_INIT;
746 		s->period->y = timelib_get_unsigned_nr((char **) &ptr, 4);
747 		ptr++;
748 		s->period->m = timelib_get_unsigned_nr((char **) &ptr, 2);
749 		ptr++;
750 		s->period->d = timelib_get_unsigned_nr((char **) &ptr, 2);
751 		ptr++;
752 		s->period->h = timelib_get_unsigned_nr((char **) &ptr, 2);
753 		ptr++;
754 		s->period->i = timelib_get_unsigned_nr((char **) &ptr, 2);
755 		ptr++;
756 		s->period->s = timelib_get_unsigned_nr((char **) &ptr, 2);
757 		s->have_period = 1;
758 		TIMELIB_DEINIT;
759 		return TIMELIB_PERIOD;
760 	}
761 #line 762 "<stdout>"
762 yy59:
763 	YYDEBUG(59, *YYCURSOR);
764 	yych = *++YYCURSOR;
765 	if (yych <= '/') goto yy13;
766 	if (yych >= ':') goto yy13;
767 	YYDEBUG(60, *YYCURSOR);
768 	yych = *++YYCURSOR;
769 	if (yych <= '/') goto yy13;
770 	if (yych >= ':') goto yy13;
771 	YYDEBUG(61, *YYCURSOR);
772 	yych = *++YYCURSOR;
773 	if (yych <= '/') {
774 		if (yych == '-') goto yy64;
775 		goto yy13;
776 	} else {
777 		if (yych <= '0') goto yy62;
778 		if (yych <= '1') goto yy63;
779 		goto yy13;
780 	}
781 yy62:
782 	YYDEBUG(62, *YYCURSOR);
783 	yych = *++YYCURSOR;
784 	if (yych <= '0') goto yy13;
785 	if (yych <= '9') goto yy85;
786 	goto yy13;
787 yy63:
788 	YYDEBUG(63, *YYCURSOR);
789 	yych = *++YYCURSOR;
790 	if (yych <= '/') goto yy13;
791 	if (yych <= '2') goto yy85;
792 	goto yy13;
793 yy64:
794 	YYDEBUG(64, *YYCURSOR);
795 	yych = *++YYCURSOR;
796 	if (yych <= '/') goto yy13;
797 	if (yych <= '0') goto yy65;
798 	if (yych <= '1') goto yy66;
799 	goto yy13;
800 yy65:
801 	YYDEBUG(65, *YYCURSOR);
802 	yych = *++YYCURSOR;
803 	if (yych <= '0') goto yy13;
804 	if (yych <= '9') goto yy67;
805 	goto yy13;
806 yy66:
807 	YYDEBUG(66, *YYCURSOR);
808 	yych = *++YYCURSOR;
809 	if (yych <= '/') goto yy13;
810 	if (yych >= '3') goto yy13;
811 yy67:
812 	YYDEBUG(67, *YYCURSOR);
813 	yych = *++YYCURSOR;
814 	if (yych != '-') goto yy13;
815 	YYDEBUG(68, *YYCURSOR);
816 	yych = *++YYCURSOR;
817 	if (yych <= '/') goto yy13;
818 	if (yych <= '0') goto yy69;
819 	if (yych <= '2') goto yy70;
820 	if (yych <= '3') goto yy71;
821 	goto yy13;
822 yy69:
823 	YYDEBUG(69, *YYCURSOR);
824 	yych = *++YYCURSOR;
825 	if (yych <= '0') goto yy13;
826 	if (yych <= '9') goto yy72;
827 	goto yy13;
828 yy70:
829 	YYDEBUG(70, *YYCURSOR);
830 	yych = *++YYCURSOR;
831 	if (yych <= '/') goto yy13;
832 	if (yych <= '9') goto yy72;
833 	goto yy13;
834 yy71:
835 	YYDEBUG(71, *YYCURSOR);
836 	yych = *++YYCURSOR;
837 	if (yych <= '/') goto yy13;
838 	if (yych >= '2') goto yy13;
839 yy72:
840 	YYDEBUG(72, *YYCURSOR);
841 	yych = *++YYCURSOR;
842 	if (yych != 'T') goto yy13;
843 	YYDEBUG(73, *YYCURSOR);
844 	yych = *++YYCURSOR;
845 	if (yych <= '/') goto yy13;
846 	if (yych <= '1') goto yy74;
847 	if (yych <= '2') goto yy75;
848 	goto yy13;
849 yy74:
850 	YYDEBUG(74, *YYCURSOR);
851 	yych = *++YYCURSOR;
852 	if (yych <= '/') goto yy13;
853 	if (yych <= '9') goto yy76;
854 	goto yy13;
855 yy75:
856 	YYDEBUG(75, *YYCURSOR);
857 	yych = *++YYCURSOR;
858 	if (yych <= '/') goto yy13;
859 	if (yych >= '5') goto yy13;
860 yy76:
861 	YYDEBUG(76, *YYCURSOR);
862 	yych = *++YYCURSOR;
863 	if (yych != ':') goto yy13;
864 	YYDEBUG(77, *YYCURSOR);
865 	yych = *++YYCURSOR;
866 	if (yych <= '/') goto yy13;
867 	if (yych >= '6') goto yy13;
868 	YYDEBUG(78, *YYCURSOR);
869 	yych = *++YYCURSOR;
870 	if (yych <= '/') goto yy13;
871 	if (yych >= ':') goto yy13;
872 	YYDEBUG(79, *YYCURSOR);
873 	yych = *++YYCURSOR;
874 	if (yych != ':') goto yy13;
875 	YYDEBUG(80, *YYCURSOR);
876 	yych = *++YYCURSOR;
877 	if (yych <= '/') goto yy13;
878 	if (yych >= '6') goto yy13;
879 	YYDEBUG(81, *YYCURSOR);
880 	yych = *++YYCURSOR;
881 	if (yych <= '/') goto yy13;
882 	if (yych >= ':') goto yy13;
883 	YYDEBUG(82, *YYCURSOR);
884 	yych = *++YYCURSOR;
885 	if (yych != 'Z') goto yy13;
886 yy83:
887 	YYDEBUG(83, *YYCURSOR);
888 	++YYCURSOR;
889 	YYDEBUG(84, *YYCURSOR);
890 #line 298 "ext/date/lib/parse_iso_intervals.re"
891 	{
892 		timelib_time *current;
893 
894 		if (s->have_date || s->have_period) {
895 			current = s->end;
896 			s->have_end_date = 1;
897 		} else {
898 			current = s->begin;
899 			s->have_begin_date = 1;
900 		}
901 		DEBUG_OUTPUT("datetimebasic | datetimeextended");
902 		TIMELIB_INIT;
903 		current->y = timelib_get_nr((char **) &ptr, 4);
904 		current->m = timelib_get_nr((char **) &ptr, 2);
905 		current->d = timelib_get_nr((char **) &ptr, 2);
906 		current->h = timelib_get_nr((char **) &ptr, 2);
907 		current->i = timelib_get_nr((char **) &ptr, 2);
908 		current->s = timelib_get_nr((char **) &ptr, 2);
909 		s->have_date = 1;
910 		TIMELIB_DEINIT;
911 		return TIMELIB_ISO_DATE;
912 	}
913 #line 914 "<stdout>"
914 yy85:
915 	YYDEBUG(85, *YYCURSOR);
916 	yych = *++YYCURSOR;
917 	if (yych <= '/') goto yy13;
918 	if (yych <= '0') goto yy86;
919 	if (yych <= '2') goto yy87;
920 	if (yych <= '3') goto yy88;
921 	goto yy13;
922 yy86:
923 	YYDEBUG(86, *YYCURSOR);
924 	yych = *++YYCURSOR;
925 	if (yych <= '0') goto yy13;
926 	if (yych <= '9') goto yy89;
927 	goto yy13;
928 yy87:
929 	YYDEBUG(87, *YYCURSOR);
930 	yych = *++YYCURSOR;
931 	if (yych <= '/') goto yy13;
932 	if (yych <= '9') goto yy89;
933 	goto yy13;
934 yy88:
935 	YYDEBUG(88, *YYCURSOR);
936 	yych = *++YYCURSOR;
937 	if (yych <= '/') goto yy13;
938 	if (yych >= '2') goto yy13;
939 yy89:
940 	YYDEBUG(89, *YYCURSOR);
941 	yych = *++YYCURSOR;
942 	if (yych != 'T') goto yy13;
943 	YYDEBUG(90, *YYCURSOR);
944 	yych = *++YYCURSOR;
945 	if (yych <= '/') goto yy13;
946 	if (yych <= '1') goto yy91;
947 	if (yych <= '2') goto yy92;
948 	goto yy13;
949 yy91:
950 	YYDEBUG(91, *YYCURSOR);
951 	yych = *++YYCURSOR;
952 	if (yych <= '/') goto yy13;
953 	if (yych <= '9') goto yy93;
954 	goto yy13;
955 yy92:
956 	YYDEBUG(92, *YYCURSOR);
957 	yych = *++YYCURSOR;
958 	if (yych <= '/') goto yy13;
959 	if (yych >= '5') goto yy13;
960 yy93:
961 	YYDEBUG(93, *YYCURSOR);
962 	yych = *++YYCURSOR;
963 	if (yych <= '/') goto yy13;
964 	if (yych >= '6') goto yy13;
965 	YYDEBUG(94, *YYCURSOR);
966 	yych = *++YYCURSOR;
967 	if (yych <= '/') goto yy13;
968 	if (yych >= ':') goto yy13;
969 	YYDEBUG(95, *YYCURSOR);
970 	yych = *++YYCURSOR;
971 	if (yych <= '/') goto yy13;
972 	if (yych >= '6') goto yy13;
973 	YYDEBUG(96, *YYCURSOR);
974 	yych = *++YYCURSOR;
975 	if (yych <= '/') goto yy13;
976 	if (yych >= ':') goto yy13;
977 	YYDEBUG(97, *YYCURSOR);
978 	yych = *++YYCURSOR;
979 	if (yych == 'Z') goto yy83;
980 	goto yy13;
981 yy98:
982 	YYDEBUG(98, *YYCURSOR);
983 	++YYCURSOR;
984 	if (YYLIMIT <= YYCURSOR) YYFILL(1);
985 	yych = *YYCURSOR;
986 	YYDEBUG(99, *YYCURSOR);
987 	if (yych <= '/') goto yy100;
988 	if (yych <= '9') goto yy98;
989 yy100:
990 	YYDEBUG(100, *YYCURSOR);
991 #line 287 "ext/date/lib/parse_iso_intervals.re"
992 	{
993 		DEBUG_OUTPUT("recurrences");
994 		TIMELIB_INIT;
995 		ptr++;
996 		s->recurrences = timelib_get_unsigned_nr((char **) &ptr, 9);
997 		TIMELIB_DEINIT;
998 		s->have_recurrences = 1;
999 		return TIMELIB_PERIOD;
1000 	}
1001 #line 1002 "<stdout>"
1002 }
1003 #line 399 "ext/date/lib/parse_iso_intervals.re"
1004 
1005 }
1006 #ifdef PHP_WIN32
1007 #pragma optimize( "", on )
1008 #endif
1009 
1010 #define YYMAXFILL 20
1011 
timelib_strtointerval(char * s,size_t len,timelib_time ** begin,timelib_time ** end,timelib_rel_time ** period,int * recurrences,struct timelib_error_container ** errors)1012 void timelib_strtointerval(char *s, size_t len,
1013                            timelib_time **begin, timelib_time **end,
1014 						   timelib_rel_time **period, int *recurrences,
1015 						   struct timelib_error_container **errors)
1016 {
1017 	Scanner in;
1018 	int t;
1019 	char *e = s + len - 1;
1020 
1021 	memset(&in, 0, sizeof(in));
1022 	in.errors = timelib_malloc(sizeof(struct timelib_error_container));
1023 	in.errors->warning_count = 0;
1024 	in.errors->warning_messages = NULL;
1025 	in.errors->error_count = 0;
1026 	in.errors->error_messages = NULL;
1027 
1028 	if (len > 0) {
1029 		while (isspace(*s) && s < e) {
1030 			s++;
1031 		}
1032 		while (isspace(*e) && e > s) {
1033 			e--;
1034 		}
1035 	}
1036 	if (e - s < 0) {
1037 		add_error(&in, "Empty string");
1038 		if (errors) {
1039 			*errors = in.errors;
1040 		} else {
1041 			timelib_error_container_dtor(in.errors);
1042 		}
1043 		return;
1044 	}
1045 	e++;
1046 
1047 	/* init cursor */
1048 	in.str = timelib_malloc((e - s) + YYMAXFILL);
1049 	memset(in.str, 0, (e - s) + YYMAXFILL);
1050 	memcpy(in.str, s, (e - s));
1051 	in.lim = in.str + (e - s) + YYMAXFILL;
1052 	in.cur = in.str;
1053 
1054 	/* init value containers */
1055 	in.begin = timelib_time_ctor();
1056 	in.begin->y = TIMELIB_UNSET;
1057 	in.begin->d = TIMELIB_UNSET;
1058 	in.begin->m = TIMELIB_UNSET;
1059 	in.begin->h = TIMELIB_UNSET;
1060 	in.begin->i = TIMELIB_UNSET;
1061 	in.begin->s = TIMELIB_UNSET;
1062 	in.begin->f = 0;
1063 	in.begin->z = 0;
1064 	in.begin->dst = 0;
1065 	in.begin->is_localtime = 0;
1066 	in.begin->zone_type = TIMELIB_ZONETYPE_OFFSET;
1067 
1068 	in.end = timelib_time_ctor();
1069 	in.end->y = TIMELIB_UNSET;
1070 	in.end->d = TIMELIB_UNSET;
1071 	in.end->m = TIMELIB_UNSET;
1072 	in.end->h = TIMELIB_UNSET;
1073 	in.end->i = TIMELIB_UNSET;
1074 	in.end->s = TIMELIB_UNSET;
1075 	in.end->f = 0;
1076 	in.end->z = 0;
1077 	in.end->dst = 0;
1078 	in.end->is_localtime = 0;
1079 	in.end->zone_type = TIMELIB_ZONETYPE_OFFSET;
1080 
1081 	in.period = timelib_rel_time_ctor();
1082 	in.period->y = 0;
1083 	in.period->d = 0;
1084 	in.period->m = 0;
1085 	in.period->h = 0;
1086 	in.period->i = 0;
1087 	in.period->s = 0;
1088 	in.period->weekday = 0;
1089 	in.period->weekday_behavior = 0;
1090 	in.period->first_last_day_of = 0;
1091 	in.period->days = TIMELIB_UNSET;
1092 
1093 	in.recurrences = 1;
1094 
1095 	do {
1096 		t = scan(&in);
1097 #ifdef DEBUG_PARSER
1098 		printf("%d\n", t);
1099 #endif
1100 	} while(t != EOI);
1101 
1102 	timelib_free(in.str);
1103 	if (errors) {
1104 		*errors = in.errors;
1105 	} else {
1106 		timelib_error_container_dtor(in.errors);
1107 	}
1108 	if (in.have_begin_date) {
1109 		*begin = in.begin;
1110 	} else {
1111 		timelib_time_dtor(in.begin);
1112 	}
1113 	if (in.have_end_date) {
1114 		*end   = in.end;
1115 	} else {
1116 		timelib_time_dtor(in.end);
1117 	}
1118 	if (in.have_period) {
1119 		*period = in.period;
1120 	} else {
1121 		timelib_rel_time_dtor(in.period);
1122 	}
1123 	if (in.have_recurrences) {
1124 		*recurrences = in.recurrences;
1125 	}
1126 }
1127 
1128 
1129 /*
1130  * vim: syntax=c
1131  */
1132