diff options
author | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:34:42 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:34:42 (GMT) |
commit | d17c6cb7e751f5a0c41dc3c759ab5d62ef034aa0 (patch) | |
tree | 57c02c1cfe4b531aa16c74be7981a79e14d25c06 | |
parent | 33212a94d6d0cfef22ff3aced4795edba0932540 (diff) | |
download | tcl-d17c6cb7e751f5a0c41dc3c759ab5d62ef034aa0.zip tcl-d17c6cb7e751f5a0c41dc3c759ab5d62ef034aa0.tar.gz tcl-d17c6cb7e751f5a0c41dc3c759ab5d62ef034aa0.tar.bz2 |
clock scan almost ready (currently test-case covered tokens only), test cases passed; todo - check other tokens from "clock.tcl"
-rw-r--r-- | generic/tclClockFmt.c | 54 | ||||
-rw-r--r-- | generic/tclDate.h | 16 |
2 files changed, 60 insertions, 10 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c index a10d05d..c8158cc 100644 --- a/generic/tclClockFmt.c +++ b/generic/tclClockFmt.c @@ -748,7 +748,7 @@ ClockScnToken_amPmInd_Proc(ClockFmtScnCmdArgs *opts, amPmObj[0] = ClockMCGet(opts, MCLIT_AM); amPmObj[1] = ClockMCGet(opts, MCLIT_PM); - if (amPmObj[0] == NULL || amPmObj == NULL) { + if (amPmObj[0] == NULL || amPmObj[1] == NULL) { return TCL_ERROR; } @@ -768,6 +768,44 @@ ClockScnToken_amPmInd_Proc(ClockFmtScnCmdArgs *opts, } static int +ClockScnToken_LocaleERA_Proc(ClockFmtScnCmdArgs *opts, + DateInfo *info, ClockScanToken *tok) +{ + ClockClientData *dataPtr = opts->clientData; + + int ret, val; + int minLen, maxLen; + Tcl_Obj *eraObj[6]; + + DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen); + + eraObj[0] = ClockMCGet(opts, MCLIT_BCE); + eraObj[1] = ClockMCGet(opts, MCLIT_CE); + eraObj[2] = dataPtr->mcLiterals[MCLIT_BCE2]; + eraObj[3] = dataPtr->mcLiterals[MCLIT_CE2]; + eraObj[4] = dataPtr->mcLiterals[MCLIT_BCE3]; + eraObj[5] = dataPtr->mcLiterals[MCLIT_CE3]; + + if (eraObj[0] == NULL || eraObj[1] == NULL) { + return TCL_ERROR; + } + + ret = ObjListSearch(opts, info, &val, eraObj, 6, + minLen, maxLen); + if (ret != TCL_OK) { + return ret; + } + + if (val & 1) { + yydate.era = CE; + } else { + yydate.era = BCE; + } + + return TCL_OK; +} + +static int ClockScnToken_LocaleListMatcher_Proc(ClockFmtScnCmdArgs *opts, DateInfo *info, ClockScanToken *tok) { @@ -782,7 +820,9 @@ ClockScnToken_LocaleListMatcher_Proc(ClockFmtScnCmdArgs *opts, return ret; } - *(time_t *)(((char *)info) + tok->map->offs) = val; + if (tok->map->offs > 0) { + *(time_t *)(((char *)info) + tok->map->offs) = val; + } return TCL_OK; } @@ -931,9 +971,14 @@ static const char *ScnSTokenWrapMapIndex[2] = { }; static const char *ScnETokenMapIndex = - ""; + "Ey"; static ClockScanTokenMap ScnETokenMap[] = { - {0, 0, 0} + /* %EE */ + {CTOKT_PARSER, 0, 0, 0, 0, TclOffset(DateInfo, date.year), + ClockScnToken_LocaleERA_Proc, (void *)MCLIT_LOCALE_NUMERALS}, + /* %Ey */ + {CTOKT_PARSER, 0, 0, 0, 0, 0, /* currently no capture, parse only token */ + ClockScnToken_LocaleListMatcher_Proc, (void *)MCLIT_LOCALE_NUMERALS}, }; static const char *ScnETokenWrapMapIndex[2] = { "", @@ -1450,7 +1495,6 @@ ClockScan( } } } - yydate.era = CE; } } diff --git a/generic/tclDate.h b/generic/tclDate.h index e78d4f8..020fa64 100644 --- a/generic/tclDate.h +++ b/generic/tclDate.h @@ -58,8 +58,8 @@ typedef enum ClockLiteral { LIT__NIL, LIT__DEFAULT_FORMAT, - LIT_SYSTEM, LIT_CURRENT, - LIT_BCE, LIT_C, LIT_CE, + LIT_SYSTEM, LIT_CURRENT, LIT_C, + LIT_BCE, LIT_CE, LIT_DAYOFMONTH, LIT_DAYOFWEEK, LIT_DAYOFYEAR, LIT_ERA, LIT_GMT, LIT_GREGORIAN, LIT_INTEGER_VALUE_TOO_LARGE, @@ -80,8 +80,8 @@ typedef enum ClockLiteral { #define CLOCK_LITERAL_ARRAY(litarr) static const char *const litarr[] = { \ "", \ "%a %b %d %H:%M:%S %Z %Y", \ - "system", "current", \ - "BCE", "C", "CE", \ + "system", "current", "C", \ + "BCE", "CE", \ "dayOfMonth", "dayOfWeek", "dayOfYear", \ "era", ":GMT", "gregorian", \ "integer value too large to represent", \ @@ -107,6 +107,9 @@ typedef enum ClockMsgCtLiteral { MCLIT_MONTHS_FULL, MCLIT_MONTHS_ABBREV, MCLIT_DAYS_OF_WEEK_FULL, MCLIT_DAYS_OF_WEEK_ABBREV, MCLIT_AM, MCLIT_PM, + MCLIT_BCE, MCLIT_CE, + MCLIT_BCE2, MCLIT_CE2, + MCLIT_BCE3, MCLIT_CE3, MCLIT_LOCALE_NUMERALS, MCLIT__END } ClockMsgCtLiteral; @@ -115,7 +118,10 @@ typedef enum ClockMsgCtLiteral { pref "", \ pref "MONTHS_FULL", pref "MONTHS_ABBREV", \ pref "DAYS_OF_WEEK_FULL", pref "DAYS_OF_WEEK_ABBREV", \ - pref "AM", pref "PM", \ + pref "AM", pref "PM", \ + pref "BCE", pref "CE", \ + pref "b.c.e.", pref "c.e.", \ + pref "b.c.", pref "a.d.", \ pref "LOCALE_NUMERALS", \ } |