Zdump continued

Olson, Arthur David (NIH/NCI) olsona at dc37a.nci.nih.gov
Mon Nov 29 18:14:39 UTC 2004


To go along with the new version of zdump.c from the previous message, here
are changes to other files.

1. Changes to zdump.8 to document the way to set both the low and high
cutoff years and to give the defaults for the cutoffs.
2. Changes to Makefile to let you "make typecheck" as a way of checking
compilability and (some) workability on systems with variant time_t types.
3. Changes to localtime.c to make it compilable on systems where time_t is
floating and to fix days-between-two-years calculations for negative years.
4. Changes to zic.c to make it compilable on systems where time_t is
floating.

There's more to do to make stuff workable (not just compilable) on systems
with unsigned or floating time_t types.

Oh and yes: in the last message I should have mentioned that zdump has been
goosed to work on systems where localtime or gmtime return NULL.

				--ado

diff -r -c old/zdump.8 new/zdump.8
*** old/zdump.8	Tue Oct 26 17:29:31 2004
--- new/zdump.8	Mon Nov 22 10:49:25 2004
***************
*** 10,16 ****
  .B \-v
  ] [
  .B \-c
! cutoffyear ] [ zonename ... ]
  .SH DESCRIPTION
  .I Zdump
  prints the current time in each
--- 10,16 ----
  .B \-v
  ] [
  .B \-c
! [loyear,]hiyear ] [ zonename ... ]
  .SH DESCRIPTION
  .I Zdump
  prints the current time in each
***************
*** 38,45 ****
  .B isdst=0
  otherwise.
  .TP
! .BI "\-c " cutoffyear
! Cut off the verbose output near the start of the given year.
  .SH "SEE ALSO"
  newctime(3), tzfile(5), zic(8)
! .\" @(#)zdump.8	7.4
--- 38,57 ----
  .B isdst=0
  otherwise.
  .TP
! .BI "\-c " [loyear,]hiyear
! Cut off verbose output near the start of the given year(s).
! By default,
! the program cuts off verbose output near the starts of the years -500 and
2500.
! .SH LIMITATIONS
! The
! .B \-v
! option may not be used on systems with floating-point time_t values
! that are neither float nor double.
! .PP
! Time discontinuities are found by sampling the results returned by
localtime
! at twelve-hour intervals.
! This works in all real-world cases;
! one can construct artificial time zones for which this fails.
  .SH "SEE ALSO"
  newctime(3), tzfile(5), zic(8)
! .\" @(#)zdump.8	7.7
diff -r -c old/localtime.c new/localtime.c
*** old/localtime.c	Tue Oct 26 17:29:30 2004
--- new/localtime.c	Mon Nov 29 12:18:27 2004
***************
*** 1,4 ****
--- 1,13 ----
  /*
+ ** XXX--do the right thing if time_t is double and
+ ** the value fed to gmtime or localtime is very very negative or
+ ** very very positive (which causes problems with the days-and-rem logic).
+ ** Also: what of systems where time_t is unsigned
+ ** (in particular when used on date files generated on systems where
+ ** time_t is signed).
+ */
+ 
+ /*
  ** This file is in the public domain, so clarified as of
  ** 1996-06-05 by Arthur David Olson (arthur_david_olson at nih.gov).
  */
***************
*** 5,11 ****
  
  #ifndef lint
  #ifndef NOID
! static char	elsieid[] = "@(#)localtime.c	7.80";
  #endif /* !defined NOID */
  #endif /* !defined lint */
  
--- 14,20 ----
  
  #ifndef lint
  #ifndef NOID
! static char	elsieid[] = "@(#)localtime.c	7.82";
  #endif /* !defined NOID */
  #endif /* !defined lint */
  
***************
*** 1188,1194 ****
  		}
  	}
  	days = *timep / SECSPERDAY;
! 	rem = *timep % SECSPERDAY;
  #ifdef mc68k
  	if (*timep == 0x80000000) {
  		/*
--- 1197,1203 ----
  		}
  	}
  	days = *timep / SECSPERDAY;
! 	rem = *timep - ((time_t) days) * SECSPERDAY;
  #ifdef mc68k
  	if (*timep == 0x80000000) {
  		/*
***************
*** 1219,1225 ****
  	if (tmp->tm_wday < 0)
  		tmp->tm_wday += DAYSPERWEEK;
  	y = EPOCH_YEAR;
! #define LEAPS_THRU_END_OF(y)	((y) / 4 - (y) / 100 + (y) / 400)
  	while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
  		register long	newy;
  
--- 1228,1235 ----
  	if (tmp->tm_wday < 0)
  		tmp->tm_wday += DAYSPERWEEK;
  	y = EPOCH_YEAR;
! #define IPQ(i, p)	((i) / (p) - (((i) % (p)) < 0))
! #define LEAPS_THRU_END_OF(y)	(IPQ((y), 4) - IPQ((y), 100) + IPQ((y),
400))
  	while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
  		register long	newy;
  
***************
*** 1450,1456 ****
  	** assuming two's complement arithmetic.
  	** If time_t is unsigned, then (1 << bits) is just above the median.
  	*/
! 	t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
  	for ( ; ; ) {
  		(*funcp)(&t, offset, &mytm);
  		dir = tmcomp(&mytm, &yourtm);
--- 1460,1466 ----
  	** assuming two's complement arithmetic.
  	** If time_t is unsigned, then (1 << bits) is just above the median.
  	*/
! 	t = TYPE_SIGNED(time_t) ? 0 : (((unsigned long) 1) << bits);
  	for ( ; ; ) {
  		(*funcp)(&t, offset, &mytm);
  		dir = tmcomp(&mytm, &yourtm);
***************
*** 1460,1467 ****
  			if (bits < 0)
  				--t; /* may be needed if new t is minimal */
  			else if (dir > 0)
! 				t -= ((time_t) 1) << bits;
! 			else	t += ((time_t) 1) << bits;
  			continue;
  		}
  		if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
--- 1470,1477 ----
  			if (bits < 0)
  				--t; /* may be needed if new t is minimal */
  			else if (dir > 0)
! 				t -= ((long) 1) << bits;
! 			else	t += ((long) 1) << bits;
  			continue;
  		}
  		if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
diff -r -c old/Makefile new/Makefile
*** old/Makefile	Tue Oct 26 17:29:30 2004
--- new/Makefile	Mon Nov 29 12:32:25 2004
***************
*** 1,4 ****
! # @(#)Makefile	7.98
  
  # Change the line below for your time zone (after finding the zone you
want in
  # the time zone files, or adding it to a time zone file).
--- 1,4 ----
! # @(#)Makefile	7.101
  
  # Change the line below for your time zone (after finding the zone you
want in
  # the time zone files, or adding it to a time zone file).
***************
*** 91,97 ****
  #  -DHAVE_GETTEXT=1 if `gettext' works (GNU, Linux, Solaris); also see
LDLIBS
  #  -DHAVE_INCOMPATIBLE_CTIME_R=1 if your system's time.h declares
  #	ctime_r and asctime_r incompatibly with the POSIX standard (Solaris
8).
- #  -DHAVE_LONG_DOUBLE=1 if your compiler supports the `long double' type
  #  -DHAVE_SETTIMEOFDAY=0 if settimeofday does not exist (SVR0?)
  #  -DHAVE_SETTIMEOFDAY=1 if settimeofday has just 1 arg (SVR4)
  #  -DHAVE_SETTIMEOFDAY=2 if settimeofday uses 2nd arg (4.3BSD)
--- 91,96 ----
***************
*** 395,400 ****
--- 394,411 ----
  		tar cf - $(DOCS) $(SOURCES) $(MISC) *.[1-8].txt | gzip -9 >
tzcode.tar.gz
  		tar cf - $(DATA) | gzip -9 > tzdata.tar.gz
  
+ typecheck:	
+ 		make clean
+ 		make CFLAGS=-Wp,-D_TIME_T,-Dtime_t=long\\\ long
+ 		./zdump -v US/Eastern 
+ 		make clean
+ 		make CFLAGS=-Wp,-D_TIME_T,-Dtime_t=double
+ 		./zdump -v US/Eastern 
+ 		make clean
+ 		make CFLAGS=-Wp,-D_TIME_T,-Dtime_t=unsigned
+ 		./zdump -v US/Eastern 
+ 		make clean
+ 
  zonenames:	$(TDATA)
  		@$(AWK) '/^Zone/ { print $$2 } /^Link/ { print $$3 }'
$(TDATA)
  
diff -r -c old/zic.c new/zic.c
*** old/zic.c	Tue Oct 26 17:29:29 2004
--- new/zic.c	Mon Nov 29 12:11:10 2004
***************
*** 1,4 ****
! static char	elsieid[] = "@(#)zic.c	7.116";
  
  #include "private.h"
  #include "locale.h"
--- 1,4 ----
! static char	elsieid[] = "@(#)zic.c	7.117";
  
  #include "private.h"
  #include "locale.h"
***************
*** 670,685 ****
  static void
  setboundaries P((void))
  {
  	if (TYPE_SIGNED(time_t)) {
! 		min_time = ~ (time_t) 0;
! 		min_time <<= TIME_T_BITS_IN_FILE - 1;
! 		max_time = ~ (time_t) 0 - min_time;
  		if (sflag)
  			min_time = 0;
  	} else {
  		min_time = 0;
  		max_time = 2 - sflag;
! 		max_time <<= TIME_T_BITS_IN_FILE - 1;
  		--max_time;
  	}
  	min_year = TM_YEAR_BASE + gmtime(&min_time)->tm_year;
--- 670,689 ----
  static void
  setboundaries P((void))
  {
+ 	register int	i;
+ 
  	if (TYPE_SIGNED(time_t)) {
! 		min_time = -1;
! 		for (i = 0; i < TIME_T_BITS_IN_FILE - 1; ++i)
! 			min_time *= 2;
! 		max_time = -(min_time + 1);
  		if (sflag)
  			min_time = 0;
  	} else {
  		min_time = 0;
  		max_time = 2 - sflag;
! 		for (i = 0; i < TIME_T_BITS_IN_FILE - 1; ++i)
! 			max_time *= 2;
  		--max_time;
  	}
  	min_year = TM_YEAR_BASE + gmtime(&min_time)->tm_year;



More information about the tz mailing list