]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/tzcode/zdump.c
2 ** This file is in the public domain, so clarified as of
3 ** 2009-05-17 by Arthur David Olson.
9 ** This code has been made independent of the rest of the time
10 ** conversion package to increase confidence in the verification it provides.
11 ** You can use this code to help in verifying other implementations.
13 ** However, include private.h when debugging, so that it overrides
14 ** time_t consistently with the rest of the package.
21 #include "stdio.h" /* for stdout, stderr, perror */
22 #include "string.h" /* for strcpy */
23 #include "sys/types.h" /* for time_t */
24 #include "time.h" /* for struct tm */
25 #include "stdlib.h" /* for exit, malloc, atoi */
26 #include "limits.h" /* for CHAR_BIT, LLONG_MAX */
27 #include "ctype.h" /* for isalpha et al. */
29 /* Enable extensions and modifications for ICU. */
39 #endif /* !defined isascii */
42 ** Substitutes for pre-C99 compilers.
43 ** Much of this section of code is stolen from private.h.
47 # define HAVE_STDINT_H \
48 (199901 <= __STDC_VERSION__ || 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
53 #ifndef HAVE_INTTYPES_H
54 # define HAVE_INTTYPES_H HAVE_STDINT_H
57 # include <inttypes.h>
60 #ifndef INT_FAST32_MAX
61 # if INT_MAX >> 31 == 0
62 typedef long int_fast32_t;
64 typedef int int_fast32_t;
69 # if defined LLONG_MAX || defined __LONG_LONG_MAX__
70 typedef long long intmax_t;
71 # define strtoimax strtoll
72 # define PRIdMAX "lld"
74 # define INTMAX_MAX LLONG_MAX
76 # define INTMAX_MAX __LONG_LONG_MAX__
79 typedef long intmax_t;
80 # define strtoimax strtol
82 # define INTMAX_MAX LONG_MAX
88 #define ZDUMP_LO_YEAR (-500)
89 #endif /* !defined ZDUMP_LO_YEAR */
92 #define ZDUMP_HI_YEAR 2500
93 #endif /* !defined ZDUMP_HI_YEAR */
95 #ifndef MAX_STRING_LENGTH
96 #define MAX_STRING_LENGTH 1024
97 #endif /* !defined MAX_STRING_LENGTH */
101 #endif /* !defined TRUE */
105 #endif /* !defined FALSE */
108 #define EXIT_SUCCESS 0
109 #endif /* !defined EXIT_SUCCESS */
112 #define EXIT_FAILURE 1
113 #endif /* !defined EXIT_FAILURE */
116 #define SECSPERMIN 60
117 #endif /* !defined SECSPERMIN */
120 #define MINSPERHOUR 60
121 #endif /* !defined MINSPERHOUR */
124 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
125 #endif /* !defined SECSPERHOUR */
128 #define HOURSPERDAY 24
129 #endif /* !defined HOURSPERDAY */
132 #define EPOCH_YEAR 1970
133 #endif /* !defined EPOCH_YEAR */
136 #define TM_YEAR_BASE 1900
137 #endif /* !defined TM_YEAR_BASE */
140 #define DAYSPERNYEAR 365
141 #endif /* !defined DAYSPERNYEAR */
144 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
145 #endif /* !defined isleap */
149 ** See tzfile.h for details on isleap_sum.
151 #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
152 #endif /* !defined isleap_sum */
154 #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
155 #define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR)
156 #define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY)
157 #define SECSPER400YEARS (SECSPERNYEAR * (intmax_t) (300 + 3) \
158 + SECSPERLYEAR * (intmax_t) (100 - 3))
161 ** True if SECSPER400YEARS is known to be representable as an
162 ** intmax_t. It's OK that SECSPER400YEARS_FITS can in theory be false
163 ** even if SECSPER400YEARS is representable, because when that happens
164 ** the code merely runs a bit more slowly, and this slowness doesn't
165 ** occur on any practical platform.
167 enum { SECSPER400YEARS_FITS
= SECSPERLYEAR
<= INTMAX_MAX
/ 400 };
170 #define HAVE_GETTEXT 0
173 #include "locale.h" /* for setlocale */
175 #endif /* HAVE_GETTEXT */
180 #else /* !defined lint */
183 #endif /* defined __GNUC__ */
184 #endif /* !defined lint */
185 #endif /* !defined GNUC_or_lint */
187 #if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
188 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
190 # define ATTRIBUTE_PURE /* empty */
194 ** For the benefit of GNU folk...
195 ** `_(MSGID)' uses the current locale's message library string for MSGID.
196 ** The default is to use gettext if available, and use MSGID otherwise.
201 #define _(msgid) gettext(msgid)
202 #else /* !HAVE_GETTEXT */
203 #define _(msgid) msgid
204 #endif /* !HAVE_GETTEXT */
205 #endif /* !defined _ */
208 #define TZ_DOMAIN "tz"
209 #endif /* !defined TZ_DOMAIN */
211 extern char ** environ
;
212 extern int getopt(int argc
, char * const argv
[],
213 const char * options
);
214 extern char * optarg
;
216 extern char * tzname
[2];
218 /* The minimum and maximum finite time values. */
219 static time_t const absolute_min_time
=
221 ? (time_t) -1 << (CHAR_BIT
* sizeof (time_t) - 1)
223 static time_t const absolute_max_time
=
225 ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT
* sizeof (time_t) - 1))
227 static size_t longest
;
228 static char * progname
;
231 static char * abbr(struct tm
* tmp
);
232 static void abbrok(const char * abbrp
, const char * zone
);
233 static intmax_t delta(struct tm
* newp
, struct tm
* oldp
) ATTRIBUTE_PURE
;
234 static void dumptime(const struct tm
* tmp
);
235 static time_t hunt(char * name
, time_t lot
, time_t hit
);
236 static void show(char * zone
, time_t t
, int v
);
237 static const char * tformat(void);
238 static time_t yeartot(intmax_t y
) ATTRIBUTE_PURE
;
240 typedef struct listentry
{
242 struct listentry
* next
;
245 static time_t huntICU(char * name
, time_t lot
, time_t hit
, FILE *fp
);
246 static void dumptimeICU(FILE * fp
, time_t t
);
247 static void showICU(FILE * fp
, char * zone
, time_t t1
, time_t t2
);
248 static int getall(struct listentry
** namelist
);
249 static void getzones(char * basedir
, char * subdir
, struct listentry
** last
, int * count
);
253 #define my_localtime localtime
254 #else /* !defined TYPECHECK */
256 my_localtime(time_t *tp
)
258 register struct tm
* tmp
;
261 if (tp
!= NULL
&& tmp
!= NULL
) {
268 (void) fflush(stdout
);
269 (void) fprintf(stderr
, "\n%s: ", progname
);
270 (void) fprintf(stderr
, tformat(), *tp
);
271 (void) fprintf(stderr
, " ->");
272 (void) fprintf(stderr
, " year=%d", tmp
->tm_year
);
273 (void) fprintf(stderr
, " mon=%d", tmp
->tm_mon
);
274 (void) fprintf(stderr
, " mday=%d", tmp
->tm_mday
);
275 (void) fprintf(stderr
, " hour=%d", tmp
->tm_hour
);
276 (void) fprintf(stderr
, " min=%d", tmp
->tm_min
);
277 (void) fprintf(stderr
, " sec=%d", tmp
->tm_sec
);
278 (void) fprintf(stderr
, " isdst=%d", tmp
->tm_isdst
);
279 (void) fprintf(stderr
, " -> ");
280 (void) fprintf(stderr
, tformat(), t
);
281 (void) fprintf(stderr
, "\n");
286 #endif /* !defined TYPECHECK */
289 abbrok(const char *const abbrp
, const char *const zone
)
291 register const char * cp
;
292 register const char * wp
;
298 while (isascii((unsigned char) *cp
) && isalpha((unsigned char) *cp
))
301 wp
= _("lacks alphabetic at start");
302 else if (cp
- abbrp
< 3)
303 wp
= _("has fewer than 3 alphabetics");
304 else if (cp
- abbrp
> 6)
305 wp
= _("has more than 6 alphabetics");
306 if (wp
== NULL
&& (*cp
== '+' || *cp
== '-')) {
308 if (isascii((unsigned char) *cp
) &&
309 isdigit((unsigned char) *cp
))
310 if (*cp
++ == '1' && *cp
>= '0' && *cp
<= '4')
313 wp
= _("differs from POSIX standard");
317 (void) fflush(stdout
);
318 (void) fprintf(stderr
,
319 _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
320 progname
, zone
, abbrp
, wp
);
325 usage(FILE * const stream
, const int status
)
327 (void) fprintf(stream
,
328 _("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n"
330 "Report bugs to %s.\n"),
331 progname
, progname
, REPORT_BUGS_TO
);
336 main(int argc
, char *argv
[])
341 register char * cutarg
;
342 register char * cuttimes
;
343 register time_t cutlotime
;
344 register time_t cuthitime
;
345 register char ** fakeenv
;
351 register struct tm
* tmp
;
352 register struct tm
* newtmp
;
358 listentry
* namelist
= NULL
;
362 cutlotime
= absolute_min_time
;
363 cuthitime
= absolute_max_time
;
365 (void) setlocale(LC_ALL
, "");
367 (void) bindtextdomain(TZ_DOMAIN
, TZ_DOMAINDIR
);
368 #endif /* defined TEXTDOMAINDIR */
369 (void) textdomain(TZ_DOMAIN
);
370 #endif /* HAVE_GETTEXT */
372 for (i
= 1; i
< argc
; ++i
)
373 if (strcmp(argv
[i
], "--version") == 0) {
374 (void) printf("zdump %s%s\n", PKGVERSION
, TZVERSION
);
376 } else if (strcmp(argv
[i
], "--help") == 0) {
377 usage(stdout
, EXIT_SUCCESS
);
380 cutarg
= cuttimes
= NULL
;
386 switch(getopt(argc
, argv
, "ac:d:it:vV")) {
387 case 'a': aflag
= 1; break;
388 case 'c': cutarg
= optarg
; break;
389 case 'd': dirarg
= optarg
; break;
390 case 'i': iflag
= 1; break;
391 case 't': cuttimes
= optarg
; break;
392 case 'v': vflag
= 1; break;
393 case 'V': Vflag
= 1; break;
395 if (! (optind
== argc
- 1 && strcmp(argv
[optind
], "=") == 0))
396 goto arg_processing_done
;
399 (void) fprintf(stderr
,
400 _("%s: usage is %s [ --version ] [ -a ] [ -v ] [ -V ] [ -i ] [ -c [loyear,]hiyear ] [ -t [lotime,]hitime] ][ -d dir ] [ zonename ... ]\n"),
406 switch (getopt(argc
, argv
, "c:t:vV")) {
407 case 'c': cutarg
= optarg
; break;
408 case 't': cuttimes
= optarg
; break;
409 case 'v': vflag
= 1; break;
410 case 'V': Vflag
= 1; break;
412 if (! (optind
== argc
- 1 && strcmp(argv
[optind
], "=") == 0))
413 goto arg_processing_done
;
416 usage(stderr
, EXIT_FAILURE
);
419 arg_processing_done
:;
422 if (dirarg
!= NULL
) {
424 /* create the output directory */
426 if ((dp
= opendir(dirarg
)) == NULL
) {
427 fprintf(stderr
, "cannot create the target directory");
438 register intmax_t cutloyear
= ZDUMP_LO_YEAR
;
439 register intmax_t cuthiyear
= ZDUMP_HI_YEAR
;
440 if (cutarg
!= NULL
) {
441 lo
= strtoimax(cutarg
, &loend
, 10);
442 if (cutarg
!= loend
&& !*loend
) {
445 } else if (cutarg
!= loend
&& *loend
== ','
446 && (hi
= strtoimax(loend
+ 1, &hiend
, 10),
447 loend
+ 1 != hiend
&& !*hiend
)) {
451 (void) fprintf(stderr
, _("%s: wild -c argument %s\n"),
456 if (cutarg
!= NULL
|| cuttimes
== NULL
) {
457 cutlotime
= yeartot(cutloyear
);
458 cuthitime
= yeartot(cuthiyear
);
460 if (cuttimes
!= NULL
) {
461 lo
= strtoimax(cuttimes
, &loend
, 10);
462 if (cuttimes
!= loend
&& !*loend
) {
464 if (hi
< cuthitime
) {
465 if (hi
< absolute_min_time
)
466 hi
= absolute_min_time
;
469 } else if (cuttimes
!= loend
&& *loend
== ','
470 && (hi
= strtoimax(loend
+ 1, &hiend
, 10),
471 loend
+ 1 != hiend
&& !*hiend
)) {
472 if (cutlotime
< lo
) {
473 if (absolute_max_time
< lo
)
474 lo
= absolute_max_time
;
477 if (hi
< cuthitime
) {
478 if (hi
< absolute_min_time
)
479 hi
= absolute_min_time
;
483 (void) fprintf(stderr
,
484 _("%s: wild -t argument %s\n"),
493 /* get all available zones */
498 count
= getall(&namelist
);
499 fakeargv
= (char **) malloc((size_t) (argc
+ count
) * sizeof *argv
);
501 if ((fakeargv = (char **) malloc((size_t) (argc + count) * sizeof *argv)) == NULL) {
505 for (i
= 0; i
< argc
; i
++) {
506 fakeargv
[i
] = argv
[i
];
508 for (i
= 0; i
< count
; i
++) {
509 fakeargv
[i
+ argc
] = namelist
->name
;
510 namelist
= namelist
->next
;
518 for (i
= optind
; i
< argc
; ++i
)
519 if (strlen(argv
[i
]) > longest
)
520 longest
= strlen(argv
[i
]);
525 for (i
= 0; environ
[i
] != NULL
; ++i
)
527 fakeenv
= malloc((i
+ 2) * sizeof *fakeenv
);
529 || (fakeenv
[0] = malloc(longest
+ 4)) == NULL
) {
530 (void) perror(progname
);
534 (void) strcpy(fakeenv
[to
++], "TZ=");
535 for (from
= 0; environ
[from
] != NULL
; ++from
)
536 if (strncmp(environ
[from
], "TZ=", 3) != 0)
537 fakeenv
[to
++] = environ
[from
];
541 for (i
= optind
; i
< argc
; ++i
) {
542 static char buf
[MAX_STRING_LENGTH
];
544 (void) strcpy(&fakeenv
[0][3], argv
[i
]);
545 if (! (vflag
| Vflag
)) {
546 show(argv
[i
], now
, FALSE
);
552 if (dirarg
== NULL
) {
553 /* we want to display a zone name here */
557 printf("ZONE: %s\n", argv
[i
]);
560 char path
[FILENAME_MAX
+ 1];
561 strcpy(path
, dirarg
);
563 zstart
= strlen(path
);
564 strcat(path
, argv
[i
]);
565 /* replace '/' with '-' */
566 while(path
[++zstart
] != 0) {
567 if (path
[zstart
] == '/') {
571 if ((fp
= fopen(path
, "w")) == NULL
) {
572 fprintf(stderr
, "cannot create output file %s\n", path
);
579 t
= absolute_min_time
;
581 /* skip displaying info for the lowest time, which is actually not
582 * a transition when -i option is set */
586 show(argv
[i
], t
, TRUE
);
588 show(argv
[i
], t
, TRUE
);
595 tmp
= my_localtime(&t
);
598 (void) strncpy(buf
, abbr(&tm
), (sizeof buf
) - 1);
601 newt
= (t
< absolute_max_time
- SECSPERDAY
/ 2
603 : absolute_max_time
);
604 if (cuthitime
<= newt
)
606 newtmp
= localtime(&newt
);
611 /* We do not want to capture transitions just for
612 * abbreviated zone name changes */
613 if ((tmp
== NULL
|| newtmp
== NULL
) ? (tmp
!= newtmp
) :
614 (delta(&newtm
, &tm
) != (newt
- t
) ||
615 newtm
.tm_isdst
!= tm
.tm_isdst
)) {
616 newt
= huntICU(argv
[i
], t
, newt
, fp
);
617 newtmp
= localtime(&newt
);
618 if (newtmp
!= NULL
) {
627 if ((tmp
== NULL
|| newtmp
== NULL
) ? (tmp
!= newtmp
) :
628 (delta(&newtm
, &tm
) != (newt
- t
) ||
629 newtm
.tm_isdst
!= tm
.tm_isdst
||
630 strcmp(abbr(&newtm
), buf
) != 0)) {
631 newt
= hunt(argv
[i
], t
, newt
);
632 newtmp
= localtime(&newt
);
633 if (newtmp
!= NULL
) {
649 /* skip displaying info for the highest time, which is actually not
650 * a transition when -i option is used*/
653 t
= absolute_max_time
;
655 show(argv
[i
], t
, TRUE
);
657 show(argv
[i
], t
, TRUE
);
667 if (fflush(stdout
) || ferror(stdout
)) {
668 (void) fprintf(stderr
, "%s: ", progname
);
669 (void) perror(_("Error writing to standard output"));
674 struct listentry
* entry
= namelist
;
675 struct listentry
* next
;
676 while (entry
!= NULL
) {
685 /* If exit fails to exit... */
690 yeartot(const intmax_t y
)
692 register intmax_t myy
, seconds
, years
;
698 if (SECSPER400YEARS_FITS
&& 400 <= y
- myy
) {
699 intmax_t diff400
= (y
- myy
) / 400;
700 if (INTMAX_MAX
/ SECSPER400YEARS
< diff400
)
701 return absolute_max_time
;
702 seconds
= diff400
* SECSPER400YEARS
;
703 years
= diff400
* 400;
705 seconds
= isleap(myy
) ? SECSPERLYEAR
: SECSPERNYEAR
;
709 if (t
> absolute_max_time
- seconds
)
710 return absolute_max_time
;
714 if (SECSPER400YEARS_FITS
&& y
+ 400 <= myy
&& myy
< 0) {
715 intmax_t diff400
= (myy
- y
) / 400;
716 if (INTMAX_MAX
/ SECSPER400YEARS
< diff400
)
717 return absolute_min_time
;
718 seconds
= diff400
* SECSPER400YEARS
;
719 years
= diff400
* 400;
721 seconds
= isleap(myy
- 1) ? SECSPERLYEAR
: SECSPERNYEAR
;
725 if (t
< absolute_min_time
+ seconds
)
726 return absolute_min_time
;
733 hunt(char *name
, time_t lot
, time_t hit
)
737 register struct tm
* lotmp
;
739 register struct tm
* tmp
;
740 char loab
[MAX_STRING_LENGTH
];
742 lotmp
= my_localtime(&lot
);
745 (void) strncpy(loab
, abbr(&lotm
), (sizeof loab
) - 1);
748 time_t diff
= hit
- lot
;
757 tmp
= my_localtime(&t
);
760 if ((lotmp
== NULL
|| tmp
== NULL
) ? (lotmp
== tmp
) :
761 (delta(&tm
, &lotm
) == (t
- lot
) &&
762 tm
.tm_isdst
== lotm
.tm_isdst
&&
763 strcmp(abbr(&tm
), loab
) == 0)) {
769 show(name
, lot
, TRUE
);
770 show(name
, hit
, TRUE
);
775 ** Thanks to Paul Eggert for logic used in delta.
779 delta(struct tm
* newp
, struct tm
*oldp
)
781 register intmax_t result
;
784 if (newp
->tm_year
< oldp
->tm_year
)
785 return -delta(oldp
, newp
);
787 for (tmy
= oldp
->tm_year
; tmy
< newp
->tm_year
; ++tmy
)
788 result
+= DAYSPERNYEAR
+ isleap_sum(tmy
, TM_YEAR_BASE
);
789 result
+= newp
->tm_yday
- oldp
->tm_yday
;
790 result
*= HOURSPERDAY
;
791 result
+= newp
->tm_hour
- oldp
->tm_hour
;
792 result
*= MINSPERHOUR
;
793 result
+= newp
->tm_min
- oldp
->tm_min
;
794 result
*= SECSPERMIN
;
795 result
+= newp
->tm_sec
- oldp
->tm_sec
;
800 show(char *zone
, time_t t
, int v
)
802 register struct tm
* tmp
;
804 (void) printf("%-*s ", (int) longest
, zone
);
808 (void) printf(tformat(), t
);
811 (void) printf(" UT");
813 (void) printf(" = ");
815 tmp
= my_localtime(&t
);
818 if (*abbr(tmp
) != '\0')
819 (void) printf(" %s", abbr(tmp
));
821 (void) printf(" isdst=%d", tmp
->tm_isdst
);
823 (void) printf(" gmtoff=%ld", tmp
->TM_GMTOFF
);
824 #endif /* defined TM_GMTOFF */
828 if (tmp
!= NULL
&& *abbr(tmp
) != '\0')
829 abbrok(abbr(tmp
), zone
);
835 register char * result
;
838 if (tmp
->tm_isdst
!= 0 && tmp
->tm_isdst
!= 1)
840 result
= tzname
[tmp
->tm_isdst
];
841 return (result
== NULL
) ? &nada
: result
;
845 ** The code below can fail on certain theoretical systems;
846 ** it works on all known real-world systems as of 2004-12-30.
852 if (0 > (time_t) -1) { /* signed */
853 if (sizeof (time_t) == sizeof (intmax_t))
855 if (sizeof (time_t) > sizeof (long))
857 if (sizeof (time_t) > sizeof (int))
862 if (sizeof (time_t) == sizeof (uintmax_t))
865 if (sizeof (time_t) > sizeof (unsigned long))
867 if (sizeof (time_t) > sizeof (unsigned int))
873 dumptime(register const struct tm
*timeptr
)
875 static const char wday_name
[][3] = {
876 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
878 static const char mon_name
[][3] = {
879 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
880 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
882 register const char * wn
;
883 register const char * mn
;
887 if (timeptr
== NULL
) {
888 (void) printf("NULL");
892 ** The packaged versions of localtime and gmtime never put out-of-range
893 ** values in tm_wday or tm_mon, but since this code might be compiled
894 ** with other (perhaps experimental) versions, paranoia is in order.
896 if (timeptr
->tm_wday
< 0 || timeptr
->tm_wday
>=
897 (int) (sizeof wday_name
/ sizeof wday_name
[0]))
899 else wn
= wday_name
[timeptr
->tm_wday
];
900 if (timeptr
->tm_mon
< 0 || timeptr
->tm_mon
>=
901 (int) (sizeof mon_name
/ sizeof mon_name
[0]))
903 else mn
= mon_name
[timeptr
->tm_mon
];
904 (void) printf("%.3s %.3s%3d %.2d:%.2d:%.2d ",
906 timeptr
->tm_mday
, timeptr
->tm_hour
,
907 timeptr
->tm_min
, timeptr
->tm_sec
);
909 trail
= timeptr
->tm_year
% DIVISOR
+ TM_YEAR_BASE
% DIVISOR
;
910 lead
= timeptr
->tm_year
/ DIVISOR
+ TM_YEAR_BASE
/ DIVISOR
+
913 if (trail
< 0 && lead
> 0) {
916 } else if (lead
< 0 && trail
> 0) {
921 (void) printf("%d", trail
);
922 else (void) printf("%d%d", lead
, ((trail
< 0) ? -trail
: trail
));
927 huntICU(char *name
, time_t lot
, time_t hit
, FILE * fp
)
932 register struct tm
* lotmp
;
934 register struct tm
* tmp
;
935 char loab
[MAX_STRING_LENGTH
];
937 lotmp
= my_localtime(&lot
);
940 (void) strncpy(loab
, abbr(&lotm
), (sizeof loab
) - 1);
943 diff
= (long) (hit
- lot
);
952 tmp
= my_localtime(&t
);
955 /* We do not want to capture transitions just for
956 * abbreviated zone name changes */
957 if ((lotmp
== NULL
|| tmp
== NULL
) ? (lotmp
== tmp
) :
958 (delta(&tm
, &lotm
) == (t
- lot
) &&
959 tm
.tm_isdst
== lotm
.tm_isdst
)) {
965 showICU(fp
, name
, lot
, hit
);
969 static void showICU(FILE * fp
, char *zone
, time_t t1
, time_t t2
)
980 static void dumptimeICU(FILE * fp
, time_t t
)
982 static const char wday_name
[][3] = {
983 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
992 loc
= *my_localtime(&t
);
994 trail
= loc
.tm_year
% DIVISOR
+ TM_YEAR_BASE
% DIVISOR
;
995 lead
= loc
.tm_year
/ DIVISOR
+ TM_YEAR_BASE
/ DIVISOR
+ trail
/ DIVISOR
;
997 if (trail
< 0 && lead
> 0) {
1000 } else if (lead
< 0 && trail
> 0) {
1005 fprintf(fp
, "%04d-%02d-%02d", lead
* DIVISOR
+ trail
, loc
.tm_mon
+ 1, loc
.tm_mday
);
1006 fprintf(fp
, " %.3s ", wday_name
[loc
.tm_wday
]);
1007 fprintf(fp
, "%02d:%02d:%02d", loc
.tm_hour
, loc
.tm_min
, loc
.tm_sec
);
1010 offset
= delta(&loc
, &gmt
);
1019 offset
= (offset
- sec
) / 60;
1023 fprintf(fp
, "%02ld", hour
);
1024 fprintf(fp
, "%02ld", min
);
1025 fprintf(fp
, "%02ld", sec
);
1026 fprintf(fp
, "[DST=%d]", loc
.tm_isdst
);
1029 static int getall(struct listentry
** namelist
) {
1031 struct listentry dummyentry
;
1032 struct listentry
* last
= &dummyentry
;
1034 getzones(TZDIR
, NULL
, &last
, &count
);
1036 *namelist
= dummyentry
.next
;
1042 static void getzones(char * basedir
, char * relpath
, struct listentry
** last
, int * count
) {
1043 char path
[FILENAME_MAX
+ 1];
1044 struct dirent
* dir
;
1047 strcpy(path
, basedir
);
1048 if (relpath
!= NULL
) {
1050 strcat(path
, relpath
);
1053 if ((dp
= opendir(path
)) == NULL
) {
1055 if (strstr(relpath
, ".tab") == NULL
&& strcmp(relpath
, "Etc/Unknown") != 0) {
1059 if ((pzonename
= malloc(strlen(relpath
) + 1)) == NULL
) {
1062 strcpy(pzonename
, relpath
);
1064 if ((pentry
= malloc(sizeof(listentry
))) == NULL
) {
1068 pentry
->name
= pzonename
;
1069 pentry
->next
= NULL
;
1070 (*last
)->next
= pentry
;
1076 while ((dir
= readdir(dp
)) != NULL
) {
1077 char subpath
[FILENAME_MAX
+ 1];
1079 if (strcmp(dir
->d_name
, ".") == 0
1080 || strcmp(dir
->d_name
, "..") == 0) {
1083 if (relpath
!= NULL
) {
1084 strcpy(subpath
, relpath
);
1085 strcat(subpath
, "/");
1086 strcat(subpath
, dir
->d_name
);
1088 strcpy(subpath
, dir
->d_name
);
1090 getzones(basedir
, subpath
, last
, count
);