Back to index

php5  5.3.10
parse_iso_intervals.c
Go to the documentation of this file.
00001 /* Generated by re2c 0.13.5 on Mon Dec  5 22:02:31 2011 */
00002 #line 1 "ext/date/lib/parse_iso_intervals.re"
00003 /*
00004    +----------------------------------------------------------------------+
00005    | PHP Version 5                                                        |
00006    +----------------------------------------------------------------------+
00007    | Copyright (c) 1997-2010 The PHP Group                                |
00008    +----------------------------------------------------------------------+
00009    | This source file is subject to version 3.01 of the PHP license,      |
00010    | that is bundled with this package in the file LICENSE, and is        |
00011    | available through the world-wide-web at the following url:           |
00012    | http://www.php.net/license/3_01.txt                                  |
00013    | If you did not receive a copy of the PHP license and are unable to   |
00014    | obtain it through the world-wide-web, please send a note to          |
00015    | license@php.net so we can mail you a copy immediately.               |
00016    +----------------------------------------------------------------------+
00017    | Authors: Derick Rethans <derick@derickrethans.nl>                    |
00018    +----------------------------------------------------------------------+
00019  */
00020 
00021 /* $Id: parse_iso_intervals.c 320478 2011-12-06 06:04:24Z derick $ */
00022 
00023 #include "timelib.h"
00024 
00025 #include <stdio.h>
00026 #include <ctype.h>
00027 
00028 #ifdef HAVE_STDLIB_H
00029 #include <stdlib.h>
00030 #endif
00031 #ifdef HAVE_STRING_H
00032 #include <string.h>
00033 #else
00034 #include <strings.h>
00035 #endif
00036 
00037 #if defined(_MSC_VER)
00038 # define strtoll(s, f, b) _atoi64(s)
00039 #elif !defined(HAVE_STRTOLL)
00040 # if defined(HAVE_ATOLL)
00041 #  define strtoll(s, f, b) atoll(s)
00042 # else
00043 #  define strtoll(s, f, b) strtol(s, f, b)
00044 # endif
00045 #endif
00046 
00047 #define TIMELIB_UNSET   -99999
00048 
00049 #define TIMELIB_SECOND  1
00050 #define TIMELIB_MINUTE  2
00051 #define TIMELIB_HOUR    3
00052 #define TIMELIB_DAY     4
00053 #define TIMELIB_MONTH   5
00054 #define TIMELIB_YEAR    6
00055 
00056 #define EOI      257
00057 
00058 #define TIMELIB_PERIOD  260
00059 #define TIMELIB_ISO_DATE 261
00060 #define TIMELIB_ERROR   999
00061 
00062 typedef unsigned char uchar;
00063 
00064 #define   BSIZE         8192
00065 
00066 #define   YYCTYPE      uchar
00067 #define   YYCURSOR     cursor
00068 #define   YYLIMIT      s->lim
00069 #define   YYMARKER     s->ptr
00070 #define   YYFILL(n)    return EOI;
00071 
00072 #define   RET(i)       {s->cur = cursor; return i;}
00073 
00074 #define timelib_string_free free
00075 
00076 #define TIMELIB_INIT  s->cur = cursor; str = timelib_string(s); ptr = str
00077 #define TIMELIB_DEINIT timelib_string_free(str)
00078 
00079 #ifdef DEBUG_PARSER
00080 #define DEBUG_OUTPUT(s) printf("%s\n", s);
00081 #define YYDEBUG(s,c) { if (s != -1) { printf("state: %d ", s); printf("[%c]\n", c); } }
00082 #else
00083 #define DEBUG_OUTPUT(s)
00084 #define YYDEBUG(s,c)
00085 #endif
00086 
00087 #include "timelib_structs.h"
00088 
00089 typedef struct Scanner {
00090        int           fd;
00091        uchar        *lim, *str, *ptr, *cur, *tok, *pos;
00092        unsigned int  line, len;
00093        struct timelib_error_container *errors;
00094 
00095        struct timelib_time     *begin;
00096        struct timelib_time     *end;
00097        struct timelib_rel_time *period;
00098        int                      recurrences;
00099 
00100        int have_period;
00101        int have_recurrences;
00102        int have_date;
00103        int have_begin_date;
00104        int have_end_date;
00105 } Scanner;
00106 
00107 #define HOUR(a) (int)(a * 60)
00108 
00109 static void add_warning(Scanner *s, char *error)
00110 {
00111        s->errors->warning_count++;
00112        s->errors->warning_messages = realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
00113        s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0;
00114        s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0;
00115        s->errors->warning_messages[s->errors->warning_count - 1].message = strdup(error);
00116 }
00117 
00118 static void add_error(Scanner *s, char *error)
00119 {
00120        s->errors->error_count++;
00121        s->errors->error_messages = realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
00122        s->errors->error_messages[s->errors->error_count - 1].position = s->tok ? s->tok - s->str : 0;
00123        s->errors->error_messages[s->errors->error_count - 1].character = s->tok ? *s->tok : 0;
00124        s->errors->error_messages[s->errors->error_count - 1].message = strdup(error);
00125 }
00126 
00127 static char *timelib_string(Scanner *s)
00128 {
00129        char *tmp = calloc(1, s->cur - s->tok + 1);
00130        memcpy(tmp, s->tok, s->cur - s->tok);
00131 
00132        return tmp;
00133 }
00134 
00135 static timelib_sll timelib_get_nr(char **ptr, int max_length)
00136 {
00137        char *begin, *end, *str;
00138        timelib_sll tmp_nr = TIMELIB_UNSET;
00139        int len = 0;
00140 
00141        while ((**ptr < '0') || (**ptr > '9')) {
00142               if (**ptr == '\0') {
00143                      return TIMELIB_UNSET;
00144               }
00145               ++*ptr;
00146        }
00147        begin = *ptr;
00148        while ((**ptr >= '0') && (**ptr <= '9') && len < max_length) {
00149               ++*ptr;
00150               ++len;
00151        }
00152        end = *ptr;
00153        str = calloc(1, end - begin + 1);
00154        memcpy(str, begin, end - begin);
00155        tmp_nr = strtoll(str, NULL, 10);
00156        free(str);
00157        return tmp_nr;
00158 }
00159 
00160 static timelib_ull timelib_get_unsigned_nr(char **ptr, int max_length)
00161 {
00162        timelib_ull dir = 1;
00163 
00164        while (((**ptr < '0') || (**ptr > '9')) && (**ptr != '+') && (**ptr != '-')) {
00165               if (**ptr == '\0') {
00166                      return TIMELIB_UNSET;
00167               }
00168               ++*ptr;
00169        }
00170 
00171        while (**ptr == '+' || **ptr == '-')
00172        {
00173               if (**ptr == '-') {
00174                      dir *= -1;
00175               }
00176               ++*ptr;
00177        }
00178        return dir * timelib_get_nr(ptr, max_length);
00179 }
00180 
00181 static long timelib_parse_tz_cor(char **ptr)
00182 {
00183        char *begin = *ptr, *end;
00184        long  tmp;
00185 
00186        while (isdigit(**ptr) || **ptr == ':') {
00187               ++*ptr;
00188        }
00189        end = *ptr;
00190        switch (end - begin) {
00191               case 1:
00192               case 2:
00193                      return HOUR(strtol(begin, NULL, 10));
00194                      break;
00195               case 3:
00196               case 4:
00197                      if (begin[1] == ':') {
00198                             tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);
00199                             return tmp;
00200                      } else if (begin[2] == ':') {
00201                             tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
00202                             return tmp;
00203                      } else {
00204                             tmp = strtol(begin, NULL, 10);
00205                             return HOUR(tmp / 100) + tmp % 100;
00206                      }
00207               case 5:
00208                      tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
00209                      return tmp;
00210        }
00211        return 0;
00212 }
00213 
00214 static void timelib_eat_spaces(char **ptr)
00215 {
00216        while (**ptr == ' ' || **ptr == '\t') {
00217               ++*ptr;
00218        }
00219 }
00220 
00221 static void timelib_eat_until_separator(char **ptr)
00222 {
00223        while (strchr(" \t.,:;/-0123456789", **ptr) == NULL) {
00224               ++*ptr;
00225        }
00226 }
00227 
00228 static long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb)
00229 {
00230        long retval = 0;
00231 
00232        *tz_not_found = 0;
00233 
00234        while (**ptr == ' ' || **ptr == '\t' || **ptr == '(') {
00235               ++*ptr;
00236        }
00237        if ((*ptr)[0] == 'G' && (*ptr)[1] == 'M' && (*ptr)[2] == 'T' && ((*ptr)[3] == '+' || (*ptr)[3] == '-')) {
00238               *ptr += 3;
00239        }
00240        if (**ptr == '+') {
00241               ++*ptr;
00242               t->is_localtime = 1;
00243               t->zone_type = TIMELIB_ZONETYPE_OFFSET;
00244               *tz_not_found = 0;
00245               t->dst = 0;
00246 
00247               retval = -1 * timelib_parse_tz_cor(ptr);
00248        } else if (**ptr == '-') {
00249               ++*ptr;
00250               t->is_localtime = 1;
00251               t->zone_type = TIMELIB_ZONETYPE_OFFSET;
00252               *tz_not_found = 0;
00253               t->dst = 0;
00254 
00255               retval = timelib_parse_tz_cor(ptr);
00256        }
00257        while (**ptr == ')') {
00258               ++*ptr;
00259        }
00260        return retval;
00261 }
00262 
00263 #define timelib_split_free(arg) {       \
00264        int i;                         \
00265        for (i = 0; i < arg.c; i++) {  \
00266               free(arg.v[i]);            \
00267        }                              \
00268        if (arg.v) {                   \
00269               free(arg.v);               \
00270        }                              \
00271 }
00272 
00273 /* date parser's scan function too large for VC6 - VC7.x
00274    drop the optimization solves the problem */
00275 #ifdef PHP_WIN32
00276 #pragma optimize( "", off )
00277 #endif
00278 static int scan(Scanner *s)
00279 {
00280        uchar *cursor = s->cur;
00281        char *str, *ptr = NULL;
00282               
00283 std:
00284        s->tok = cursor;
00285        s->len = 0;
00286 #line 311 "ext/date/lib/parse_iso_intervals.re"
00287 
00288 
00289 
00290 #line 291 "ext/date/lib/parse_iso_intervals.c"
00291 {
00292        YYCTYPE yych;
00293        unsigned int yyaccept = 0;
00294        static const unsigned char yybm[] = {
00295                 0,   0,   0,   0,   0,   0,   0,   0, 
00296                 0,   0,   0,   0,   0,   0,   0,   0, 
00297                 0,   0,   0,   0,   0,   0,   0,   0, 
00298                 0,   0,   0,   0,   0,   0,   0,   0, 
00299                 0,   0,   0,   0,   0,   0,   0,   0, 
00300                 0,   0,   0,   0,   0,   0,   0,   0, 
00301               128, 128, 128, 128, 128, 128, 128, 128, 
00302               128, 128,   0,   0,   0,   0,   0,   0, 
00303                 0,   0,   0,   0,   0,   0,   0,   0, 
00304                 0,   0,   0,   0,   0,   0,   0,   0, 
00305                 0,   0,   0,   0,   0,   0,   0,   0, 
00306                 0,   0,   0,   0,   0,   0,   0,   0, 
00307                 0,   0,   0,   0,   0,   0,   0,   0, 
00308                 0,   0,   0,   0,   0,   0,   0,   0, 
00309                 0,   0,   0,   0,   0,   0,   0,   0, 
00310                 0,   0,   0,   0,   0,   0,   0,   0, 
00311                 0,   0,   0,   0,   0,   0,   0,   0, 
00312                 0,   0,   0,   0,   0,   0,   0,   0, 
00313                 0,   0,   0,   0,   0,   0,   0,   0, 
00314                 0,   0,   0,   0,   0,   0,   0,   0, 
00315                 0,   0,   0,   0,   0,   0,   0,   0, 
00316                 0,   0,   0,   0,   0,   0,   0,   0, 
00317                 0,   0,   0,   0,   0,   0,   0,   0, 
00318                 0,   0,   0,   0,   0,   0,   0,   0, 
00319                 0,   0,   0,   0,   0,   0,   0,   0, 
00320                 0,   0,   0,   0,   0,   0,   0,   0, 
00321                 0,   0,   0,   0,   0,   0,   0,   0, 
00322                 0,   0,   0,   0,   0,   0,   0,   0, 
00323                 0,   0,   0,   0,   0,   0,   0,   0, 
00324                 0,   0,   0,   0,   0,   0,   0,   0, 
00325                 0,   0,   0,   0,   0,   0,   0,   0, 
00326                 0,   0,   0,   0,   0,   0,   0,   0, 
00327        };
00328 
00329        YYDEBUG(0, *YYCURSOR);
00330        if ((YYLIMIT - YYCURSOR) < 20) YYFILL(20);
00331        yych = *YYCURSOR;
00332        if (yych <= ',') {
00333               if (yych <= '\n') {
00334                      if (yych <= 0x00) goto yy9;
00335                      if (yych <= 0x08) goto yy11;
00336                      if (yych <= '\t') goto yy7;
00337                      goto yy9;
00338               } else {
00339                      if (yych == ' ') goto yy7;
00340                      if (yych <= '+') goto yy11;
00341                      goto yy7;
00342               }
00343        } else {
00344               if (yych <= 'O') {
00345                      if (yych <= '-') goto yy11;
00346                      if (yych <= '/') goto yy7;
00347                      if (yych <= '9') goto yy4;
00348                      goto yy11;
00349               } else {
00350                      if (yych <= 'P') goto yy5;
00351                      if (yych != 'R') goto yy11;
00352               }
00353        }
00354        YYDEBUG(2, *YYCURSOR);
00355        ++YYCURSOR;
00356        if ((yych = *YYCURSOR) <= '/') goto yy3;
00357        if (yych <= '9') goto yy98;
00358 yy3:
00359        YYDEBUG(3, *YYCURSOR);
00360 #line 424 "ext/date/lib/parse_iso_intervals.re"
00361        {
00362               add_error(s, "Unexpected character");
00363               goto std;
00364        }
00365 #line 366 "ext/date/lib/parse_iso_intervals.c"
00366 yy4:
00367        YYDEBUG(4, *YYCURSOR);
00368        yyaccept = 0;
00369        yych = *(YYMARKER = ++YYCURSOR);
00370        if (yych <= '/') goto yy3;
00371        if (yych <= '9') goto yy59;
00372        goto yy3;
00373 yy5:
00374        YYDEBUG(5, *YYCURSOR);
00375        yyaccept = 1;
00376        yych = *(YYMARKER = ++YYCURSOR);
00377        if (yych <= '/') goto yy6;
00378        if (yych <= '9') goto yy12;
00379        if (yych == 'T') goto yy14;
00380 yy6:
00381        YYDEBUG(6, *YYCURSOR);
00382 #line 351 "ext/date/lib/parse_iso_intervals.re"
00383        {
00384               timelib_sll nr;
00385               int         in_time = 0;
00386               DEBUG_OUTPUT("period");
00387               TIMELIB_INIT;
00388               ptr++;
00389               do {
00390                      if ( *ptr == 'T' ) {
00391                             in_time = 1;
00392                             ptr++;
00393                      }
00394                      if ( *ptr == '\0' ) {
00395                             add_error(s, "Missing expected time part");
00396                             break;
00397                      }
00398 
00399                      nr = timelib_get_unsigned_nr((char **) &ptr, 12);
00400                      switch (*ptr) {
00401                             case 'Y': s->period->y = nr; break;
00402                             case 'W': s->period->d = nr * 7; break;
00403                             case 'D': s->period->d = nr; break;
00404                             case 'H': s->period->h = nr; break;
00405                             case 'S': s->period->s = nr; break;
00406                             case 'M': 
00407                                    if (in_time) {
00408                                           s->period->i = nr;
00409                                    } else {
00410                                           s->period->m = nr; 
00411                                    }
00412                                    break;
00413                             default:
00414                                    add_error(s, "Undefined period specifier");
00415                                    break;
00416                      }
00417                      ptr++;
00418               } while (*ptr);
00419               s->have_period = 1;
00420               TIMELIB_DEINIT;
00421               return TIMELIB_PERIOD;
00422        }
00423 #line 424 "ext/date/lib/parse_iso_intervals.c"
00424 yy7:
00425        YYDEBUG(7, *YYCURSOR);
00426        ++YYCURSOR;
00427        YYDEBUG(8, *YYCURSOR);
00428 #line 413 "ext/date/lib/parse_iso_intervals.re"
00429        {
00430               goto std;
00431        }
00432 #line 433 "ext/date/lib/parse_iso_intervals.c"
00433 yy9:
00434        YYDEBUG(9, *YYCURSOR);
00435        ++YYCURSOR;
00436        YYDEBUG(10, *YYCURSOR);
00437 #line 418 "ext/date/lib/parse_iso_intervals.re"
00438        {
00439               s->pos = cursor; s->line++;
00440               goto std;
00441        }
00442 #line 443 "ext/date/lib/parse_iso_intervals.c"
00443 yy11:
00444        YYDEBUG(11, *YYCURSOR);
00445        yych = *++YYCURSOR;
00446        goto yy3;
00447 yy12:
00448        YYDEBUG(12, *YYCURSOR);
00449        yych = *++YYCURSOR;
00450        if (yych <= 'L') {
00451               if (yych <= '9') {
00452                      if (yych >= '0') goto yy25;
00453               } else {
00454                      if (yych == 'D') goto yy24;
00455               }
00456        } else {
00457               if (yych <= 'W') {
00458                      if (yych <= 'M') goto yy27;
00459                      if (yych >= 'W') goto yy26;
00460               } else {
00461                      if (yych == 'Y') goto yy28;
00462               }
00463        }
00464 yy13:
00465        YYDEBUG(13, *YYCURSOR);
00466        YYCURSOR = YYMARKER;
00467        if (yyaccept <= 0) {
00468               goto yy3;
00469        } else {
00470               goto yy6;
00471        }
00472 yy14:
00473        YYDEBUG(14, *YYCURSOR);
00474        yyaccept = 1;
00475        yych = *(YYMARKER = ++YYCURSOR);
00476        if (yybm[0+yych] & 128) {
00477               goto yy15;
00478        }
00479        goto yy6;
00480 yy15:
00481        YYDEBUG(15, *YYCURSOR);
00482        ++YYCURSOR;
00483        if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
00484        yych = *YYCURSOR;
00485        YYDEBUG(16, *YYCURSOR);
00486        if (yybm[0+yych] & 128) {
00487               goto yy15;
00488        }
00489        if (yych <= 'L') {
00490               if (yych == 'H') goto yy19;
00491               goto yy13;
00492        } else {
00493               if (yych <= 'M') goto yy18;
00494               if (yych != 'S') goto yy13;
00495        }
00496 yy17:
00497        YYDEBUG(17, *YYCURSOR);
00498        yych = *++YYCURSOR;
00499        goto yy6;
00500 yy18:
00501        YYDEBUG(18, *YYCURSOR);
00502        yyaccept = 1;
00503        yych = *(YYMARKER = ++YYCURSOR);
00504        if (yych <= '/') goto yy6;
00505        if (yych <= '9') goto yy22;
00506        goto yy6;
00507 yy19:
00508        YYDEBUG(19, *YYCURSOR);
00509        yyaccept = 1;
00510        yych = *(YYMARKER = ++YYCURSOR);
00511        if (yych <= '/') goto yy6;
00512        if (yych >= ':') goto yy6;
00513 yy20:
00514        YYDEBUG(20, *YYCURSOR);
00515        ++YYCURSOR;
00516        if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
00517        yych = *YYCURSOR;
00518        YYDEBUG(21, *YYCURSOR);
00519        if (yych <= 'L') {
00520               if (yych <= '/') goto yy13;
00521               if (yych <= '9') goto yy20;
00522               goto yy13;
00523        } else {
00524               if (yych <= 'M') goto yy18;
00525               if (yych == 'S') goto yy17;
00526               goto yy13;
00527        }
00528 yy22:
00529        YYDEBUG(22, *YYCURSOR);
00530        ++YYCURSOR;
00531        if (YYLIMIT <= YYCURSOR) YYFILL(1);
00532        yych = *YYCURSOR;
00533        YYDEBUG(23, *YYCURSOR);
00534        if (yych <= '/') goto yy13;
00535        if (yych <= '9') goto yy22;
00536        if (yych == 'S') goto yy17;
00537        goto yy13;
00538 yy24:
00539        YYDEBUG(24, *YYCURSOR);
00540        yych = *++YYCURSOR;
00541        if (yych == 'T') goto yy14;
00542        goto yy6;
00543 yy25:
00544        YYDEBUG(25, *YYCURSOR);
00545        yych = *++YYCURSOR;
00546        if (yych <= 'L') {
00547               if (yych <= '9') {
00548                      if (yych <= '/') goto yy13;
00549                      goto yy35;
00550               } else {
00551                      if (yych == 'D') goto yy24;
00552                      goto yy13;
00553               }
00554        } else {
00555               if (yych <= 'W') {
00556                      if (yych <= 'M') goto yy27;
00557                      if (yych <= 'V') goto yy13;
00558               } else {
00559                      if (yych == 'Y') goto yy28;
00560                      goto yy13;
00561               }
00562        }
00563 yy26:
00564        YYDEBUG(26, *YYCURSOR);
00565        yyaccept = 1;
00566        yych = *(YYMARKER = ++YYCURSOR);
00567        if (yych <= '/') goto yy6;
00568        if (yych <= '9') goto yy33;
00569        if (yych == 'T') goto yy14;
00570        goto yy6;
00571 yy27:
00572        YYDEBUG(27, *YYCURSOR);
00573        yyaccept = 1;
00574        yych = *(YYMARKER = ++YYCURSOR);
00575        if (yych <= '/') goto yy6;
00576        if (yych <= '9') goto yy31;
00577        if (yych == 'T') goto yy14;
00578        goto yy6;
00579 yy28:
00580        YYDEBUG(28, *YYCURSOR);
00581        yyaccept = 1;
00582        yych = *(YYMARKER = ++YYCURSOR);
00583        if (yych <= '/') goto yy6;
00584        if (yych <= '9') goto yy29;
00585        if (yych == 'T') goto yy14;
00586        goto yy6;
00587 yy29:
00588        YYDEBUG(29, *YYCURSOR);
00589        ++YYCURSOR;
00590        if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
00591        yych = *YYCURSOR;
00592        YYDEBUG(30, *YYCURSOR);
00593        if (yych <= 'D') {
00594               if (yych <= '/') goto yy13;
00595               if (yych <= '9') goto yy29;
00596               if (yych <= 'C') goto yy13;
00597               goto yy24;
00598        } else {
00599               if (yych <= 'M') {
00600                      if (yych <= 'L') goto yy13;
00601                      goto yy27;
00602               } else {
00603                      if (yych == 'W') goto yy26;
00604                      goto yy13;
00605               }
00606        }
00607 yy31:
00608        YYDEBUG(31, *YYCURSOR);
00609        ++YYCURSOR;
00610        if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
00611        yych = *YYCURSOR;
00612        YYDEBUG(32, *YYCURSOR);
00613        if (yych <= 'C') {
00614               if (yych <= '/') goto yy13;
00615               if (yych <= '9') goto yy31;
00616               goto yy13;
00617        } else {
00618               if (yych <= 'D') goto yy24;
00619               if (yych == 'W') goto yy26;
00620               goto yy13;
00621        }
00622 yy33:
00623        YYDEBUG(33, *YYCURSOR);
00624        ++YYCURSOR;
00625        if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
00626        yych = *YYCURSOR;
00627        YYDEBUG(34, *YYCURSOR);
00628        if (yych <= '/') goto yy13;
00629        if (yych <= '9') goto yy33;
00630        if (yych == 'D') goto yy24;
00631        goto yy13;
00632 yy35:
00633        YYDEBUG(35, *YYCURSOR);
00634        yych = *++YYCURSOR;
00635        if (yych <= 'L') {
00636               if (yych <= '9') {
00637                      if (yych <= '/') goto yy13;
00638               } else {
00639                      if (yych == 'D') goto yy24;
00640                      goto yy13;
00641               }
00642        } else {
00643               if (yych <= 'W') {
00644                      if (yych <= 'M') goto yy27;
00645                      if (yych <= 'V') goto yy13;
00646                      goto yy26;
00647               } else {
00648                      if (yych == 'Y') goto yy28;
00649                      goto yy13;
00650               }
00651        }
00652        YYDEBUG(36, *YYCURSOR);
00653        yych = *++YYCURSOR;
00654        if (yych != '-') goto yy39;
00655        YYDEBUG(37, *YYCURSOR);
00656        yych = *++YYCURSOR;
00657        if (yych <= '/') goto yy13;
00658        if (yych <= '0') goto yy40;
00659        if (yych <= '1') goto yy41;
00660        goto yy13;
00661 yy38:
00662        YYDEBUG(38, *YYCURSOR);
00663        ++YYCURSOR;
00664        if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
00665        yych = *YYCURSOR;
00666 yy39:
00667        YYDEBUG(39, *YYCURSOR);
00668        if (yych <= 'L') {
00669               if (yych <= '9') {
00670                      if (yych <= '/') goto yy13;
00671                      goto yy38;
00672               } else {
00673                      if (yych == 'D') goto yy24;
00674                      goto yy13;
00675               }
00676        } else {
00677               if (yych <= 'W') {
00678                      if (yych <= 'M') goto yy27;
00679                      if (yych <= 'V') goto yy13;
00680                      goto yy26;
00681               } else {
00682                      if (yych == 'Y') goto yy28;
00683                      goto yy13;
00684               }
00685        }
00686 yy40:
00687        YYDEBUG(40, *YYCURSOR);
00688        yych = *++YYCURSOR;
00689        if (yych <= '/') goto yy13;
00690        if (yych <= '9') goto yy42;
00691        goto yy13;
00692 yy41:
00693        YYDEBUG(41, *YYCURSOR);
00694        yych = *++YYCURSOR;
00695        if (yych <= '/') goto yy13;
00696        if (yych >= '3') goto yy13;
00697 yy42:
00698        YYDEBUG(42, *YYCURSOR);
00699        yych = *++YYCURSOR;
00700        if (yych != '-') goto yy13;
00701        YYDEBUG(43, *YYCURSOR);
00702        yych = *++YYCURSOR;
00703        if (yych <= '/') goto yy13;
00704        if (yych <= '0') goto yy44;
00705        if (yych <= '2') goto yy45;
00706        if (yych <= '3') goto yy46;
00707        goto yy13;
00708 yy44:
00709        YYDEBUG(44, *YYCURSOR);
00710        yych = *++YYCURSOR;
00711        if (yych <= '/') goto yy13;
00712        if (yych <= '9') goto yy47;
00713        goto yy13;
00714 yy45:
00715        YYDEBUG(45, *YYCURSOR);
00716        yych = *++YYCURSOR;
00717        if (yych <= '/') goto yy13;
00718        if (yych <= '9') goto yy47;
00719        goto yy13;
00720 yy46:
00721        YYDEBUG(46, *YYCURSOR);
00722        yych = *++YYCURSOR;
00723        if (yych <= '/') goto yy13;
00724        if (yych >= '2') goto yy13;
00725 yy47:
00726        YYDEBUG(47, *YYCURSOR);
00727        yych = *++YYCURSOR;
00728        if (yych != 'T') goto yy13;
00729        YYDEBUG(48, *YYCURSOR);
00730        yych = *++YYCURSOR;
00731        if (yych <= '/') goto yy13;
00732        if (yych <= '1') goto yy49;
00733        if (yych <= '2') goto yy50;
00734        goto yy13;
00735 yy49:
00736        YYDEBUG(49, *YYCURSOR);
00737        yych = *++YYCURSOR;
00738        if (yych <= '/') goto yy13;
00739        if (yych <= '9') goto yy51;
00740        goto yy13;
00741 yy50:
00742        YYDEBUG(50, *YYCURSOR);
00743        yych = *++YYCURSOR;
00744        if (yych <= '/') goto yy13;
00745        if (yych >= '5') goto yy13;
00746 yy51:
00747        YYDEBUG(51, *YYCURSOR);
00748        yych = *++YYCURSOR;
00749        if (yych != ':') goto yy13;
00750        YYDEBUG(52, *YYCURSOR);
00751        yych = *++YYCURSOR;
00752        if (yych <= '/') goto yy13;
00753        if (yych >= '6') goto yy13;
00754        YYDEBUG(53, *YYCURSOR);
00755        yych = *++YYCURSOR;
00756        if (yych <= '/') goto yy13;
00757        if (yych >= ':') goto yy13;
00758        YYDEBUG(54, *YYCURSOR);
00759        yych = *++YYCURSOR;
00760        if (yych != ':') goto yy13;
00761        YYDEBUG(55, *YYCURSOR);
00762        yych = *++YYCURSOR;
00763        if (yych <= '/') goto yy13;
00764        if (yych >= '6') goto yy13;
00765        YYDEBUG(56, *YYCURSOR);
00766        yych = *++YYCURSOR;
00767        if (yych <= '/') goto yy13;
00768        if (yych >= ':') goto yy13;
00769        YYDEBUG(57, *YYCURSOR);
00770        ++YYCURSOR;
00771        YYDEBUG(58, *YYCURSOR);
00772 #line 393 "ext/date/lib/parse_iso_intervals.re"
00773        {
00774               DEBUG_OUTPUT("combinedrep");
00775               TIMELIB_INIT;
00776               s->period->y = timelib_get_unsigned_nr((char **) &ptr, 4);
00777               ptr++;
00778               s->period->m = timelib_get_unsigned_nr((char **) &ptr, 2);
00779               ptr++;
00780               s->period->d = timelib_get_unsigned_nr((char **) &ptr, 2);
00781               ptr++;
00782               s->period->h = timelib_get_unsigned_nr((char **) &ptr, 2);
00783               ptr++;
00784               s->period->i = timelib_get_unsigned_nr((char **) &ptr, 2);
00785               ptr++;
00786               s->period->s = timelib_get_unsigned_nr((char **) &ptr, 2);
00787               s->have_period = 1;
00788               TIMELIB_DEINIT;
00789               return TIMELIB_PERIOD;
00790        }
00791 #line 792 "ext/date/lib/parse_iso_intervals.c"
00792 yy59:
00793        YYDEBUG(59, *YYCURSOR);
00794        yych = *++YYCURSOR;
00795        if (yych <= '/') goto yy13;
00796        if (yych >= ':') goto yy13;
00797        YYDEBUG(60, *YYCURSOR);
00798        yych = *++YYCURSOR;
00799        if (yych <= '/') goto yy13;
00800        if (yych >= ':') goto yy13;
00801        YYDEBUG(61, *YYCURSOR);
00802        yych = *++YYCURSOR;
00803        if (yych <= '/') {
00804               if (yych == '-') goto yy64;
00805               goto yy13;
00806        } else {
00807               if (yych <= '0') goto yy62;
00808               if (yych <= '1') goto yy63;
00809               goto yy13;
00810        }
00811 yy62:
00812        YYDEBUG(62, *YYCURSOR);
00813        yych = *++YYCURSOR;
00814        if (yych <= '0') goto yy13;
00815        if (yych <= '9') goto yy85;
00816        goto yy13;
00817 yy63:
00818        YYDEBUG(63, *YYCURSOR);
00819        yych = *++YYCURSOR;
00820        if (yych <= '/') goto yy13;
00821        if (yych <= '2') goto yy85;
00822        goto yy13;
00823 yy64:
00824        YYDEBUG(64, *YYCURSOR);
00825        yych = *++YYCURSOR;
00826        if (yych <= '/') goto yy13;
00827        if (yych <= '0') goto yy65;
00828        if (yych <= '1') goto yy66;
00829        goto yy13;
00830 yy65:
00831        YYDEBUG(65, *YYCURSOR);
00832        yych = *++YYCURSOR;
00833        if (yych <= '0') goto yy13;
00834        if (yych <= '9') goto yy67;
00835        goto yy13;
00836 yy66:
00837        YYDEBUG(66, *YYCURSOR);
00838        yych = *++YYCURSOR;
00839        if (yych <= '/') goto yy13;
00840        if (yych >= '3') goto yy13;
00841 yy67:
00842        YYDEBUG(67, *YYCURSOR);
00843        yych = *++YYCURSOR;
00844        if (yych != '-') goto yy13;
00845        YYDEBUG(68, *YYCURSOR);
00846        yych = *++YYCURSOR;
00847        if (yych <= '/') goto yy13;
00848        if (yych <= '0') goto yy69;
00849        if (yych <= '2') goto yy70;
00850        if (yych <= '3') goto yy71;
00851        goto yy13;
00852 yy69:
00853        YYDEBUG(69, *YYCURSOR);
00854        yych = *++YYCURSOR;
00855        if (yych <= '0') goto yy13;
00856        if (yych <= '9') goto yy72;
00857        goto yy13;
00858 yy70:
00859        YYDEBUG(70, *YYCURSOR);
00860        yych = *++YYCURSOR;
00861        if (yych <= '/') goto yy13;
00862        if (yych <= '9') goto yy72;
00863        goto yy13;
00864 yy71:
00865        YYDEBUG(71, *YYCURSOR);
00866        yych = *++YYCURSOR;
00867        if (yych <= '/') goto yy13;
00868        if (yych >= '2') goto yy13;
00869 yy72:
00870        YYDEBUG(72, *YYCURSOR);
00871        yych = *++YYCURSOR;
00872        if (yych != 'T') goto yy13;
00873        YYDEBUG(73, *YYCURSOR);
00874        yych = *++YYCURSOR;
00875        if (yych <= '/') goto yy13;
00876        if (yych <= '1') goto yy74;
00877        if (yych <= '2') goto yy75;
00878        goto yy13;
00879 yy74:
00880        YYDEBUG(74, *YYCURSOR);
00881        yych = *++YYCURSOR;
00882        if (yych <= '/') goto yy13;
00883        if (yych <= '9') goto yy76;
00884        goto yy13;
00885 yy75:
00886        YYDEBUG(75, *YYCURSOR);
00887        yych = *++YYCURSOR;
00888        if (yych <= '/') goto yy13;
00889        if (yych >= '5') goto yy13;
00890 yy76:
00891        YYDEBUG(76, *YYCURSOR);
00892        yych = *++YYCURSOR;
00893        if (yych != ':') goto yy13;
00894        YYDEBUG(77, *YYCURSOR);
00895        yych = *++YYCURSOR;
00896        if (yych <= '/') goto yy13;
00897        if (yych >= '6') goto yy13;
00898        YYDEBUG(78, *YYCURSOR);
00899        yych = *++YYCURSOR;
00900        if (yych <= '/') goto yy13;
00901        if (yych >= ':') goto yy13;
00902        YYDEBUG(79, *YYCURSOR);
00903        yych = *++YYCURSOR;
00904        if (yych != ':') goto yy13;
00905        YYDEBUG(80, *YYCURSOR);
00906        yych = *++YYCURSOR;
00907        if (yych <= '/') goto yy13;
00908        if (yych >= '6') goto yy13;
00909        YYDEBUG(81, *YYCURSOR);
00910        yych = *++YYCURSOR;
00911        if (yych <= '/') goto yy13;
00912        if (yych >= ':') goto yy13;
00913        YYDEBUG(82, *YYCURSOR);
00914        yych = *++YYCURSOR;
00915        if (yych != 'Z') goto yy13;
00916 yy83:
00917        YYDEBUG(83, *YYCURSOR);
00918        ++YYCURSOR;
00919        YYDEBUG(84, *YYCURSOR);
00920 #line 327 "ext/date/lib/parse_iso_intervals.re"
00921        {
00922               timelib_time *current;
00923 
00924               if (s->have_date || s->have_period) {
00925                      current = s->end;
00926                      s->have_end_date = 1;
00927               } else {
00928                      current = s->begin;
00929                      s->have_begin_date = 1;
00930               }
00931               DEBUG_OUTPUT("datetimebasic | datetimeextended");
00932               TIMELIB_INIT;
00933               current->y = timelib_get_nr((char **) &ptr, 4);
00934               current->m = timelib_get_nr((char **) &ptr, 2);
00935               current->d = timelib_get_nr((char **) &ptr, 2);
00936               current->h = timelib_get_nr((char **) &ptr, 2);
00937               current->i = timelib_get_nr((char **) &ptr, 2);
00938               current->s = timelib_get_nr((char **) &ptr, 2);
00939               s->have_date = 1;
00940               TIMELIB_DEINIT;
00941               return TIMELIB_ISO_DATE;
00942        }
00943 #line 944 "ext/date/lib/parse_iso_intervals.c"
00944 yy85:
00945        YYDEBUG(85, *YYCURSOR);
00946        yych = *++YYCURSOR;
00947        if (yych <= '/') goto yy13;
00948        if (yych <= '0') goto yy86;
00949        if (yych <= '2') goto yy87;
00950        if (yych <= '3') goto yy88;
00951        goto yy13;
00952 yy86:
00953        YYDEBUG(86, *YYCURSOR);
00954        yych = *++YYCURSOR;
00955        if (yych <= '0') goto yy13;
00956        if (yych <= '9') goto yy89;
00957        goto yy13;
00958 yy87:
00959        YYDEBUG(87, *YYCURSOR);
00960        yych = *++YYCURSOR;
00961        if (yych <= '/') goto yy13;
00962        if (yych <= '9') goto yy89;
00963        goto yy13;
00964 yy88:
00965        YYDEBUG(88, *YYCURSOR);
00966        yych = *++YYCURSOR;
00967        if (yych <= '/') goto yy13;
00968        if (yych >= '2') goto yy13;
00969 yy89:
00970        YYDEBUG(89, *YYCURSOR);
00971        yych = *++YYCURSOR;
00972        if (yych != 'T') goto yy13;
00973        YYDEBUG(90, *YYCURSOR);
00974        yych = *++YYCURSOR;
00975        if (yych <= '/') goto yy13;
00976        if (yych <= '1') goto yy91;
00977        if (yych <= '2') goto yy92;
00978        goto yy13;
00979 yy91:
00980        YYDEBUG(91, *YYCURSOR);
00981        yych = *++YYCURSOR;
00982        if (yych <= '/') goto yy13;
00983        if (yych <= '9') goto yy93;
00984        goto yy13;
00985 yy92:
00986        YYDEBUG(92, *YYCURSOR);
00987        yych = *++YYCURSOR;
00988        if (yych <= '/') goto yy13;
00989        if (yych >= '5') goto yy13;
00990 yy93:
00991        YYDEBUG(93, *YYCURSOR);
00992        yych = *++YYCURSOR;
00993        if (yych <= '/') goto yy13;
00994        if (yych >= '6') goto yy13;
00995        YYDEBUG(94, *YYCURSOR);
00996        yych = *++YYCURSOR;
00997        if (yych <= '/') goto yy13;
00998        if (yych >= ':') goto yy13;
00999        YYDEBUG(95, *YYCURSOR);
01000        yych = *++YYCURSOR;
01001        if (yych <= '/') goto yy13;
01002        if (yych >= '6') goto yy13;
01003        YYDEBUG(96, *YYCURSOR);
01004        yych = *++YYCURSOR;
01005        if (yych <= '/') goto yy13;
01006        if (yych >= ':') goto yy13;
01007        YYDEBUG(97, *YYCURSOR);
01008        yych = *++YYCURSOR;
01009        if (yych == 'Z') goto yy83;
01010        goto yy13;
01011 yy98:
01012        YYDEBUG(98, *YYCURSOR);
01013        ++YYCURSOR;
01014        if (YYLIMIT <= YYCURSOR) YYFILL(1);
01015        yych = *YYCURSOR;
01016        YYDEBUG(99, *YYCURSOR);
01017        if (yych <= '/') goto yy100;
01018        if (yych <= '9') goto yy98;
01019 yy100:
01020        YYDEBUG(100, *YYCURSOR);
01021 #line 316 "ext/date/lib/parse_iso_intervals.re"
01022        {
01023               DEBUG_OUTPUT("recurrences");
01024               TIMELIB_INIT;
01025               ptr++;
01026               s->recurrences = timelib_get_unsigned_nr((char **) &ptr, 9);
01027               TIMELIB_DEINIT;
01028               s->have_recurrences = 1;
01029               return TIMELIB_PERIOD;
01030        }
01031 #line 1032 "ext/date/lib/parse_iso_intervals.c"
01032 }
01033 #line 428 "ext/date/lib/parse_iso_intervals.re"
01034 
01035 }
01036 #ifdef PHP_WIN32
01037 #pragma optimize( "", on )
01038 #endif
01039 
01040 #define YYMAXFILL 20
01041 
01042 void timelib_strtointerval(char *s, int len, 
01043                            timelib_time **begin, timelib_time **end, 
01044                                              timelib_rel_time **period, int *recurrences, 
01045                                              struct timelib_error_container **errors)
01046 {
01047        Scanner in;
01048        int t;
01049        char *e = s + len - 1;
01050 
01051        memset(&in, 0, sizeof(in));
01052        in.errors = malloc(sizeof(struct timelib_error_container));
01053        in.errors->warning_count = 0;
01054        in.errors->warning_messages = NULL;
01055        in.errors->error_count = 0;
01056        in.errors->error_messages = NULL;
01057 
01058        if (len > 0) {
01059               while (isspace(*s) && s < e) {
01060                      s++;
01061               }
01062               while (isspace(*e) && e > s) {
01063                      e--;
01064               }
01065        }
01066        if (e - s < 0) {
01067               add_error(&in, "Empty string");
01068               if (errors) {
01069                      *errors = in.errors;
01070               } else {
01071                      timelib_error_container_dtor(in.errors);
01072               }
01073               return;
01074        }
01075        e++;
01076 
01077        /* init cursor */
01078        in.str = malloc((e - s) + YYMAXFILL);
01079        memset(in.str, 0, (e - s) + YYMAXFILL);
01080        memcpy(in.str, s, (e - s));
01081        in.lim = in.str + (e - s) + YYMAXFILL;
01082        in.cur = in.str;
01083 
01084        /* init value containers */
01085        in.begin = timelib_time_ctor();
01086        in.begin->y = TIMELIB_UNSET;
01087        in.begin->d = TIMELIB_UNSET;
01088        in.begin->m = TIMELIB_UNSET;
01089        in.begin->h = TIMELIB_UNSET;
01090        in.begin->i = TIMELIB_UNSET;
01091        in.begin->s = TIMELIB_UNSET;
01092        in.begin->f = 0;
01093        in.begin->z = 0;
01094        in.begin->dst = 0;
01095        in.begin->is_localtime = 0;
01096        in.begin->zone_type = TIMELIB_ZONETYPE_OFFSET;
01097 
01098        in.end = timelib_time_ctor();
01099        in.end->y = TIMELIB_UNSET;
01100        in.end->d = TIMELIB_UNSET;
01101        in.end->m = TIMELIB_UNSET;
01102        in.end->h = TIMELIB_UNSET;
01103        in.end->i = TIMELIB_UNSET;
01104        in.end->s = TIMELIB_UNSET;
01105        in.end->f = 0;
01106        in.end->z = 0;
01107        in.end->dst = 0;
01108        in.end->is_localtime = 0;
01109        in.end->zone_type = TIMELIB_ZONETYPE_OFFSET;
01110 
01111        in.period = timelib_rel_time_ctor();
01112        in.period->y = 0;
01113        in.period->d = 0;
01114        in.period->m = 0;
01115        in.period->h = 0;
01116        in.period->i = 0;
01117        in.period->s = 0;
01118        in.period->weekday = 0;
01119        in.period->weekday_behavior = 0;
01120        in.period->first_last_day_of = 0;
01121        in.period->days = TIMELIB_UNSET;
01122 
01123        in.recurrences = 1;
01124 
01125        do {
01126               t = scan(&in);
01127 #ifdef DEBUG_PARSER
01128               printf("%d\n", t);
01129 #endif
01130        } while(t != EOI);
01131 
01132        free(in.str);
01133        if (errors) {
01134               *errors = in.errors;
01135        } else {
01136               timelib_error_container_dtor(in.errors);
01137        }
01138        if (in.have_begin_date) {
01139               *begin = in.begin;
01140        } else {
01141               timelib_time_dtor(in.begin);
01142        }
01143        if (in.have_end_date) {
01144               *end   = in.end;
01145        } else {
01146               timelib_time_dtor(in.end);
01147        }
01148        if (in.have_period) {
01149               *period = in.period;
01150        } else {
01151               timelib_rel_time_dtor(in.period);
01152        }
01153        if (in.have_recurrences) {
01154               *recurrences = in.recurrences;
01155        }
01156 }
01157 
01158 
01159 /*
01160  * vim: syntax=c
01161  */