OLD | NEW |
1 static char» elsieid[] = "@(#)zdump.c» 8.8"; | 1 /* |
| 2 ** This file is in the public domain, so clarified as of |
| 3 ** 2009-05-17 by Arthur David Olson. |
| 4 */ |
| 5 |
| 6 #include "version.h" |
2 | 7 |
3 /* | 8 /* |
4 ** This code has been made independent of the rest of the time | 9 ** This code has been made independent of the rest of the time |
5 ** conversion package to increase confidence in the verification it provides. | 10 ** conversion package to increase confidence in the verification it provides. |
6 ** You can use this code to help in verifying other implementations. | 11 ** You can use this code to help in verifying other implementations. |
| 12 ** |
| 13 ** However, include private.h when debugging, so that it overrides |
| 14 ** time_t consistently with the rest of the package. |
7 */ | 15 */ |
8 | 16 |
9 /* | 17 #ifdef time_tz |
10 * ICU note: Mr. Arthur David Olson (olsona@dc37a.nci.nih.gov) stated that | 18 # include "private.h" |
11 * "zdump.c is indeed in the public domain" in e-mail on Feb 22, 2007. | 19 #endif |
12 * This version of zdump.c is modified by ICU team to change output format | |
13 * and some additional options. | |
14 */ | |
15 | |
16 | 20 |
17 #include "stdio.h" /* for stdout, stderr, perror */ | 21 #include "stdio.h" /* for stdout, stderr, perror */ |
18 #include "string.h" /* for strcpy */ | 22 #include "string.h" /* for strcpy */ |
19 #include "sys/types.h" /* for time_t */ | 23 #include "sys/types.h" /* for time_t */ |
20 #include "time.h" /* for struct tm */ | 24 #include "time.h" /* for struct tm */ |
21 #include "stdlib.h" /* for exit, malloc, atoi */ | 25 #include "stdlib.h" /* for exit, malloc, atoi */ |
22 #include "float.h"» /* for FLT_MAX and DBL_MAX */ | 26 #include "limits.h"» /* for CHAR_BIT, LLONG_MAX */ |
23 #include "ctype.h" /* for isalpha et al. */ | 27 #include "ctype.h" /* for isalpha et al. */ |
24 | 28 |
25 /* Enable extensions and modifications for ICU. */ | 29 /* Enable extensions and modifications for ICU. */ |
26 #define ICU | 30 #define ICU |
27 | 31 |
28 #ifdef ICU | 32 #ifdef ICU |
29 #include "dirent.h" | 33 #include "dirent.h" |
30 #endif | 34 #endif |
31 | 35 |
32 #ifndef isascii | 36 #ifndef isascii |
33 #define isascii(x) 1 | 37 #define isascii(x) 1 |
34 #endif /* !defined isascii */ | 38 #endif /* !defined isascii */ |
35 | 39 |
| 40 /* |
| 41 ** Substitutes for pre-C99 compilers. |
| 42 ** Much of this section of code is stolen from private.h. |
| 43 */ |
| 44 |
| 45 #ifndef HAVE_STDINT_H |
| 46 # define HAVE_STDINT_H \ |
| 47 (199901 <= __STDC_VERSION__ || 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) |
| 48 #endif |
| 49 #if HAVE_STDINT_H |
| 50 # include "stdint.h" |
| 51 #endif |
| 52 #ifndef HAVE_INTTYPES_H |
| 53 # define HAVE_INTTYPES_H HAVE_STDINT_H |
| 54 #endif |
| 55 #if HAVE_INTTYPES_H |
| 56 # include <inttypes.h> |
| 57 #endif |
| 58 |
| 59 #ifndef INT_FAST32_MAX |
| 60 # if INT_MAX >> 31 == 0 |
| 61 typedef long int_fast32_t; |
| 62 # else |
| 63 typedef int int_fast32_t; |
| 64 # endif |
| 65 #endif |
| 66 |
| 67 #ifndef INTMAX_MAX |
| 68 # if defined LLONG_MAX || defined __LONG_LONG_MAX__ |
| 69 typedef long long intmax_t; |
| 70 # define strtoimax strtoll |
| 71 # define PRIdMAX "lld" |
| 72 # ifdef LLONG_MAX |
| 73 # define INTMAX_MAX LLONG_MAX |
| 74 # else |
| 75 # define INTMAX_MAX __LONG_LONG_MAX__ |
| 76 # endif |
| 77 # else |
| 78 typedef long intmax_t; |
| 79 # define strtoimax strtol |
| 80 # define PRIdMAX "ld" |
| 81 # define INTMAX_MAX LONG_MAX |
| 82 # endif |
| 83 #endif |
| 84 |
| 85 |
36 #ifndef ZDUMP_LO_YEAR | 86 #ifndef ZDUMP_LO_YEAR |
37 #define ZDUMP_LO_YEAR (-500) | 87 #define ZDUMP_LO_YEAR (-500) |
38 #endif /* !defined ZDUMP_LO_YEAR */ | 88 #endif /* !defined ZDUMP_LO_YEAR */ |
39 | 89 |
40 #ifndef ZDUMP_HI_YEAR | 90 #ifndef ZDUMP_HI_YEAR |
41 #define ZDUMP_HI_YEAR 2500 | 91 #define ZDUMP_HI_YEAR 2500 |
42 #endif /* !defined ZDUMP_HI_YEAR */ | 92 #endif /* !defined ZDUMP_HI_YEAR */ |
43 | 93 |
44 #ifndef MAX_STRING_LENGTH | 94 #ifndef MAX_STRING_LENGTH |
45 #define MAX_STRING_LENGTH 1024 | 95 #define MAX_STRING_LENGTH 1024 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) | 143 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) |
94 #endif /* !defined isleap */ | 144 #endif /* !defined isleap */ |
95 | 145 |
96 #ifndef isleap_sum | 146 #ifndef isleap_sum |
97 /* | 147 /* |
98 ** See tzfile.h for details on isleap_sum. | 148 ** See tzfile.h for details on isleap_sum. |
99 */ | 149 */ |
100 #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) | 150 #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) |
101 #endif /* !defined isleap_sum */ | 151 #endif /* !defined isleap_sum */ |
102 | 152 |
103 #define SECSPERDAY» ((long) SECSPERHOUR * HOURSPERDAY) | 153 #define SECSPERDAY» ((int_fast32_t) SECSPERHOUR * HOURSPERDAY) |
104 #define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR) | 154 #define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR) |
105 #define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY) | 155 #define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY) |
| 156 #define SECSPER400YEARS (SECSPERNYEAR * (intmax_t) (300 + 3) \ |
| 157 + SECSPERLYEAR * (intmax_t) (100 - 3)) |
| 158 |
| 159 /* |
| 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. |
| 165 */ |
| 166 enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 }; |
106 | 167 |
107 #ifndef HAVE_GETTEXT | 168 #ifndef HAVE_GETTEXT |
108 #define HAVE_GETTEXT 0 | 169 #define HAVE_GETTEXT 0 |
109 #endif | 170 #endif |
110 #if HAVE_GETTEXT | 171 #if HAVE_GETTEXT |
111 #include "locale.h" /* for setlocale */ | 172 #include "locale.h" /* for setlocale */ |
112 #include "libintl.h" | 173 #include "libintl.h" |
113 #endif /* HAVE_GETTEXT */ | 174 #endif /* HAVE_GETTEXT */ |
114 | 175 |
115 #ifndef GNUC_or_lint | 176 #ifndef GNUC_or_lint |
116 #ifdef lint | 177 #ifdef lint |
117 #define GNUC_or_lint | 178 #define GNUC_or_lint |
118 #else /* !defined lint */ | 179 #else /* !defined lint */ |
119 #ifdef __GNUC__ | 180 #ifdef __GNUC__ |
120 #define GNUC_or_lint | 181 #define GNUC_or_lint |
121 #endif /* defined __GNUC__ */ | 182 #endif /* defined __GNUC__ */ |
122 #endif /* !defined lint */ | 183 #endif /* !defined lint */ |
123 #endif /* !defined GNUC_or_lint */ | 184 #endif /* !defined GNUC_or_lint */ |
124 | 185 |
125 #ifndef INITIALIZE | 186 #if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__) |
126 #ifdef GNUC_or_lint | 187 # define ATTRIBUTE_PURE __attribute__ ((__pure__)) |
127 #define INITIALIZE(x)» ((x) = 0) | 188 #else |
128 #else /* !defined GNUC_or_lint */ | 189 # define ATTRIBUTE_PURE /* empty */ |
129 #define INITIALIZE(x) | 190 #endif |
130 #endif /* !defined GNUC_or_lint */ | |
131 #endif /* !defined INITIALIZE */ | |
132 | 191 |
133 /* | 192 /* |
134 ** For the benefit of GNU folk... | 193 ** For the benefit of GNU folk... |
135 ** `_(MSGID)' uses the current locale's message library string for MSGID. | 194 ** `_(MSGID)' uses the current locale's message library string for MSGID. |
136 ** The default is to use gettext if available, and use MSGID otherwise. | 195 ** The default is to use gettext if available, and use MSGID otherwise. |
137 */ | 196 */ |
138 | 197 |
139 #ifndef _ | 198 #ifndef _ |
140 #if HAVE_GETTEXT | 199 #if HAVE_GETTEXT |
141 #define _(msgid) gettext(msgid) | 200 #define _(msgid) gettext(msgid) |
142 #else /* !HAVE_GETTEXT */ | 201 #else /* !HAVE_GETTEXT */ |
143 #define _(msgid) msgid | 202 #define _(msgid) msgid |
144 #endif /* !HAVE_GETTEXT */ | 203 #endif /* !HAVE_GETTEXT */ |
145 #endif /* !defined _ */ | 204 #endif /* !defined _ */ |
146 | 205 |
147 #ifndef TZ_DOMAIN | 206 #ifndef TZ_DOMAIN |
148 #define TZ_DOMAIN "tz" | 207 #define TZ_DOMAIN "tz" |
149 #endif /* !defined TZ_DOMAIN */ | 208 #endif /* !defined TZ_DOMAIN */ |
150 | 209 |
151 extern char ** environ; | 210 extern char ** environ; |
152 extern int getopt(int argc, char * const argv[], | 211 extern int getopt(int argc, char * const argv[], |
153 const char * options); | 212 const char * options); |
154 extern char * optarg; | 213 extern char * optarg; |
155 extern int optind; | 214 extern int optind; |
156 extern char * tzname[2]; | 215 extern char * tzname[2]; |
157 | 216 |
158 static time_t» absolute_min_time; | 217 /* The minimum and maximum finite time values. */ |
159 static time_t» absolute_max_time; | 218 static time_t const absolute_min_time = |
| 219 ((time_t) -1 < 0 |
| 220 ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1) |
| 221 : 0); |
| 222 static time_t const absolute_max_time = |
| 223 ((time_t) -1 < 0 |
| 224 ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)) |
| 225 : -1); |
160 static size_t longest; | 226 static size_t longest; |
161 static char * progname; | 227 static char * progname; |
162 static int warned; | 228 static int warned; |
163 | 229 |
164 static char * abbr(struct tm * tmp); | 230 static char * abbr(struct tm * tmp); |
165 static void abbrok(const char * abbrp, const char * zone); | 231 static void abbrok(const char * abbrp, const char * zone); |
166 static long» delta(struct tm * newp, struct tm * oldp); | 232 static intmax_t»delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE; |
167 static void dumptime(const struct tm * tmp); | 233 static void dumptime(const struct tm * tmp); |
168 static time_t hunt(char * name, time_t lot, time_t hit); | 234 static time_t hunt(char * name, time_t lot, time_t hit); |
169 static void setabsolutes(void); | |
170 static void show(char * zone, time_t t, int v); | 235 static void show(char * zone, time_t t, int v); |
171 static const char * tformat(void); | 236 static const char * tformat(void); |
172 static time_t» yeartot(long y); | 237 static time_t» yeartot(intmax_t y) ATTRIBUTE_PURE; |
173 #ifdef ICU | 238 #ifdef ICU |
174 typedef struct listentry { | 239 typedef struct listentry { |
175 char * name; | 240 char * name; |
176 struct listentry * next; | 241 struct listentry * next; |
177 } listentry; | 242 } listentry; |
178 | 243 |
179 static time_t huntICU(char * name, time_t lot, time_t hit, FILE *fp); | 244 static time_t huntICU(char * name, time_t lot, time_t hit, FILE *fp); |
180 static void dumptimeICU(FILE * fp, time_t t); | 245 static void dumptimeICU(FILE * fp, time_t t); |
181 static void showICU(FILE * fp, char * zone, time_t t1, time_t t2); | 246 static void showICU(FILE * fp, char * zone, time_t t1, time_t t2); |
182 static int getall(struct listentry ** namelist); | 247 static int getall(struct listentry ** namelist); |
183 static void getzones(char * basedir, char * subdir, struct listentry ** last, in
t * count); | 248 static void getzones(char * basedir, char * subdir, struct listentry ** last, in
t * count); |
184 #endif | 249 #endif |
185 | 250 |
186 #ifndef TYPECHECK | 251 #ifndef TYPECHECK |
187 #define my_localtime localtime | 252 #define my_localtime localtime |
188 #else /* !defined TYPECHECK */ | 253 #else /* !defined TYPECHECK */ |
189 static struct tm * | 254 static struct tm * |
190 my_localtime(tp) | 255 my_localtime(time_t *tp) |
191 time_t *» tp; | |
192 { | 256 { |
193 register struct tm * tmp; | 257 register struct tm * tmp; |
194 | 258 |
195 tmp = localtime(tp); | 259 tmp = localtime(tp); |
196 if (tp != NULL && tmp != NULL) { | 260 if (tp != NULL && tmp != NULL) { |
197 struct tm tm; | 261 struct tm tm; |
198 register time_t t; | 262 register time_t t; |
199 | 263 |
200 tm = *tmp; | 264 tm = *tmp; |
201 t = mktime(&tm); | 265 t = mktime(&tm); |
202 » » if (t - *tp >= 1 || *tp - t >= 1) { | 266 » » if (t != *tp) { |
203 (void) fflush(stdout); | 267 (void) fflush(stdout); |
204 (void) fprintf(stderr, "\n%s: ", progname); | 268 (void) fprintf(stderr, "\n%s: ", progname); |
205 (void) fprintf(stderr, tformat(), *tp); | 269 (void) fprintf(stderr, tformat(), *tp); |
206 (void) fprintf(stderr, " ->"); | 270 (void) fprintf(stderr, " ->"); |
207 (void) fprintf(stderr, " year=%d", tmp->tm_year); | 271 (void) fprintf(stderr, " year=%d", tmp->tm_year); |
208 (void) fprintf(stderr, " mon=%d", tmp->tm_mon); | 272 (void) fprintf(stderr, " mon=%d", tmp->tm_mon); |
209 (void) fprintf(stderr, " mday=%d", tmp->tm_mday); | 273 (void) fprintf(stderr, " mday=%d", tmp->tm_mday); |
210 (void) fprintf(stderr, " hour=%d", tmp->tm_hour); | 274 (void) fprintf(stderr, " hour=%d", tmp->tm_hour); |
211 (void) fprintf(stderr, " min=%d", tmp->tm_min); | 275 (void) fprintf(stderr, " min=%d", tmp->tm_min); |
212 (void) fprintf(stderr, " sec=%d", tmp->tm_sec); | 276 (void) fprintf(stderr, " sec=%d", tmp->tm_sec); |
213 (void) fprintf(stderr, " isdst=%d", tmp->tm_isdst); | 277 (void) fprintf(stderr, " isdst=%d", tmp->tm_isdst); |
214 (void) fprintf(stderr, " -> "); | 278 (void) fprintf(stderr, " -> "); |
215 (void) fprintf(stderr, tformat(), t); | 279 (void) fprintf(stderr, tformat(), t); |
216 (void) fprintf(stderr, "\n"); | 280 (void) fprintf(stderr, "\n"); |
217 } | 281 } |
218 } | 282 } |
219 return tmp; | 283 return tmp; |
220 } | 284 } |
221 #endif /* !defined TYPECHECK */ | 285 #endif /* !defined TYPECHECK */ |
222 | 286 |
223 static void | 287 static void |
224 abbrok(abbrp, zone) | 288 abbrok(const char *const abbrp, const char *const zone) |
225 const char * const» abbrp; | |
226 const char * const» zone; | |
227 { | 289 { |
228 register const char * cp; | 290 register const char * cp; |
229 » register char *»» wp; | 291 » register const char *» wp; |
230 | 292 |
231 if (warned) | 293 if (warned) |
232 return; | 294 return; |
233 cp = abbrp; | 295 cp = abbrp; |
234 wp = NULL; | 296 wp = NULL; |
235 while (isascii((unsigned char) *cp) && isalpha((unsigned char) *cp)) | 297 while (isascii((unsigned char) *cp) && isalpha((unsigned char) *cp)) |
236 ++cp; | 298 ++cp; |
237 if (cp - abbrp == 0) | 299 if (cp - abbrp == 0) |
238 wp = _("lacks alphabetic at start"); | 300 wp = _("lacks alphabetic at start"); |
239 else if (cp - abbrp < 3) | 301 else if (cp - abbrp < 3) |
(...skipping 12 matching lines...) Expand all Loading... |
252 if (wp == NULL) | 314 if (wp == NULL) |
253 return; | 315 return; |
254 (void) fflush(stdout); | 316 (void) fflush(stdout); |
255 (void) fprintf(stderr, | 317 (void) fprintf(stderr, |
256 _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"), | 318 _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"), |
257 progname, zone, abbrp, wp); | 319 progname, zone, abbrp, wp); |
258 warned = TRUE; | 320 warned = TRUE; |
259 } | 321 } |
260 | 322 |
261 static void | 323 static void |
262 usage(const char *progname, FILE *stream, int status) | 324 usage(FILE * const stream, const int status) |
263 { | 325 { |
264 (void) fprintf(stream, | 326 (void) fprintf(stream, |
265 _("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonena
me ...\n\ | 327 _("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n" |
266 \n\ | 328 "\n" |
267 Report bugs to tz@elsie.nci.nih.gov.\n"), | 329 "Report bugs to %s.\n"), |
268 » » progname, progname); | 330 » » progname, progname, REPORT_BUGS_TO); |
269 exit(status); | 331 exit(status); |
270 } | 332 } |
271 | 333 |
272 int | 334 int |
273 main(argc, argv) | 335 main(int argc, char *argv[]) |
274 int» argc; | |
275 char *» argv[]; | |
276 { | 336 { |
277 register int i; | 337 register int i; |
278 register int c; | |
279 register int vflag; | 338 register int vflag; |
| 339 register int Vflag; |
280 register char * cutarg; | 340 register char * cutarg; |
281 » register long» » cutloyear = ZDUMP_LO_YEAR; | 341 » register char *»» cuttimes; |
282 » register long» » cuthiyear = ZDUMP_HI_YEAR; | |
283 register time_t cutlotime; | 342 register time_t cutlotime; |
284 register time_t cuthitime; | 343 register time_t cuthitime; |
285 register char ** fakeenv; | 344 register char ** fakeenv; |
286 time_t now; | 345 time_t now; |
287 time_t t; | 346 time_t t; |
288 time_t newt; | 347 time_t newt; |
289 struct tm tm; | 348 struct tm tm; |
290 struct tm newtm; | 349 struct tm newtm; |
291 register struct tm * tmp; | 350 register struct tm * tmp; |
292 register struct tm * newtmp; | 351 register struct tm * newtmp; |
293 #ifdef ICU | 352 #ifdef ICU |
294 int nextopt; | 353 int nextopt; |
295 char * dirarg; | 354 char * dirarg; |
296 int aflag; | 355 int aflag; |
297 int iflag; | 356 int iflag; |
298 listentry * namelist = NULL; | 357 listentry * namelist = NULL; |
299 FILE * fp = stdout; | 358 FILE * fp = stdout; |
300 #endif | 359 #endif |
301 | 360 |
302 » INITIALIZE(cutlotime); | 361 » cutlotime = absolute_min_time; |
303 » INITIALIZE(cuthitime); | 362 » cuthitime = absolute_max_time; |
304 #if HAVE_GETTEXT | 363 #if HAVE_GETTEXT |
305 (void) setlocale(LC_ALL, ""); | 364 (void) setlocale(LC_ALL, ""); |
306 #ifdef TZ_DOMAINDIR | 365 #ifdef TZ_DOMAINDIR |
307 (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); | 366 (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); |
308 #endif /* defined TEXTDOMAINDIR */ | 367 #endif /* defined TEXTDOMAINDIR */ |
309 (void) textdomain(TZ_DOMAIN); | 368 (void) textdomain(TZ_DOMAIN); |
310 #endif /* HAVE_GETTEXT */ | 369 #endif /* HAVE_GETTEXT */ |
311 progname = argv[0]; | 370 progname = argv[0]; |
312 for (i = 1; i < argc; ++i) | 371 for (i = 1; i < argc; ++i) |
313 if (strcmp(argv[i], "--version") == 0) { | 372 if (strcmp(argv[i], "--version") == 0) { |
314 » » » (void) printf("%s\n", elsieid); | 373 » » » (void) printf("zdump %s%s\n", PKGVERSION, TZVERSION); |
315 exit(EXIT_SUCCESS); | 374 exit(EXIT_SUCCESS); |
316 } else if (strcmp(argv[i], "--help") == 0) { | 375 } else if (strcmp(argv[i], "--help") == 0) { |
317 » » » usage(progname, stdout, EXIT_SUCCESS); | 376 » » » usage(stdout, EXIT_SUCCESS); |
318 } | 377 } |
319 » vflag = 0; | 378 » vflag = Vflag = 0; |
320 » cutarg = NULL; | 379 » cutarg = cuttimes = NULL; |
321 #ifdef ICU | 380 #ifdef ICU |
322 aflag = 0; | 381 aflag = 0; |
323 iflag = 0; | 382 iflag = 0; |
324 dirarg = NULL; | 383 dirarg = NULL; |
325 » nextopt = 1; | 384 » for (;;) |
326 » while(nextopt) { | 385 » » switch(getopt(argc, argv, "ac:d:it:vV")) { |
327 » » c = getopt(argc, argv, "ac:d:iv"); | 386 » » case 'a': aflag = 1; break; |
328 » » switch(c) { | 387 » » case 'c': cutarg = optarg; break; |
329 » » case 'a': | 388 » » case 'd': dirarg = optarg; break; |
330 » » » aflag = 1; | 389 » » case 'i': iflag = 1; break; |
331 » » » break; | 390 » » case 't': cuttimes = optarg; break; |
332 » » case 'c': | 391 » » case 'v': vflag = 1; break; |
333 » » » cutarg = optarg; | 392 » » case 'V': Vflag = 1; break; |
334 » » » break; | 393 » » case -1: |
335 » » case 'd': | 394 » » » if (! (optind == argc - 1 && strcmp(argv[optind], "=") =
= 0)) |
336 » » » dirarg = optarg; | 395 » » » » goto arg_processing_done; |
337 » » » break; | 396 » » /* Fall through. */ |
338 » » case 'i': | |
339 » » » iflag = 1; | |
340 » » » break; | |
341 » » case 'v': | |
342 » » » vflag = 1; | |
343 » » » break; | |
344 default: | 397 default: |
345 nextopt = 0; | |
346 break; | |
347 } | |
348 } | |
349 if ((c != EOF && c != -1) || | |
350 (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { | |
351 (void) fprintf(stderr, | 398 (void) fprintf(stderr, |
352 » » » » _("%s: usage is %s [ --version ] [ -a ] [ -v ] [
-i ] [ -c [loyear,]hiyear ] [ -d dir ] [ zonename ... ]\n"), | 399 » » » » _("%s: usage is %s [ --version ] [ -a ] [ -v ] [
-V ] [ -i ] [ -c [loyear,]hiyear ] [ -t [lotime,]hitime] ][ -d dir ] [ zonename
... ]\n"), |
353 progname, progname); | 400 progname, progname); |
354 exit(EXIT_FAILURE); | 401 exit(EXIT_FAILURE); |
355 » } | 402 » » } |
| 403 #else |
| 404 » for (;;) |
| 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; |
| 410 » case -1: |
| 411 » if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) |
| 412 » goto arg_processing_done; |
| 413 » /* Fall through. */ |
| 414 » default: |
| 415 » usage(stderr, EXIT_FAILURE); |
| 416 » } |
| 417 #endif |
| 418 arg_processing_done:; |
356 | 419 |
| 420 #ifdef ICU |
357 if (dirarg != NULL) { | 421 if (dirarg != NULL) { |
358 DIR * dp; | 422 DIR * dp; |
359 /* create the output directory */ | 423 /* create the output directory */ |
360 mkdir(dirarg, 0777); | 424 mkdir(dirarg, 0777); |
361 if ((dp = opendir(dirarg)) == NULL) { | 425 if ((dp = opendir(dirarg)) == NULL) { |
362 fprintf(stderr, "cannot create the target directory"); | 426 fprintf(stderr, "cannot create the target directory"); |
363 exit(EXIT_FAILURE); | 427 exit(EXIT_FAILURE); |
364 } | 428 } |
365 closedir(dp); | 429 closedir(dp); |
366 } | 430 } |
367 #else | 431 #endif ICU |
368 » while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v') | 432 |
369 » » if (c == 'v') | 433 » if (vflag | Vflag) { |
370 » » » vflag = 1; | 434 » » intmax_t» lo; |
371 » » else» cutarg = optarg; | 435 » » intmax_t» hi; |
372 » if ((c != EOF && c != -1) || | 436 » » char *loend, *hiend; |
373 » » (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { | 437 » » register intmax_t cutloyear = ZDUMP_LO_YEAR; |
374 » » » usage(progname, stderr, EXIT_FAILURE); | 438 » » register intmax_t cuthiyear = ZDUMP_HI_YEAR; |
375 » } | |
376 #endif | |
377 » if (vflag) { | |
378 if (cutarg != NULL) { | 439 if (cutarg != NULL) { |
379 » » » long» lo; | 440 » » » lo = strtoimax(cutarg, &loend, 10); |
380 » » » long» hi; | 441 » » » if (cutarg != loend && !*loend) { |
381 » » » char» dummy; | 442 » » » » hi = lo; |
382 | |
383 » » » if (sscanf(cutarg, "%ld%c", &hi, &dummy) == 1) { | |
384 cuthiyear = hi; | 443 cuthiyear = hi; |
385 » » » } else if (sscanf(cutarg, "%ld,%ld%c", | 444 » » » } else if (cutarg != loend && *loend == ',' |
386 » » » » &lo, &hi, &dummy) == 2) { | 445 » » » » && (hi = strtoimax(loend + 1, &hiend, 10), |
387 » » » » » cutloyear = lo; | 446 » » » » loend + 1 != hiend && !*hiend)) { |
388 » » » » » cuthiyear = hi; | 447 » » » » cutloyear = lo; |
| 448 » » » » cuthiyear = hi; |
389 } else { | 449 } else { |
390 (void) fprintf(stderr, _("%s: wild -c argument %s\n"), | 450 (void) fprintf(stderr, _("%s: wild -c argument %s\n"), |
391 progname, cutarg); | 451 progname, cutarg); |
392 exit(EXIT_FAILURE); | 452 exit(EXIT_FAILURE); |
393 } | 453 } |
394 } | 454 } |
395 » » setabsolutes(); | 455 » » if (cutarg != NULL || cuttimes == NULL) { |
396 » » cutlotime = yeartot(cutloyear); | 456 » » » cutlotime = yeartot(cutloyear); |
397 » » cuthitime = yeartot(cuthiyear); | 457 » » » cuthitime = yeartot(cuthiyear); |
| 458 » » } |
| 459 » » if (cuttimes != NULL) { |
| 460 » » » lo = strtoimax(cuttimes, &loend, 10); |
| 461 » » » if (cuttimes != loend && !*loend) { |
| 462 » » » » hi = lo; |
| 463 » » » » if (hi < cuthitime) { |
| 464 » » » » » if (hi < absolute_min_time) |
| 465 » » » » » » hi = absolute_min_time; |
| 466 » » » » » cuthitime = hi; |
| 467 » » » » } |
| 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; |
| 474 » » » » » cutlotime = lo; |
| 475 » » » » } |
| 476 » » » » if (hi < cuthitime) { |
| 477 » » » » » if (hi < absolute_min_time) |
| 478 » » » » » » hi = absolute_min_time; |
| 479 » » » » » cuthitime = hi; |
| 480 » » » » } |
| 481 » » » } else { |
| 482 » » » » (void) fprintf(stderr, |
| 483 » » » » » _("%s: wild -t argument %s\n"), |
| 484 » » » » » progname, cuttimes); |
| 485 » » » » exit(EXIT_FAILURE); |
| 486 » » » } |
| 487 » » } |
398 } | 488 } |
399 | 489 |
400 #ifdef ICU | 490 #ifdef ICU |
401 if (aflag) { | 491 if (aflag) { |
402 /* get all available zones */ | 492 /* get all available zones */ |
403 char ** fakeargv; | 493 char ** fakeargv; |
404 int i; | 494 int i; |
405 int count; | 495 int count; |
406 | 496 |
407 count = getall(&namelist); | 497 count = getall(&namelist); |
(...skipping 19 matching lines...) Expand all Loading... |
427 longest = 0; | 517 longest = 0; |
428 for (i = optind; i < argc; ++i) | 518 for (i = optind; i < argc; ++i) |
429 if (strlen(argv[i]) > longest) | 519 if (strlen(argv[i]) > longest) |
430 longest = strlen(argv[i]); | 520 longest = strlen(argv[i]); |
431 { | 521 { |
432 register int from; | 522 register int from; |
433 register int to; | 523 register int to; |
434 | 524 |
435 for (i = 0; environ[i] != NULL; ++i) | 525 for (i = 0; environ[i] != NULL; ++i) |
436 continue; | 526 continue; |
437 » » fakeenv = (char **) malloc((size_t) ((i + 2) * | 527 » » fakeenv = malloc((i + 2) * sizeof *fakeenv); |
438 » » » sizeof *fakeenv)); | 528 » » if (fakeenv == NULL |
439 » » if (fakeenv == NULL || | 529 » » || (fakeenv[0] = malloc(longest + 4)) == NULL) { |
440 » » » (fakeenv[0] = (char *) malloc(longest + 4)) == NULL) { | |
441 (void) perror(progname); | 530 (void) perror(progname); |
442 exit(EXIT_FAILURE); | 531 exit(EXIT_FAILURE); |
443 } | 532 } |
444 to = 0; | 533 to = 0; |
445 (void) strcpy(fakeenv[to++], "TZ="); | 534 (void) strcpy(fakeenv[to++], "TZ="); |
446 for (from = 0; environ[from] != NULL; ++from) | 535 for (from = 0; environ[from] != NULL; ++from) |
447 if (strncmp(environ[from], "TZ=", 3) != 0) | 536 if (strncmp(environ[from], "TZ=", 3) != 0) |
448 fakeenv[to++] = environ[from]; | 537 fakeenv[to++] = environ[from]; |
449 fakeenv[to] = NULL; | 538 fakeenv[to] = NULL; |
450 environ = fakeenv; | 539 environ = fakeenv; |
451 } | 540 } |
452 for (i = optind; i < argc; ++i) { | 541 for (i = optind; i < argc; ++i) { |
453 static char buf[MAX_STRING_LENGTH]; | 542 static char buf[MAX_STRING_LENGTH]; |
454 | 543 |
455 (void) strcpy(&fakeenv[0][3], argv[i]); | 544 (void) strcpy(&fakeenv[0][3], argv[i]); |
456 » » if (!vflag) { | 545 » » if (! (vflag | Vflag)) { |
457 show(argv[i], now, FALSE); | 546 show(argv[i], now, FALSE); |
458 continue; | 547 continue; |
459 } | 548 } |
460 #ifdef ICU | 549 #ifdef ICU |
461 fp = NULL; | 550 fp = NULL; |
462 if (iflag) { | 551 if (iflag) { |
463 if (dirarg == NULL) { | 552 if (dirarg == NULL) { |
464 /* we want to display a zone name here */ | 553 /* we want to display a zone name here */ |
465 if (i != optind) { | 554 if (i != optind) { |
466 printf("\n"); | 555 printf("\n"); |
(...skipping 19 matching lines...) Expand all Loading... |
486 } | 575 } |
487 } | 576 } |
488 #endif | 577 #endif |
489 warned = FALSE; | 578 warned = FALSE; |
490 t = absolute_min_time; | 579 t = absolute_min_time; |
491 #ifdef ICU | 580 #ifdef ICU |
492 /* skip displaying info for the lowest time, which is actually n
ot | 581 /* skip displaying info for the lowest time, which is actually n
ot |
493 * a transition when -i option is set */ | 582 * a transition when -i option is set */ |
494 if (!iflag) { | 583 if (!iflag) { |
495 #endif | 584 #endif |
496 » » show(argv[i], t, TRUE); | 585 » » if (!Vflag) { |
497 » » t += SECSPERHOUR * HOURSPERDAY; | 586 » » » show(argv[i], t, TRUE); |
498 » » show(argv[i], t, TRUE); | 587 » » » t += SECSPERDAY; |
| 588 » » » show(argv[i], t, TRUE); |
| 589 » » } |
499 #ifdef ICU | 590 #ifdef ICU |
500 } | 591 } |
501 #endif | 592 #endif |
502 if (t < cutlotime) | 593 if (t < cutlotime) |
503 t = cutlotime; | 594 t = cutlotime; |
504 tmp = my_localtime(&t); | 595 tmp = my_localtime(&t); |
505 if (tmp != NULL) { | 596 if (tmp != NULL) { |
506 tm = *tmp; | 597 tm = *tmp; |
507 (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); | 598 (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); |
508 } | 599 } |
509 for ( ; ; ) { | 600 for ( ; ; ) { |
510 » » » if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12) | 601 » » » newt = (t < absolute_max_time - SECSPERDAY / 2 |
| 602 » » » » ? t + SECSPERDAY / 2 |
| 603 » » » » : absolute_max_time); |
| 604 » » » if (cuthitime <= newt) |
511 break; | 605 break; |
512 newt = t + SECSPERHOUR * 12; | |
513 newtmp = localtime(&newt); | 606 newtmp = localtime(&newt); |
514 if (newtmp != NULL) | 607 if (newtmp != NULL) |
515 newtm = *newtmp; | 608 newtm = *newtmp; |
516 #ifdef ICU | 609 #ifdef ICU |
517 if (iflag) { | 610 if (iflag) { |
518 /* We do not want to capture transitions just f
or | 611 /* We do not want to capture transitions just f
or |
519 * abbreviated zone name changes */ | 612 * abbreviated zone name changes */ |
520 if ((tmp == NULL || newtmp == NULL) ? (tmp != ne
wtmp) : | 613 if ((tmp == NULL || newtmp == NULL) ? (tmp != ne
wtmp) : |
521 (delta(&newtm, &tm) != (newt - t) || | 614 (delta(&newtm, &tm) != (newt - t) || |
522 newtm.tm_isdst != tm.tm_isdst)) { | 615 newtm.tm_isdst != tm.tm_isdst)) { |
(...skipping 26 matching lines...) Expand all Loading... |
549 #endif | 642 #endif |
550 t = newt; | 643 t = newt; |
551 tm = newtm; | 644 tm = newtm; |
552 tmp = newtmp; | 645 tmp = newtmp; |
553 } | 646 } |
554 #ifdef ICU | 647 #ifdef ICU |
555 if (!iflag) { | 648 if (!iflag) { |
556 /* skip displaying info for the highest time, which is actually
not | 649 /* skip displaying info for the highest time, which is actually
not |
557 * a transition when -i option is used*/ | 650 * a transition when -i option is used*/ |
558 #endif | 651 #endif |
559 » » t = absolute_max_time; | 652 » » if (!Vflag) { |
560 » » t -= SECSPERHOUR * HOURSPERDAY; | 653 » » » t = absolute_max_time; |
561 » » show(argv[i], t, TRUE); | 654 » » » t -= SECSPERDAY; |
562 » » t += SECSPERHOUR * HOURSPERDAY; | 655 » » » show(argv[i], t, TRUE); |
563 » » show(argv[i], t, TRUE); | 656 » » » t += SECSPERDAY; |
564 | 657 » » » show(argv[i], t, TRUE); |
| 658 » » } |
565 #ifdef ICU | 659 #ifdef ICU |
566 } | 660 } |
567 /* close file */ | 661 /* close file */ |
568 if (fp != NULL) { | 662 if (fp != NULL) { |
569 fclose(fp); | 663 fclose(fp); |
570 } | 664 } |
571 #endif | 665 #endif |
572 } | 666 } |
573 if (fflush(stdout) || ferror(stdout)) { | 667 if (fflush(stdout) || ferror(stdout)) { |
574 (void) fprintf(stderr, "%s: ", progname); | 668 (void) fprintf(stderr, "%s: ", progname); |
(...skipping 10 matching lines...) Expand all Loading... |
585 free(entry); | 679 free(entry); |
586 entry = next; | 680 entry = next; |
587 } | 681 } |
588 } | 682 } |
589 #endif | 683 #endif |
590 exit(EXIT_SUCCESS); | 684 exit(EXIT_SUCCESS); |
591 /* If exit fails to exit... */ | 685 /* If exit fails to exit... */ |
592 return EXIT_FAILURE; | 686 return EXIT_FAILURE; |
593 } | 687 } |
594 | 688 |
595 static void | 689 static time_t |
596 setabsolutes(void) | 690 yeartot(const intmax_t y) |
597 { | 691 { |
598 » if (0.5 == (time_t) 0.5) { | 692 » register intmax_t» myy, seconds, years; |
599 » » /* | 693 » register time_t»» t; |
600 » » ** time_t is floating. | |
601 » » */ | |
602 » » if (sizeof (time_t) == sizeof (float)) { | |
603 » » » absolute_min_time = (time_t) -FLT_MAX; | |
604 » » » absolute_max_time = (time_t) FLT_MAX; | |
605 » » } else if (sizeof (time_t) == sizeof (double)) { | |
606 » » » absolute_min_time = (time_t) -DBL_MAX; | |
607 » » » absolute_max_time = (time_t) DBL_MAX; | |
608 » » } else { | |
609 » » » (void) fprintf(stderr, | |
610 _("%s: use of -v on system with floating time_t other than float or double\n"), | |
611 » » » » progname); | |
612 » » » exit(EXIT_FAILURE); | |
613 » » } | |
614 » } else if (0 > (time_t) -1) { | |
615 » » /* | |
616 » » ** time_t is signed. Assume overflow wraps around. | |
617 » » */ | |
618 » » time_t t = 0; | |
619 » » time_t t1 = 1; | |
620 | |
621 » » while (t < t1) { | |
622 » » » t = t1; | |
623 » » » t1 = 2 * t1 + 1; | |
624 » » } | |
625 | |
626 » » absolute_max_time = t; | |
627 » » t = -t; | |
628 » » absolute_min_time = t - 1; | |
629 » » if (t < absolute_min_time) | |
630 » » » absolute_min_time = t; | |
631 » } else { | |
632 » » /* | |
633 » » ** time_t is unsigned. | |
634 » » */ | |
635 » » absolute_min_time = 0; | |
636 » » absolute_max_time = absolute_min_time - 1; | |
637 » } | |
638 } | |
639 | |
640 static time_t | |
641 yeartot(y) | |
642 const long» y; | |
643 { | |
644 » register long» myy; | |
645 » register long» seconds; | |
646 » register time_t»t; | |
647 | 694 |
648 myy = EPOCH_YEAR; | 695 myy = EPOCH_YEAR; |
649 t = 0; | 696 t = 0; |
650 » while (myy != y) { | 697 » while (myy < y) { |
651 » » if (myy < y) { | 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; |
| 704 } else { |
652 seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR; | 705 seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR; |
653 » » » ++myy; | 706 » » » years = 1; |
654 » » » if (t > absolute_max_time - seconds) { | 707 » » } |
655 » » » » t = absolute_max_time; | 708 » » myy += years; |
656 » » » » break; | 709 » » if (t > absolute_max_time - seconds) |
657 » » » } | 710 » » » return absolute_max_time; |
658 » » » t += seconds; | 711 » » t += seconds; |
| 712 » } |
| 713 » while (y < myy) { |
| 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; |
659 } else { | 720 } else { |
660 » » » --myy; | 721 » » » seconds = isleap(myy - 1) ? SECSPERLYEAR : SECSPERNYEAR; |
661 » » » seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR; | 722 » » » years = 1; |
662 » » » if (t < absolute_min_time + seconds) { | |
663 » » » » t = absolute_min_time; | |
664 » » » » break; | |
665 » » » } | |
666 » » » t -= seconds; | |
667 } | 723 } |
| 724 myy -= years; |
| 725 if (t < absolute_min_time + seconds) |
| 726 return absolute_min_time; |
| 727 t -= seconds; |
668 } | 728 } |
669 return t; | 729 return t; |
670 } | 730 } |
671 | 731 |
672 static time_t | 732 static time_t |
673 hunt(char *name, time_t lot, time_t hit) | 733 hunt(char *name, time_t lot, time_t hit) |
674 { | 734 { |
675 time_t t; | 735 time_t t; |
676 long diff; | |
677 struct tm lotm; | 736 struct tm lotm; |
678 register struct tm * lotmp; | 737 register struct tm * lotmp; |
679 struct tm tm; | 738 struct tm tm; |
680 register struct tm * tmp; | 739 register struct tm * tmp; |
681 char loab[MAX_STRING_LENGTH]; | 740 char loab[MAX_STRING_LENGTH]; |
682 | 741 |
683 lotmp = my_localtime(&lot); | 742 lotmp = my_localtime(&lot); |
684 if (lotmp != NULL) { | 743 if (lotmp != NULL) { |
685 lotm = *lotmp; | 744 lotm = *lotmp; |
686 (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); | 745 (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); |
687 } | 746 } |
688 for ( ; ; ) { | 747 for ( ; ; ) { |
689 » » diff = (long) (hit - lot); | 748 » » time_t diff = hit - lot; |
690 if (diff < 2) | 749 if (diff < 2) |
691 break; | 750 break; |
692 t = lot; | 751 t = lot; |
693 t += diff / 2; | 752 t += diff / 2; |
694 if (t <= lot) | 753 if (t <= lot) |
695 ++t; | 754 ++t; |
696 else if (t >= hit) | 755 else if (t >= hit) |
697 --t; | 756 --t; |
698 tmp = my_localtime(&t); | 757 tmp = my_localtime(&t); |
699 if (tmp != NULL) | 758 if (tmp != NULL) |
700 tm = *tmp; | 759 tm = *tmp; |
701 if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) : | 760 if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) : |
702 (delta(&tm, &lotm) == (t - lot) && | 761 (delta(&tm, &lotm) == (t - lot) && |
703 tm.tm_isdst == lotm.tm_isdst && | 762 tm.tm_isdst == lotm.tm_isdst && |
704 strcmp(abbr(&tm), loab) == 0)) { | 763 strcmp(abbr(&tm), loab) == 0)) { |
705 lot = t; | 764 lot = t; |
706 lotm = tm; | 765 lotm = tm; |
707 lotmp = tmp; | 766 lotmp = tmp; |
708 } else hit = t; | 767 } else hit = t; |
709 } | 768 } |
710 show(name, lot, TRUE); | 769 show(name, lot, TRUE); |
711 show(name, hit, TRUE); | 770 show(name, hit, TRUE); |
712 return hit; | 771 return hit; |
713 } | 772 } |
714 | 773 |
715 /* | 774 /* |
716 ** Thanks to Paul Eggert for logic used in delta. | 775 ** Thanks to Paul Eggert for logic used in delta. |
717 */ | 776 */ |
718 | 777 |
719 static long | 778 static intmax_t |
720 delta(newp, oldp) | 779 delta(struct tm * newp, struct tm *oldp) |
721 struct tm *» newp; | |
722 struct tm *» oldp; | |
723 { | 780 { |
724 » register long» result; | 781 » register intmax_t» result; |
725 » register int» tmy; | 782 » register int» » tmy; |
726 | 783 |
727 if (newp->tm_year < oldp->tm_year) | 784 if (newp->tm_year < oldp->tm_year) |
728 return -delta(oldp, newp); | 785 return -delta(oldp, newp); |
729 result = 0; | 786 result = 0; |
730 for (tmy = oldp->tm_year; tmy < newp->tm_year; ++tmy) | 787 for (tmy = oldp->tm_year; tmy < newp->tm_year; ++tmy) |
731 result += DAYSPERNYEAR + isleap_sum(tmy, TM_YEAR_BASE); | 788 result += DAYSPERNYEAR + isleap_sum(tmy, TM_YEAR_BASE); |
732 result += newp->tm_yday - oldp->tm_yday; | 789 result += newp->tm_yday - oldp->tm_yday; |
733 result *= HOURSPERDAY; | 790 result *= HOURSPERDAY; |
734 result += newp->tm_hour - oldp->tm_hour; | 791 result += newp->tm_hour - oldp->tm_hour; |
735 result *= MINSPERHOUR; | 792 result *= MINSPERHOUR; |
736 result += newp->tm_min - oldp->tm_min; | 793 result += newp->tm_min - oldp->tm_min; |
737 result *= SECSPERMIN; | 794 result *= SECSPERMIN; |
738 result += newp->tm_sec - oldp->tm_sec; | 795 result += newp->tm_sec - oldp->tm_sec; |
739 return result; | 796 return result; |
740 } | 797 } |
741 | 798 |
742 static void | 799 static void |
743 show(char *zone, time_t t, int v) | 800 show(char *zone, time_t t, int v) |
744 { | 801 { |
745 register struct tm * tmp; | 802 register struct tm * tmp; |
746 | 803 |
747 (void) printf("%-*s ", (int) longest, zone); | 804 (void) printf("%-*s ", (int) longest, zone); |
748 if (v) { | 805 if (v) { |
749 tmp = gmtime(&t); | 806 tmp = gmtime(&t); |
750 if (tmp == NULL) { | 807 if (tmp == NULL) { |
751 (void) printf(tformat(), t); | 808 (void) printf(tformat(), t); |
752 } else { | 809 } else { |
753 dumptime(tmp); | 810 dumptime(tmp); |
754 » » » (void) printf(" UTC"); | 811 » » » (void) printf(" UT"); |
755 } | 812 } |
756 (void) printf(" = "); | 813 (void) printf(" = "); |
757 } | 814 } |
758 tmp = my_localtime(&t); | 815 tmp = my_localtime(&t); |
759 dumptime(tmp); | 816 dumptime(tmp); |
760 if (tmp != NULL) { | 817 if (tmp != NULL) { |
761 if (*abbr(tmp) != '\0') | 818 if (*abbr(tmp) != '\0') |
762 (void) printf(" %s", abbr(tmp)); | 819 (void) printf(" %s", abbr(tmp)); |
763 if (v) { | 820 if (v) { |
764 (void) printf(" isdst=%d", tmp->tm_isdst); | 821 (void) printf(" isdst=%d", tmp->tm_isdst); |
765 #ifdef TM_GMTOFF | 822 #ifdef TM_GMTOFF |
766 (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF); | 823 (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF); |
767 #endif /* defined TM_GMTOFF */ | 824 #endif /* defined TM_GMTOFF */ |
768 } | 825 } |
769 } | 826 } |
770 (void) printf("\n"); | 827 (void) printf("\n"); |
771 if (tmp != NULL && *abbr(tmp) != '\0') | 828 if (tmp != NULL && *abbr(tmp) != '\0') |
772 abbrok(abbr(tmp), zone); | 829 abbrok(abbr(tmp), zone); |
773 } | 830 } |
774 | 831 |
775 static char * | 832 static char * |
776 abbr(tmp) | 833 abbr(struct tm *tmp) |
777 struct tm *» tmp; | |
778 { | 834 { |
779 register char * result; | 835 register char * result; |
780 static char nada; | 836 static char nada; |
781 | 837 |
782 if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1) | 838 if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1) |
783 return &nada; | 839 return &nada; |
784 result = tzname[tmp->tm_isdst]; | 840 result = tzname[tmp->tm_isdst]; |
785 return (result == NULL) ? &nada : result; | 841 return (result == NULL) ? &nada : result; |
786 } | 842 } |
787 | 843 |
788 /* | 844 /* |
789 ** The code below can fail on certain theoretical systems; | 845 ** The code below can fail on certain theoretical systems; |
790 ** it works on all known real-world systems as of 2004-12-30. | 846 ** it works on all known real-world systems as of 2004-12-30. |
791 */ | 847 */ |
792 | 848 |
793 static const char * | 849 static const char * |
794 tformat(void) | 850 tformat(void) |
795 { | 851 { |
796 if (0.5 == (time_t) 0.5) { /* floating */ | |
797 if (sizeof (time_t) > sizeof (double)) | |
798 return "%Lg"; | |
799 return "%g"; | |
800 } | |
801 if (0 > (time_t) -1) { /* signed */ | 852 if (0 > (time_t) -1) { /* signed */ |
| 853 if (sizeof (time_t) == sizeof (intmax_t)) |
| 854 return "%"PRIdMAX; |
802 if (sizeof (time_t) > sizeof (long)) | 855 if (sizeof (time_t) > sizeof (long)) |
803 return "%lld"; | 856 return "%lld"; |
804 if (sizeof (time_t) > sizeof (int)) | 857 if (sizeof (time_t) > sizeof (int)) |
805 return "%ld"; | 858 return "%ld"; |
806 return "%d"; | 859 return "%d"; |
807 } | 860 } |
| 861 #ifdef PRIuMAX |
| 862 if (sizeof (time_t) == sizeof (uintmax_t)) |
| 863 return "%"PRIuMAX; |
| 864 #endif |
808 if (sizeof (time_t) > sizeof (unsigned long)) | 865 if (sizeof (time_t) > sizeof (unsigned long)) |
809 return "%llu"; | 866 return "%llu"; |
810 if (sizeof (time_t) > sizeof (unsigned int)) | 867 if (sizeof (time_t) > sizeof (unsigned int)) |
811 return "%lu"; | 868 return "%lu"; |
812 return "%u"; | 869 return "%u"; |
813 } | 870 } |
814 | 871 |
815 static void | 872 static void |
816 dumptime(timeptr) | 873 dumptime(register const struct tm *timeptr) |
817 register const struct tm *» timeptr; | |
818 { | 874 { |
819 static const char wday_name[][3] = { | 875 static const char wday_name[][3] = { |
820 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" | 876 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" |
821 }; | 877 }; |
822 static const char mon_name[][3] = { | 878 static const char mon_name[][3] = { |
823 "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 879 "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
824 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | 880 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
825 }; | 881 }; |
826 register const char * wn; | 882 register const char * wn; |
827 register const char * mn; | 883 register const char * mn; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 strcat(subpath, dir->d_name); | 1086 strcat(subpath, dir->d_name); |
1031 } else { | 1087 } else { |
1032 strcpy(subpath, dir->d_name); | 1088 strcpy(subpath, dir->d_name); |
1033 } | 1089 } |
1034 getzones(basedir, subpath, last, count); | 1090 getzones(basedir, subpath, last, count); |
1035 } | 1091 } |
1036 closedir(dp); | 1092 closedir(dp); |
1037 } | 1093 } |
1038 } | 1094 } |
1039 #endif | 1095 #endif |
OLD | NEW |