From: foobar Date: Thu, 17 Nov 2005 09:58:28 +0000 (+0000) Subject: MFH X-Git-Tag: php-5.1.0RC6~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=52747127f8bb5f8832ad7d680cbf9aa098655673;p=php MFH --- diff --git a/ext/date/lib/README b/ext/date/lib/README index 2603bc7c6f..bc450f633d 100644 --- a/ext/date/lib/README +++ b/ext/date/lib/README @@ -1,6 +1,6 @@ Regenerating Parser =================== -Make sure you use re2c 0.9.8dev or higher: +Make sure you use re2c 0.9.10 or higher: -/dat/dev/sf/re2c/re2c -d -b resource/parse_date.re > parse_date.c +/dat/dev/sf/re2c/re2c -d -b -o ext/date/parse_date.c ext/date/parse_date.re diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index 59ad04533a..942b0892f6 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,5 +1,5 @@ -/* Generated by re2c 0.9.10.dev on Wed Oct 19 15:42:32 2005 */ -#line 1 "resource/parse_date.re" +/* Generated by re2c 0.9.10 on Thu Nov 17 11:55:55 2005 */ +#line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ | PHP Version 5 | @@ -695,7 +695,7 @@ static int scan(Scanner *s) std: s->tok = cursor; s->len = 0; -#line 802 "resource/parse_date.re" +#line 802 "ext/date/lib/parse_date.re" { @@ -734,7 +734,7 @@ std: 0, 0, 0, 0, 0, 0, 0, 0, }; -#line 738 "" +#line 738 "ext/date/lib/parse_date.c" { YYCTYPE yych; unsigned int yyaccept; @@ -819,7 +819,7 @@ yy2: yy3: YYDEBUG(3, *YYCURSOR); -#line 1300 "resource/parse_date.re" +#line 1300 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("tzcorrection | tz"); @@ -829,7 +829,7 @@ yy3: TIMELIB_DEINIT; return TIMELIB_TIMEZONE; } -#line 826 "" +#line 826 "ext/date/lib/parse_date.c" yy4: YYDEBUG(4, *YYCURSOR); yych = *++YYCURSOR; @@ -939,13 +939,13 @@ yy7: yy8: YYDEBUG(8, *YYCURSOR); -#line 1366 "resource/parse_date.re" +#line 1366 "ext/date/lib/parse_date.re" { /* printf("unexpected character: #%d, %c ", *s->tok, *s->tok); */ s->errors++; goto std; } -#line 931 "" +#line 931 "ext/date/lib/parse_date.c" yy9: YYDEBUG(9, *YYCURSOR); yyaccept = 0; @@ -1854,11 +1854,11 @@ yy43: yy44: YYDEBUG(44, *YYCURSOR); -#line 1355 "resource/parse_date.re" +#line 1355 "ext/date/lib/parse_date.re" { goto std; } -#line 1767 "" +#line 1767 "ext/date/lib/parse_date.c" yy45: YYDEBUG(45, *YYCURSOR); ++YYCURSOR; @@ -1866,12 +1866,12 @@ yy45: yy46: YYDEBUG(46, *YYCURSOR); -#line 1360 "resource/parse_date.re" +#line 1360 "ext/date/lib/parse_date.re" { s->pos = cursor; s->line++; goto std; } -#line 1776 "" +#line 1776 "ext/date/lib/parse_date.c" yy47: YYDEBUG(47, *YYCURSOR); yych = *++YYCURSOR; @@ -2329,7 +2329,7 @@ yy84: yy85: YYDEBUG(85, *YYCURSOR); -#line 1339 "resource/parse_date.re" +#line 1339 "ext/date/lib/parse_date.re" { timelib_ull i; DEBUG_OUTPUT("relative"); @@ -2344,7 +2344,7 @@ yy85: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 2166 "" +#line 2166 "ext/date/lib/parse_date.c" yy86: YYDEBUG(86, *YYCURSOR); ++YYCURSOR; @@ -3037,12 +3037,12 @@ yy150: yy151: YYDEBUG(151, *YYCURSOR); -#line 1294 "resource/parse_date.re" +#line 1294 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("dayabbr"); goto std; } -#line 2730 "" +#line 2730 "ext/date/lib/parse_date.c" yy152: YYDEBUG(152, *YYCURSOR); yyaccept = 1; @@ -3081,7 +3081,7 @@ yy157: yy158: YYDEBUG(158, *YYCURSOR); -#line 1277 "resource/parse_date.re" +#line 1277 "ext/date/lib/parse_date.re" { const timelib_relunit* relunit; DEBUG_OUTPUT("dayfull"); @@ -3097,7 +3097,7 @@ yy158: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 2771 "" +#line 2771 "ext/date/lib/parse_date.c" yy159: YYDEBUG(159, *YYCURSOR); yyaccept = 1; @@ -3466,7 +3466,7 @@ yy189: yy190: YYDEBUG(190, *YYCURSOR); -#line 1260 "resource/parse_date.re" +#line 1260 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior; @@ -3482,7 +3482,7 @@ yy190: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 3090 "" +#line 3090 "ext/date/lib/parse_date.c" yy191: YYDEBUG(191, *YYCURSOR); ++YYCURSOR; @@ -9112,7 +9112,7 @@ yy508: yy509: YYDEBUG(509, *YYCURSOR); -#line 1082 "resource/parse_date.re" +#line 1082 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datetextual | datenoyear"); TIMELIB_INIT; @@ -9124,7 +9124,7 @@ yy509: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 8083 "" +#line 8083 "ext/date/lib/parse_date.c" yy510: YYDEBUG(510, *YYCURSOR); yych = *++YYCURSOR; @@ -9284,7 +9284,7 @@ yy526: yy527: YYDEBUG(527, *YYCURSOR); -#line 1311 "resource/parse_date.re" +#line 1311 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz"); @@ -9311,7 +9311,7 @@ yy527: TIMELIB_DEINIT; return TIMELIB_SHORTDATE_WITH_TIME; } -#line 8234 "" +#line 8234 "ext/date/lib/parse_date.c" yy528: YYDEBUG(528, *YYCURSOR); yyaccept = 7; @@ -9624,7 +9624,7 @@ yy561: yy562: YYDEBUG(562, *YYCURSOR); -#line 1056 "resource/parse_date.re" +#line 1056 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenoday"); TIMELIB_INIT; @@ -9636,7 +9636,7 @@ yy562: TIMELIB_DEINIT; return TIMELIB_DATE_NO_DAY; } -#line 8489 "" +#line 8489 "ext/date/lib/parse_date.c" yy563: YYDEBUG(563, *YYCURSOR); yyaccept = 6; @@ -9936,7 +9936,7 @@ yy587: yy588: YYDEBUG(588, *YYCURSOR); -#line 1191 "resource/parse_date.re" +#line 1191 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pgtextshort"); TIMELIB_INIT; @@ -9948,7 +9948,7 @@ yy588: TIMELIB_DEINIT; return TIMELIB_PG_TEXT; } -#line 8748 "" +#line 8748 "ext/date/lib/parse_date.c" yy589: YYDEBUG(589, *YYCURSOR); yych = *++YYCURSOR; @@ -11452,7 +11452,7 @@ yy683: yy684: YYDEBUG(684, *YYCURSOR); -#line 1245 "resource/parse_date.re" +#line 1245 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("ago"); TIMELIB_INIT; @@ -11466,7 +11466,7 @@ yy684: TIMELIB_DEINIT; return TIMELIB_AGO; } -#line 10073 "" +#line 10073 "ext/date/lib/parse_date.c" yy685: YYDEBUG(685, *YYCURSOR); yyaccept = 1; @@ -13401,7 +13401,7 @@ yy787: yy788: YYDEBUG(788, *YYCURSOR); -#line 1095 "resource/parse_date.re" +#line 1095 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenoyearrev"); TIMELIB_INIT; @@ -13411,7 +13411,7 @@ yy788: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 11806 "" +#line 11806 "ext/date/lib/parse_date.c" yy789: YYDEBUG(789, *YYCURSOR); yyaccept = 10; @@ -13521,7 +13521,7 @@ yy798: yy799: YYDEBUG(799, *YYCURSOR); -#line 886 "resource/parse_date.re" +#line 886 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("timetiny12 | timeshort12 | timelong12"); TIMELIB_INIT; @@ -13537,7 +13537,7 @@ yy799: TIMELIB_DEINIT; return TIMELIB_TIME12; } -#line 11910 "" +#line 11910 "ext/date/lib/parse_date.c" yy800: YYDEBUG(800, *YYCURSOR); yych = *++YYCURSOR; @@ -13557,7 +13557,7 @@ yy801: yy802: YYDEBUG(802, *YYCURSOR); -#line 903 "resource/parse_date.re" +#line 903 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("timeshort24 | timelong24 | iso8601long"); @@ -13580,7 +13580,7 @@ yy802: TIMELIB_DEINIT; return TIMELIB_TIME24_WITH_ZONE; } -#line 11947 "" +#line 11947 "ext/date/lib/parse_date.c" yy803: YYDEBUG(803, *YYCURSOR); yyaccept = 11; @@ -13823,7 +13823,7 @@ yy827: yy828: YYDEBUG(828, *YYCURSOR); -#line 1030 "resource/parse_date.re" +#line 1030 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datefull"); TIMELIB_INIT; @@ -13835,7 +13835,7 @@ yy828: TIMELIB_DEINIT; return TIMELIB_DATE_FULL; } -#line 12150 "" +#line 12150 "ext/date/lib/parse_date.c" yy829: YYDEBUG(829, *YYCURSOR); yych = *++YYCURSOR; @@ -14470,7 +14470,7 @@ yy896: yy897: YYDEBUG(897, *YYCURSOR); -#line 1043 "resource/parse_date.re" +#line 1043 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pointed date"); TIMELIB_INIT; @@ -14482,7 +14482,7 @@ yy897: TIMELIB_DEINIT; return TIMELIB_DATE_FULL_POINTED; } -#line 12659 "" +#line 12659 "ext/date/lib/parse_date.c" yy898: YYDEBUG(898, *YYCURSOR); yych = *++YYCURSOR; @@ -15050,7 +15050,7 @@ yy942: yy943: YYDEBUG(943, *YYCURSOR); -#line 1017 "resource/parse_date.re" +#line 1017 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("gnudateshort"); TIMELIB_INIT; @@ -15062,7 +15062,7 @@ yy943: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 13147 "" +#line 13147 "ext/date/lib/parse_date.c" yy944: YYDEBUG(944, *YYCURSOR); yych = *++YYCURSOR; @@ -15084,7 +15084,7 @@ yy946: yy947: YYDEBUG(947, *YYCURSOR); -#line 990 "resource/parse_date.re" +#line 990 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("americanshort | american"); TIMELIB_INIT; @@ -15098,7 +15098,7 @@ yy947: TIMELIB_DEINIT; return TIMELIB_AMERICAN; } -#line 13175 "" +#line 13175 "ext/date/lib/parse_date.c" yy948: YYDEBUG(948, *YYCURSOR); yyaccept = 12; @@ -15320,7 +15320,7 @@ yy979: yy980: YYDEBUG(980, *YYCURSOR); -#line 1217 "resource/parse_date.re" +#line 1217 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("clf"); @@ -15338,7 +15338,7 @@ yy980: TIMELIB_DEINIT; return TIMELIB_CLF; } -#line 13349 "" +#line 13349 "ext/date/lib/parse_date.c" yy981: YYDEBUG(981, *YYCURSOR); yyaccept = 13; @@ -15647,7 +15647,7 @@ yy1019: yy1020: YYDEBUG(1020, *YYCURSOR); -#line 1204 "resource/parse_date.re" +#line 1204 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pgtextreverse"); TIMELIB_INIT; @@ -15659,7 +15659,7 @@ yy1020: TIMELIB_DEINIT; return TIMELIB_PG_TEXT; } -#line 13589 "" +#line 13589 "ext/date/lib/parse_date.c" yy1021: YYDEBUG(1021, *YYCURSOR); yych = *++YYCURSOR; @@ -15792,7 +15792,7 @@ yy1031: yy1032: YYDEBUG(1032, *YYCURSOR); -#line 1236 "resource/parse_date.re" +#line 1236 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("year4"); TIMELIB_INIT; @@ -15800,7 +15800,7 @@ yy1032: TIMELIB_DEINIT; return TIMELIB_CLF; } -#line 13705 "" +#line 13705 "ext/date/lib/parse_date.c" yy1033: YYDEBUG(1033, *YYCURSOR); yych = *++YYCURSOR; @@ -15936,7 +15936,7 @@ yy1040: yy1041: YYDEBUG(1041, *YYCURSOR); -#line 1069 "resource/parse_date.re" +#line 1069 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenodayrev"); TIMELIB_INIT; @@ -15948,7 +15948,7 @@ yy1041: TIMELIB_DEINIT; return TIMELIB_DATE_NO_DAY; } -#line 13832 "" +#line 13832 "ext/date/lib/parse_date.c" yy1042: YYDEBUG(1042, *YYCURSOR); yych = *++YYCURSOR; @@ -16157,7 +16157,7 @@ yy1060: yy1061: YYDEBUG(1061, *YYCURSOR); -#line 1172 "resource/parse_date.re" +#line 1172 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweek"); @@ -16175,7 +16175,7 @@ yy1061: TIMELIB_DEINIT; return TIMELIB_ISO_WEEK; } -#line 14019 "" +#line 14019 "ext/date/lib/parse_date.c" yy1062: YYDEBUG(1062, *YYCURSOR); ++YYCURSOR; @@ -16183,7 +16183,7 @@ yy1062: yy1063: YYDEBUG(1063, *YYCURSOR); -#line 1153 "resource/parse_date.re" +#line 1153 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweekday"); @@ -16201,7 +16201,7 @@ yy1063: TIMELIB_DEINIT; return TIMELIB_ISO_WEEK; } -#line 14041 "" +#line 14041 "ext/date/lib/parse_date.c" yy1064: YYDEBUG(1064, *YYCURSOR); yych = *++YYCURSOR; @@ -16270,7 +16270,7 @@ yy1066: yy1067: YYDEBUG(1067, *YYCURSOR); -#line 1140 "resource/parse_date.re" +#line 1140 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pgydotd"); TIMELIB_INIT; @@ -16282,7 +16282,7 @@ yy1067: TIMELIB_DEINIT; return TIMELIB_PG_YEARDAY; } -#line 14114 "" +#line 14114 "ext/date/lib/parse_date.c" yy1068: YYDEBUG(1068, *YYCURSOR); yych = *++YYCURSOR; @@ -16397,7 +16397,7 @@ yy1073: yy1074: YYDEBUG(1074, *YYCURSOR); -#line 1106 "resource/parse_date.re" +#line 1106 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenocolon"); TIMELIB_INIT; @@ -16408,7 +16408,7 @@ yy1074: TIMELIB_DEINIT; return TIMELIB_DATE_NOCOLON; } -#line 14222 "" +#line 14222 "ext/date/lib/parse_date.c" yy1075: YYDEBUG(1075, *YYCURSOR); yych = *++YYCURSOR; @@ -16506,7 +16506,7 @@ yy1084: yy1085: YYDEBUG(1085, *YYCURSOR); -#line 1118 "resource/parse_date.re" +#line 1118 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx"); @@ -16527,7 +16527,7 @@ yy1085: TIMELIB_DEINIT; return TIMELIB_XMLRPC_SOAP; } -#line 14319 "" +#line 14319 "ext/date/lib/parse_date.c" yy1086: YYDEBUG(1086, *YYCURSOR); yych = *++YYCURSOR; @@ -17130,7 +17130,7 @@ yy1175: yy1176: YYDEBUG(1176, *YYCURSOR); -#line 1005 "resource/parse_date.re" +#line 1005 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("iso8601date | iso8601dateslash | dateslash"); TIMELIB_INIT; @@ -17141,7 +17141,7 @@ yy1176: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 14751 "" +#line 14751 "ext/date/lib/parse_date.c" yy1177: YYDEBUG(1177, *YYCURSOR); yych = *++YYCURSOR; @@ -17956,7 +17956,7 @@ yy1268: yy1269: YYDEBUG(1269, *YYCURSOR); -#line 927 "resource/parse_date.re" +#line 927 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("gnunocolon"); TIMELIB_INIT; @@ -17977,7 +17977,7 @@ yy1269: TIMELIB_DEINIT; return TIMELIB_GNU_NOCOLON; } -#line 15398 "" +#line 15398 "ext/date/lib/parse_date.c" yy1270: YYDEBUG(1270, *YYCURSOR); yych = *++YYCURSOR; @@ -18074,7 +18074,7 @@ yy1276: yy1277: YYDEBUG(1277, *YYCURSOR); -#line 972 "resource/parse_date.re" +#line 972 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("iso8601nocolon"); @@ -18091,7 +18091,7 @@ yy1277: TIMELIB_DEINIT; return TIMELIB_ISO_NOCOLON; } -#line 15496 "" +#line 15496 "ext/date/lib/parse_date.c" yy1278: YYDEBUG(1278, *YYCURSOR); yyaccept = 21; @@ -18388,7 +18388,7 @@ yy1301: yy1302: YYDEBUG(1302, *YYCURSOR); -#line 862 "resource/parse_date.re" +#line 862 "ext/date/lib/parse_date.re" { timelib_ull i; @@ -18411,7 +18411,7 @@ yy1302: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 15760 "" +#line 15760 "ext/date/lib/parse_date.c" yy1303: YYDEBUG(1303, *YYCURSOR); yych = *++YYCURSOR; @@ -18482,7 +18482,7 @@ yy1310: yy1311: YYDEBUG(1311, *YYCURSOR); -#line 850 "resource/parse_date.re" +#line 850 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("tomorrow"); TIMELIB_INIT; @@ -18493,7 +18493,7 @@ yy1311: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 15824 "" +#line 15824 "ext/date/lib/parse_date.c" yy1312: YYDEBUG(1312, *YYCURSOR); yych = *++YYCURSOR; @@ -18506,7 +18506,7 @@ yy1313: yy1314: YYDEBUG(1314, *YYCURSOR); -#line 840 "resource/parse_date.re" +#line 840 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("midnight | today"); TIMELIB_INIT; @@ -18515,7 +18515,7 @@ yy1314: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 15840 "" +#line 15840 "ext/date/lib/parse_date.c" yy1315: YYDEBUG(1315, *YYCURSOR); yych = *++YYCURSOR; @@ -18596,7 +18596,7 @@ yy1322: yy1323: YYDEBUG(1323, *YYCURSOR); -#line 819 "resource/parse_date.re" +#line 819 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("now"); TIMELIB_INIT; @@ -18604,7 +18604,7 @@ yy1323: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 15911 "" +#line 15911 "ext/date/lib/parse_date.c" yy1324: YYDEBUG(1324, *YYCURSOR); yych = *++YYCURSOR; @@ -18624,7 +18624,7 @@ yy1325: yy1326: YYDEBUG(1326, *YYCURSOR); -#line 828 "resource/parse_date.re" +#line 828 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("noon"); TIMELIB_INIT; @@ -18635,7 +18635,7 @@ yy1326: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 15936 "" +#line 15936 "ext/date/lib/parse_date.c" yy1327: YYDEBUG(1327, *YYCURSOR); yych = *++YYCURSOR; @@ -18693,7 +18693,7 @@ yy1334: yy1335: YYDEBUG(1335, *YYCURSOR); -#line 807 "resource/parse_date.re" +#line 807 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("yesterday"); TIMELIB_INIT; @@ -18704,10 +18704,10 @@ yy1335: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 15987 "" +#line 15987 "ext/date/lib/parse_date.c" } } -#line 1371 "resource/parse_date.re" +#line 1371 "ext/date/lib/parse_date.re" } diff --git a/ext/date/lib/resource/README b/ext/date/lib/resource/README deleted file mode 100644 index 2603bc7c6f..0000000000 --- a/ext/date/lib/resource/README +++ /dev/null @@ -1,6 +0,0 @@ -Regenerating Parser -=================== - -Make sure you use re2c 0.9.8dev or higher: - -/dat/dev/sf/re2c/re2c -d -b resource/parse_date.re > parse_date.c diff --git a/ext/date/lib/resource/parse_date.re b/ext/date/lib/resource/parse_date.re deleted file mode 100644 index 34f9aa5723..0000000000 --- a/ext/date/lib/resource/parse_date.re +++ /dev/null @@ -1,1487 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2005 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Derick Rethans | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "timelib.h" - -#include - -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#else -#include -#endif - -#if defined(_MSC_VER) -# define strtoll(s, f, b) _atoi64(s) -#elif !defined(HAVE_STRTOLL) -# if defined(HAVE_ATOLL) -# define strtoll(s, f, b) atoll(s) -# else -# define strtoll(s, f, b) strtol(s, f, b) -# endif -#endif - -#define TIMELIB_SECOND 1 -#define TIMELIB_MINUTE 2 -#define TIMELIB_HOUR 3 -#define TIMELIB_DAY 4 -#define TIMELIB_MONTH 5 -#define TIMELIB_YEAR 6 -#define TIMELIB_WEEKDAY 7 - -#define EOI 257 -#define TIME 258 -#define DATE 259 - -#define TIMELIB_XMLRPC_SOAP 260 -#define TIMELIB_TIME12 261 -#define TIMELIB_TIME24 262 -#define TIMELIB_GNU_NOCOLON 263 -#define TIMELIB_GNU_NOCOLON_TZ 264 -#define TIMELIB_ISO_NOCOLON 265 - -#define TIMELIB_AMERICAN 266 -#define TIMELIB_ISO_DATE 267 -#define TIMELIB_DATE_FULL 268 -#define TIMELIB_DATE_TEXT 269 -#define TIMELIB_DATE_NOCOLON 270 -#define TIMELIB_PG_YEARDAY 271 -#define TIMELIB_PG_TEXT 272 -#define TIMELIB_PG_REVERSE 273 -#define TIMELIB_CLF 274 -#define TIMELIB_DATE_NO_DAY 275 -#define TIMELIB_SHORTDATE_WITH_TIME 276 -#define TIMELIB_DATE_FULL_POINTED 277 -#define TIMELIB_TIME24_WITH_ZONE 278 -#define TIMELIB_ISO_WEEK 279 - -#define TIMELIB_TIMEZONE 300 -#define TIMELIB_AGO 301 - -#define TIMELIB_RELATIVE 310 - -#define TIMELIB_ERROR 999 - -typedef unsigned char uchar; - -#define BSIZE 8192 - -#define YYCTYPE uchar -#define YYCURSOR cursor -#define YYLIMIT s->lim -#define YYMARKER s->ptr -#define YYFILL(n) return EOI; - -#define RET(i) {s->cur = cursor; return i;} - -#define timelib_string_free free - -#define TIMELIB_HAVE_TIME() { if (s->time->have_time) { return TIMELIB_ERROR; } else { s->time->have_time = 1; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->f = 0; } } -#define TIMELIB_UNHAVE_TIME() { s->time->have_time = 0; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->f = 0; } -#define TIMELIB_HAVE_DATE() { if (s->time->have_date) { return TIMELIB_ERROR; } else { s->time->have_date = 1; } } -#define TIMELIB_UNHAVE_DATE() { s->time->have_date = 0; s->time->d = 0; s->time->m = 0; s->time->y = 0; } -#define TIMELIB_HAVE_RELATIVE() { s->time->have_relative = 1; s->time->relative.weekday_behavior = 0; } -#define TIMELIB_HAVE_WEEKDAY_RELATIVE() { s->time->have_weekday_relative = 1; } -#define TIMELIB_HAVE_TZ() { s->cur = cursor; if (s->time->have_zone) { return TIMELIB_ERROR; } else { s->time.have_zone = 1; } } - -#define TIMELIB_INIT s->cur = cursor; str = timelib_string(s); ptr = str -#define TIMELIB_DEINIT timelib_string_free(str) -#define TIMELIB_ADJUST_RELATIVE_WEEKDAY() if (in->time.have_weekday_relative && (in.rel.d > 0)) { in.rel.d -= 7; } - -#define TIMELIB_PROCESS_YEAR(x) { \ - if ((x) == -1) { \ - /* (x) = 0; */ \ - } else if ((x) < 100) { \ - if ((x) < 70) { \ - (x) += 2000; \ - } else { \ - (x) += 1900; \ - } \ - } \ -} - -#ifdef DEBUG_PARSER -#define DEBUG_OUTPUT(s) printf("%s\n", s); -#define YYDEBUG(s,c) { if (s != -1) { printf("state: %d ", s); printf("[%c]\n", c); } } -#else -#define DEBUG_OUTPUT(s) -#define YYDEBUG(s,c) -#endif - -#include "timelib_structs.h" - -typedef struct timelib_elems { - unsigned int c; /* Number of elements */ - char **v; /* Values */ -} timelib_elems; - -typedef struct Scanner { - int fd; - uchar *lim, *str, *ptr, *cur, *tok, *pos; - unsigned int line, len; - int errors; - - struct timelib_time *time; - timelib_tzdb *tzdb; -} Scanner; - -typedef struct _timelib_lookup_table { - const char *name; - int type; - int value; -} timelib_lookup_table; - -typedef struct _timelib_relunit { - const char *name; - int unit; - int multiplier; -} timelib_relunit; - -#define HOUR(a) (int)(a * 60) - -/* The timezone table. */ -static timelib_tz_lookup_table timelib_timezone_lookup[] = { -#include "timezonemap.h" - { NULL, 0, 0, NULL }, -}; - -static timelib_tz_lookup_table timelib_timezone_fallbackmap[] = { -#include "fallbackmap.h" - { NULL, 0, 0, NULL }, -}; - -static timelib_relunit const timelib_relunit_lookup[] = { - { "sec", TIMELIB_SECOND, 1 }, - { "secs", TIMELIB_SECOND, 1 }, - { "second", TIMELIB_SECOND, 1 }, - { "seconds", TIMELIB_SECOND, 1 }, - { "min", TIMELIB_MINUTE, 1 }, - { "mins", TIMELIB_MINUTE, 1 }, - { "minute", TIMELIB_MINUTE, 1 }, - { "minutes", TIMELIB_MINUTE, 1 }, - { "hour", TIMELIB_HOUR, 1 }, - { "hours", TIMELIB_HOUR, 1 }, - { "day", TIMELIB_DAY, 1 }, - { "days", TIMELIB_DAY, 1 }, - { "week", TIMELIB_DAY, 7 }, - { "weeks", TIMELIB_DAY, 7 }, - { "fortnight", TIMELIB_DAY, 14 }, - { "fortnights", TIMELIB_DAY, 14 }, - { "forthnight", TIMELIB_DAY, 14 }, - { "forthnights", TIMELIB_DAY, 14 }, - { "month", TIMELIB_MONTH, 1 }, - { "months", TIMELIB_MONTH, 1 }, - { "year", TIMELIB_YEAR, 1 }, - { "years", TIMELIB_YEAR, 1 }, - - { "monday", TIMELIB_WEEKDAY, 1 }, - { "tuesday", TIMELIB_WEEKDAY, 2 }, - { "wednesday", TIMELIB_WEEKDAY, 3 }, - { "thursday", TIMELIB_WEEKDAY, 4 }, - { "friday", TIMELIB_WEEKDAY, 5 }, - { "saturday", TIMELIB_WEEKDAY, 6 }, - { "sunday", TIMELIB_WEEKDAY, 0 }, - - { NULL, 0, 0 } -}; - -/* The relative text table. */ -static timelib_lookup_table const timelib_reltext_lookup[] = { - { "first", 0, 1 }, - { "next", 0, 1 }, - { "second", 0, 2 }, - { "third", 0, 3 }, - { "fourth", 0, 4 }, - { "fifth", 0, 5 }, - { "sixth", 0, 6 }, - { "seventh", 0, 7 }, - { "eight", 0, 8 }, - { "ninth", 0, 9 }, - { "tenth", 0, 10 }, - { "eleventh", 0, 11 }, - { "twelfth", 0, 12 }, - { "last", 0, -1 }, - { "previous", 0, -1 }, - { "this", 1, 0 }, - { NULL, 1, 0 } -}; - -/* The month table. */ -static timelib_lookup_table const timelib_month_lookup[] = { - { "jan", 0, 1 }, - { "feb", 0, 2 }, - { "mar", 0, 3 }, - { "apr", 0, 4 }, - { "may", 0, 5 }, - { "jun", 0, 6 }, - { "jul", 0, 7 }, - { "aug", 0, 8 }, - { "sep", 0, 9 }, - { "sept", 0, 9 }, - { "oct", 0, 10 }, - { "nov", 0, 11 }, - { "dec", 0, 12 }, - { "i", 0, 1 }, - { "ii", 0, 2 }, - { "iii", 0, 3 }, - { "iv", 0, 4 }, - { "v", 0, 5 }, - { "vi", 0, 6 }, - { "vii", 0, 7 }, - { "viii", 0, 8 }, - { "ix", 0, 9 }, - { "x", 0, 10 }, - { "xi", 0, 11 }, - { "xii", 0, 12 }, - - { "january", 0, 1 }, - { "february", 0, 2 }, - { "march", 0, 3 }, - { "april", 0, 4 }, - { "may", 0, 5 }, - { "june", 0, 6 }, - { "july", 0, 7 }, - { "august", 0, 8 }, - { "september", 0, 9 }, - { "october", 0, 10 }, - { "november", 0, 11 }, - { "december", 0, 12 }, - { NULL, 0, 0 } -}; - -#if 0 -static char* timelib_ltrim(char *s) -{ - char *ptr = s; - while (ptr[0] == ' ') { - ptr++; - } - return ptr; -} -#endif - -#if 0 -uchar *fill(Scanner *s, uchar *cursor){ - if(!s->eof){ - unsigned int cnt = s->tok - s->bot; - if(cnt){ - memcpy(s->bot, s->tok, s->lim - s->tok); - s->tok = s->bot; - s->ptr -= cnt; - cursor -= cnt; - s->pos -= cnt; - s->lim -= cnt; - } - if((s->top - s->lim) < BSIZE){ - uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar)); - memcpy(buf, s->tok, s->lim - s->tok); - s->tok = buf; - s->ptr = &buf[s->ptr - s->bot]; - cursor = &buf[cursor - s->bot]; - s->pos = &buf[s->pos - s->bot]; - s->lim = &buf[s->lim - s->bot]; - s->top = &s->lim[BSIZE]; - free(s->bot); - s->bot = buf; - } - if((cnt = read(s->fd, (char*) s->lim, BSIZE)) != BSIZE){ - s->eof = &s->lim[cnt]; *(s->eof)++ = '\n'; - } - s->lim += cnt; - } - return cursor; -} -#endif - -static timelib_sll timelib_meridian(char **ptr, timelib_sll h) -{ - timelib_sll retval = 0; - - while (!strchr("AaPp", **ptr)) { - ++*ptr; - } - if (**ptr == 'a' || **ptr == 'A') { - if (h == 12) { - retval = -12; - } - } else if (h != 12) { - retval = 12; - } - ++*ptr; - if (**ptr == '.') { - *ptr += 3; - } else { - ++*ptr; - } - return retval; -} - -static char *timelib_string(Scanner *s) -{ - char *tmp = calloc(1, s->cur - s->tok + 1); - memcpy(tmp, s->tok, s->cur - s->tok); - - return tmp; -} - -static timelib_sll timelib_get_nr(char **ptr, int max_length) -{ - char *begin, *end, *str; - timelib_sll tmp_nr = -1; - int len = 0; - - while ((**ptr < '0') || (**ptr > '9')) { - if (**ptr == '\0') { - return -1; - } - ++*ptr; - } - begin = *ptr; - while ((**ptr >= '0') && (**ptr <= '9') && len < max_length) { - ++*ptr; - ++len; - } - end = *ptr; - str = calloc(1, end - begin + 1); - memcpy(str, begin, end - begin); - tmp_nr = strtoll(str, NULL, 10); - free(str); - return tmp_nr; -} - -static double timelib_get_frac_nr(char **ptr, int max_length) -{ - char *begin, *end, *str; - double tmp_nr = -1; - int len = 0; - - while ((**ptr != '.') && ((**ptr < '0') || (**ptr > '9'))) { - if (**ptr == '\0') { - return -1; - } - ++*ptr; - } - begin = *ptr; - while (((**ptr == '.') || ((**ptr >= '0') && (**ptr <= '9'))) && len < max_length) { - ++*ptr; - ++len; - } - end = *ptr; - str = calloc(1, end - begin + 1); - memcpy(str, begin, end - begin); - tmp_nr = strtod(str, NULL); - free(str); - return tmp_nr; -} - -static timelib_ull timelib_get_unsigned_nr(char **ptr, int max_length) -{ - timelib_ull dir = 1; - - while (((**ptr < '0') || (**ptr > '9')) && (**ptr != '+') && (**ptr != '-')) { - if (**ptr == '\0') { - return -1; - } - ++*ptr; - } - if (**ptr == '+') { - ++*ptr; - } else if (**ptr == '-') { - dir = -1; - ++*ptr; - } - return dir * timelib_get_nr(ptr, max_length); -} - -static long timelib_parse_tz_cor(char **ptr) -{ - char *begin = *ptr, *end; - long tmp; - - while (**ptr != '\0') { - ++*ptr; - } - end = *ptr; - switch (end - begin) { - case 1: - case 2: - return HOUR(strtol(begin, NULL, 10)); - break; - case 3: - case 4: - tmp = strtol(begin, NULL, 10); - return HOUR(tmp / 100) + tmp % 100; - case 5: - tmp = HOUR(strtol(begin, NULL, 10)) + - strtol(begin + 3, NULL, 10); - return tmp; - } - return 0; -} - -static timelib_sll timelib_lookup_relative_text(char **ptr, int *behavior) -{ - char *word; - char *begin = *ptr, *end; - timelib_sll value = 0; - const timelib_lookup_table *tp; - - while ((**ptr >= 'A' && **ptr <= 'Z') || (**ptr >= 'a' && **ptr <= 'z')) { - ++*ptr; - } - end = *ptr; - word = calloc(1, end - begin + 1); - memcpy(word, begin, end - begin); - - for (tp = timelib_reltext_lookup; tp->name; tp++) { - if (strcasecmp(word, tp->name) == 0) { - value = tp->value; - *behavior = tp->type; - } - } - - free(word); - return value; -} - -static timelib_sll timelib_get_relative_text(char **ptr, int *behavior) -{ - while (**ptr == ' ' || **ptr == '-' || **ptr == '/') { - ++*ptr; - } - return timelib_lookup_relative_text(ptr, behavior); -} - -static long timelib_lookup_month(char **ptr) -{ - char *word; - char *begin = *ptr, *end; - long value = 0; - const timelib_lookup_table *tp; - - while ((**ptr >= 'A' && **ptr <= 'Z') || (**ptr >= 'a' && **ptr <= 'z')) { - ++*ptr; - } - end = *ptr; - word = calloc(1, end - begin + 1); - memcpy(word, begin, end - begin); - - for (tp = timelib_month_lookup; tp->name; tp++) { - if (strcasecmp(word, tp->name) == 0) { - value = tp->value; - } - } - - free(word); - return value; -} - -static long timelib_get_month(char **ptr) -{ - while (**ptr == ' ' || **ptr == '-' || **ptr == '.' || **ptr == '/') { - ++*ptr; - } - return timelib_lookup_month(ptr); -} - -static void timelib_eat_spaces(char **ptr) -{ - while (**ptr == ' ') { - ++*ptr; - } -} - -static const timelib_relunit* timelib_lookup_relunit(char **ptr) -{ - char *word; - char *begin = *ptr, *end; - const timelib_relunit *tp, *value = NULL; - - while (**ptr != '\0' && **ptr != ' ') { - ++*ptr; - } - end = *ptr; - word = calloc(1, end - begin + 1); - memcpy(word, begin, end - begin); - - for (tp = timelib_relunit_lookup; tp->name; tp++) { - if (strcasecmp(word, tp->name) == 0) { - value = tp; - break; - } - } - - free(word); - return value; -} - -static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, Scanner *s) -{ - const timelib_relunit* relunit; - - relunit = timelib_lookup_relunit(ptr); - switch (relunit->unit) { - case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break; - case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break; - case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break; - case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break; - case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break; - case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break; - - case TIMELIB_WEEKDAY: - TIMELIB_HAVE_WEEKDAY_RELATIVE(); - TIMELIB_UNHAVE_TIME(); - s->time->relative.d += (amount > 0 ? amount - 1 : amount) * 7; - s->time->relative.weekday = relunit->multiplier; - s->time->relative.weekday_behavior = behavior; - break; - } -} - -static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, int isdst) -{ - int first_found = 0; - timelib_tz_lookup_table *tp, *first_found_elem; - timelib_tz_lookup_table *fmp; - - for (tp = timelib_timezone_lookup; tp->name; tp++) { - if (strcasecmp(word, tp->name) == 0) { - if (!first_found) { - first_found = 1; - first_found_elem = tp; - if (gmtoffset == -1) { - return tp; - } - } - if (tp->gmtoffset == gmtoffset) { - return tp; - } - } - } - if (first_found) { - return first_found_elem; - } - /* Still didn't find anything, let's find the zone solely based on - * offset/isdst then */ - for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) { - if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) { - return fmp; - } - } - return NULL; -} - -static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found) -{ - char *word; - char *begin = *ptr, *end; - long value = 0; - timelib_tz_lookup_table *tp; - - while (**ptr != '\0') { - ++*ptr; - } - end = *ptr; - word = calloc(1, end - begin + 1); - memcpy(word, begin, end - begin); - - if ((tp = zone_search(word, -1, 0))) { - value = -tp->gmtoffset / 60; - *dst = tp->type; - value += tp->type * 60; - *found = 1; - } else { - *found = 0; - } - - *tz_abbr = word; - return value; -} - -static long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, timelib_tzdb *tzdb) -{ - timelib_tzinfo *res; - - *tz_not_found = 0; - - while (**ptr == ' ') { - ++*ptr; - } - if (**ptr == '+') { - ++*ptr; - t->is_localtime = 1; - t->zone_type = TIMELIB_ZONETYPE_OFFSET; - *tz_not_found = 0; - t->dst = 0; - - return -1 * timelib_parse_tz_cor(ptr); - } else if (**ptr == '-') { - ++*ptr; - t->is_localtime = 1; - t->zone_type = TIMELIB_ZONETYPE_OFFSET; - *tz_not_found = 0; - t->dst = 0; - - return timelib_parse_tz_cor(ptr); - } else { - int found = 0; - long offset; - char *tz_abbr; - - t->is_localtime = 1; - t->zone_type = TIMELIB_ZONETYPE_ABBR; - offset = timelib_lookup_zone(ptr, dst, &tz_abbr, &found); -#if 0 - /* If we found a TimeZone identifier, use it */ - if (tz_name) { - t->tz_info = timelib_parse_tzfile(tz_name); - t->zone_type = TIMELIB_ZONETYPE_ID; - } -#endif - /* If we have a TimeZone identifier to start with, use it */ - if (strstr(tz_abbr, "/")) { - if ((res = timelib_parse_tzfile(tz_abbr, tzdb)) != NULL) { - t->tz_info = res; - t->zone_type = TIMELIB_ZONETYPE_ID; - found++; - } - } - if (t->zone_type != TIMELIB_ZONETYPE_ID) { - timelib_time_tz_abbr_update(t, tz_abbr); - } - free(tz_abbr); - *tz_not_found = (found == 0); - return offset; - } -} - -#define timelib_split_free(arg) { \ - int i; \ - for (i = 0; i < arg.c; i++) { \ - free(arg.v[i]); \ - } \ - if (arg.v) { \ - free(arg.v); \ - } \ -} - -static int scan(Scanner *s) -{ - uchar *cursor = s->cur; - char *str, *ptr = NULL; - -std: - s->tok = cursor; - s->len = 0; -/*!re2c -any = [\000-\377]; - -space = [ ]+; -frac = "."[0-9]+; - -ago = 'ago'; - -hour24 = [01]?[0-9] | "2"[0-3]; -hour24lz = [01][0-9] | "2"[0-3]; -hour12 = "0"?[1-9] | "1"[0-2]; -minute = [0-5]?[0-9]; -minutelz = [0-5][0-9]; -second = minute | "60"; -secondlz = minutelz | "60"; -meridian = [AaPp] "."? [Mm] "."?; -tz = [A-Za-z]{1,4} | [A-Z][a-z]+([_/][A-Z][a-z]+)+; -tzcorrection = [+-] hour24 ":"? minutelz?; - -month = "0"? [0-9] | "1"[0-2]; -day = [0-2]?[0-9] | "3"[01]; -year = [0-9]{1,4}; -year2 = [0-9]{2}; -year4 = [0-9]{4}; - -dayofyear = "00"[1-9] | "0"[1-9][0-9] | [1-2][0-9][0-9] | "3"[0-5][0-9] | "36"[0-6]; -weekofyear = "0"[1-9] | [1-4][0-9] | "5"[0-3]; - -monthlz = "0" [1-9] | "1" [0-2]; -daylz = "0" [1-9] | [1-2][0-9] | "3" [01]; - -dayfull = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday'; -dayabbr = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun'; -daytext = dayfull | dayabbr; - -monthfull = 'january' | 'february' | 'march' | 'april' | 'may' | 'june' | 'july' | 'august' | 'september' | 'october' | 'november' | 'december'; -monthabbr = 'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'sept' | 'oct' | 'nov' | 'dec'; -monthroman = "I" | "II" | "III" | "IV" | "V" | "VI" | "VII" | "VIII" | "IX" | "X" | "XI" | "XII"; -monthtext = monthfull | monthabbr | monthroman; - -/* Time formats */ -timetiny12 = hour12 space? meridian; -timeshort12 = hour12[:.]minutelz space? meridian; -timelong12 = hour12[:.]minute[:.]secondlz space? meridian; - -timeshort24 = hour24[:.]minute; -timelong24 = hour24[:.]minute[:.]second; -iso8601long = hour24 [:.] minute [:.] second frac; - -/* iso8601shorttz = hour24 [:] minutelz space? (tzcorrection | tz); */ -iso8601normtz = hour24 [:.] minute [:.] secondlz space? (tzcorrection | tz); -/* iso8601longtz = hour24 [:] minute [:] secondlz frac space? (tzcorrection | tz); */ - -gnunocolon = hour24lz minutelz; -/* gnunocolontz = hour24lz minutelz space? (tzcorrection | tz); */ -iso8601nocolon = hour24lz minutelz secondlz; -/* iso8601nocolontz = hour24lz minutelz secondlz space? (tzcorrection | tz); */ - -/* Date formats */ -americanshort = month "/" day; -american = month "/" day "/" year; -iso8601dateslash = year4 "/" monthlz "/" daylz "/"?; -dateslash = year4 "/" month "/" day; -gnudateshort = year "-" month "-" day; -iso8601date = year4 "-" monthlz "-" daylz; -pointeddate = day "." month "." year; -datefull = day ([ -.])* monthtext ([ -.])* year; -datenoday = monthtext ([ -.])* year4; -datenodayrev = year4 ([ -.])* monthtext; -datetextual = monthtext ([ -.])* day [,.stndrh ]* year; -datenoyear = monthtext ([ -.])* day [,.stndrh ]*; -datenoyearrev = day ([ -.])* monthtext; -datenocolon = year4 monthlz daylz; - -/* Special formats */ -soap = year4 "-" monthlz "-" daylz "T" hour24lz ":" minutelz ":" secondlz frac tzcorrection; -xmlrpc = year4 monthlz daylz "T" hour24 ":" minutelz ":" secondlz; -xmlrpcnocolon = year4 monthlz daylz 't' hour24 minutelz secondlz; -wddx = year4 "-" monthlz "-" daylz "T" hour24 ":" minutelz ":" secondlz; -pgydotd = year4 "."? dayofyear; -pgtextshort = monthabbr "-" daylz "-" year; -pgtextreverse = year "-" monthabbr "-" daylz; -isoweekday = year4 "W" weekofyear [0-7]; -isoweek = year4 "W" weekofyear; - -/* Common Log Format: 10/Oct/2000:13:55:36 -0700 */ -clf = day "/" monthabbr "/" year4 ":" hour24lz ":" minutelz ":" secondlz space tzcorrection; - -/* Timestamp format: @1126396800 */ -timestamp = "@" "-"? [1-9] [0-9]*; - -/* To fix some ambiguities */ -dateshortwithtimeshort = datenoyear timeshort24; -dateshortwithtimelong = datenoyear timelong24; -dateshortwithtimelongtz = datenoyear iso8601normtz; - -/* - * Relative regexps - */ -reltextnumber = 'first'|'next'|'second'|'third'|'fourth'|'fifth'|'sixth'|'seventh'|'eight'|'ninth'|'tenth'|'eleventh'|'twelfth'|'last'|'previous'|'this'; -reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'week'|'fortnight'|'forthnight'|'month'|'year') 's'?) | dayfull; - -relnumber = ([+-]?[0-9]+); -relative = (relnumber space? reltextunit)+; -relativetext = (reltextnumber space? reltextunit)+; - -*/ - -/*!re2c - /* so that vim highlights correctly */ - "yesterday" - { - DEBUG_OUTPUT("yesterday"); - TIMELIB_INIT; - TIMELIB_HAVE_RELATIVE(); - TIMELIB_UNHAVE_TIME(); - - s->time->relative.d = -1; - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - "now" - { - DEBUG_OUTPUT("now"); - TIMELIB_INIT; - - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - "noon" - { - DEBUG_OUTPUT("noon"); - TIMELIB_INIT; - TIMELIB_UNHAVE_TIME(); - TIMELIB_HAVE_TIME(); - s->time->h = 12; - - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - "midnight" | "today" - { - DEBUG_OUTPUT("midnight | today"); - TIMELIB_INIT; - TIMELIB_UNHAVE_TIME(); - - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - "tomorrow" - { - DEBUG_OUTPUT("tomorrow"); - TIMELIB_INIT; - TIMELIB_HAVE_RELATIVE(); - TIMELIB_UNHAVE_TIME(); - - s->time->relative.d = 1; - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - timestamp - { - timelib_ull i; - - TIMELIB_INIT; - TIMELIB_HAVE_RELATIVE(); - TIMELIB_UNHAVE_DATE(); - TIMELIB_UNHAVE_TIME(); - - i = timelib_get_unsigned_nr((char **) &ptr, 24); - s->time->y = 1970; - s->time->m = 1; - s->time->d = 1; - s->time->h = s->time->i = s->time->s = 0; - s->time->f = 0.0; - s->time->relative.s += i; - s->time->is_localtime = 1; - s->time->zone_type = TIMELIB_ZONETYPE_OFFSET; - s->time->z = 0; - - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - timetiny12 | timeshort12 | timelong12 - { - DEBUG_OUTPUT("timetiny12 | timeshort12 | timelong12"); - TIMELIB_INIT; - TIMELIB_HAVE_TIME(); - s->time->h = timelib_get_nr((char **) &ptr, 2); - if (*ptr == ':' || *ptr == '.') { - s->time->i = timelib_get_nr((char **) &ptr, 2); - if (*ptr == ':' || *ptr == '.') { - s->time->s = timelib_get_nr((char **) &ptr, 2); - } - } - s->time->h += timelib_meridian((char **) &ptr, s->time->h); - TIMELIB_DEINIT; - return TIMELIB_TIME12; - } - - timeshort24 | timelong24 /* | iso8601short | iso8601norm */ | iso8601long /*| iso8601shorttz | iso8601normtz | iso8601longtz*/ - { - int tz_not_found; - DEBUG_OUTPUT("timeshort24 | timelong24 | iso8601long"); - TIMELIB_INIT; - TIMELIB_HAVE_TIME(); - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - if (*ptr == ':' || *ptr == '.') { - s->time->s = timelib_get_nr((char **) &ptr, 2); - - if (*ptr == '.') { - s->time->f = timelib_get_frac_nr((char **) &ptr, 8); - } - } - - if (*ptr != '\0') { - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); - s->errors += tz_not_found; - } - TIMELIB_DEINIT; - return TIMELIB_TIME24_WITH_ZONE; - } - - gnunocolon - { - DEBUG_OUTPUT("gnunocolon"); - TIMELIB_INIT; - switch (s->time->have_time) { - case 0: - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - s->time->s = 0; - break; - case 1: - s->time->y = timelib_get_nr((char **) &ptr, 4); - break; - default: - TIMELIB_DEINIT; - return TIMELIB_ERROR; - } - s->time->have_time++; - TIMELIB_DEINIT; - return TIMELIB_GNU_NOCOLON; - } -/* - gnunocolontz - { - DEBUG_OUTPUT("gnunocolontz"); - TIMELIB_INIT; - switch (s->time->have_time) { - case 0: - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - s->time->s = 0; - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, s->tzdb); - break; - case 1: - s->time->y = timelib_get_nr((char **) &ptr, 4); - break; - default: - TIMELIB_DEINIT; - return TIMELIB_ERROR; - } - s->time->have_time++; - TIMELIB_DEINIT; - return TIMELIB_GNU_NOCOLON_TZ; - } -*/ - iso8601nocolon /*| iso8601nocolontz*/ - { - int tz_not_found; - DEBUG_OUTPUT("iso8601nocolon"); - TIMELIB_INIT; - TIMELIB_HAVE_TIME(); - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - s->time->s = timelib_get_nr((char **) &ptr, 2); - - if (*ptr != '\0') { - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); - s->errors += tz_not_found; - } - TIMELIB_DEINIT; - return TIMELIB_ISO_NOCOLON; - } - - americanshort | american - { - DEBUG_OUTPUT("americanshort | american"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->m = timelib_get_nr((char **) &ptr, 2); - s->time->d = timelib_get_nr((char **) &ptr, 2); - if (*ptr == '/') { - s->time->y = timelib_get_nr((char **) &ptr, 4); - TIMELIB_PROCESS_YEAR(s->time->y); - } - TIMELIB_DEINIT; - return TIMELIB_AMERICAN; - } - - iso8601date | iso8601dateslash | dateslash - { - DEBUG_OUTPUT("iso8601date | iso8601dateslash | dateslash"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->m = timelib_get_nr((char **) &ptr, 2); - s->time->d = timelib_get_nr((char **) &ptr, 2); - TIMELIB_DEINIT; - return TIMELIB_ISO_DATE; - } - - gnudateshort - { - DEBUG_OUTPUT("gnudateshort"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->m = timelib_get_nr((char **) &ptr, 2); - s->time->d = timelib_get_nr((char **) &ptr, 2); - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_ISO_DATE; - } - - datefull - { - DEBUG_OUTPUT("datefull"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->m = timelib_get_month((char **) &ptr); - s->time->y = timelib_get_nr((char **) &ptr, 4); - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_DATE_FULL; - } - - pointeddate - { - DEBUG_OUTPUT("pointed date"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->m = timelib_get_nr((char **) &ptr, 2); - s->time->y = timelib_get_nr((char **) &ptr, 4); - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_DATE_FULL_POINTED; - } - - datenoday - { - DEBUG_OUTPUT("datenoday"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->m = timelib_get_month((char **) &ptr); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->d = 1; - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_DATE_NO_DAY; - } - - datenodayrev - { - DEBUG_OUTPUT("datenodayrev"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->m = timelib_get_month((char **) &ptr); - s->time->d = 1; - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_DATE_NO_DAY; - } - - datetextual | datenoyear - { - DEBUG_OUTPUT("datetextual | datenoyear"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->m = timelib_get_month((char **) &ptr); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->y = timelib_get_nr((char **) &ptr, 4); - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_DATE_TEXT; - } - - datenoyearrev - { - DEBUG_OUTPUT("datenoyearrev"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->m = timelib_get_month((char **) &ptr); - TIMELIB_DEINIT; - return TIMELIB_DATE_TEXT; - } - - datenocolon - { - DEBUG_OUTPUT("datenocolon"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->m = timelib_get_nr((char **) &ptr, 2); - s->time->d = timelib_get_nr((char **) &ptr, 2); - TIMELIB_DEINIT; - return TIMELIB_DATE_NOCOLON; - } - - xmlrpc | xmlrpcnocolon | soap | wddx - { - int tz_not_found; - DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx"); - TIMELIB_INIT; - TIMELIB_HAVE_TIME(); - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->m = timelib_get_nr((char **) &ptr, 2); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - s->time->s = timelib_get_nr((char **) &ptr, 2); - if (*ptr == '.') { - s->time->f = timelib_get_frac_nr((char **) &ptr, 9); - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); - s->errors += tz_not_found; - } - TIMELIB_DEINIT; - return TIMELIB_XMLRPC_SOAP; - } - - pgydotd - { - DEBUG_OUTPUT("pgydotd"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->d = timelib_get_nr((char **) &ptr, 3); - s->time->m = 1; - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_PG_YEARDAY; - } - - isoweekday - { - timelib_sll w, d; - DEBUG_OUTPUT("isoweekday"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - TIMELIB_HAVE_RELATIVE(); - - s->time->y = timelib_get_nr((char **) &ptr, 4); - w = timelib_get_nr((char **) &ptr, 2); - d = timelib_get_nr((char **) &ptr, 1); - s->time->m = 1; - s->time->d = 1; - s->time->relative.d = timelib_daynr_from_weeknr(s->time->y, w, d); - - TIMELIB_DEINIT; - return TIMELIB_ISO_WEEK; - } - - isoweek - { - timelib_sll w, d; - DEBUG_OUTPUT("isoweek"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - TIMELIB_HAVE_RELATIVE(); - - s->time->y = timelib_get_nr((char **) &ptr, 4); - w = timelib_get_nr((char **) &ptr, 2); - d = 1; - s->time->m = 1; - s->time->d = 1; - s->time->relative.d = timelib_daynr_from_weeknr(s->time->y, w, d); - - TIMELIB_DEINIT; - return TIMELIB_ISO_WEEK; - } - - pgtextshort - { - DEBUG_OUTPUT("pgtextshort"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->m = timelib_get_month((char **) &ptr); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->y = timelib_get_nr((char **) &ptr, 4); - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_PG_TEXT; - } - - pgtextreverse - { - DEBUG_OUTPUT("pgtextreverse"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->m = timelib_get_month((char **) &ptr); - s->time->d = timelib_get_nr((char **) &ptr, 2); - TIMELIB_PROCESS_YEAR(s->time->y); - TIMELIB_DEINIT; - return TIMELIB_PG_TEXT; - } - - clf - { - int tz_not_found; - DEBUG_OUTPUT("clf"); - TIMELIB_INIT; - TIMELIB_HAVE_TIME(); - TIMELIB_HAVE_DATE(); - s->time->d = timelib_get_nr((char **) &ptr, 2); - s->time->m = timelib_get_month((char **) &ptr); - s->time->y = timelib_get_nr((char **) &ptr, 4); - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - s->time->s = timelib_get_nr((char **) &ptr, 2); - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); - s->errors += tz_not_found; - TIMELIB_DEINIT; - return TIMELIB_CLF; - } - - year4 - { - DEBUG_OUTPUT("year4"); - TIMELIB_INIT; - s->time->y = timelib_get_nr((char **) &ptr, 4); - TIMELIB_DEINIT; - return TIMELIB_CLF; - } - - ago - { - DEBUG_OUTPUT("ago"); - TIMELIB_INIT; - s->time->relative.y = 0 - s->time->relative.y; - s->time->relative.m = 0 - s->time->relative.m; - s->time->relative.d = 0 - s->time->relative.d; - s->time->relative.h = 0 - s->time->relative.h; - s->time->relative.i = 0 - s->time->relative.i; - s->time->relative.s = 0 - s->time->relative.s; - s->time->relative.weekday = 0 - s->time->relative.weekday; - TIMELIB_DEINIT; - return TIMELIB_AGO; - } - - relativetext - { - timelib_sll i; - int behavior; - DEBUG_OUTPUT("relativetext"); - TIMELIB_INIT; - TIMELIB_HAVE_RELATIVE(); - - while(*ptr) { - i = timelib_get_relative_text((char **) &ptr, &behavior); - timelib_eat_spaces((char **) &ptr); - timelib_set_relative((char **) &ptr, i, behavior, s); - } - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - dayfull - { - const timelib_relunit* relunit; - DEBUG_OUTPUT("dayfull"); - TIMELIB_INIT; - TIMELIB_HAVE_RELATIVE(); - TIMELIB_HAVE_WEEKDAY_RELATIVE(); - TIMELIB_UNHAVE_TIME(); - - relunit = timelib_lookup_relunit((char**) &ptr); - s->time->relative.weekday = relunit->multiplier; - s->time->relative.weekday_behavior = 1; - - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - dayabbr - { - DEBUG_OUTPUT("dayabbr"); - goto std; - } - - tzcorrection | tz - { - int tz_not_found; - DEBUG_OUTPUT("tzcorrection | tz"); - TIMELIB_INIT; - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); - s->errors += tz_not_found; - TIMELIB_DEINIT; - return TIMELIB_TIMEZONE; - } - - dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz - { - int tz_not_found; - DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz"); - TIMELIB_INIT; - TIMELIB_HAVE_DATE(); - s->time->m = timelib_get_month((char **) &ptr); - s->time->d = timelib_get_nr((char **) &ptr, 2); - - TIMELIB_HAVE_TIME(); - s->time->h = timelib_get_nr((char **) &ptr, 2); - s->time->i = timelib_get_nr((char **) &ptr, 2); - if (*ptr == ':') { - s->time->s = timelib_get_nr((char **) &ptr, 2); - - if (*ptr == '.') { - s->time->f = timelib_get_frac_nr((char **) &ptr, 8); - } - } - - if (*ptr != '\0') { - s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); - s->errors += tz_not_found; - } - TIMELIB_DEINIT; - return TIMELIB_SHORTDATE_WITH_TIME; - } - - relative - { - timelib_ull i; - DEBUG_OUTPUT("relative"); - TIMELIB_INIT; - TIMELIB_HAVE_RELATIVE(); - - while(*ptr) { - i = timelib_get_unsigned_nr((char **) &ptr, 24); - timelib_eat_spaces((char **) &ptr); - timelib_set_relative((char **) &ptr, i, 0, s); - } - TIMELIB_DEINIT; - return TIMELIB_RELATIVE; - } - - [ .,] - { - goto std; - } - - "\000"|"\n" - { - s->pos = cursor; s->line++; - goto std; - } - - any - { -/* printf("unexpected character: #%d, %c ", *s->tok, *s->tok); */ - s->errors++; - goto std; - } -*/ -} - -/*!max:re2c */ - -timelib_time* timelib_strtotime(char *s, int *errors, timelib_tzdb *tzdb) -{ - Scanner in; - int t; - - memset(&in, 0, sizeof(in)); - in.str = malloc(strlen(s) + YYMAXFILL); - memset(in.str, 0, strlen(s) + YYMAXFILL); - memcpy(in.str, s, strlen(s)); - in.lim = in.str + strlen(s) + YYMAXFILL; - in.cur = in.str; - in.time = timelib_time_ctor(); - in.time->y = -1; - in.time->d = -1; - in.time->m = -1; - in.time->h = -1; - in.time->i = -1; - in.time->s = -1; - in.time->f = -1; - in.time->z = -1; - in.time->dst = -1; - in.errors = 0; - in.tzdb = tzdb; - - do { - t = scan(&in); -#ifdef DEBUG_PARSER - printf("%d\n", t); -#endif - } while(t != EOI); - - free(in.str); - *errors = in.errors; - return in.time; -} - -void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options) -{ - if (!(options && TIMELIB_OVERRIDE_TIME) && parsed->have_date && !parsed->have_time) { - parsed->h = 0; - parsed->i = 0; - parsed->s = 0; - parsed->f = 0; - } - if (parsed->y == -1) parsed->y = now->y != -1 ? now->y : 0; - if (parsed->d == -1) parsed->d = now->d != -1 ? now->d : 0; - if (parsed->m == -1) parsed->m = now->m != -1 ? now->m : 0; - if (parsed->h == -1) parsed->h = now->h != -1 ? now->h : 0; - if (parsed->i == -1) parsed->i = now->i != -1 ? now->i : 0; - if (parsed->s == -1) parsed->s = now->s != -1 ? now->s : 0; - if (parsed->f == -1) parsed->f = now->f != -1 ? now->f : 0; - if (parsed->z == -1) parsed->z = now->z != -1 ? now->z : 0; - if (parsed->dst == -1) parsed->dst = now->dst != -1 ? now->dst : 0; - - if (!parsed->tz_abbr) { - parsed->tz_abbr = now->tz_abbr ? strdup(now->tz_abbr) : NULL; - } - if (!parsed->tz_info) { - parsed->tz_info = now->tz_info ? timelib_tzinfo_clone(now->tz_info) : NULL; - } - if (parsed->zone_type == 0 && now->zone_type != 0) { - parsed->zone_type = now->zone_type; -/* parsed->tz_abbr = now->tz_abbr ? strdup(now->tz_abbr) : NULL; - parsed->tz_info = now->tz_info ? timelib_tzinfo_clone(now->tz_info) : NULL; -*/ parsed->is_localtime = 1; - } -/* timelib_dump_date(parsed, 2); - timelib_dump_date(now, 2); -*/ -} - -char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst) -{ - timelib_tz_lookup_table *tp; - - tp = zone_search(abbr, gmtoffset, isdst); - if (tp) { - return (tp->full_tz_name); - } else { - return NULL; - } -} - -timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void) -{ - return timelib_timezone_lookup; -} - -#ifdef DEBUG_PARSER_STUB -int main(void) -{ - timelib_time time = timelib_strtotime("May 12"); - - printf ("%04d-%02d-%02d %02d:%02d:%02d.%-5d %+04d %1d", - time.y, time.m, time.d, time.h, time.i, time.s, time.f, time.z, time.dst); - if (time.have_relative) { - printf ("%3dY %3dM %3dD / %3dH %3dM %3dS", - time.relative.y, time.relative.m, time.relative.d, time.relative.h, time.relative.i, time.relative.s); - } - if (time.have_weekday_relative) { - printf (" / %d", time.relative.weekday); - } - if (time.have_weeknr_day) { - printf(" / %dW%d", time.relative.weeknr_day.weeknr, time.relative.weeknr_day.dayofweek); - } - return 0; -} -#endif - -/* - * vim: syntax=c - */