/*
* tclClock.c --
*
* Contains the time and date related commands. This code
* is derived from the time and date facilities of TclX,
* by Mark Diekhans and Karl Lehenbauer.
*
* Copyright 1991-1995 Karl Lehenbauer and Mark Diekhans.
* Copyright (c) 1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tclClock.c 1.20 96/07/23 16:14:45
*/
#include "tcl.h"
#include "tclInt.h"
#include "tclPort.h"
/*
* Function prototypes for local procedures in this file:
*/
char *format));
/*
*-----------------------------------------------------------------------------
*
* Tcl_ClockCmd --
*
* This procedure is invoked to process the "clock" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*-----------------------------------------------------------------------------
*/
int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int c;
char **argPtr;
int useGMT = 0;
unsigned long clockVal;
if (argc < 2) {
return TCL_ERROR;
}
c = argv[1][0];
if (argc != 2) {
return TCL_ERROR;
}
return TCL_OK;
" format clockval ?-format string? ?-gmt boolean?",
(char *) NULL);
return TCL_ERROR;
}
return TCL_ERROR;
}
argc -= 3;
return TCL_ERROR;
}
} else {
"\": must be -format or -gmt", (char *) NULL);
return TCL_ERROR;
}
argPtr += 2;
argc -= 2;
}
if (argc != 0) {
goto wrongFmtArgs;
}
unsigned long baseClock;
long zone;
" scan dateString ?-base clockValue? ?-gmt boolean?",
(char *) NULL);
return TCL_ERROR;
}
argc -= 3;
return TCL_ERROR;
}
} else {
"\": must be -base or -gmt", (char *) NULL);
return TCL_ERROR;
}
argPtr += 2;
argc -= 2;
}
if (argc != 0) {
goto wrongScanArgs;
}
return TCL_ERROR;
} else {
baseClock = TclpGetSeconds();
}
if (useGMT) {
} else {
}
return TCL_ERROR;
}
return TCL_OK;
if (argc != 2) {
return TCL_ERROR;
}
return TCL_OK;
} else {
"\": must be clicks, format, scan, or seconds",
(char *) NULL);
return TCL_ERROR;
}
}
/*
*-----------------------------------------------------------------------------
*
* ParseTime --
*
* Given a string, produce the corresponding time_t value.
*
* Results:
* The return value is normally TCL_OK; in this case *timePtr
* will be set to the integer value equivalent to string. If
* string is improperly formed then TCL_ERROR is returned and
* an error message will be left in interp->result.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
static int
char *string;
unsigned long *timePtr;
{
char *end, *p;
unsigned long i;
/*
* Since some strtoul functions don't detect negative numbers, check
* in advance.
*/
errno = 0;
/* Empty loop body. */
}
if (*p == '+') {
p++;
}
if (end == p) {
goto badTime;
}
return TCL_ERROR;
}
end++;
}
if (*end != '\0') {
goto badTime;
}
if (*timePtr != i) {
goto badTime;
}
return TCL_OK;
return TCL_ERROR;
}
/*
*-----------------------------------------------------------------------------
*
* FormatClock --
*
* Formats a time value based on seconds into a human readable
* string.
*
* Results:
* Standard Tcl result.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
static int
unsigned long clockVal; /* Time in seconds. */
int useGMT; /* Boolean */
char *format; /* Format string */
{
int bufSize;
char *p;
#ifdef TCL_USE_TIMEZONE_VAR
int savedTimeZone;
char *savedTZEnv;
#endif
#ifdef HAVE_TZSET
/*
* Some systems forgot to call tzset in localtime, make sure its done.
*/
static int calledTzset = 0;
if (!calledTzset) {
tzset();
calledTzset = 1;
}
#endif
#ifdef TCL_USE_TIMEZONE_VAR
/*
* This is a horrible kludge for systems not having the timezone in
* struct tm. No matter what was specified, they use the global time
* zone. (Thanks Solaris).
*/
if (useGMT) {
char *varValue;
} else {
savedTZEnv = NULL;
}
timezone = 0;
tzset();
}
#endif
/*
* Make a guess at the upper limit on the substituted string size
* based on the number of percents in the string.
*/
if (*p == '%') {
bufSize += 40;
} else {
bufSize++;
}
}
timeDataPtr) == 0) {
return TCL_ERROR;
}
#ifdef TCL_USE_TIMEZONE_VAR
if (useGMT) {
if (savedTZEnv != NULL) {
} else {
}
tzset();
}
#endif
return TCL_OK;
}