parse_iso_intervals.c 24 KB

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