]>
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. */
38 #endif /* !defined isascii */
41 ** Substitutes for pre-C99 compilers.
42 ** Much of this section of code is stolen from private.h.
46 # define HAVE_STDINT_H \
47 (199901 <= __STDC_VERSION__ || 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
52 #ifndef HAVE_INTTYPES_H
53 # define HAVE_INTTYPES_H HAVE_STDINT_H
56 # include <inttypes.h>
59 #ifndef INT_FAST32_MAX
60 # if INT_MAX >> 31 == 0
61 typedef long int_fast32_t;
63 typedef int int_fast32_t;
68 # if defined LLONG_MAX || defined __LONG_LONG_MAX__
69 typedef long long intmax_t;
70 # define strtoimax strtoll
71 # define PRIdMAX "lld"
73 # define INTMAX_MAX LLONG_MAX
75 # define INTMAX_MAX __LONG_LONG_MAX__
78 typedef long intmax_t;
79 # define strtoimax strtol
81 # define INTMAX_MAX LONG_MAX
87 #define ZDUMP_LO_YEAR (-500)
88 #endif /* !defined ZDUMP_LO_YEAR */
91 #define ZDUMP_HI_YEAR 2500
92 #endif /* !defined ZDUMP_HI_YEAR */
94 #ifndef MAX_STRING_LENGTH
95 #define MAX_STRING_LENGTH 1024
96 #endif /* !defined MAX_STRING_LENGTH */
100 #endif /* !defined TRUE */
104 #endif /* !defined FALSE */
107 #define EXIT_SUCCESS 0
108 #endif /* !defined EXIT_SUCCESS */
111 #define EXIT_FAILURE 1
112 #endif /* !defined EXIT_FAILURE */
115 #define SECSPERMIN 60
116 #endif /* !defined SECSPERMIN */
119 #define MINSPERHOUR 60
120 #endif /* !defined MINSPERHOUR */
123 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
124 #endif /* !defined SECSPERHOUR */
127 #define HOURSPERDAY 24
128 #endif /* !defined HOURSPERDAY */
131 #define EPOCH_YEAR 1970
132 #endif /* !defined EPOCH_YEAR */
135 #define TM_YEAR_BASE 1900
136 #endif /* !defined TM_YEAR_BASE */
139 #define DAYSPERNYEAR 365
140 #endif /* !defined DAYSPERNYEAR */
143 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
144 #endif /* !defined isleap */
148 ** See tzfile.h for details on isleap_sum.
150 #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
151 #endif /* !defined isleap_sum */
153 #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
154 #define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR)
155 #define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY)
156 #define SECSPER400YEARS (SECSPERNYEAR * (intmax_t) (300 + 3) \
157 + SECSPERLYEAR * (intmax_t) (100 - 3))
160 ** True if SECSPER400YEARS is known to be representable as an
161 ** intmax_t. It's OK that SECSPER400YEARS_FITS can in theory be false
162 ** even if SECSPER400YEARS is representable, because when that happens
163 ** the code merely runs a bit more slowly, and this slowness doesn't
164 ** occur on any practical platform.
166 enum { SECSPER400YEARS_FITS
= SECSPERLYEAR
<= INTMAX_MAX
/ 400 };
169 #define HAVE_GETTEXT 0
172 #include "locale.h" /* for setlocale */
174 #endif /* HAVE_GETTEXT */
179 #else /* !defined lint */
182 #endif /* defined __GNUC__ */
183 #endif /* !defined lint */
184 #endif /* !defined GNUC_or_lint */
186 #if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
187 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
189 # define ATTRIBUTE_PURE /* empty */
193 ** For the benefit of GNU folk...
194 ** `_(MSGID)' uses the current locale's message library string for MSGID.
195 ** The default is to use gettext if available, and use MSGID otherwise.
200 #define _(msgid) gettext(msgid)
201 #else /* !HAVE_GETTEXT */
202 #define _(msgid) msgid
203 #endif /* !HAVE_GETTEXT */
204 #endif /* !defined _ */
207 #define TZ_DOMAIN "tz"
208 #endif /* !defined TZ_DOMAIN */
210 extern char ** environ
;
211 extern int getopt(int argc
, char * const argv
[],
212 const char * options
);
213 extern char * optarg
;
215 extern char * tzname
[2];
217 /* The minimum and maximum finite time values. */
218 static time_t const absolute_min_time
=
220 ? (time_t) -1 << (CHAR_BIT
* sizeof (time_t) - 1)
222 static time_t const absolute_max_time
=
224 ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT
* sizeof (time_t) - 1))
226 static size_t longest
;
227 static char * progname
;
230 static char * abbr(struct tm
* tmp
);
231 static void abbrok(const char * abbrp
, const char * zone
);
232 static intmax_t delta(struct tm
* newp
, struct tm
* oldp
) ATTRIBUTE_PURE
;
233 static void dumptime(const struct tm
* tmp
);
234 static time_t hunt(char * name
, time_t lot
, time_t hit
);
235 static void show(char * zone
, time_t t
, int v
);
236 static const char * tformat(void);
237 static time_t yeartot(intmax_t y
) ATTRIBUTE_PURE
;
239 typedef struct listentry
{
241 struct listentry
* next
;
244 static time_t huntICU(char * name
, time_t lot
, time_t hit
, FILE *fp
);
245 static void dumptimeICU(FILE * fp
, time_t t
);
246 static void showICU(FILE * fp
, char * zone
, time_t t1
, time_t t2
);
247 static int getall(struct listentry
** namelist
);
248 static void getzones(char * basedir
, char * subdir
, struct listentry
** last
, int * count
);
252 #define my_localtime localtime
253 #else /* !defined TYPECHECK */
255 my_localtime(time_t *tp
)
257 register struct tm
* tmp
;
260 if (tp
!= NULL
&& tmp
!= NULL
) {
267 (void) fflush(stdout
);
268 (void) fprintf(stderr
, "\n%s: ", progname
);
269 (void) fprintf(stderr
, tformat(), *tp
);
270 (void) fprintf(stderr
, " ->");
271 (void) fprintf(stderr
, " year=%d", tmp
->tm_year
);
272 (void) fprintf(stderr
, " mon=%d", tmp
->tm_mon
);
273 (void) fprintf(stderr
, " mday=%d", tmp
->tm_mday
);
274 (void) fprintf(stderr
, " hour=%d", tmp
->tm_hour
);
275 (void) fprintf(stderr
, " min=%d", tmp
->tm_min
);
276 (void) fprintf(stderr
, " sec=%d", tmp
->tm_sec
);
277 (void) fprintf(stderr
, " isdst=%d", tmp
->tm_isdst
);
278 (void) fprintf(stderr
, " -> ");
279 (void) fprintf(stderr
, tformat(), t
);
280 (void) fprintf(stderr
, "\n");
285 #endif /* !defined TYPECHECK */
288 abbrok(const char *const abbrp
, const char *const zone
)
290 register const char * cp
;
291 register const char * wp
;
297 while (isascii((unsigned char) *cp
) && isalpha((unsigned char) *cp
))
300 wp
= _("lacks alphabetic at start");
301 else if (cp
- abbrp
< 3)
302 wp
= _("has fewer than 3 alphabetics");
303 else if (cp
- abbrp
> 6)
304 wp
= _("has more than 6 alphabetics");
305 if (wp
== NULL
&& (*cp
== '+' || *cp
== '-')) {
307 if (isascii((unsigned char) *cp
) &&
308 isdigit((unsigned char) *cp
))
309 if (*cp
++ == '1' && *cp
>= '0' && *cp
<= '4')
312 wp
= _("differs from POSIX standard");
316 (void) fflush(stdout
);
317 (void) fprintf(stderr
,
318 _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
319 progname
, zone
, abbrp
, wp
);
324 usage(FILE * const stream
, const int status
)
326 (void) fprintf(stream
,
327 _("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n"
329 "Report bugs to %s.\n"),
330 progname
, progname
, REPORT_BUGS_TO
);
335 main(int argc
, char *argv
[])
340 register char * cutarg
;
341 register char * cuttimes
;
342 register time_t cutlotime
;
343 register time_t cuthitime
;
344 register char ** fakeenv
;
350 register struct tm
* tmp
;
351 register struct tm
* newtmp
;
357 listentry
* namelist
= NULL
;
361 cutlotime
= absolute_min_time
;
362 cuthitime
= absolute_max_time
;
364 (void) setlocale(LC_ALL
, "");
366 (void) bindtextdomain(TZ_DOMAIN
, TZ_DOMAINDIR
);
367 #endif /* defined TEXTDOMAINDIR */
368 (void) textdomain(TZ_DOMAIN
);
369 #endif /* HAVE_GETTEXT */
371 for (i
= 1; i
< argc
; ++i
)
372 if (strcmp(argv
[i
], "--version") == 0) {
373 (void) printf("zdump %s%s\n", PKGVERSION
, TZVERSION
);
375 } else if (strcmp(argv
[i
], "--help") == 0) {
376 usage(stdout
, EXIT_SUCCESS
);
379 cutarg
= cuttimes
= NULL
;
385 switch(getopt(argc
, argv
, "ac:d:it:vV")) {
386 case 'a': aflag
= 1; break;
387 case 'c': cutarg
= optarg
; break;
388 case 'd': dirarg
= optarg
; break;
389 case 'i': iflag
= 1; break;
390 case 't': cuttimes
= optarg
; break;
391 case 'v': vflag
= 1; break;
392 case 'V': Vflag
= 1; break;
394 if (! (optind
== argc
- 1 && strcmp(argv
[optind
], "=") == 0))
395 goto arg_processing_done
;
398 (void) fprintf(stderr
,
399 _("%s: usage is %s [ --version ] [ -a ] [ -v ] [ -V ] [ -i ] [ -c [loyear,]hiyear ] [ -t [lotime,]hitime] ][ -d dir ] [ zonename ... ]\n"),
405 switch (getopt(argc
, argv
, "c:t:vV")) {
406 case 'c': cutarg
= optarg
; break;
407 case 't': cuttimes
= optarg
; break;
408 case 'v': vflag
= 1; break;
409 case 'V': Vflag
= 1; break;
411 if (! (optind
== argc
- 1 && strcmp(argv
[optind
], "=") == 0))
412 goto arg_processing_done
;
415 usage(stderr
, EXIT_FAILURE
);
418 arg_processing_done
:;
421 if (dirarg
!= NULL
) {
423 /* create the output directory */
425 if ((dp
= opendir(dirarg
)) == NULL
) {
426 fprintf(stderr
, "cannot create the target directory");
437 register intmax_t cutloyear
= ZDUMP_LO_YEAR
;
438 register intmax_t cuthiyear
= ZDUMP_HI_YEAR
;
439 if (cutarg
!= NULL
) {
440 lo
= strtoimax(cutarg
, &loend
, 10);
441 if (cutarg
!= loend
&& !*loend
) {
444 } else if (cutarg
!= loend
&& *loend
== ','
445 && (hi
= strtoimax(loend
+ 1, &hiend
, 10),
446 loend
+ 1 != hiend
&& !*hiend
)) {
450 (void) fprintf(stderr
, _("%s: wild -c argument %s\n"),
455 if (cutarg
!= NULL
|| cuttimes
== NULL
) {
456 cutlotime
= yeartot(cutloyear
);
457 cuthitime
= yeartot(cuthiyear
);
459 if (cuttimes
!= NULL
) {
460 lo
= strtoimax(cuttimes
, &loend
, 10);
461 if (cuttimes
!= loend
&& !*loend
) {
463 if (hi
< cuthitime
) {
464 if (hi
< absolute_min_time
)
465 hi
= absolute_min_time
;
468 } else if (cuttimes
!= loend
&& *loend
== ','
469 && (hi
= strtoimax(loend
+ 1, &hiend
, 10),
470 loend
+ 1 != hiend
&& !*hiend
)) {
471 if (cutlotime
< lo
) {
472 if (absolute_max_time
< lo
)
473 lo
= absolute_max_time
;
476 if (hi
< cuthitime
) {
477 if (hi
< absolute_min_time
)
478 hi
= absolute_min_time
;
482 (void) fprintf(stderr
,
483 _("%s: wild -t argument %s\n"),
492 /* get all available zones */
497 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
, "%02d", hour
);
1024 fprintf(fp
, "%02d", min
);
1025 fprintf(fp
, "%02d", 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
);