summaryrefslogtreecommitdiffstats
path: root/generic/tclClock.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclClock.c')
-rw-r--r--generic/tclClock.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c
index cf52673..8e176b6 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -149,18 +149,13 @@ struct ClockCommand {
const char *name; /* The tail of the command name. The full name
* is "::tcl::clock::<name>". When NULL marks
* the end of the table. */
- Tcl_ObjCmdProc *objCmdProc; /* Function that implements the command. This
+ Tcl_ObjCmdProc *objCmdProc; /* Function that implements the command. This
* will always have the ClockClientData sent
* to it, but may well ignore this data. */
};
static const struct ClockCommand clockCommands[] = {
- { "add", ClockAddObjCmd },
- { "clicks", ClockClicksObjCmd },
{ "getenv", ClockGetenvObjCmd },
- { "microseconds", ClockMicrosecondsObjCmd },
- { "milliseconds", ClockMillisecondsObjCmd },
- { "seconds", ClockSecondsObjCmd },
{ "format", ClockFormatObjCmd },
{ "scan", ClockScanObjCmd },
{ "configure", ClockConfigureObjCmd },
@@ -203,6 +198,19 @@ TclClockInit(
ClockClientData *data;
int i;
+ /* Structure of the 'clock' ensemble */
+
+ static const EnsembleImplMap clockImplMap[] = {
+ {"add", NULL, TclCompileBasicMin1ArgCmd, NULL, NULL, 0},
+ {"clicks", ClockClicksObjCmd, TclCompileClockClicksCmd, NULL, NULL, 0},
+ {"format", NULL, TclCompileBasicMin1ArgCmd, NULL, NULL, 0},
+ {"microseconds", ClockMicrosecondsObjCmd, TclCompileClockReadingCmd, NULL, INT2PTR(1), 0},
+ {"milliseconds", ClockMillisecondsObjCmd, TclCompileClockReadingCmd, NULL, INT2PTR(2), 0},
+ {"scan", NULL, TclCompileBasicMin1ArgCmd, NULL, NULL , 0},
+ {"seconds", ClockSecondsObjCmd, TclCompileClockReadingCmd, NULL, INT2PTR(3), 0},
+ {NULL, NULL, NULL, NULL, NULL, 0}
+ };
+
/*
* Safe interps get [::clock] as alias to a master, so do not need their
* own copies of the support routines.
@@ -250,6 +258,7 @@ TclClockInit(
/*
* Install the commands.
+ * TODO - Let Tcl_MakeEnsemble do this?
*/
#define TCL_CLOCK_PREFIX_LEN 14 /* == strlen("::tcl::clock::") */
@@ -260,6 +269,10 @@ TclClockInit(
Tcl_CreateObjCommand(interp, cmdName, clockCmdPtr->objCmdProc, data,
ClockDeleteCmdProc);
}
+
+ /* Make the clock ensemble */
+
+ TclMakeEnsemble(interp, "clock", clockImplMap);
}
/*
@@ -1991,7 +2004,7 @@ ConvertUTCToLocal(
if (ConvertUTCToLocalUsingTable(interp, fields, rowc, rowv,
dataPtr->UTC2Local.rangesVal) != TCL_OK) {
return TCL_ERROR;
- }
+ }
}
/* Cache the last conversion */
@@ -2563,9 +2576,9 @@ GetJulianDayFromEraYearMonthDay(
* See above bug for details. The casts are necessary.
*/
if (ym1 >= 0)
- ym1o4 = ym1 / 4;
+ ym1o4 = ym1 / 4;
else {
- ym1o4 = - (int) (((unsigned int) -ym1) / 4);
+ ym1o4 = - (int) (((unsigned int) -ym1) / 4);
}
#endif
if (ym1 % 4 < 0) {
@@ -2982,7 +2995,7 @@ ClockParseFmtScnArgs(
ClockFmtScnCmdArgs *opts, /* Result vector: format, locale, timezone... */
TclDateFields *date, /* Extracted date-time corresponding base
* (by scan or add) resp. clockval (by format) */
- int objc, /* Parameter count */
+ int objc, /* Parameter count */
Tcl_Obj *const objv[], /* Parameter vector */
int flags /* Flags, differentiates between format, scan, add */
) {
@@ -3018,7 +3031,7 @@ ClockParseFmtScnArgs(
Tcl_WideInt num;
if (TclGetWideIntFromObj(NULL, objv[i], &num) == TCL_OK) {
continue;
- }
+ }
}
/* get option */
if (Tcl_GetIndexFromObj(interp, objv[i], options,
@@ -3054,10 +3067,10 @@ ClockParseFmtScnArgs(
case CLC_ARGS_BASE:
if ( !(flags & (CLC_SCN_ARGS)) ) {
goto badOptionMsg;
- }
+ }
opts->baseObj = objv[i+1];
break;
- }
+ }
saw |= (1 << optionIndex);
}
@@ -3117,10 +3130,10 @@ ClockParseFmtScnArgs(
i = 1;
goto badOption;
}
- /*
+ /*
* seconds could be an unsigned number that overflowed. Make sure
* that it isn't.
- */
+ */
if (opts->baseObj->typePtr == &tclBignumType) {
Tcl_SetObjResult(interp, dataPtr->literals[LIT_INTEGER_VALUE_TOO_LARGE]);
@@ -4029,14 +4042,14 @@ ClockSecondsObjCmd(
static unsigned long
TzsetGetEpoch(void)
{
- static char* tzWas = INT2PTR(-1); /* Previous value of TZ, protected by
- * clockMutex. */
+ static char* tzWas = INT2PTR(-1); /* Previous value of TZ, protected by
+ * clockMutex. */
static long tzLastRefresh = 0; /* Used for latency before next refresh */
static unsigned long tzWasEpoch = 0; /* Epoch, signals that TZ changed */
static unsigned long tzEnvEpoch = 0; /* Last env epoch, for faster signaling,
that TZ changed via TCL */
- const char *tzIsNow; /* Current value of TZ */
+ const char *tzIsNow; /* Current value of TZ */
/*
* Prevent performance regression on some platforms by resolving of system time zone:
@@ -4055,7 +4068,7 @@ TzsetGetEpoch(void)
Tcl_MutexLock(&clockMutex);
tzIsNow = getenv("TCL_TZ");
if (tzIsNow == NULL) {
- tzIsNow = getenv("TZ");
+ tzIsNow = getenv("TZ");
}
if (tzIsNow != NULL && (tzWas == NULL || tzWas == INT2PTR(-1)
|| strcmp(tzIsNow, tzWas) != 0)) {
@@ -4076,8 +4089,7 @@ TzsetGetEpoch(void)
return tzWasEpoch;
}
-
-static void
+ static void
TzsetIfNecessary(void)
{
TzsetGetEpoch();