1 diff -u -r ../tzcode.orig/Makefile ./Makefile
2 --- ../tzcode.orig/Makefile 2003-12-15 06:33:34.000000000 -0800
3 +++ ./Makefile 2004-05-24 14:30:31.659356800 -0700
5 # (and subdirectories).
6 # Use an absolute path name for TZDIR unless you're just testing the software.
8 -TZDIR= $(TOPDIR)/etc/zoneinfo
11 # The "tzselect", "zic", and "zdump" commands get installed in. . .
15 ###############################################################################
19 CC= $(cc) -DTZDIR=\"$(TZDIR)\"
23 TZCSRCS= zic.c localtime.c asctime.c scheck.c ialloc.c
24 TZCOBJS= zic.o localtime.o asctime.o scheck.o ialloc.o
25 TZDSRCS= zdump.c localtime.c asctime.c ialloc.c
30 -all: tzselect zic zdump $(LIBOBJS)
34 +all: tzselect zic zdump $(LIBOBJS) tz2icu
40 $(CC) $(CFLAGS) $(LFLAGS) $(TZDOBJS) $(LDLIBS) -o $@
42 -zic: $(TZCOBJS) yearistype
43 +zic: $(TZCOBJS) yearistype tz2icu.h
44 $(CC) $(CFLAGS) $(LFLAGS) $(TZCOBJS) $(LDLIBS) -o $@
46 +tz2icu: tz2icu.cpp tz2icu.h
47 + $(CPP) -W -Wall -pedantic tz2icu.cpp -o $@
49 yearistype: yearistype.sh
50 cp yearistype.sh yearistype
53 right_only: zic leapseconds $(TDATA)
54 $(ZIC) -y $(YEARISTYPE) -d $(TZDIR) -L leapseconds $(TDATA)
56 +icu_data: tz2icu posix_only
57 + ./tz2icu zoneinfo zone.tab `$(LS) tzdata*.tar.gz | $(SED) -e "s/^tzdata//;s/\.tar\.gz$$//"`
59 # In earlier versions of this makefile, the other two directories were
60 # subdirectories of $(TZDIR). However, this led to configuration errors.
61 # For example, with posix_right under the earlier scheme,
62 diff -u -r ../tzcode.orig/zic.c ./zic.c
63 --- ../tzcode.orig/zic.c 2003-12-15 06:36:35.000000000 -0800
64 +++ ./zic.c 2004-05-24 14:03:43.937566400 -0700
66 #define MKDIR_UMASK 0755
69 +/* Enable extensions and modifications for ICU. */
72 +/* Continue executing after link failure. Even if ICU is undefined
73 + * (for vanilla zic behavior), ICU_LINKS should be defined, since zic
74 + * appears to fail on the 2003 data the first time through during the
75 + * linking phase. Running zic twice, with ICU_LINKS defined, causes
76 + * links to be handled correctly. */
84 ** On some ancient hosts, predicates like `isspace(C)' are defined
85 ** only if isascii(C) || C == EOF. Modern hosts obey the C Standard,
89 static void addtt P((time_t starttime, int type));
91 +static int addtype P((long gmtoff, long rawoff, long dstoff,
92 + const char * abbr, int isdst,
93 + int ttisstd, int ttisgmt));
95 static int addtype P((long gmtoff, const char * abbr, int isdst,
96 int ttisstd, int ttisgmt));
98 static void leapadd P((time_t t, int positive, int rolling, int count));
99 static void adjleap P((void));
100 static void associate P((void));
107 +/* Indices into rules[] for final rules. They will occur in pairs,
108 + * with finalRules[i] occurring before finalRules[i+1] in the year.
109 + * Each zone need only store a start year, a standard offset, and an
110 + * index into finalRules[]. FinalRules[] are aliases into rules[]. */
112 +static const struct rule ** finalRules;
113 +static int finalRulesCount;
117 static struct lookup const * byword P((const char * string,
118 const struct lookup * lp));
122 } attypes[TZ_MAX_TIMES];
123 static long gmtoffs[TZ_MAX_TYPES];
125 +/* gmtoffs[i] = rawoffs[i] + dstoffs[i] */
126 +static long rawoffs[TZ_MAX_TYPES];
127 +static long dstoffs[TZ_MAX_TYPES];
129 static char isdsts[TZ_MAX_TYPES];
130 static unsigned char abbrinds[TZ_MAX_TYPES];
131 static char ttisstds[TZ_MAX_TYPES];
133 (void) exit(EXIT_FAILURE);
138 +/* File into which we will write supplemental ICU data. */
139 +static FILE * icuFile;
141 +void emit_icu_zone(FILE* f, const char* zoneName, int zoneOffset,
142 + const struct rule* rule,
143 + int ruleIndex, int startYear) {
144 + /* machine-readable section */
145 + fprintf(f, "zone %s %d %d %s", zoneName, zoneOffset, startYear, rule->r_name);
147 + /* human-readable section */
148 + fprintf(f, " # zone %s, offset %d, year >= %d, rule %s (%d)\n",
149 + zoneName, zoneOffset, startYear,
150 + rule->r_name, ruleIndex);
153 +void emit_icu_link(FILE* f, const char* from, const char* to) {
154 + /* machine-readable section */
155 + fprintf(f, "link %s %s\n", from, to);
158 +static const char* DYCODE[] = {"DOM", "DOWGEQ", "DOWLEQ"};
160 +void emit_icu_rule(FILE* f, const struct rule* r, int ruleIndex) {
161 + if (r->r_yrtype != NULL) {
162 + warning("year types not supported by ICU");
163 + fprintf(stderr, "rule %s, file %s, line %d\n",
164 + r->r_name, r->r_filename, r->r_linenum);
167 + /* machine-readable section */
168 + fprintf(f, "rule %s %s %d %d %d %d %d %d %d",
169 + r->r_name, DYCODE[r->r_dycode],
170 + r->r_month, r->r_dayofmonth,
171 + (r->r_dycode == DC_DOM ? -1 : r->r_wday),
172 + r->r_tod, r->r_todisstd, r->r_todisgmt, r->r_stdoff
175 + /* human-readable section */
176 + fprintf(f, " # %d: %s, file %s, line %d",
177 + ruleIndex, r->r_name, r->r_filename, r->r_linenum);
178 + fprintf(f, ", mode %s", DYCODE[r->r_dycode]);
179 + fprintf(f, ", %s, dom %d", mon_names[r->r_month].l_word, r->r_dayofmonth);
180 + if (r->r_dycode != DC_DOM) {
181 + fprintf(f, ", %s", wday_names[r->r_wday].l_word);
183 + fprintf(f, ", time %d", r->r_tod);
184 + fprintf(f, ", isstd %d", r->r_todisstd);
185 + fprintf(f, ", isgmt %d", r->r_todisgmt);
186 + fprintf(f, ", offset %ld", r->r_stdoff);
192 static const char * psxrules;
193 static const char * lcltime;
194 static const char * directory;
200 + if ((icuFile = fopen(ICU_ZONE_FILE, "w")) == NULL) {
201 + const char *e = strerror(errno);
202 + (void) fprintf(stderr, _("%s: Can't open %s: %s\n"),
203 + progname, ICU_ZONE_FILE, e);
204 + (void) exit(EXIT_FAILURE);
207 for (i = optind; i < argc; ++i)
211 for (i = 0; i < nlinks; ++i) {
212 eat(links[i].l_filename, links[i].l_linenum);
213 dolink(links[i].l_from, links[i].l_to);
215 + emit_icu_link(icuFile, links[i].l_from, links[i].l_to);
218 if (lcltime != NULL) {
219 eat("command line", 1);
221 eat("command line", 1);
222 dolink(psxrules, TZDEFRULES);
225 + for (i=0; i<finalRulesCount; ++i) {
226 + emit_icu_rule(icuFile, finalRules[i], i);
229 return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
233 (void) fprintf(stderr,
234 _("%s: Can't link from %s to %s: %s\n"),
235 progname, fromname, toname, e);
237 (void) exit(EXIT_FAILURE);
242 @@ -1503,7 +1614,12 @@
243 convert(eitol(timecnt), tzh.tzh_timecnt);
244 convert(eitol(typecnt), tzh.tzh_typecnt);
245 convert(eitol(charcnt), tzh.tzh_charcnt);
247 + * (ICUZoneinfoVersion*) &tzh.tzh_reserved = TZ_ICU_VERSION;
248 + (void) strncpy(tzh.tzh_magic, TZ_ICU_MAGIC, sizeof tzh.tzh_magic);
250 (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic);
252 #define DO(field) (void) fwrite((void *) tzh.field, (size_t) sizeof tzh.field, (size_t) 1, fp)
255 @@ -1527,7 +1643,12 @@
256 (void) fwrite((void *) types, (size_t) sizeof types[0],
257 (size_t) timecnt, fp);
258 for (i = 0; i < typecnt; ++i) {
260 + puttzcode((long) rawoffs[i], fp);
261 + puttzcode((long) dstoffs[i], fp);
263 puttzcode((long) gmtoffs[i], fp);
265 (void) putc(isdsts[i], fp);
266 (void) putc(abbrinds[i], fp);
268 @@ -1583,6 +1704,24 @@
274 +int add_icu_final_rules(const struct rule* r1, const struct rule* r2) {
277 + for (i=0; i<finalRulesCount; ++i) { /* i+=2 should work too */
278 + if (r1==finalRules[i]) return i; /* [sic] pointer comparison */
281 + finalRules = (const struct rule**) (void*) erealloc((char *) finalRules,
282 + (finalRulesCount + 2) * sizeof(*finalRules));
283 + finalRules[finalRulesCount++] = r1;
284 + finalRules[finalRulesCount++] = r2;
285 + return finalRulesCount - 2;
291 outzone(zpfirst, zonecount)
292 const struct zone * const zpfirst;
293 @@ -1601,6 +1740,11 @@
294 register int startttisgmt;
296 char startbuf[BUFSIZ];
298 + int finalRuleYear, finalRuleIndex;
299 + const struct rule* finalRule1;
300 + const struct rule* finalRule2;
303 INITIALIZE(untiltime);
304 INITIALIZE(starttime);
305 @@ -1630,11 +1774,55 @@
306 eat(zp->z_filename, zp->z_linenum);
308 startoff = zp->z_gmtoff;
310 + finalRuleYear = finalRuleIndex = -1;
311 + finalRule1 = finalRule2 = NULL;
312 + if (i == (zonecount - 1)) { /* !useuntil */
313 + /* Look for exactly 2 rules that end at 'max' and
314 + * note them. Determine max(r_loyear) for the 2 of
316 + for (j=0; j<zp->z_nrules; ++j) {
317 + rp = &zp->z_rules[j];
318 + if (rp->r_hiyear == INT_MAX) {
319 + if (finalRule1 == NULL) {
321 + finalRuleYear = rp->r_loyear;
322 + } else if (finalRule2 == NULL) {
324 + if (rp->r_loyear > finalRuleYear) {
325 + finalRuleYear = rp->r_loyear;
328 + error("more than two max rules found (ICU)");
329 + exit(EXIT_FAILURE);
333 + if (finalRule1 != NULL && finalRule2 == NULL) {
334 + error("only one max rule found (ICU)");
335 + exit(EXIT_FAILURE);
337 + if (finalRule1 != NULL) {
338 + /* Swap if necessary so finalRule1 occurs before
340 + if (finalRule1->r_month > finalRule2->r_month) {
341 + const struct rule* t = finalRule1;
342 + finalRule1 = finalRule2;
345 + /* Add final rule to our list */
346 + finalRuleIndex = add_icu_final_rules(finalRule1, finalRule2);
350 if (zp->z_nrules == 0) {
351 stdoff = zp->z_stdoff;
352 doabbr(startbuf, zp->z_format,
353 (char *) NULL, stdoff != 0);
354 type = addtype(oadd(zp->z_gmtoff, stdoff),
356 + zp->z_gmtoff, stdoff,
358 startbuf, stdoff != 0, startttisstd,
361 @@ -1708,6 +1896,15 @@
362 break; /* go on to next year */
363 rp = &zp->z_rules[k];
366 + if (year >= finalRuleYear && rp == finalRule1) {
367 + emit_icu_zone(icuFile,
368 + zpfirst->z_name, zp->z_gmtoff,
369 + rp, finalRuleIndex, year);
370 + /* only emit this for the first year */
374 if (useuntil && ktime >= untiltime)
376 stdoff = rp->r_stdoff;
377 @@ -1735,8 +1932,14 @@
378 doabbr(buf, zp->z_format, rp->r_abbrvar,
380 offset = oadd(zp->z_gmtoff, rp->r_stdoff);
382 + type = addtype(offset, zp->z_gmtoff, rp->r_stdoff,
383 + buf, rp->r_stdoff != 0,
384 + rp->r_todisstd, rp->r_todisgmt);
386 type = addtype(offset, buf, rp->r_stdoff != 0,
387 rp->r_todisstd, rp->r_todisgmt);
392 @@ -1750,10 +1953,19 @@
393 if (*startbuf == '\0')
394 error(_("can't determine time zone abbreviation to use just after until time"));
395 else addtt(starttime,
398 + zp->z_gmtoff, startoff - zp->z_gmtoff,
400 + startoff != zp->z_gmtoff,
404 addtype(startoff, startbuf,
405 startoff != zp->z_gmtoff,
411 ** Now we may get to set starttime for the next zone line.
412 @@ -1779,6 +1991,10 @@
413 if (starttime <= min_time ||
414 (timecnt == 1 && attypes[0].at < min_time)) {
415 gmtoffs[0] = gmtoffs[type];
417 + rawoffs[0] = rawoffs[type];
418 + dstoffs[0] = dstoffs[type];
420 isdsts[0] = isdsts[type];
421 ttisstds[0] = ttisstds[type];
422 ttisgmts[0] = ttisgmts[type];
423 @@ -1800,8 +2016,15 @@
428 +addtype(gmtoff, rawoff, dstoff, abbr, isdst, ttisstd, ttisgmt)
433 addtype(gmtoff, abbr, isdst, ttisstd, ttisgmt)
436 const char * const abbr;
439 @@ -1821,12 +2044,25 @@
440 error(_("internal error - addtype called with bad ttisgmt"));
441 (void) exit(EXIT_FAILURE);
444 + if (isdst != (dstoff != 0)) {
445 + error(_("internal error - addtype called with bad isdst/dstoff"));
446 + (void) exit(EXIT_FAILURE);
448 + if (gmtoff != (rawoff + dstoff)) {
449 + error(_("internal error - addtype called with bad gmt/raw/dstoff"));
450 + (void) exit(EXIT_FAILURE);
454 ** See if there's already an entry for this zone type.
455 ** If so, just return its index.
457 for (i = 0; i < typecnt; ++i) {
458 if (gmtoff == gmtoffs[i] && isdst == isdsts[i] &&
460 + rawoff == rawoffs[i] && dstoff == dstoffs[i] &&
462 strcmp(abbr, &chars[abbrinds[i]]) == 0 &&
463 ttisstd == ttisstds[i] &&
464 ttisgmt == ttisgmts[i])
465 @@ -1841,6 +2077,10 @@
466 (void) exit(EXIT_FAILURE);
470 + rawoffs[i] = rawoff;
471 + dstoffs[i] = dstoff;
474 ttisstds[i] = ttisstd;
475 ttisgmts[i] = ttisgmt;