diff options
author | Kevin B Kenny <kennykb@acm.org> | 2003-04-12 19:08:33 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2003-04-12 19:08:33 (GMT) |
commit | d9d5ceb548007b7defbb5645b67360bab19d188a (patch) | |
tree | 10de907612fc1a0378ac5d6c42cee184ae2785ff /generic | |
parent | 1e3d8de94601b1efb0a694e0f756a0beeeded462 (diff) | |
download | tcl-d9d5ceb548007b7defbb5645b67360bab19d188a.zip tcl-d9d5ceb548007b7defbb5645b67360bab19d188a.tar.gz tcl-d9d5ceb548007b7defbb5645b67360bab19d188a.tar.bz2 |
Implemented TIP #124 (clock clicks -microseconds and Tcl_WideInt
return values). Fixed Bug 710310 (duplicate test numbers in
clock.test). Made major changes to tclWinTime.c and related code
to improve loop filter stability.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclClock.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c index 55c3bab..d9f6a1e 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclClock.c,v 1.20 2003/02/01 21:27:55 kennykb Exp $ + * RCS: @(#) $Id: tclClock.c,v 1.21 2003/04/12 19:08:54 kennykb Exp $ */ #include "tcl.h" @@ -61,18 +61,21 @@ Tcl_ClockObjCmd (client, interp, objc, objv) Tcl_Obj *CONST *objPtr; int useGMT = 0; char *format = "%a %b %d %X %Z %Y"; + int clickType = 2; int dummy; unsigned long baseClock, clockVal; long zone; Tcl_Obj *baseObjPtr = NULL; char *scanStr; - int n; + Tcl_Time now; /* Current time */ static CONST char *switches[] = {"clicks", "format", "scan", "seconds", (char *) NULL}; enum command { COMMAND_CLICKS, COMMAND_FORMAT, COMMAND_SCAN, COMMAND_SECONDS }; + static CONST char *clicksSwitches[] = {"-milliseconds", "-microseconds", + (char*) NULL}; static CONST char *formatSwitches[] = {"-format", "-gmt", (char *) NULL}; static CONST char *scanSwitches[] = {"-base", "-gmt", (char *) NULL}; @@ -88,35 +91,36 @@ Tcl_ClockObjCmd (client, interp, objc, objv) } switch ((enum command) index) { case COMMAND_CLICKS: { /* clicks */ - int forceMilli = 0; if (objc == 3) { - format = Tcl_GetStringFromObj(objv[2], &n); - if ( ( n >= 2 ) - && ( strncmp( format, "-milliseconds", - (unsigned int) n) == 0 ) ) { - forceMilli = 1; - } else { - Tcl_AppendStringsToObj(resultPtr, - "bad switch \"", format, - "\": must be -milliseconds", (char *) NULL); + if ( Tcl_GetIndexFromObj( interp, objv[2], clicksSwitches, + "option", 0, &clickType ) + != TCL_OK ) { return TCL_ERROR; } } else if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, "?-milliseconds?"); return TCL_ERROR; } - if (forceMilli) { - /* - * We can enforce at least millisecond granularity - */ - Tcl_Time time; - Tcl_GetTime(&time); - Tcl_SetLongObj(resultPtr, - (long) (time.sec*1000 + time.usec/1000)); - } else { - Tcl_SetLongObj(resultPtr, (long) TclpGetClicks()); + switch ( clickType ) { + case 0: /* milliseconds */ + Tcl_GetTime( &now ); + Tcl_SetWideIntObj( resultPtr, + ( (Tcl_WideInt) now.sec * 1000 + + now.usec / 1000 ) ); + break; + case 1: /* microseconds */ + Tcl_GetTime( &now ); + Tcl_SetWideIntObj( resultPtr, + ( (Tcl_WideInt) now.sec * 1000000 + + now.usec ) ); + break; + case 2: /* native clicks */ + Tcl_SetWideIntObj( resultPtr, + TclpGetClicks() ); + break; } + return TCL_OK; } |