]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/tzcode/patch-icu-tzcode
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / tools / tzcode / patch-icu-tzcode
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
4 @@ -40,7 +40,7 @@
5 # (and subdirectories).
6 # Use an absolute path name for TZDIR unless you're just testing the software.
7
8 -TZDIR= $(TOPDIR)/etc/zoneinfo
9 +TZDIR= zoneinfo
10
11 # The "tzselect", "zic", and "zdump" commands get installed in. . .
12
13 @@ -239,9 +239,11 @@
14
15 ###############################################################################
16
17 -cc= cc
18 +cc= gcc
19 CC= $(cc) -DTZDIR=\"$(TZDIR)\"
20
21 +CPP= g++
22 +
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
26 @@ -275,7 +277,10 @@
27
28 SHELL= /bin/sh
29
30 -all: tzselect zic zdump $(LIBOBJS)
31 +LS= /usr/bin/ls
32 +SED= /usr/bin/sed
33 +
34 +all: tzselect zic zdump $(LIBOBJS) tz2icu
35
36 ALL: all date
37
38 @@ -308,9 +313,12 @@
39 zdump: $(TZDOBJS)
40 $(CC) $(CFLAGS) $(LFLAGS) $(TZDOBJS) $(LDLIBS) -o $@
41
42 -zic: $(TZCOBJS) yearistype
43 +zic: $(TZCOBJS) yearistype tz2icu.h
44 $(CC) $(CFLAGS) $(LFLAGS) $(TZCOBJS) $(LDLIBS) -o $@
45
46 +tz2icu: tz2icu.cpp tz2icu.h
47 + $(CPP) -W -Wall -pedantic tz2icu.cpp -o $@
48 +
49 yearistype: yearistype.sh
50 cp yearistype.sh yearistype
51 chmod +x yearistype
52 @@ -321,6 +329,9 @@
53 right_only: zic leapseconds $(TDATA)
54 $(ZIC) -y $(YEARISTYPE) -d $(TZDIR) -L leapseconds $(TDATA)
55
56 +icu_data: tz2icu posix_only
57 + ./tz2icu zoneinfo zone.tab `$(LS) tzdata*.tar.gz | $(SED) -e "s/^tzdata//;s/\.tar\.gz$$//"`
58 +
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
65 @@ -13,6 +13,20 @@
66 #define MKDIR_UMASK 0755
67 #endif
68
69 +/* Enable extensions and modifications for ICU. */
70 +#define ICU
71 +
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. */
77 +#define ICU_LINKS
78 +
79 +#ifdef ICU
80 +#include "tz2icu.h"
81 +#endif
82 +
83 /*
84 ** On some ancient hosts, predicates like `isspace(C)' are defined
85 ** only if isascii(C) || C == EOF. Modern hosts obey the C Standard,
86 @@ -86,8 +100,14 @@
87 extern int optind;
88
89 static void addtt P((time_t starttime, int type));
90 +#ifdef ICU
91 +static int addtype P((long gmtoff, long rawoff, long dstoff,
92 + const char * abbr, int isdst,
93 + int ttisstd, int ttisgmt));
94 +#else
95 static int addtype P((long gmtoff, const char * abbr, int isdst,
96 int ttisstd, int ttisgmt));
97 +#endif
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));
101 @@ -256,6 +276,18 @@
102 const int l_value;
103 };
104
105 +#ifdef ICU
106 +
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[]. */
111 +
112 +static const struct rule ** finalRules;
113 +static int finalRulesCount;
114 +
115 +#endif
116 +
117 static struct lookup const * byword P((const char * string,
118 const struct lookup * lp));
119
120 @@ -338,6 +370,11 @@
121 unsigned char type;
122 } attypes[TZ_MAX_TIMES];
123 static long gmtoffs[TZ_MAX_TYPES];
124 +#ifdef ICU
125 +/* gmtoffs[i] = rawoffs[i] + dstoffs[i] */
126 +static long rawoffs[TZ_MAX_TYPES];
127 +static long dstoffs[TZ_MAX_TYPES];
128 +#endif
129 static char isdsts[TZ_MAX_TYPES];
130 static unsigned char abbrinds[TZ_MAX_TYPES];
131 static char ttisstds[TZ_MAX_TYPES];
132 @@ -447,6 +484,62 @@
133 (void) exit(EXIT_FAILURE);
134 }
135
136 +#ifdef ICU
137 +
138 +/* File into which we will write supplemental ICU data. */
139 +static FILE * icuFile;
140 +
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);
146 +
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);
151 +}
152 +
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);
156 +}
157 +
158 +static const char* DYCODE[] = {"DOM", "DOWGEQ", "DOWLEQ"};
159 +
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);
165 + }
166 +
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
173 + );
174 +
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);
182 + }
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);
187 + fprintf(f, "\n");
188 +}
189 +
190 +#endif
191 +
192 static const char * psxrules;
193 static const char * lcltime;
194 static const char * directory;
195 @@ -554,6 +647,14 @@
196 adjleap();
197 }
198
199 +#ifdef ICU
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);
205 + }
206 +#endif
207 for (i = optind; i < argc; ++i)
208 infile(argv[i]);
209 if (errors)
210 @@ -573,6 +674,9 @@
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);
214 +#ifdef ICU
215 + emit_icu_link(icuFile, links[i].l_from, links[i].l_to);
216 +#endif
217 }
218 if (lcltime != NULL) {
219 eat("command line", 1);
220 @@ -582,6 +686,11 @@
221 eat("command line", 1);
222 dolink(psxrules, TZDEFRULES);
223 }
224 +#ifdef ICU
225 + for (i=0; i<finalRulesCount; ++i) {
226 + emit_icu_rule(icuFile, finalRules[i], i);
227 + }
228 +#endif /*ICU*/
229 return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
230 }
231
232 @@ -642,7 +751,9 @@
233 (void) fprintf(stderr,
234 _("%s: Can't link from %s to %s: %s\n"),
235 progname, fromname, toname, e);
236 +#ifndef ICU_LINKS
237 (void) exit(EXIT_FAILURE);
238 +#endif
239 }
240 }
241 ifree(fromname);
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);
246 +#ifdef ICU
247 + * (ICUZoneinfoVersion*) &tzh.tzh_reserved = TZ_ICU_VERSION;
248 + (void) strncpy(tzh.tzh_magic, TZ_ICU_MAGIC, sizeof tzh.tzh_magic);
249 +#else
250 (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic);
251 +#endif
252 #define DO(field) (void) fwrite((void *) tzh.field, (size_t) sizeof tzh.field, (size_t) 1, fp)
253 DO(tzh_magic);
254 DO(tzh_reserved);
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) {
259 +#ifdef ICU
260 + puttzcode((long) rawoffs[i], fp);
261 + puttzcode((long) dstoffs[i], fp);
262 +#else
263 puttzcode((long) gmtoffs[i], fp);
264 +#endif
265 (void) putc(isdsts[i], fp);
266 (void) putc(abbrinds[i], fp);
267 }
268 @@ -1583,6 +1704,24 @@
269 }
270 }
271
272 +#ifdef ICU
273 +
274 +int add_icu_final_rules(const struct rule* r1, const struct rule* r2) {
275 + int i;
276 +
277 + for (i=0; i<finalRulesCount; ++i) { /* i+=2 should work too */
278 + if (r1==finalRules[i]) return i; /* [sic] pointer comparison */
279 + }
280 +
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;
286 +}
287 +
288 +#endif /*ICU*/
289 +
290 static void
291 outzone(zpfirst, zonecount)
292 const struct zone * const zpfirst;
293 @@ -1601,6 +1740,11 @@
294 register int startttisgmt;
295 register int type;
296 char startbuf[BUFSIZ];
297 +#ifdef ICU
298 + int finalRuleYear, finalRuleIndex;
299 + const struct rule* finalRule1;
300 + const struct rule* finalRule2;
301 +#endif
302
303 INITIALIZE(untiltime);
304 INITIALIZE(starttime);
305 @@ -1630,11 +1774,55 @@
306 eat(zp->z_filename, zp->z_linenum);
307 *startbuf = '\0';
308 startoff = zp->z_gmtoff;
309 +#ifdef ICU
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
315 + * them. */
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) {
320 + finalRule1 = rp;
321 + finalRuleYear = rp->r_loyear;
322 + } else if (finalRule2 == NULL) {
323 + finalRule2 = rp;
324 + if (rp->r_loyear > finalRuleYear) {
325 + finalRuleYear = rp->r_loyear;
326 + }
327 + } else {
328 + error("more than two max rules found (ICU)");
329 + exit(EXIT_FAILURE);
330 + }
331 + }
332 + }
333 + if (finalRule1 != NULL && finalRule2 == NULL) {
334 + error("only one max rule found (ICU)");
335 + exit(EXIT_FAILURE);
336 + }
337 + if (finalRule1 != NULL) {
338 + /* Swap if necessary so finalRule1 occurs before
339 + * finalRule2 */
340 + if (finalRule1->r_month > finalRule2->r_month) {
341 + const struct rule* t = finalRule1;
342 + finalRule1 = finalRule2;
343 + finalRule2 = t;
344 + }
345 + /* Add final rule to our list */
346 + finalRuleIndex = add_icu_final_rules(finalRule1, finalRule2);
347 + }
348 + }
349 +#endif
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),
355 +#ifdef ICU
356 + zp->z_gmtoff, stdoff,
357 +#endif
358 startbuf, stdoff != 0, startttisstd,
359 startttisgmt);
360 if (usestart) {
361 @@ -1708,6 +1896,15 @@
362 break; /* go on to next year */
363 rp = &zp->z_rules[k];
364 rp->r_todo = FALSE;
365 +#ifdef ICU
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 */
371 + finalRule1 = NULL;
372 + }
373 +#endif
374 if (useuntil && ktime >= untiltime)
375 break;
376 stdoff = rp->r_stdoff;
377 @@ -1735,8 +1932,14 @@
378 doabbr(buf, zp->z_format, rp->r_abbrvar,
379 rp->r_stdoff != 0);
380 offset = oadd(zp->z_gmtoff, rp->r_stdoff);
381 +#ifdef ICU
382 + type = addtype(offset, zp->z_gmtoff, rp->r_stdoff,
383 + buf, rp->r_stdoff != 0,
384 + rp->r_todisstd, rp->r_todisgmt);
385 +#else
386 type = addtype(offset, buf, rp->r_stdoff != 0,
387 rp->r_todisstd, rp->r_todisgmt);
388 +#endif
389 addtt(ktime, type);
390 }
391 }
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,
396 +#ifdef ICU
397 + addtype(startoff,
398 + zp->z_gmtoff, startoff - zp->z_gmtoff,
399 + startbuf,
400 + startoff != zp->z_gmtoff,
401 + startttisstd,
402 + startttisgmt));
403 +#else
404 addtype(startoff, startbuf,
405 startoff != zp->z_gmtoff,
406 startttisstd,
407 startttisgmt));
408 +#endif
409 }
410 /*
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];
416 +#ifdef ICU
417 + rawoffs[0] = rawoffs[type];
418 + dstoffs[0] = dstoffs[type];
419 +#endif
420 isdsts[0] = isdsts[type];
421 ttisstds[0] = ttisstds[type];
422 ttisgmts[0] = ttisgmts[type];
423 @@ -1800,8 +2016,15 @@
424 }
425
426 static int
427 +#ifdef ICU
428 +addtype(gmtoff, rawoff, dstoff, abbr, isdst, ttisstd, ttisgmt)
429 +const long gmtoff;
430 +const long rawoff;
431 +const long dstoff;
432 +#else
433 addtype(gmtoff, abbr, isdst, ttisstd, ttisgmt)
434 const long gmtoff;
435 +#endif
436 const char * const abbr;
437 const int isdst;
438 const int ttisstd;
439 @@ -1821,12 +2044,25 @@
440 error(_("internal error - addtype called with bad ttisgmt"));
441 (void) exit(EXIT_FAILURE);
442 }
443 +#ifdef ICU
444 + if (isdst != (dstoff != 0)) {
445 + error(_("internal error - addtype called with bad isdst/dstoff"));
446 + (void) exit(EXIT_FAILURE);
447 + }
448 + if (gmtoff != (rawoff + dstoff)) {
449 + error(_("internal error - addtype called with bad gmt/raw/dstoff"));
450 + (void) exit(EXIT_FAILURE);
451 + }
452 +#endif
453 /*
454 ** See if there's already an entry for this zone type.
455 ** If so, just return its index.
456 */
457 for (i = 0; i < typecnt; ++i) {
458 if (gmtoff == gmtoffs[i] && isdst == isdsts[i] &&
459 +#ifdef ICU
460 + rawoff == rawoffs[i] && dstoff == dstoffs[i] &&
461 +#endif
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);
467 }
468 gmtoffs[i] = gmtoff;
469 +#ifdef ICU
470 + rawoffs[i] = rawoff;
471 + dstoffs[i] = dstoff;
472 +#endif
473 isdsts[i] = isdst;
474 ttisstds[i] = ttisstd;
475 ttisgmts[i] = ttisgmt;