zdump.c revision 80868c5387b92f32fe0e8ea709e36cb535287e03
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* 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
#define ZDUMP_LO_YEAR (-500)
#endif /* !defined ZDUMP_LO_YEAR */
#ifndef ZDUMP_HI_YEAR
#define ZDUMP_HI_YEAR 2500
#endif /* !defined ZDUMP_HI_YEAR */
#ifndef MAX_STRING_LENGTH
#define MAX_STRING_LENGTH 1024
#endif /* !defined MAX_STRING_LENGTH */
#ifndef TRUE
#define TRUE 1
#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 time_t absolute_min_time;
static time_t absolute_max_time;
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
#define my_localtime localtime
#else /* !defined TYPECHECK */
static struct tm *
{
register time_t t;
}
}
return (tmp);
}
#endif /* !defined TYPECHECK */
static void
const char * const abbrp;
const char * const zone;
{
register const char *cp;
int error = 0;
if (warned)
return;
++cp;
/*
* TRANSLATION_NOTE
* The first %s prints for the program name (zdump),
* the second %s prints the timezone name, the third
* %s prints the timezone abbreviation (tzname[0] or
* tzname[1]).
*/
"abbreviation \"%s\" lacks alphabetic at start\n"),
error = 1;
"abbreviation \"%s\" has fewer than 3 alphabetics\n"),
error = 1;
"abbreviation \"%s\" has more than 6 alphabetics\n"),
error = 1;
}
++cp;
++cp;
}
"abbreviation \"%s\" differs from POSIX standard\n"),
error = 1;
}
if (error)
}
int
int argc;
char *argv[];
{
register int i;
register int c;
register int vflag;
register char *cutarg;
register long cutloyear = ZDUMP_LO_YEAR;
register long cuthiyear = ZDUMP_HI_YEAR;
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;
static char buf[MAX_STRING_LENGTH];
(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;
break;
if (newt <= t)
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;
char loab[MAX_STRING_LENGTH];
}
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 (eggert@twinsun.com) 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
{
static const char wday_name[][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char mon_name[][3] = {
"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 ",
#define DIVISOR 10
--lead;
++lead;
}
if (lead == 0)
else
}
static void
usage()
{
"%s: [ --version ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n"),
progname);
/* NOTREACHED */
}