/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* zdump 7.24
* Taken from elsie.nci.nih.gov to replace the existing Solaris zdump,
* which was based on an earlier version of the elsie code.
*
* For zdump 7.24, the following changes were made to the elsie code:
* locale/textdomain/messages to match existing Solaris style.
* Solaris verbose mode is documented to display the current time first.
* cstyle cleaned code.
* removed old locale/textdomain code.
*/
/*
* This code has been made independent of the rest of the time
* conversion package to increase confidence in the verification it provides.
* You can use this code to help in verifying other implementations.
*/
#include "stdio.h" /* for stdout, stderr, perror */
#include "string.h" /* for strcpy */
#include "time.h" /* for struct tm */
#include "stdlib.h" /* for exit, malloc, atoi */
#include "locale.h" /* for setlocale, textdomain */
#include "libintl.h"
#include <ctype.h>
#include "tzfile.h" /* for defines */
#include <limits.h>
#ifndef ZDUMP_LO_YEAR
#endif /* !defined ZDUMP_LO_YEAR */
#ifndef ZDUMP_HI_YEAR
#endif /* !defined ZDUMP_HI_YEAR */
#ifndef MAX_STRING_LENGTH
#endif /* !defined MAX_STRING_LENGTH */
#ifndef TRUE
#endif /* !defined TRUE */
#ifndef FALSE
#define FALSE 0
#endif /* !defined FALSE */
#ifndef isleap_sum
/*
* See tzfile.h for details on isleap_sum.
*/
#endif /* !defined isleap_sum */
#ifndef SECSPERDAY
#endif
#ifndef GNUC_or_lint
#ifdef lint
#define GNUC_or_lint
#else /* !defined lint */
#ifdef __GNUC__
#define GNUC_or_lint
#endif /* defined __GNUC__ */
#endif /* !defined lint */
#endif /* !defined GNUC_or_lint */
#ifndef INITIALIZE
#ifdef GNUC_or_lint
#define INITIALIZE(x) ((x) = 0)
#else /* !defined GNUC_or_lint */
#define INITIALIZE(x)
#endif /* !defined GNUC_or_lint */
#endif /* !defined INITIALIZE */
static char *progname;
static int warned;
static void abbrok(const char *, const char *);
static void setabsolutes(void);
static void usage(void);
static const char *tformat(void);
#ifndef TYPECHECK
#else /* !defined TYPECHECK */
static struct tm *
{
register time_t t;
}
}
return (tmp);
}
#endif /* !defined TYPECHECK */
static void
{
register const char *cp;
int error = 0;
if (warned)
return;
++cp;
"abbreviation \"%s\" has fewer than 3 alphabetics\n"),
error = 1;
"abbreviation \"%s\" has more than 6 characters\n"),
error = 1;
} else if (*cp != '\0') {
"abbreviation \"%s\" has characters other than "
error = 1;
}
if (error)
}
int
int argc;
char *argv[];
{
register int i;
register int c;
register int vflag;
register char *cutarg;
time_t t;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
for (i = 1; i < argc; ++i)
}
vflag = 0;
if (c == 'v')
vflag = 1;
if (c != EOF ||
usage();
/* NOTREACHED */
}
if (vflag) {
long lo;
long hi;
char dummy;
} else {
}
}
setabsolutes();
}
longest = 0;
(void) unsetenv("TZ");
}
}
if (!vflag) {
continue;
}
#if defined(sun)
/*
* We show the current time first, probably because we froze
* the behavior of zdump some time ago and then it got
* changed.
*/
#endif
t = absolute_min_time;
t += SECSPERHOUR * HOURSPERDAY;
if (t < cutlotime)
t = cutlotime;
tmp = my_localtime(&t);
}
for (;;) {
if (t >= cuthitime)
break;
/* check if newt will overrun maximum time_t value */
break;
break;
sizeof (buf) - 1);
}
}
t = newt;
}
t = absolute_max_time;
#if defined(sun)
t -= SECSPERHOUR * HOURSPERDAY;
#else /* !defined(sun) */
t -= SECSPERHOUR * HOURSPERDAY;
t += SECSPERHOUR * HOURSPERDAY;
#endif /* !defined(sun) */
}
}
return (EXIT_SUCCESS);
}
static void
{
#if defined(sun)
#else
/*
* time_t is floating.
*/
if (sizeof (time_t) == sizeof (float)) {
} else if (sizeof (time_t) == sizeof (double)) {
} else {
"system with floating time_t other than float "
"or double\n"), progname);
}
} else
/*CONSTANTCONDITION*/
if (0 > (time_t)-1) {
/*
* time_t is signed.
*/
continue;
} else {
/*
* time_t is unsigned.
*/
absolute_min_time = 0;
}
#endif
}
static time_t
yeartot(y)
const long y;
{
register long myy;
register long seconds;
register time_t t;
myy = EPOCH_YEAR;
t = 0;
while (myy != y) {
if (myy < y) {
++myy;
if (t > absolute_max_time - seconds) {
t = absolute_max_time;
break;
}
t += seconds;
} else {
--myy;
if (t < absolute_min_time + seconds) {
t = absolute_min_time;
break;
}
t -= seconds;
}
}
return (t);
}
static time_t
char *name;
{
time_t t;
long diff;
}
for (;;) {
if (diff < 2)
break;
t = lot;
t += diff / 2;
if (t <= lot)
++t;
else if (t >= hit)
--t;
tmp = my_localtime(&t);
lot = t;
} else hit = t;
}
return (hit);
}
/*
* Thanks to Paul Eggert for logic used in delta.
*/
static long
{
register long result;
register int tmy;
result = 0;
result *= HOURSPERDAY;
result *= MINSPERHOUR;
result *= SECSPERMIN;
return (result);
}
static void
char *zone;
time_t t;
int v;
{
if (v) {
} else {
(void) printf(" UTC");
}
(void) printf(" = ");
}
tmp = my_localtime(&t);
if (v) {
#ifdef TM_GMTOFF
#endif /* defined TM_GMTOFF */
}
}
(void) printf("\n");
}
static char *
{
register char *result;
static char nada;
return (&nada);
}
/*
* The code below can fail on certain theoretical systems;
* it works on all known real-world systems as of 2004-12-30.
*/
static const char *
tformat()
{
#if defined(sun)
/* time_t is signed long */
return ("%ld");
#else
/*CONSTANTCONDITION*/
/*CONSTANTCONDITION*/
if (sizeof (time_t) > sizeof (double))
return ("%Lg");
return ("%g");
}
/*CONSTANTCONDITION*/
/*CONSTANTCONDITION*/
if (sizeof (time_t) > sizeof (long))
return ("%lld");
/*CONSTANTCONDITION*/
if (sizeof (time_t) > sizeof (int))
return ("%ld");
return ("%d");
}
/*CONSTANTCONDITION*/
if (sizeof (time_t) > sizeof (unsigned long))
return ("%llu");
/*CONSTANTCONDITION*/
if (sizeof (time_t) > sizeof (unsigned int))
return ("%lu");
return ("%u");
#endif
}
static void
{
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
register const char *wn;
register const char *mn;
register int lead;
register int trail;
(void) printf("NULL");
return;
}
/*
* The packaged versions of localtime and gmtime never put out-of-range
* values in tm_wday or tm_mon, but since this code might be compiled
* with other (perhaps experimental) versions, paranoia is in order.
*/
wn = "???";
mn = "???";
(void) printf("%.3s %.3s%3d %.2d:%.2d:%.2d ",
--lead;
++lead;
}
if (lead == 0)
else
}
static void
usage()
{
"%s: [ --version ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n"),
progname);
/* NOTREACHED */
}