Update timezone code from tzcode 2013i.

Now we have Paul's support for version-3 tz files checked in, this
patch updates all the code we take (unmodified) from tzcode to version
2013i (which includes the support for generating version-3 tz files
where necessary).

Tested x86_64.

	* timezone/checktab.awk: Update from tzcode 2013i.
	* timezone/private.h: Likewise.
	* timezone/scheck.c: Likewise.
	* timezone/tzfile.h: Likewise.
	* timezone/tzselect.ksh: Likewise.
	* timezone/zdump.c: Likewise.
	* timezone/zic.c: Likewise.
This commit is contained in:
Joseph Myers 2013-12-20 13:10:07 +00:00
parent b7867a3bfb
commit 85bff96ad6
8 changed files with 1071 additions and 479 deletions

View file

@ -1,5 +1,13 @@
2013-12-20 Joseph Myers <joseph@codesourcery.com> 2013-12-20 Joseph Myers <joseph@codesourcery.com>
* timezone/checktab.awk: Update from tzcode 2013i.
* timezone/private.h: Likewise.
* timezone/scheck.c: Likewise.
* timezone/tzfile.h: Likewise.
* timezone/tzselect.ksh: Likewise.
* timezone/zdump.c: Likewise.
* timezone/zic.c: Likewise.
* math/auto-libm-test-in: Add tests of cpow. * math/auto-libm-test-in: Add tests of cpow.
* math/auto-libm-test-out: Regenerated. * math/auto-libm-test-out: Regenerated.
* math/libm-test.inc (cpow_test_data): Use AUTO_TESTS_cc_c. * math/libm-test.inc (cpow_test_data): Use AUTO_TESTS_cc_c.

View file

@ -9,6 +9,9 @@ BEGIN {
if (!zone_table) zone_table = "zone.tab" if (!zone_table) zone_table = "zone.tab"
if (!want_warnings) want_warnings = -1 if (!want_warnings) want_warnings = -1
# A special (and we hope temporary) case.
tztab["America/Montreal"] = 1
while (getline <iso_table) { while (getline <iso_table) {
iso_NR++ iso_NR++
if ($0 ~ /^#/) continue if ($0 ~ /^#/) continue
@ -69,13 +72,10 @@ BEGIN {
status = 1 status = 1
} }
cc0 = cc cc0 = cc
if (tz2cc[tz]) { cctz = cc tz
printf "%s:%d: %s: duplicate TZ column\n", \ cctztab[cctz] = 1
zone_table, zone_NR, tz >>"/dev/stderr" tztab[tz] = 1
status = 1 tz2comments[cctz] = comments
}
tz2cc[tz] = cc
tz2comments[tz] = comments
tz2NR[tz] = zone_NR tz2NR[tz] = zone_NR
if (cc2name[cc]) { if (cc2name[cc]) {
cc_used[cc]++ cc_used[cc]++
@ -92,16 +92,19 @@ BEGIN {
} }
} }
for (tz in tz2cc) { for (cctz in cctztab) {
if (cc_used[tz2cc[tz]] == 1) { cc = substr (cctz, 1, 2)
if (tz2comments[tz]) { tz = substr (cctz, 3)
if (cc_used[cc] == 1) {
if (tz2comments[cctz]) {
printf "%s:%d: unnecessary comment `%s'\n", \ printf "%s:%d: unnecessary comment `%s'\n", \
zone_table, tz2NR[tz], tz2comments[tz] \ zone_table, tz2NR[tz], \
tz2comments[cctz] \
>>"/dev/stderr" >>"/dev/stderr"
status = 1 status = 1
} }
} else { } else {
if (!tz2comments[tz]) { if (!tz2comments[cctz]) {
printf "%s:%d: missing comment\n", \ printf "%s:%d: missing comment\n", \
zone_table, tz2NR[tz] >>"/dev/stderr" zone_table, tz2NR[tz] >>"/dev/stderr"
status = 1 status = 1
@ -125,7 +128,7 @@ BEGIN {
if (src != dst) tz = $3 if (src != dst) tz = $3
} }
if (tz && tz ~ /\//) { if (tz && tz ~ /\//) {
if (!tz2cc[tz]) { if (!tztab[tz]) {
printf "%s: no data for `%s'\n", zone_table, tz \ printf "%s: no data for `%s'\n", zone_table, tz \
>>"/dev/stderr" >>"/dev/stderr"
status = 1 status = 1

View file

@ -34,6 +34,10 @@
#define HAVE_INCOMPATIBLE_CTIME_R 0 #define HAVE_INCOMPATIBLE_CTIME_R 0
#endif /* !defined INCOMPATIBLE_CTIME_R */ #endif /* !defined INCOMPATIBLE_CTIME_R */
#ifndef HAVE_LINK
#define HAVE_LINK 1
#endif /* !defined HAVE_LINK */
#ifndef HAVE_SETTIMEOFDAY #ifndef HAVE_SETTIMEOFDAY
#define HAVE_SETTIMEOFDAY 3 #define HAVE_SETTIMEOFDAY 3
#endif /* !defined HAVE_SETTIMEOFDAY */ #endif /* !defined HAVE_SETTIMEOFDAY */
@ -124,19 +128,76 @@
#include "stdint.h" #include "stdint.h"
#endif /* !HAVE_STDINT_H */ #endif /* !HAVE_STDINT_H */
#ifndef HAVE_INTTYPES_H
# define HAVE_INTTYPES_H HAVE_STDINT_H
#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifndef INT_FAST64_MAX #ifndef INT_FAST64_MAX
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
#if defined LLONG_MAX || defined __LONG_LONG_MAX__ #if defined LLONG_MAX || defined __LONG_LONG_MAX__
typedef long long int_fast64_t; typedef long long int_fast64_t;
# ifdef LLONG_MAX
# define INT_FAST64_MIN LLONG_MIN
# define INT_FAST64_MAX LLONG_MAX
# else
# define INT_FAST64_MIN __LONG_LONG_MIN__
# define INT_FAST64_MAX __LONG_LONG_MAX__
# endif
# define SCNdFAST64 "lld"
#else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
#if (LONG_MAX >> 31) < 0xffffffff #if (LONG_MAX >> 31) < 0xffffffff
Please use a compiler that supports a 64-bit integer type (or wider); Please use a compiler that supports a 64-bit integer type (or wider);
you may need to compile with "-DHAVE_STDINT_H". you may need to compile with "-DHAVE_STDINT_H".
#endif /* (LONG_MAX >> 31) < 0xffffffff */ #endif /* (LONG_MAX >> 31) < 0xffffffff */
typedef long int_fast64_t; typedef long int_fast64_t;
# define INT_FAST64_MIN LONG_MIN
# define INT_FAST64_MAX LONG_MAX
# define SCNdFAST64 "ld"
#endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
#endif /* !defined INT_FAST64_MAX */ #endif /* !defined INT_FAST64_MAX */
#ifndef INT_FAST32_MAX
# if INT_MAX >> 31 == 0
typedef long int_fast32_t;
# else
typedef int int_fast32_t;
# endif
#endif
#ifndef INTMAX_MAX
# if defined LLONG_MAX || defined __LONG_LONG_MAX__
typedef long long intmax_t;
# define strtoimax strtoll
# define PRIdMAX "lld"
# ifdef LLONG_MAX
# define INTMAX_MAX LLONG_MAX
# define INTMAX_MIN LLONG_MIN
# else
# define INTMAX_MAX __LONG_LONG_MAX__
# define INTMAX_MIN __LONG_LONG_MIN__
# endif
# else
typedef long intmax_t;
# define strtoimax strtol
# define PRIdMAX "ld"
# define INTMAX_MAX LONG_MAX
# define INTMAX_MIN LONG_MIN
# endif
#endif
#ifndef UINTMAX_MAX
# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
typedef unsigned long long uintmax_t;
# define PRIuMAX "llu"
# else
typedef unsigned long uintmax_t;
# define PRIuMAX "lu"
# endif
#endif
#ifndef INT32_MAX #ifndef INT32_MAX
#define INT32_MAX 0x7fffffff #define INT32_MAX 0x7fffffff
#endif /* !defined INT32_MAX */ #endif /* !defined INT32_MAX */
@ -144,10 +205,26 @@ typedef long int_fast64_t;
#define INT32_MIN (-1 - INT32_MAX) #define INT32_MIN (-1 - INT32_MAX)
#endif /* !defined INT32_MIN */ #endif /* !defined INT32_MIN */
#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__) #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
# define ATTRIBUTE_CONST __attribute__ ((const))
# define ATTRIBUTE_PURE __attribute__ ((__pure__)) # define ATTRIBUTE_PURE __attribute__ ((__pure__))
# define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
#else #else
# define ATTRIBUTE_CONST /* empty */
# define ATTRIBUTE_PURE /* empty */ # define ATTRIBUTE_PURE /* empty */
# define ATTRIBUTE_FORMAT(spec) /* empty */
#endif
#if !defined _Noreturn && __STDC_VERSION__ < 201112
# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
# define _Noreturn __attribute__ ((__noreturn__))
# else
# define _Noreturn
# endif
#endif
#if __STDC_VERSION__ < 199901 && !defined restrict
# define restrict /* empty */
#endif #endif
/* /*
@ -164,6 +241,58 @@ typedef long int_fast64_t;
extern char * asctime_r(struct tm const *, char *); extern char * asctime_r(struct tm const *, char *);
#endif #endif
/*
** Compile with -Dtime_tz=T to build the tz package with a private
** time_t type equivalent to T rather than the system-supplied time_t.
** This debugging feature can test unusual design decisions
** (e.g., time_t wider than 'long', or unsigned time_t) even on
** typical platforms.
*/
#ifdef time_tz
static time_t sys_time(time_t *x) { return time(x); }
# undef ctime
# define ctime tz_ctime
# undef ctime_r
# define ctime_r tz_ctime_r
# undef difftime
# define difftime tz_difftime
# undef gmtime
# define gmtime tz_gmtime
# undef gmtime_r
# define gmtime_r tz_gmtime_r
# undef localtime
# define localtime tz_localtime
# undef localtime_r
# define localtime_r tz_localtime_r
# undef mktime
# define mktime tz_mktime
# undef time
# define time tz_time
# undef time_t
# define time_t tz_time_t
typedef time_tz time_t;
char *ctime(time_t const *);
char *ctime_r(time_t const *, char *);
double difftime(time_t, time_t);
struct tm *gmtime(time_t const *);
struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
struct tm *localtime(time_t const *);
struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
time_t mktime(struct tm *);
static time_t
time(time_t *p)
{
time_t r = sys_time(0);
if (p)
*p = r;
return r;
}
#endif
/* /*
** Private function declarations. ** Private function declarations.
*/ */
@ -192,14 +321,15 @@ const char * scheck(const char * string, const char * format);
#define TYPE_SIGNED(type) (((type) -1) < 0) #define TYPE_SIGNED(type) (((type) -1) < 0)
#endif /* !defined TYPE_SIGNED */ #endif /* !defined TYPE_SIGNED */
/* /* The minimum and maximum finite time values. */
** Since the definition of TYPE_INTEGRAL contains floating point numbers, static time_t const time_t_min =
** it cannot be used in preprocessor directives. (TYPE_SIGNED(time_t)
*/ ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
: 0);
#ifndef TYPE_INTEGRAL static time_t const time_t_max =
#define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5) (TYPE_SIGNED(time_t)
#endif /* !defined TYPE_INTEGRAL */ ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
: -1);
#ifndef INT_STRLEN_MAXIMUM #ifndef INT_STRLEN_MAXIMUM
/* /*

View file

@ -25,26 +25,35 @@ scheck(const char *const string, const char *const format)
return result; return result;
fp = format; fp = format;
tp = fbuf; tp = fbuf;
/*
** Copy directives, suppressing each conversion that is not
** already suppressed. Scansets containing '%' are not
** supported; e.g., the conversion specification "%[%]" is not
** supported. Also, multibyte characters containing a
** non-leading '%' byte are not supported.
*/
while ((*tp++ = c = *fp++) != '\0') { while ((*tp++ = c = *fp++) != '\0') {
if (c != '%') if (c != '%')
continue; continue;
if (*fp == '%') { if (is_digit(*fp)) {
*tp++ = *fp++; char const *f = fp;
continue; char *t = tp;
do {
*t++ = c = *f++;
} while (is_digit(c));
if (c == '$') {
fp = f;
tp = t;
}
} }
*tp++ = '*'; *tp++ = '*';
if (*fp == '*') if (*fp == '*')
++fp; ++fp;
while (is_digit(*fp))
*tp++ = *fp++;
if (*fp == 'l' || *fp == 'h')
*tp++ = *fp++;
else if (*fp == '[')
do *tp++ = *fp++;
while (*fp != '\0' && *fp != ']');
if ((*tp++ = *fp++) == '\0') if ((*tp++ = *fp++) == '\0')
break; break;
} }
*(tp - 1) = '%'; *(tp - 1) = '%';
*tp++ = 'c'; *tp++ = 'c';
*tp = '\0'; *tp = '\0';

View file

@ -39,7 +39,7 @@
struct tzhead { struct tzhead {
char tzh_magic[4]; /* TZ_MAGIC */ char tzh_magic[4]; /* TZ_MAGIC */
char tzh_version[1]; /* '\0' or '2' as of 2005 */ char tzh_version[1]; /* '\0' or '2' or '3' as of 2013 */
char tzh_reserved[15]; /* reserved--must be zero */ char tzh_reserved[15]; /* reserved--must be zero */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
@ -55,7 +55,7 @@ struct tzhead {
** tzh_timecnt (char [4])s coded transition times a la time(2) ** tzh_timecnt (char [4])s coded transition times a la time(2)
** tzh_timecnt (unsigned char)s types of local time starting at above ** tzh_timecnt (unsigned char)s types of local time starting at above
** tzh_typecnt repetitions of ** tzh_typecnt repetitions of
** one (char [4]) coded UTC offset in seconds ** one (char [4]) coded UT offset in seconds
** one (unsigned char) used to set tm_isdst ** one (unsigned char) used to set tm_isdst
** one (unsigned char) that's an abbreviation list index ** one (unsigned char) that's an abbreviation list index
** tzh_charcnt (char)s '\0'-terminated zone abbreviations ** tzh_charcnt (char)s '\0'-terminated zone abbreviations
@ -68,7 +68,7 @@ struct tzhead {
** if absent, transition times are ** if absent, transition times are
** assumed to be wall clock time ** assumed to be wall clock time
** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition ** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
** time is UTC, if FALSE, ** time is UT, if FALSE,
** transition time is local time ** transition time is local time
** if absent, transition times are ** if absent, transition times are
** assumed to be local time ** assumed to be local time
@ -82,6 +82,13 @@ struct tzhead {
** instants after the last transition time stored in the file ** instants after the last transition time stored in the file
** (with nothing between the newlines if there is no POSIX representation for ** (with nothing between the newlines if there is no POSIX representation for
** such instants). ** such instants).
**
** If tz_version is '3' or greater, the above is extended as follows.
** First, the POSIX TZ string's hour offset may range from -167
** through 167 as compared to the POSIX-required 0 through 24.
** Second, its DST start time may be January 1 at 00:00 and its stop
** time December 31 at 24:00 plus the difference between DST and
** standard time, indicating DST all year.
*/ */
/* /*
@ -94,16 +101,8 @@ struct tzhead {
#endif /* !defined TZ_MAX_TIMES */ #endif /* !defined TZ_MAX_TIMES */
#ifndef TZ_MAX_TYPES #ifndef TZ_MAX_TYPES
#ifndef NOSOLAR /* This must be at least 17 for Europe/Samara and Europe/Vilnius. */
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
#endif /* !defined NOSOLAR */
#ifdef NOSOLAR
/*
** Must be at least 14 for Europe/Riga as of Jan 12 1995,
** as noted by Earl Chew.
*/
#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
#endif /* !defined NOSOLAR */
#endif /* !defined TZ_MAX_TYPES */ #endif /* !defined TZ_MAX_TYPES */
#ifndef TZ_MAX_CHARS #ifndef TZ_MAX_CHARS
@ -122,7 +121,7 @@ struct tzhead {
#define DAYSPERNYEAR 365 #define DAYSPERNYEAR 365
#define DAYSPERLYEAR 366 #define DAYSPERLYEAR 366
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
#define MONSPERYEAR 12 #define MONSPERYEAR 12
#define TM_SUNDAY 0 #define TM_SUNDAY 0

View file

@ -11,7 +11,7 @@ REPORT_BUGS_TO=tz@iana.org
# Porting notes: # Porting notes:
# #
# This script requires a Posix-like shell with the extension of a # This script requires a Posix-like shell and prefers the extension of a
# 'select' statement. The 'select' statement was introduced in the # 'select' statement. The 'select' statement was introduced in the
# Korn shell and is available in Bash and other shell implementations. # Korn shell and is available in Bash and other shell implementations.
# If your host lacks both Bash and the Korn shell, you can get their # If your host lacks both Bash and the Korn shell, you can get their
@ -21,6 +21,10 @@ REPORT_BUGS_TO=tz@iana.org
# Korn Shell <http://www.kornshell.com/> # Korn Shell <http://www.kornshell.com/>
# Public Domain Korn Shell <http://www.cs.mun.ca/~michael/pdksh/> # Public Domain Korn Shell <http://www.cs.mun.ca/~michael/pdksh/>
# #
# For portability to Solaris 9 /bin/sh this script avoids some POSIX
# features and common extensions, such as $(...) (which works sometimes
# but not others), $((...)), and $10.
#
# This script also uses several features of modern awk programs. # This script also uses several features of modern awk programs.
# If your host lacks awk, or has an old awk that does not conform to Posix, # If your host lacks awk, or has an old awk that does not conform to Posix,
# you can use either of the following free programs instead: # you can use either of the following free programs instead:
@ -31,7 +35,7 @@ REPORT_BUGS_TO=tz@iana.org
# Specify default values for environment variables if they are unset. # Specify default values for environment variables if they are unset.
: ${AWK=awk} : ${AWK=awk}
: ${TZDIR=$(pwd)} : ${TZDIR=`pwd`}
# Check for awk Posix compliance. # Check for awk Posix compliance.
($AWK -v x=y 'BEGIN { exit 123 }') </dev/null >/dev/null 2>&1 ($AWK -v x=y 'BEGIN { exit 123 }') </dev/null >/dev/null 2>&1
@ -40,21 +44,125 @@ REPORT_BUGS_TO=tz@iana.org
exit 1 exit 1
} }
if [ "$1" = "--help" ]; then coord=
cat <<EOF location_limit=10
Usage: tzselect
usage="Usage: tzselect [--version] [--help] [-c COORD] [-n LIMIT]
Select a time zone interactively. Select a time zone interactively.
Report bugs to $REPORT_BUGS_TO. Options:
EOF
exit -c COORD
elif [ "$1" = "--version" ]; then Instead of asking for continent and then country and then city,
cat <<EOF ask for selection from time zones whose largest cities
tzselect $PKGVERSION$TZVERSION are closest to the location with geographical coordinates COORD.
EOF COORD should use ISO 6709 notation, for example, '-c +4852+00220'
exit for Paris (in degrees and minutes, North and East), or
'-c -35-058' for Buenos Aires (in degrees, South and West).
-n LIMIT
Display at most LIMIT locations when -c is used (default $location_limit).
--version
Output version information.
--help
Output this help.
Report bugs to $REPORT_BUGS_TO."
# Ask the user to select from the function's arguments,
# and assign the selected argument to the variable 'select_result'.
# Exit on EOF or I/O error. Use the shell's 'select' builtin if available,
# falling back on a less-nice but portable substitute otherwise.
if
case $BASH_VERSION in
?*) : ;;
'')
# '; exit' should be redundant, but Dash doesn't properly fail without it.
(eval 'set --; select x; do break; done; exit') 2>/dev/null
esac
then
# Do this inside 'eval', as otherwise the shell might exit when parsing it
# even though it is never executed.
eval '
doselect() {
select select_result
do
case $select_result in
"") echo >&2 "Please enter a number in range." ;;
?*) break
esac
done || exit
}
# Work around a bug in bash 1.14.7 and earlier, where $PS3 is sent to stdout.
case $BASH_VERSION in
[01].*)
case `echo 1 | (select x in x; do break; done) 2>/dev/null` in
?*) PS3=
esac
esac
'
else
doselect() {
# Field width of the prompt numbers.
select_width=`expr $# : '.*'`
select_i=
while :
do
case $select_i in
'')
select_i=0
for select_word
do
select_i=`expr $select_i + 1`
printf >&2 "%${select_width}d) %s\\n" $select_i "$select_word"
done ;;
*[!0-9]*)
echo >&2 'Please enter a number in range.' ;;
*)
if test 1 -le $select_i && test $select_i -le $#; then
shift `expr $select_i - 1`
select_result=$1
break
fi
echo >&2 'Please enter a number in range.'
esac
# Prompt and read input.
printf >&2 %s "${PS3-#? }"
read select_i || exit
done
}
fi fi
while getopts c:n:-: opt
do
case $opt$OPTARG in
c*)
coord=$OPTARG ;;
n*)
location_limit=$OPTARG ;;
-help)
exec echo "$usage" ;;
-version)
exec echo "tzselect $PKGVERSION$TZVERSION" ;;
-*)
echo >&2 "$0: -$opt$OPTARG: unknown option; try '$0 --help'"; exit 1 ;;
*)
echo >&2 "$0: try '$0 --help'"; exit 1 ;;
esac
done
shift `expr $OPTIND - 1`
case $# in
0) ;;
*) echo >&2 "$0: $1: unknown argument"; exit 1 ;;
esac
# Make sure the tables are readable. # Make sure the tables are readable.
TZ_COUNTRY_TABLE=$TZDIR/iso3166.tab TZ_COUNTRY_TABLE=$TZDIR/iso3166.tab
TZ_ZONE_TABLE=$TZDIR/zone.tab TZ_ZONE_TABLE=$TZDIR/zone.tab
@ -71,11 +179,65 @@ newline='
IFS=$newline IFS=$newline
# Work around a bug in bash 1.14.7 and earlier, where $PS3 is sent to stdout. # Awk script to read a time zone table and output the same table,
case $(echo 1 | (select x in x; do break; done) 2>/dev/null) in # with each column preceded by its distance from 'here'.
?*) PS3= output_distances='
esac BEGIN {
FS = "\t"
while (getline <TZ_COUNTRY_TABLE)
if ($0 ~ /^[^#]/)
country[$1] = $2
country["US"] = "US" # Otherwise the strings get too long.
}
function convert_coord(coord, deg, min, ilen, sign, sec) {
if (coord ~ /^[-+]?[0-9]?[0-9][0-9][0-9][0-9][0-9][0-9]([^0-9]|$)/) {
degminsec = coord
intdeg = degminsec < 0 ? -int(-degminsec / 10000) : int(degminsec / 10000)
minsec = degminsec - intdeg * 10000
intmin = minsec < 0 ? -int(-minsec / 100) : int(minsec / 100)
sec = minsec - intmin * 100
deg = (intdeg * 3600 + intmin * 60 + sec) / 3600
} else if (coord ~ /^[-+]?[0-9]?[0-9][0-9][0-9][0-9]([^0-9]|$)/) {
degmin = coord
intdeg = degmin < 0 ? -int(-degmin / 100) : int(degmin / 100)
min = degmin - intdeg * 100
deg = (intdeg * 60 + min) / 60
} else
deg = coord
return deg * 0.017453292519943296
}
function convert_latitude(coord) {
match(coord, /..*[-+]/)
return convert_coord(substr(coord, 1, RLENGTH - 1))
}
function convert_longitude(coord) {
match(coord, /..*[-+]/)
return convert_coord(substr(coord, RLENGTH))
}
# Great-circle distance between points with given latitude and longitude.
# Inputs and output are in radians. This uses the great-circle special
# case of the Vicenty formula for distances on ellipsoids.
function dist(lat1, long1, lat2, long2, dlong, x, y, num, denom) {
dlong = long2 - long1
x = cos (lat2) * sin (dlong)
y = cos (lat1) * sin (lat2) - sin (lat1) * cos (lat2) * cos (dlong)
num = sqrt (x * x + y * y)
denom = sin (lat1) * sin (lat2) + cos (lat1) * cos (lat2) * cos (dlong)
return atan2(num, denom)
}
BEGIN {
coord_lat = convert_latitude(coord)
coord_long = convert_longitude(coord)
}
/^[^#]/ {
here_lat = convert_latitude($2)
here_long = convert_longitude($2)
line = $1 "\t" $2 "\t" $3 "\t" country[$1]
if (NF == 4)
line = line " - " $4
printf "%g\t%s\n", dist(coord_lat, coord_long, here_lat, here_long), line
}
'
# Begin the main loop. We come back here if the user wants to retry. # Begin the main loop. We come back here if the user wants to retry.
while while
@ -87,39 +249,46 @@ while
country= country=
region= region=
case $coord in
?*)
continent=coord;;
'')
# Ask the user for continent or ocean. # Ask the user for continent or ocean.
echo >&2 'Please select a continent or ocean.' echo >&2 'Please select a continent, ocean, "coord", or "TZ".'
select continent in \ quoted_continents=`
Africa \ $AWK '
Americas \ BEGIN { FS = "\t" }
Antarctica \ /^[^#]/ {
'Arctic Ocean' \ entry = substr($3, 1, index($3, "/") - 1)
Asia \ if (entry == "America")
'Atlantic Ocean' \ entry = entry "s"
Australia \ if (entry ~ /^(Arctic|Atlantic|Indian|Pacific)$/)
Europe \ entry = entry " Ocean"
'Indian Ocean' \ printf "'\''%s'\''\n", entry
'Pacific Ocean' \ }
'none - I want to specify the time zone using the Posix TZ format.' ' $TZ_ZONE_TABLE |
do sort -u |
tr '\n' ' '
echo ''
`
eval '
doselect '"$quoted_continents"' \
"coord - I want to use geographical coordinates." \
"TZ - I want to specify the time zone using the Posix TZ format."
continent=$select_result
case $continent in case $continent in
'') Americas) continent=America;;
echo >&2 'Please enter a number in range.';; *" "*) continent=`expr "$continent" : '\''\([^ ]*\)'\''`
?*)
case $continent in
Americas) continent=America;;
*' '*) continent=$(expr "$continent" : '\([^ ]*\)')
esac
break
esac esac
done '
esac
case $continent in case $continent in
'') TZ)
exit 1;;
none)
# Ask the user for a Posix TZ string. Check that it conforms. # Ask the user for a Posix TZ string. Check that it conforms.
while while
echo >&2 'Please enter the desired value' \ echo >&2 'Please enter the desired value' \
@ -144,11 +313,46 @@ while
done done
TZ_for_date=$TZ;; TZ_for_date=$TZ;;
*) *)
case $continent in
coord)
case $coord in
'')
echo >&2 'Please enter coordinates' \
'in ISO 6709 notation.'
echo >&2 'For example, +4042-07403 stands for'
echo >&2 '40 degrees 42 minutes north,' \
'74 degrees 3 minutes west.'
read coord;;
esac
distance_table=`$AWK \
-v coord="$coord" \
-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
"$output_distances" <$TZ_ZONE_TABLE |
sort -n |
sed "${location_limit}q"
`
regions=`echo "$distance_table" | $AWK '
BEGIN { FS = "\t" }
{ print $NF }
'`
echo >&2 'Please select one of the following' \
'time zone regions,'
echo >&2 'listed roughly in increasing order' \
"of distance from $coord".
doselect $regions
region=$select_result
TZ=`echo "$distance_table" | $AWK -v region="$region" '
BEGIN { FS="\t" }
$NF == region { print $4 }
'`
;;
*)
# Get list of names of countries in the continent or ocean. # Get list of names of countries in the continent or ocean.
countries=$($AWK -F'\t' \ countries=`$AWK \
-v continent="$continent" \ -v continent="$continent" \
-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \ -v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
' '
BEGIN { FS = "\t" }
/^#/ { next } /^#/ { next }
$3 ~ ("^" continent "/") { $3 ~ ("^" continent "/") {
if (!cc_seen[$1]++) cc_list[++ccs] = $1 if (!cc_seen[$1]++) cc_list[++ccs] = $1
@ -165,35 +369,28 @@ while
print country print country
} }
} }
' <$TZ_ZONE_TABLE | sort -f) ' <$TZ_ZONE_TABLE | sort -f`
# If there's more than one country, ask the user which one. # If there's more than one country, ask the user which one.
case $countries in case $countries in
*"$newline"*) *"$newline"*)
echo >&2 'Please select a country.' echo >&2 'Please select a country' \
select country in $countries 'whose clocks agree with yours.'
do doselect $countries
case $country in country=$select_result;;
'') echo >&2 'Please enter a number in range.';;
?*) break
esac
done
case $country in
'') exit 1
esac;;
*) *)
country=$countries country=$countries
esac esac
# Get list of names of time zone rule regions in the country. # Get list of names of time zone rule regions in the country.
regions=$($AWK -F'\t' \ regions=`$AWK \
-v country="$country" \ -v country="$country" \
-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \ -v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
' '
BEGIN { BEGIN {
FS = "\t"
cc = country cc = country
while (getline <TZ_COUNTRY_TABLE) { while (getline <TZ_COUNTRY_TABLE) {
if ($0 !~ /^#/ && country == $2) { if ($0 !~ /^#/ && country == $2) {
@ -203,7 +400,7 @@ while
} }
} }
$1 == cc { print $4 } $1 == cc { print $4 }
' <$TZ_ZONE_TABLE) ' <$TZ_ZONE_TABLE`
# If there's more than one region, ask the user which one. # If there's more than one region, ask the user which one.
@ -211,27 +408,20 @@ while
*"$newline"*) *"$newline"*)
echo >&2 'Please select one of the following' \ echo >&2 'Please select one of the following' \
'time zone regions.' 'time zone regions.'
select region in $regions doselect $regions
do region=$select_result;;
case $region in
'') echo >&2 'Please enter a number in range.';;
?*) break
esac
done
case $region in
'') exit 1
esac;;
*) *)
region=$regions region=$regions
esac esac
# Determine TZ from country and region. # Determine TZ from country and region.
TZ=$($AWK -F'\t' \ TZ=`$AWK \
-v country="$country" \ -v country="$country" \
-v region="$region" \ -v region="$region" \
-v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \ -v TZ_COUNTRY_TABLE="$TZ_COUNTRY_TABLE" \
' '
BEGIN { BEGIN {
FS = "\t"
cc = country cc = country
while (getline <TZ_COUNTRY_TABLE) { while (getline <TZ_COUNTRY_TABLE) {
if ($0 !~ /^#/ && country == $2) { if ($0 !~ /^#/ && country == $2) {
@ -241,7 +431,8 @@ while
} }
} }
$1 == cc && $4 == region { print $3 } $1 == cc && $4 == region { print $3 }
' <$TZ_ZONE_TABLE) ' <$TZ_ZONE_TABLE`
esac
# Make sure the corresponding zoneinfo file exists. # Make sure the corresponding zoneinfo file exists.
TZ_for_date=$TZDIR/$TZ TZ_for_date=$TZDIR/$TZ
@ -259,10 +450,10 @@ while
extra_info= extra_info=
for i in 1 2 3 4 5 6 7 8 for i in 1 2 3 4 5 6 7 8
do do
TZdate=$(LANG=C TZ="$TZ_for_date" date) TZdate=`LANG=C TZ="$TZ_for_date" date`
UTdate=$(LANG=C TZ=UTC0 date) UTdate=`LANG=C TZ=UTC0 date`
TZsec=$(expr "$TZdate" : '.*:\([0-5][0-9]\)') TZsec=`expr "$TZdate" : '.*:\([0-5][0-9]\)'`
UTsec=$(expr "$UTdate" : '.*:\([0-5][0-9]\)') UTsec=`expr "$UTdate" : '.*:\([0-5][0-9]\)'`
case $TZsec in case $TZsec in
$UTsec) $UTsec)
extra_info=" extra_info="
@ -278,28 +469,23 @@ Universal Time is now: $UTdate."
echo >&2 "" echo >&2 ""
echo >&2 "The following information has been given:" echo >&2 "The following information has been given:"
echo >&2 "" echo >&2 ""
case $country+$region in case $country%$region%$coord in
?*+?*) echo >&2 " $country$newline $region";; ?*%?*%) echo >&2 " $country$newline $region";;
?*+) echo >&2 " $country";; ?*%%) echo >&2 " $country";;
%?*%?*) echo >&2 " coord $coord$newline $region";;
%%?*) echo >&2 " coord $coord";;
+) echo >&2 " TZ='$TZ'" +) echo >&2 " TZ='$TZ'"
esac esac
echo >&2 "" echo >&2 ""
echo >&2 "Therefore TZ='$TZ' will be used.$extra_info" echo >&2 "Therefore TZ='$TZ' will be used.$extra_info"
echo >&2 "Is the above information OK?" echo >&2 "Is the above information OK?"
ok= doselect Yes No
select ok in Yes No ok=$select_result
do
case $ok in
'') echo >&2 'Please enter 1 for Yes, or 2 for No.';;
?*) break
esac
done
case $ok in case $ok in
'') exit 1;;
Yes) break Yes) break
esac esac
do : do coord=
done done
case $SHELL in case $SHELL in

View file

@ -9,20 +9,72 @@
** This code has been made independent of the rest of the time ** This code has been made independent of the rest of the time
** conversion package to increase confidence in the verification it provides. ** conversion package to increase confidence in the verification it provides.
** You can use this code to help in verifying other implementations. ** You can use this code to help in verifying other implementations.
**
** However, include private.h when debugging, so that it overrides
** time_t consistently with the rest of the package.
*/ */
#ifdef time_tz
# include "private.h"
#endif
#include "stdio.h" /* for stdout, stderr, perror */ #include "stdio.h" /* for stdout, stderr, perror */
#include "string.h" /* for strcpy */ #include "string.h" /* for strcpy */
#include "sys/types.h" /* for time_t */ #include "sys/types.h" /* for time_t */
#include "time.h" /* for struct tm */ #include "time.h" /* for struct tm */
#include "stdlib.h" /* for exit, malloc, atoi */ #include "stdlib.h" /* for exit, malloc, atoi */
#include "float.h" /* for FLT_MAX and DBL_MAX */
#include "limits.h" /* for CHAR_BIT, LLONG_MAX */ #include "limits.h" /* for CHAR_BIT, LLONG_MAX */
#include "ctype.h" /* for isalpha et al. */ #include "ctype.h" /* for isalpha et al. */
#ifndef isascii #ifndef isascii
#define isascii(x) 1 #define isascii(x) 1
#endif /* !defined isascii */ #endif /* !defined isascii */
/*
** Substitutes for pre-C99 compilers.
** Much of this section of code is stolen from private.h.
*/
#ifndef HAVE_STDINT_H
# define HAVE_STDINT_H \
(199901 <= __STDC_VERSION__ || 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
#endif
#if HAVE_STDINT_H
# include "stdint.h"
#endif
#ifndef HAVE_INTTYPES_H
# define HAVE_INTTYPES_H HAVE_STDINT_H
#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifndef INT_FAST32_MAX
# if INT_MAX >> 31 == 0
typedef long int_fast32_t;
# else
typedef int int_fast32_t;
# endif
#endif
#ifndef INTMAX_MAX
# if defined LLONG_MAX || defined __LONG_LONG_MAX__
typedef long long intmax_t;
# define strtoimax strtoll
# define PRIdMAX "lld"
# ifdef LLONG_MAX
# define INTMAX_MAX LLONG_MAX
# else
# define INTMAX_MAX __LONG_LONG_MAX__
# endif
# else
typedef long intmax_t;
# define strtoimax strtol
# define PRIdMAX "ld"
# define INTMAX_MAX LONG_MAX
# endif
#endif
#ifndef ZDUMP_LO_YEAR #ifndef ZDUMP_LO_YEAR
#define ZDUMP_LO_YEAR (-500) #define ZDUMP_LO_YEAR (-500)
#endif /* !defined ZDUMP_LO_YEAR */ #endif /* !defined ZDUMP_LO_YEAR */
@ -90,9 +142,20 @@
#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
#endif /* !defined isleap_sum */ #endif /* !defined isleap_sum */
#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
#define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR) #define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR)
#define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY) #define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY)
#define SECSPER400YEARS (SECSPERNYEAR * (intmax_t) (300 + 3) \
+ SECSPERLYEAR * (intmax_t) (100 - 3))
/*
** True if SECSPER400YEARS is known to be representable as an
** intmax_t. It's OK that SECSPER400YEARS_FITS can in theory be false
** even if SECSPER400YEARS is representable, because when that happens
** the code merely runs a bit more slowly, and this slowness doesn't
** occur on any practical platform.
*/
enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 };
#ifndef HAVE_GETTEXT #ifndef HAVE_GETTEXT
#define HAVE_GETTEXT 0 #define HAVE_GETTEXT 0
@ -112,14 +175,6 @@
#endif /* !defined lint */ #endif /* !defined lint */
#endif /* !defined GNUC_or_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 */
#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__) #if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
# define ATTRIBUTE_PURE __attribute__ ((__pure__)) # define ATTRIBUTE_PURE __attribute__ ((__pure__))
#else #else
@ -151,48 +206,27 @@ extern char * optarg;
extern int optind; extern int optind;
extern char * tzname[2]; extern char * tzname[2];
/* The minimum and maximum finite time values. Shift 'long long' or /* The minimum and maximum finite time values. */
'long' instead of 'time_t'; this avoids compile-time errors when
time_t is floating-point. In practice, 'long long' is wide enough. */
static time_t const absolute_min_time = static time_t const absolute_min_time =
((time_t) 0.5 == 0.5 ((time_t) -1 < 0
? (sizeof (time_t) == sizeof (float) ? (time_t) -FLT_MAX ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
: sizeof (time_t) == sizeof (double) ? (time_t) -DBL_MAX
: sizeof (time_t) == sizeof (long double) ? (time_t) -LDBL_MAX
: 0)
: (time_t) -1 < 0
#ifdef LLONG_MAX
? (time_t) ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1))
#else
? (time_t) ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1))
#endif
: 0); : 0);
static time_t const absolute_max_time = static time_t const absolute_max_time =
((time_t) 0.5 == 0.5 ((time_t) -1 < 0
? (sizeof (time_t) == sizeof (float) ? (time_t) FLT_MAX ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
: sizeof (time_t) == sizeof (double) ? (time_t) DBL_MAX : -1);
: sizeof (time_t) == sizeof (long double) ? (time_t) LDBL_MAX
: -1)
: (time_t) -1 < 0
#ifdef LLONG_MAX
? (time_t) (- (~ 0 < 0) - ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1)))
#else
? (time_t) (- (~ 0 < 0) - ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1)))
#endif
: (time_t) -1);
static size_t longest; static size_t longest;
static char * progname; static char * progname;
static int warned; static int warned;
static char * abbr(struct tm * tmp); static char * abbr(struct tm * tmp);
static void abbrok(const char * abbrp, const char * zone); static void abbrok(const char * abbrp, const char * zone);
static long delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE; static intmax_t delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE;
static void dumptime(const struct tm * tmp); static void dumptime(const struct tm * tmp);
static time_t hunt(char * name, time_t lot, time_t hit); static time_t hunt(char * name, time_t lot, time_t hit);
static void checkabsolutes(void);
static void show(char * zone, time_t t, int v); static void show(char * zone, time_t t, int v);
static const char * tformat(void); static const char * tformat(void);
static time_t yeartot(long y) ATTRIBUTE_PURE; static time_t yeartot(intmax_t y) ATTRIBUTE_PURE;
#ifndef TYPECHECK #ifndef TYPECHECK
#define my_localtime localtime #define my_localtime localtime
@ -209,7 +243,7 @@ my_localtime(time_t *tp)
tm = *tmp; tm = *tmp;
t = mktime(&tm); t = mktime(&tm);
if (t - *tp >= 1 || *tp - t >= 1) { if (t != *tp) {
(void) fflush(stdout); (void) fflush(stdout);
(void) fprintf(stderr, "\n%s: ", progname); (void) fprintf(stderr, "\n%s: ", progname);
(void) fprintf(stderr, tformat(), *tp); (void) fprintf(stderr, tformat(), *tp);
@ -270,9 +304,9 @@ static void
usage(FILE * const stream, const int status) usage(FILE * const stream, const int status)
{ {
(void) fprintf(stream, (void) fprintf(stream,
_("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\ _("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n"
\n\ "\n"
Report bugs to %s.\n"), "Report bugs to %s.\n"),
progname, progname, REPORT_BUGS_TO); progname, progname, REPORT_BUGS_TO);
exit(status); exit(status);
} }
@ -281,11 +315,10 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
register int i; register int i;
register int c;
register int vflag; register int vflag;
register int Vflag;
register char * cutarg; register char * cutarg;
register long cutloyear = ZDUMP_LO_YEAR; register char * cuttimes;
register long cuthiyear = ZDUMP_HI_YEAR;
register time_t cutlotime; register time_t cutlotime;
register time_t cuthitime; register time_t cuthitime;
register char ** fakeenv; register char ** fakeenv;
@ -297,8 +330,8 @@ main(int argc, char *argv[])
register struct tm * tmp; register struct tm * tmp;
register struct tm * newtmp; register struct tm * newtmp;
INITIALIZE(cutlotime); cutlotime = absolute_min_time;
INITIALIZE(cuthitime); cuthitime = absolute_max_time;
#if HAVE_GETTEXT #if HAVE_GETTEXT
(void) setlocale(LC_ALL, ""); (void) setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR #ifdef TZ_DOMAINDIR
@ -314,37 +347,78 @@ main(int argc, char *argv[])
} else if (strcmp(argv[i], "--help") == 0) { } else if (strcmp(argv[i], "--help") == 0) {
usage(stdout, EXIT_SUCCESS); usage(stdout, EXIT_SUCCESS);
} }
vflag = 0; vflag = Vflag = 0;
cutarg = NULL; cutarg = cuttimes = NULL;
while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') for (;;)
if (c == 'v') switch (getopt(argc, argv, "c:t:vV")) {
vflag = 1; case 'c': cutarg = optarg; break;
else cutarg = optarg; case 't': cuttimes = optarg; break;
if ((c != EOF && c != -1) || case 'v': vflag = 1; break;
(optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { case 'V': Vflag = 1; break;
usage(stderr, EXIT_FAILURE); case -1:
} if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0))
if (vflag) { goto arg_processing_done;
if (cutarg != NULL) { /* Fall through. */
long lo; default:
long hi; usage(stderr, EXIT_FAILURE);
char dummy; }
arg_processing_done:;
if (sscanf(cutarg, "%ld%c", &hi, &dummy) == 1) { if (vflag | Vflag) {
intmax_t lo;
intmax_t hi;
char *loend, *hiend;
register intmax_t cutloyear = ZDUMP_LO_YEAR;
register intmax_t cuthiyear = ZDUMP_HI_YEAR;
if (cutarg != NULL) {
lo = strtoimax(cutarg, &loend, 10);
if (cutarg != loend && !*loend) {
hi = lo;
cuthiyear = hi;
} else if (cutarg != loend && *loend == ','
&& (hi = strtoimax(loend + 1, &hiend, 10),
loend + 1 != hiend && !*hiend)) {
cutloyear = lo;
cuthiyear = hi; cuthiyear = hi;
} else if (sscanf(cutarg, "%ld,%ld%c",
&lo, &hi, &dummy) == 2) {
cutloyear = lo;
cuthiyear = hi;
} else { } else {
(void) fprintf(stderr, _("%s: wild -c argument %s\n"), (void) fprintf(stderr, _("%s: wild -c argument %s\n"),
progname, cutarg); progname, cutarg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
checkabsolutes(); if (cutarg != NULL || cuttimes == NULL) {
cutlotime = yeartot(cutloyear); cutlotime = yeartot(cutloyear);
cuthitime = yeartot(cuthiyear); cuthitime = yeartot(cuthiyear);
}
if (cuttimes != NULL) {
lo = strtoimax(cuttimes, &loend, 10);
if (cuttimes != loend && !*loend) {
hi = lo;
if (hi < cuthitime) {
if (hi < absolute_min_time)
hi = absolute_min_time;
cuthitime = hi;
}
} else if (cuttimes != loend && *loend == ','
&& (hi = strtoimax(loend + 1, &hiend, 10),
loend + 1 != hiend && !*hiend)) {
if (cutlotime < lo) {
if (absolute_max_time < lo)
lo = absolute_max_time;
cutlotime = lo;
}
if (hi < cuthitime) {
if (hi < absolute_min_time)
hi = absolute_min_time;
cuthitime = hi;
}
} else {
(void) fprintf(stderr,
_("%s: wild -t argument %s\n"),
progname, cuttimes);
exit(EXIT_FAILURE);
}
}
} }
(void) time(&now); (void) time(&now);
longest = 0; longest = 0;
@ -375,15 +449,17 @@ main(int argc, char *argv[])
static char buf[MAX_STRING_LENGTH]; static char buf[MAX_STRING_LENGTH];
(void) strcpy(&fakeenv[0][3], argv[i]); (void) strcpy(&fakeenv[0][3], argv[i]);
if (!vflag) { if (! (vflag | Vflag)) {
show(argv[i], now, FALSE); show(argv[i], now, FALSE);
continue; continue;
} }
warned = FALSE; warned = FALSE;
t = absolute_min_time; t = absolute_min_time;
show(argv[i], t, TRUE); if (!Vflag) {
t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE);
show(argv[i], t, TRUE); t += SECSPERDAY;
show(argv[i], t, TRUE);
}
if (t < cutlotime) if (t < cutlotime)
t = cutlotime; t = cutlotime;
tmp = my_localtime(&t); tmp = my_localtime(&t);
@ -392,9 +468,11 @@ main(int argc, char *argv[])
(void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1);
} }
for ( ; ; ) { for ( ; ; ) {
if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12) newt = (t < absolute_max_time - SECSPERDAY / 2
? t + SECSPERDAY / 2
: absolute_max_time);
if (cuthitime <= newt)
break; break;
newt = t + SECSPERHOUR * 12;
newtmp = localtime(&newt); newtmp = localtime(&newt);
if (newtmp != NULL) if (newtmp != NULL)
newtm = *newtmp; newtm = *newtmp;
@ -415,11 +493,13 @@ main(int argc, char *argv[])
tm = newtm; tm = newtm;
tmp = newtmp; tmp = newtmp;
} }
t = absolute_max_time; if (!Vflag) {
t -= SECSPERHOUR * HOURSPERDAY; t = absolute_max_time;
show(argv[i], t, TRUE); t -= SECSPERDAY;
t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE);
show(argv[i], t, TRUE); t += SECSPERDAY;
show(argv[i], t, TRUE);
}
} }
if (fflush(stdout) || ferror(stdout)) { if (fflush(stdout) || ferror(stdout)) {
(void) fprintf(stderr, "%s: ", progname); (void) fprintf(stderr, "%s: ", progname);
@ -431,44 +511,45 @@ main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
static void
checkabsolutes(void)
{
if (absolute_max_time < absolute_min_time) {
(void) fprintf(stderr,
_("%s: use of -v on system with floating time_t other than float or double\n"),
progname);
exit(EXIT_FAILURE);
}
}
static time_t static time_t
yeartot(const long y) yeartot(const intmax_t y)
{ {
register long myy; register intmax_t myy, seconds, years;
register long seconds; register time_t t;
register time_t t;
myy = EPOCH_YEAR; myy = EPOCH_YEAR;
t = 0; t = 0;
while (myy != y) { while (myy < y) {
if (myy < y) { if (SECSPER400YEARS_FITS && 400 <= y - myy) {
intmax_t diff400 = (y - myy) / 400;
if (INTMAX_MAX / SECSPER400YEARS < diff400)
return absolute_max_time;
seconds = diff400 * SECSPER400YEARS;
years = diff400 * 400;
} else {
seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR; seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR;
++myy; years = 1;
if (t > absolute_max_time - seconds) {
t = absolute_max_time;
break;
}
t += seconds;
} else {
--myy;
seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR;
if (t < absolute_min_time + seconds) {
t = absolute_min_time;
break;
}
t -= seconds;
} }
myy += years;
if (t > absolute_max_time - seconds)
return absolute_max_time;
t += seconds;
}
while (y < myy) {
if (SECSPER400YEARS_FITS && y + 400 <= myy && myy < 0) {
intmax_t diff400 = (myy - y) / 400;
if (INTMAX_MAX / SECSPER400YEARS < diff400)
return absolute_min_time;
seconds = diff400 * SECSPER400YEARS;
years = diff400 * 400;
} else {
seconds = isleap(myy - 1) ? SECSPERLYEAR : SECSPERNYEAR;
years = 1;
}
myy -= years;
if (t < absolute_min_time + seconds)
return absolute_min_time;
t -= seconds;
} }
return t; return t;
} }
@ -477,7 +558,6 @@ static time_t
hunt(char *name, time_t lot, time_t hit) hunt(char *name, time_t lot, time_t hit)
{ {
time_t t; time_t t;
long diff;
struct tm lotm; struct tm lotm;
register struct tm * lotmp; register struct tm * lotmp;
struct tm tm; struct tm tm;
@ -490,7 +570,7 @@ hunt(char *name, time_t lot, time_t hit)
(void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1);
} }
for ( ; ; ) { for ( ; ; ) {
diff = (long) (hit - lot); time_t diff = hit - lot;
if (diff < 2) if (diff < 2)
break; break;
t = lot; t = lot;
@ -520,11 +600,11 @@ hunt(char *name, time_t lot, time_t hit)
** Thanks to Paul Eggert for logic used in delta. ** Thanks to Paul Eggert for logic used in delta.
*/ */
static long static intmax_t
delta(struct tm * newp, struct tm *oldp) delta(struct tm * newp, struct tm *oldp)
{ {
register long result; register intmax_t result;
register int tmy; register int tmy;
if (newp->tm_year < oldp->tm_year) if (newp->tm_year < oldp->tm_year)
return -delta(oldp, newp); return -delta(oldp, newp);
@ -553,7 +633,7 @@ show(char *zone, time_t t, int v)
(void) printf(tformat(), t); (void) printf(tformat(), t);
} else { } else {
dumptime(tmp); dumptime(tmp);
(void) printf(" UTC"); (void) printf(" UT");
} }
(void) printf(" = "); (void) printf(" = ");
} }
@ -594,18 +674,19 @@ abbr(struct tm *tmp)
static const char * static const char *
tformat(void) tformat(void)
{ {
if (0.5 == (time_t) 0.5) { /* floating */
if (sizeof (time_t) > sizeof (double))
return "%Lg";
return "%g";
}
if (0 > (time_t) -1) { /* signed */ if (0 > (time_t) -1) { /* signed */
if (sizeof (time_t) == sizeof (intmax_t))
return "%"PRIdMAX;
if (sizeof (time_t) > sizeof (long)) if (sizeof (time_t) > sizeof (long))
return "%lld"; return "%lld";
if (sizeof (time_t) > sizeof (int)) if (sizeof (time_t) > sizeof (int))
return "%ld"; return "%ld";
return "%d"; return "%d";
} }
#ifdef PRIuMAX
if (sizeof (time_t) == sizeof (uintmax_t))
return "%"PRIuMAX;
#endif
if (sizeof (time_t) > sizeof (unsigned long)) if (sizeof (time_t) > sizeof (unsigned long))
return "%llu"; return "%llu";
if (sizeof (time_t) > sizeof (unsigned int)) if (sizeof (time_t) > sizeof (unsigned int))

File diff suppressed because it is too large Load diff