OLD | NEW |
1 /* | 1 /* |
2 ** This file is in the public domain, so clarified as of | 2 ** This file is in the public domain, so clarified as of |
3 ** 2006-07-17 by Arthur David Olson. | 3 ** 2006-07-17 by Arthur David Olson. |
4 */ | 4 */ |
5 | 5 |
6 static char» elsieid[] = "@(#)zic.c» 8.18"; | 6 /* Enable extensions and modifications for ICU. */ |
| 7 #define ICU |
7 | 8 |
| 9 /* Continue executing after link failure. Even if ICU is undefined |
| 10 * (for vanilla zic behavior), ICU_LINKS should be defined, since zic |
| 11 * appears to fail on the 2003 data the first time through during the |
| 12 * linking phase. Running zic twice, with ICU_LINKS defined, causes |
| 13 * links to be handled correctly. */ |
| 14 #define ICU_LINKS |
| 15 |
| 16 #define LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH |
| 17 |
| 18 #ifdef ICU |
| 19 /* These constants are embedded in dynamically generated header |
| 20 * version.h in the standard tzcode distribution. */ |
| 21 static char const PKGVERSION[]="N/A"; |
| 22 static char const TZVERSION[]="N/A"; |
| 23 static char const REPORT_BUGS_TO[]="N/A"; |
| 24 #else |
| 25 #include "version.h" |
| 26 #endif |
8 #include "private.h" | 27 #include "private.h" |
9 #include "locale.h" | 28 #include "locale.h" |
10 #include "tzfile.h" | 29 #include "tzfile.h" |
11 | 30 |
12 #define»ZIC_VERSION» '2' | 31 #include <stdarg.h> |
| 32 |
| 33 #define»ZIC_VERSION_PRE_2013 '2' |
| 34 #define»ZIC_VERSION» '3' |
13 | 35 |
14 typedef int_fast64_t zic_t; | 36 typedef int_fast64_t zic_t; |
| 37 #define ZIC_MIN INT_FAST64_MIN |
| 38 #define ZIC_MAX INT_FAST64_MAX |
| 39 #define SCNdZIC SCNdFAST64 |
15 | 40 |
16 #ifndef ZIC_MAX_ABBR_LEN_WO_WARN | 41 #ifndef ZIC_MAX_ABBR_LEN_WO_WARN |
17 #define ZIC_MAX_ABBR_LEN_WO_WARN 6 | 42 #define ZIC_MAX_ABBR_LEN_WO_WARN 6 |
18 #endif /* !defined ZIC_MAX_ABBR_LEN_WO_WARN */ | 43 #endif /* !defined ZIC_MAX_ABBR_LEN_WO_WARN */ |
19 | 44 |
20 #if HAVE_SYS_STAT_H | 45 #if HAVE_SYS_STAT_H |
21 #include "sys/stat.h" | 46 #include "sys/stat.h" |
22 #endif | 47 #endif |
23 #ifdef S_IRUSR | 48 #ifdef S_IRUSR |
24 #define MKDIR_UMASK (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) | 49 #define MKDIR_UMASK (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) |
25 #else | 50 #else |
26 #define MKDIR_UMASK 0755 | 51 #define MKDIR_UMASK 0755 |
27 #endif | 52 #endif |
28 | 53 |
29 /* Enable extensions and modifications for ICU. */ | |
30 #define ICU | |
31 | |
32 /* Continue executing after link failure. Even if ICU is undefined | |
33 * (for vanilla zic behavior), ICU_LINKS should be defined, since zic | |
34 * appears to fail on the 2003 data the first time through during the | |
35 * linking phase. Running zic twice, with ICU_LINKS defined, causes | |
36 * links to be handled correctly. */ | |
37 #define ICU_LINKS | |
38 | |
39 #ifdef ICU | 54 #ifdef ICU |
40 #include "tz2icu.h" | 55 #include "tz2icu.h" |
41 #endif | 56 #endif |
42 | 57 |
43 /* | 58 /* |
44 ** On some ancient hosts, predicates like `isspace(C)' are defined | 59 ** On some ancient hosts, predicates like `isspace(C)' are defined |
45 ** only if isascii(C) || C == EOF. Modern hosts obey the C Standard, | 60 ** only if isascii(C) || C == EOF. Modern hosts obey the C Standard, |
46 ** which says they are defined only if C == ((unsigned char) C) || C == EOF. | 61 ** which says they are defined only if C == ((unsigned char) C) || C == EOF. |
47 ** Neither the C Standard nor Posix require that `isascii' exist. | 62 ** Neither the C Standard nor Posix require that `isascii' exist. |
48 ** For portability, we check both ancient and modern requirements. | 63 ** For portability, we check both ancient and modern requirements. |
49 ** If isascii is not defined, the isascii check succeeds trivially. | 64 ** If isascii is not defined, the isascii check succeeds trivially. |
50 */ | 65 */ |
51 #include "ctype.h" | 66 #include "ctype.h" |
52 #ifndef isascii | 67 #ifndef isascii |
53 #define isascii(x) 1 | 68 #define isascii(x) 1 |
54 #endif | 69 #endif |
55 | 70 |
56 #define OFFSET_STRLEN_MAXIMUM (7 + INT_STRLEN_MAXIMUM(long)) | |
57 #define RULE_STRLEN_MAXIMUM 8 /* "Mdd.dd.d" */ | |
58 | |
59 #define end(cp) (strchr((cp), '\0')) | 71 #define end(cp) (strchr((cp), '\0')) |
60 | 72 |
61 struct rule { | 73 struct rule { |
62 const char * r_filename; | 74 const char * r_filename; |
63 int r_linenum; | 75 int r_linenum; |
64 const char * r_name; | 76 const char * r_name; |
65 | 77 |
66 » int» » r_loyear;» /* for example, 1986 */ | 78 » zic_t» » r_loyear;» /* for example, 1986 */ |
67 » int» » r_hiyear;» /* for example, 1986 */ | 79 » zic_t» » r_hiyear;» /* for example, 1986 */ |
68 const char * r_yrtype; | 80 const char * r_yrtype; |
69 int r_lowasnum; | 81 int r_lowasnum; |
70 int r_hiwasnum; | 82 int r_hiwasnum; |
71 | 83 |
72 int r_month; /* 0..11 */ | 84 int r_month; /* 0..11 */ |
73 | 85 |
74 int r_dycode; /* see below */ | 86 int r_dycode; /* see below */ |
75 int r_dayofmonth; | 87 int r_dayofmonth; |
76 int r_wday; | 88 int r_wday; |
77 | 89 |
78 » long» » r_tod;» » /* time from midnight */ | 90 » zic_t» » r_tod;» » /* time from midnight */ |
79 int r_todisstd; /* above is standard time if TRUE */ | 91 int r_todisstd; /* above is standard time if TRUE */ |
80 /* or wall clock time if FALSE */ | 92 /* or wall clock time if FALSE */ |
81 int r_todisgmt; /* above is GMT if TRUE */ | 93 int r_todisgmt; /* above is GMT if TRUE */ |
82 /* or local time if FALSE */ | 94 /* or local time if FALSE */ |
83 » long» » r_stdoff;» /* offset from standard time */ | 95 » zic_t» » r_stdoff;» /* offset from standard time */ |
84 const char * r_abbrvar; /* variable part of abbreviation */ | 96 const char * r_abbrvar; /* variable part of abbreviation */ |
85 | 97 |
86 int r_todo; /* a rule to do (used in outzone) */ | 98 int r_todo; /* a rule to do (used in outzone) */ |
87 zic_t r_temp; /* used in outzone */ | 99 zic_t r_temp; /* used in outzone */ |
88 }; | 100 }; |
89 | 101 |
90 /* | 102 /* |
91 ** r_dycode r_dayofmonth r_wday | 103 ** r_dycode r_dayofmonth r_wday |
92 */ | 104 */ |
93 | 105 |
94 #define DC_DOM 0 /* 1..31 */ /* unused */ | 106 #define DC_DOM 0 /* 1..31 */ /* unused */ |
95 #define DC_DOWGEQ 1 /* 1..31 */ /* 0..6 (Sun..Sat) */ | 107 #define DC_DOWGEQ 1 /* 1..31 */ /* 0..6 (Sun..Sat) */ |
96 #define DC_DOWLEQ 2 /* 1..31 */ /* 0..6 (Sun..Sat) */ | 108 #define DC_DOWLEQ 2 /* 1..31 */ /* 0..6 (Sun..Sat) */ |
97 | 109 |
98 struct zone { | 110 struct zone { |
99 const char * z_filename; | 111 const char * z_filename; |
100 int z_linenum; | 112 int z_linenum; |
101 | 113 |
102 const char * z_name; | 114 const char * z_name; |
103 » long» » z_gmtoff; | 115 » zic_t» » z_gmtoff; |
104 const char * z_rule; | 116 const char * z_rule; |
105 const char * z_format; | 117 const char * z_format; |
106 | 118 |
107 » long» » z_stdoff; | 119 » zic_t» » z_stdoff; |
108 | 120 |
109 struct rule * z_rules; | 121 struct rule * z_rules; |
110 int z_nrules; | 122 int z_nrules; |
111 | 123 |
112 struct rule z_untilrule; | 124 struct rule z_untilrule; |
113 zic_t z_untiltime; | 125 zic_t z_untiltime; |
114 }; | 126 }; |
115 | 127 |
116 extern int getopt(int argc, char * const argv[], | 128 extern int getopt(int argc, char * const argv[], |
117 const char * options); | 129 const char * options); |
118 extern int link(const char * fromname, const char * toname); | 130 extern int link(const char * fromname, const char * toname); |
119 extern char * optarg; | 131 extern char * optarg; |
120 extern int optind; | 132 extern int optind; |
121 | 133 |
| 134 #if ! HAVE_LINK |
| 135 # define link(from, to) (-1) |
| 136 #endif |
| 137 #if ! HAVE_SYMLINK |
| 138 # define symlink(from, to) (-1) |
| 139 #endif |
| 140 |
122 static void addtt(zic_t starttime, int type); | 141 static void addtt(zic_t starttime, int type); |
123 #ifdef ICU | 142 #ifdef ICU |
124 static int» addtype(long gmtoff, long rawoff, long dstoff, | 143 static int» addtype(const zic_t gmtoff, const zic_t rawoff, const zic_t dsto
ff, |
125 » » » » const char * abbr, int isdst, | 144 » » » » char *const abbr, int isdst, |
126 int ttisstd, int ttisgmt); | 145 int ttisstd, int ttisgmt); |
127 #else | 146 #else |
128 static int» addtype(long gmtoff, const char * abbr, int isdst, | 147 static int» addtype(zic_t gmtoff, const char * abbr, int isdst, |
129 int ttisstd, int ttisgmt); | 148 int ttisstd, int ttisgmt); |
130 #endif | 149 #endif |
131 static void leapadd(zic_t t, int positive, int rolling, int count); | 150 static void leapadd(zic_t t, int positive, int rolling, int count); |
132 static void adjleap(void); | 151 static void adjleap(void); |
133 static void associate(void); | 152 static void associate(void); |
134 static int ciequal(const char * ap, const char * bp); | |
135 static void convert(long val, char * buf); | |
136 static void convert64(zic_t val, char * buf); | |
137 static void dolink(const char * fromfield, const char * tofield); | 153 static void dolink(const char * fromfield, const char * tofield); |
138 static void doabbr(char * abbr, const char * format, | |
139 const char * letters, int isdst, int doquotes); | |
140 static void eat(const char * name, int num); | |
141 static void eats(const char * name, int num, | |
142 const char * rname, int rnum); | |
143 static long eitol(int i); | |
144 static void error(const char * message); | |
145 static char ** getfields(char * buf); | 154 static char ** getfields(char * buf); |
146 static long» gethms(const char * string, const char * errstrng, | 155 static zic_t» gethms(const char * string, const char * errstrng, |
147 » » » int signable); | 156 » » int signable); |
148 static void infile(const char * filename); | 157 static void infile(const char * filename); |
149 static void inleap(char ** fields, int nfields); | 158 static void inleap(char ** fields, int nfields); |
150 static void inlink(char ** fields, int nfields); | 159 static void inlink(char ** fields, int nfields); |
151 static void inrule(char ** fields, int nfields); | 160 static void inrule(char ** fields, int nfields); |
152 static int inzcont(char ** fields, int nfields); | 161 static int inzcont(char ** fields, int nfields); |
153 static int inzone(char ** fields, int nfields); | 162 static int inzone(char ** fields, int nfields); |
154 static int inzsub(char ** fields, int nfields, int iscont); | 163 static int inzsub(char ** fields, int nfields, int iscont); |
155 static int is32(zic_t x); | |
156 static int itsabbr(const char * abbr, const char * word); | |
157 static int itsdir(const char * name); | 164 static int itsdir(const char * name); |
158 static int lowerit(int c); | 165 static int lowerit(int c); |
159 static char * memcheck(char * tocheck); | |
160 static int mkdirs(char * filename); | 166 static int mkdirs(char * filename); |
161 static void newabbr(const char * abbr); | 167 static void newabbr(const char * abbr); |
162 static long» oadd(long t1, long t2); | 168 static zic_t» oadd(zic_t t1, zic_t t2); |
163 static void outzone(const struct zone * zp, int ntzones); | 169 static void outzone(const struct zone * zp, int ntzones); |
164 static void» puttzcode(long code, FILE * fp); | 170 static zic_t» rpytime(const struct rule * rp, zic_t wantedy); |
165 static void» puttzcode64(zic_t code, FILE * fp); | |
166 static int» rcomp(const void * leftp, const void * rightp); | |
167 static zic_t» rpytime(const struct rule * rp, int wantedy); | |
168 static void rulesub(struct rule * rp, | 171 static void rulesub(struct rule * rp, |
169 const char * loyearp, const char * hiyearp, | 172 const char * loyearp, const char * hiyearp, |
170 const char * typep, const char * monthp, | 173 const char * typep, const char * monthp, |
171 const char * dayp, const char * timep); | 174 const char * dayp, const char * timep); |
172 static int » stringoffset(char * result, long offset); | 175 static zic_t» tadd(zic_t t1, zic_t t2); |
173 static int» stringrule(char * result, const struct rule * rp, | |
174 » » » long dstoff, long gmtoff); | |
175 static void » stringzone(char * result, | |
176 » » » const struct zone * zp, int ntzones); | |
177 static void» setboundaries(void); | |
178 static zic_t» tadd(zic_t t1, long t2); | |
179 static void» usage(FILE *stream, int status); | |
180 static void» writezone(const char * name, const char * string); | |
181 static int yearistype(int year, const char * type); | 176 static int yearistype(int year, const char * type); |
182 #ifdef ICU | 177 #ifdef ICU |
183 static void emit_icu_zone(FILE* f, const char* zoneName, int zoneOffset, | 178 static void emit_icu_zone(FILE* f, const char* zoneName, int zoneOffset, |
184 const struct rule* rule, | 179 const struct rule* rule, |
185 int ruleIndex, int startYear); | 180 int ruleIndex, int startYear); |
186 static void emit_icu_link(FILE* f, const char* from, const char* to); | 181 static void emit_icu_link(FILE* f, const char* from, const char* to); |
187 static void emit_icu_rule(FILE* f, const struct rule* r, int ruleIndex); | 182 static void emit_icu_rule(FILE* f, const struct rule* r, int ruleIndex); |
188 static int add_icu_final_rules(const struct rule* r1, const struct rule* r2
); | 183 static int add_icu_final_rules(const struct rule* r1, const struct rule* r2
); |
189 #endif | 184 #endif |
190 | 185 |
191 static int charcnt; | 186 static int charcnt; |
192 static int errors; | 187 static int errors; |
193 static const char * filename; | 188 static const char * filename; |
194 static int leapcnt; | 189 static int leapcnt; |
195 static int leapseen; | 190 static int leapseen; |
196 static int» » leapminyear; | 191 static zic_t» » leapminyear; |
197 static int» » leapmaxyear; | 192 static zic_t» » leapmaxyear; |
198 static int linenum; | 193 static int linenum; |
199 static int max_abbrvar_len; | 194 static int max_abbrvar_len; |
200 static int max_format_len; | 195 static int max_format_len; |
201 static zic_t» » max_time; | 196 static zic_t» » max_year; |
202 static int» » max_year; | 197 static zic_t» » min_year; |
203 static zic_t» » min_time; | |
204 static int» » min_year; | |
205 static int noise; | 198 static int noise; |
206 static const char * rfilename; | 199 static const char * rfilename; |
207 static int rlinenum; | 200 static int rlinenum; |
208 static const char * progname; | 201 static const char * progname; |
209 static int timecnt; | 202 static int timecnt; |
| 203 static int timecnt_alloc; |
210 static int typecnt; | 204 static int typecnt; |
211 | 205 |
212 /* | 206 /* |
213 ** Line codes. | 207 ** Line codes. |
214 */ | 208 */ |
215 | 209 |
216 #define LC_RULE 0 | 210 #define LC_RULE 0 |
217 #define LC_ZONE 1 | 211 #define LC_ZONE 1 |
218 #define LC_LINK 2 | 212 #define LC_LINK 2 |
219 #define LC_LEAP 3 | 213 #define LC_LEAP 3 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 /* | 279 /* |
286 ** Year synonyms. | 280 ** Year synonyms. |
287 */ | 281 */ |
288 | 282 |
289 #define YR_MINIMUM 0 | 283 #define YR_MINIMUM 0 |
290 #define YR_MAXIMUM 1 | 284 #define YR_MAXIMUM 1 |
291 #define YR_ONLY 2 | 285 #define YR_ONLY 2 |
292 | 286 |
293 static struct rule * rules; | 287 static struct rule * rules; |
294 static int nrules; /* number of rules */ | 288 static int nrules; /* number of rules */ |
| 289 static int nrules_alloc; |
295 | 290 |
296 static struct zone * zones; | 291 static struct zone * zones; |
297 static int nzones; /* number of zones */ | 292 static int nzones; /* number of zones */ |
| 293 static int nzones_alloc; |
298 | 294 |
299 struct link { | 295 struct link { |
300 const char * l_filename; | 296 const char * l_filename; |
301 int l_linenum; | 297 int l_linenum; |
302 const char * l_from; | 298 const char * l_from; |
303 const char * l_to; | 299 const char * l_to; |
304 }; | 300 }; |
305 | 301 |
306 static struct link * links; | 302 static struct link * links; |
307 static int nlinks; | 303 static int nlinks; |
| 304 static int nlinks_alloc; |
308 | 305 |
309 struct lookup { | 306 struct lookup { |
310 const char * l_word; | 307 const char * l_word; |
311 const int l_value; | 308 const int l_value; |
312 }; | 309 }; |
313 | 310 |
314 #ifdef ICU | 311 #ifdef ICU |
315 /* Indices into rules[] for final rules. They will occur in pairs, | 312 /* Indices into rules[] for final rules. They will occur in pairs, |
316 * with finalRules[i] occurring before finalRules[i+1] in the year. | 313 * with finalRules[i] occurring before finalRules[i+1] in the year. |
317 * Each zone need only store a start year, a standard offset, and an | 314 * Each zone need only store a start year, a standard offset, and an |
318 * index into finalRules[]. FinalRules[] are aliases into rules[]. */ | 315 * index into finalRules[]. FinalRules[] are aliases into rules[]. */ |
319 static const struct rule **» finalRules; | 316 static const struct rule **» finalRules = NULL; |
320 static int» » » » » finalRulesCount; | 317 static int» » » » » finalRulesCount = 0; |
321 #endif | 318 #endif |
322 | 319 |
323 static struct lookup const * byword(const char * string, | 320 static struct lookup const * byword(const char * string, |
324 const struct lookup * lp); | 321 const struct lookup * lp); |
325 | 322 |
326 static struct lookup const line_codes[] = { | 323 static struct lookup const line_codes[] = { |
327 { "Rule", LC_RULE }, | 324 { "Rule", LC_RULE }, |
328 { "Zone", LC_ZONE }, | 325 { "Zone", LC_ZONE }, |
329 { "Link", LC_LINK }, | 326 { "Link", LC_LINK }, |
330 { "Leap", LC_LEAP }, | 327 { "Leap", LC_LEAP }, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } | 390 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
394 }; | 391 }; |
395 | 392 |
396 static const int len_years[2] = { | 393 static const int len_years[2] = { |
397 DAYSPERNYEAR, DAYSPERLYEAR | 394 DAYSPERNYEAR, DAYSPERLYEAR |
398 }; | 395 }; |
399 | 396 |
400 static struct attype { | 397 static struct attype { |
401 zic_t at; | 398 zic_t at; |
402 unsigned char type; | 399 unsigned char type; |
403 }» » » attypes[TZ_MAX_TIMES]; | 400 } *» » » attypes; |
404 static long» » gmtoffs[TZ_MAX_TYPES]; | 401 static zic_t» » gmtoffs[TZ_MAX_TYPES]; |
405 #ifdef ICU | 402 #ifdef ICU |
406 /* gmtoffs[i] = rawoffs[i] + dstoffs[i] */ | 403 /* gmtoffs[i] = rawoffs[i] + dstoffs[i] */ |
407 static long» » rawoffs[TZ_MAX_TYPES]; | 404 static zic_t» » rawoffs[TZ_MAX_TYPES]; |
408 static long» » dstoffs[TZ_MAX_TYPES]; | 405 static zic_t» » dstoffs[TZ_MAX_TYPES]; |
409 #endif | 406 #endif |
410 static char isdsts[TZ_MAX_TYPES]; | 407 static char isdsts[TZ_MAX_TYPES]; |
411 static unsigned char abbrinds[TZ_MAX_TYPES]; | 408 static unsigned char abbrinds[TZ_MAX_TYPES]; |
412 static char ttisstds[TZ_MAX_TYPES]; | 409 static char ttisstds[TZ_MAX_TYPES]; |
413 static char ttisgmts[TZ_MAX_TYPES]; | 410 static char ttisgmts[TZ_MAX_TYPES]; |
414 static char chars[TZ_MAX_CHARS]; | 411 static char chars[TZ_MAX_CHARS]; |
415 static zic_t trans[TZ_MAX_LEAPS]; | 412 static zic_t trans[TZ_MAX_LEAPS]; |
416 static long» » corr[TZ_MAX_LEAPS]; | 413 static zic_t» » corr[TZ_MAX_LEAPS]; |
417 static char roll[TZ_MAX_LEAPS]; | 414 static char roll[TZ_MAX_LEAPS]; |
418 | 415 |
419 /* | 416 /* |
420 ** Memory allocation. | 417 ** Memory allocation. |
421 */ | 418 */ |
422 | 419 |
423 static char * | 420 static _Noreturn void |
424 memcheck(ptr) | 421 memory_exhausted(const char *msg) |
425 char * const» ptr; | |
426 { | 422 { |
427 » if (ptr == NULL) { | 423 » fprintf(stderr, _("%s: Memory exhausted: %s\n"), progname, msg); |
428 » » const char *e = strerror(errno); | 424 » exit(EXIT_FAILURE); |
| 425 } |
429 | 426 |
430 » » (void) fprintf(stderr, _("%s: Memory exhausted: %s\n"), | 427 static ATTRIBUTE_PURE size_t |
431 » » » progname, e); | 428 size_product(size_t nitems, size_t itemsize) |
432 » » exit(EXIT_FAILURE); | 429 { |
433 » } | 430 » if (SIZE_MAX / itemsize < nitems) |
| 431 » » memory_exhausted("size overflow"); |
| 432 » return nitems * itemsize; |
| 433 } |
| 434 |
| 435 static ATTRIBUTE_PURE void * |
| 436 memcheck(void *const ptr) |
| 437 { |
| 438 » if (ptr == NULL) |
| 439 » » memory_exhausted(strerror(errno)); |
434 return ptr; | 440 return ptr; |
435 } | 441 } |
436 | 442 |
437 #define emalloc(size)» » memcheck(imalloc(size)) | 443 #define emalloc(size)» » memcheck(malloc(size)) |
438 #define erealloc(ptr, size)» memcheck(irealloc((ptr), (size))) | 444 #define erealloc(ptr, size)» memcheck(realloc(ptr, size)) |
439 #define ecpyalloc(ptr) memcheck(icpyalloc(ptr)) | 445 #define ecpyalloc(ptr) memcheck(icpyalloc(ptr)) |
440 #define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp))) | 446 #define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp))) |
441 | 447 |
| 448 static void * |
| 449 growalloc(void *ptr, size_t itemsize, int nitems, int *nitems_alloc) |
| 450 { |
| 451 if (nitems < *nitems_alloc) |
| 452 return ptr; |
| 453 else { |
| 454 int amax = INT_MAX < SIZE_MAX ? INT_MAX : SIZE_MAX; |
| 455 if ((amax - 1) / 3 * 2 < *nitems_alloc) |
| 456 memory_exhausted("int overflow"); |
| 457 *nitems_alloc = *nitems_alloc + (*nitems_alloc >> 1) + 1; |
| 458 return erealloc(ptr, size_product(*nitems_alloc, itemsize)); |
| 459 } |
| 460 } |
| 461 |
442 /* | 462 /* |
443 ** Error handling. | 463 ** Error handling. |
444 */ | 464 */ |
445 | 465 |
446 static void | 466 static void |
447 eats(name, num, rname, rnum) | 467 eats(const char *const name, const int num, const char *const rname, |
448 const char * const» name; | 468 const int rnum) |
449 const int» » num; | |
450 const char * const» rname; | |
451 const int» » rnum; | |
452 { | 469 { |
453 filename = name; | 470 filename = name; |
454 linenum = num; | 471 linenum = num; |
455 rfilename = rname; | 472 rfilename = rname; |
456 rlinenum = rnum; | 473 rlinenum = rnum; |
457 } | 474 } |
458 | 475 |
459 static void | 476 static void |
460 eat(name, num) | 477 eat(const char *const name, const int num) |
461 const char * const» name; | |
462 const int» » num; | |
463 { | 478 { |
464 » eats(name, num, (char *) NULL, -1); | 479 » eats(name, num, NULL, -1); |
465 } | 480 } |
466 | 481 |
467 static void | 482 static void ATTRIBUTE_FORMAT((printf, 1, 0)) |
468 error(string) | 483 verror(const char *const string, va_list args) |
469 const char * const» string; | |
470 { | 484 { |
471 /* | 485 /* |
472 ** Match the format of "cc" to allow sh users to | 486 ** Match the format of "cc" to allow sh users to |
473 ** zic ... 2>&1 | error -t "*" -v | 487 ** zic ... 2>&1 | error -t "*" -v |
474 ** on BSD systems. | 488 ** on BSD systems. |
475 */ | 489 */ |
476 » (void) fprintf(stderr, _("\"%s\", line %d: %s"), | 490 » fprintf(stderr, _("\"%s\", line %d: "), filename, linenum); |
477 » » filename, linenum, string); | 491 » vfprintf(stderr, string, args); |
478 if (rfilename != NULL) | 492 if (rfilename != NULL) |
479 (void) fprintf(stderr, _(" (rule from \"%s\", line %d)"), | 493 (void) fprintf(stderr, _(" (rule from \"%s\", line %d)"), |
480 rfilename, rlinenum); | 494 rfilename, rlinenum); |
481 (void) fprintf(stderr, "\n"); | 495 (void) fprintf(stderr, "\n"); |
482 ++errors; | 496 ++errors; |
483 } | 497 } |
484 | 498 |
485 static void | 499 static void ATTRIBUTE_FORMAT((printf, 1, 2)) |
486 warning(string) | 500 error(const char *const string, ...) |
487 const char * const» string; | |
488 { | 501 { |
489 » char *» cp; | 502 » va_list args; |
| 503 » va_start(args, string); |
| 504 » verror(string, args); |
| 505 » va_end(args); |
| 506 } |
490 | 507 |
491 » cp = ecpyalloc(_("warning: ")); | 508 static void ATTRIBUTE_FORMAT((printf, 1, 2)) |
492 » cp = ecatalloc(cp, string); | 509 warning(const char *const string, ...) |
493 » error(cp); | 510 { |
494 » ifree(cp); | 511 » va_list args; |
| 512 » fprintf(stderr, _("warning: ")); |
| 513 » va_start(args, string); |
| 514 » verror(string, args); |
| 515 » va_end(args); |
495 --errors; | 516 --errors; |
496 } | 517 } |
497 | 518 |
498 static void | 519 static _Noreturn void |
499 usage(FILE *stream, int status) | 520 usage(FILE *stream, int status) |
500 { | 521 { |
501 (void) fprintf(stream, _("%s: usage is %s \ | 522 (void) fprintf(stream, _("%s: usage is %s \ |
502 [ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\ | 523 [ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\ |
503 \t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\ | 524 \t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\ |
504 \n\ | 525 \n\ |
505 Report bugs to tz@elsie.nci.nih.gov.\n"), | 526 Report bugs to %s.\n"), |
506 » » progname, progname); | 527 » » progname, progname, REPORT_BUGS_TO); |
507 exit(status); | 528 exit(status); |
508 } | 529 } |
509 | 530 |
510 #ifdef ICU | 531 #ifdef ICU |
511 /* File into which we will write supplemental ICU data. */ | 532 /* File into which we will write supplemental ICU data. */ |
512 static FILE * icuFile; | 533 static FILE * icuFile; |
513 | 534 |
514 static void | 535 static void |
515 emit_icu_zone(FILE* f, const char* zoneName, int zoneOffset, | 536 emit_icu_zone(FILE* f, const char* zoneName, int zoneOffset, |
516 const struct rule* rule, | 537 const struct rule* rule, |
(...skipping 17 matching lines...) Expand all Loading... |
534 | 555 |
535 static void | 556 static void |
536 emit_icu_rule(FILE* f, const struct rule* r, int ruleIndex) { | 557 emit_icu_rule(FILE* f, const struct rule* r, int ruleIndex) { |
537 if (r->r_yrtype != NULL) { | 558 if (r->r_yrtype != NULL) { |
538 warning("year types not supported by ICU"); | 559 warning("year types not supported by ICU"); |
539 fprintf(stderr, "rule %s, file %s, line %d\n", | 560 fprintf(stderr, "rule %s, file %s, line %d\n", |
540 r->r_name, r->r_filename, r->r_linenum); | 561 r->r_name, r->r_filename, r->r_linenum); |
541 } | 562 } |
542 | 563 |
543 /* machine-readable section */ | 564 /* machine-readable section */ |
544 » fprintf(f, "rule %s %s %d %d %d %ld %d %d %ld", | 565 » fprintf(f, "rule %s %s %d %d %d %lld %d %d %lld", |
545 r->r_name, DYCODE[r->r_dycode], | 566 r->r_name, DYCODE[r->r_dycode], |
546 r->r_month, r->r_dayofmonth, | 567 r->r_month, r->r_dayofmonth, |
547 (r->r_dycode == DC_DOM ? -1 : r->r_wday), | 568 (r->r_dycode == DC_DOM ? -1 : r->r_wday), |
548 r->r_tod, r->r_todisstd, r->r_todisgmt, r->r_stdoff | 569 r->r_tod, r->r_todisstd, r->r_todisgmt, r->r_stdoff |
549 ); | 570 ); |
550 | 571 |
551 /* human-readable section */ | 572 /* human-readable section */ |
552 fprintf(f, " # %d: %s, file %s, line %d", | 573 fprintf(f, " # %d: %s, file %s, line %d", |
553 ruleIndex, r->r_name, r->r_filename, r->r_linenum); | 574 ruleIndex, r->r_name, r->r_filename, r->r_linenum); |
554 fprintf(f, ", mode %s", DYCODE[r->r_dycode]); | 575 fprintf(f, ", mode %s", DYCODE[r->r_dycode]); |
555 fprintf(f, ", %s, dom %d", mon_names[r->r_month].l_word, r->r_dayofmonth
); | 576 fprintf(f, ", %s, dom %d", mon_names[r->r_month].l_word, r->r_dayofmonth
); |
556 if (r->r_dycode != DC_DOM) { | 577 if (r->r_dycode != DC_DOM) { |
557 fprintf(f, ", %s", wday_names[r->r_wday].l_word); | 578 fprintf(f, ", %s", wday_names[r->r_wday].l_word); |
558 } | 579 } |
559 » fprintf(f, ", time %ld", r->r_tod); | 580 » fprintf(f, ", time %lld", r->r_tod); |
560 fprintf(f, ", isstd %d", r->r_todisstd); | 581 fprintf(f, ", isstd %d", r->r_todisstd); |
561 fprintf(f, ", isgmt %d", r->r_todisgmt); | 582 fprintf(f, ", isgmt %d", r->r_todisgmt); |
562 » fprintf(f, ", offset %ld", r->r_stdoff); | 583 » fprintf(f, ", offset %lld", r->r_stdoff); |
563 fprintf(f, "\n"); | 584 fprintf(f, "\n"); |
564 } | 585 } |
565 | 586 |
566 static int | 587 static int |
567 add_icu_final_rules(const struct rule* r1, const struct rule* r2) { | 588 add_icu_final_rules(const struct rule* r1, const struct rule* r2) { |
568 int i; | 589 int i; |
569 | 590 |
570 for (i=0; i<finalRulesCount; ++i) { /* i+=2 should work too */ | 591 for (i=0; i<finalRulesCount; ++i) { /* i+=2 should work too */ |
571 if (r1==finalRules[i]) return i; /* [sic] pointer comparison */ | 592 if (r1==finalRules[i]) return i; /* [sic] pointer comparison */ |
572 } | 593 } |
573 | 594 |
574 finalRules = (const struct rule**) (void*) erealloc((char *) finalRules, | 595 finalRules = (const struct rule**) (void*) erealloc((char *) finalRules, |
575 (finalRulesCount + 2) * sizeof(*finalRules)); | 596 (finalRulesCount + 2) * sizeof(*finalRules)); |
576 finalRules[finalRulesCount++] = r1; | 597 finalRules[finalRulesCount++] = r1; |
577 finalRules[finalRulesCount++] = r2; | 598 finalRules[finalRulesCount++] = r2; |
578 return finalRulesCount - 2; | 599 return finalRulesCount - 2; |
579 } | 600 } |
580 #endif | 601 #endif |
581 | 602 |
582 static const char * psxrules; | 603 static const char * psxrules; |
583 static const char * lcltime; | 604 static const char * lcltime; |
584 static const char * directory; | 605 static const char * directory; |
585 static const char * leapsec; | 606 static const char * leapsec; |
586 static const char * yitcommand; | 607 static const char * yitcommand; |
587 | 608 |
588 int | 609 int |
589 main(argc, argv) | 610 main(int argc, char **argv) |
590 int» argc; | |
591 char *» argv[]; | |
592 { | 611 { |
593 register int i; | 612 register int i; |
594 register int j; | 613 register int j; |
595 register int c; | 614 register int c; |
596 | 615 |
597 #ifdef unix | 616 #ifdef S_IWGRP |
598 (void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); | 617 (void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); |
599 #endif /* defined unix */ | 618 #endif |
600 #if HAVE_GETTEXT | 619 #if HAVE_GETTEXT |
601 (void) setlocale(LC_ALL, ""); | 620 (void) setlocale(LC_ALL, ""); |
602 #ifdef TZ_DOMAINDIR | 621 #ifdef TZ_DOMAINDIR |
603 (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); | 622 (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); |
604 #endif /* defined TEXTDOMAINDIR */ | 623 #endif /* defined TEXTDOMAINDIR */ |
605 (void) textdomain(TZ_DOMAIN); | 624 (void) textdomain(TZ_DOMAIN); |
606 #endif /* HAVE_GETTEXT */ | 625 #endif /* HAVE_GETTEXT */ |
607 progname = argv[0]; | 626 progname = argv[0]; |
608 if (TYPE_BIT(zic_t) < 64) { | 627 if (TYPE_BIT(zic_t) < 64) { |
609 (void) fprintf(stderr, "%s: %s\n", progname, | 628 (void) fprintf(stderr, "%s: %s\n", progname, |
610 _("wild compilation-time specification of zic_t")); | 629 _("wild compilation-time specification of zic_t")); |
611 exit(EXIT_FAILURE); | 630 exit(EXIT_FAILURE); |
612 } | 631 } |
613 for (i = 1; i < argc; ++i) | 632 for (i = 1; i < argc; ++i) |
614 if (strcmp(argv[i], "--version") == 0) { | 633 if (strcmp(argv[i], "--version") == 0) { |
615 » » » (void) printf("%s\n", elsieid); | 634 » » » (void) printf("zic %s%s\n", PKGVERSION, TZVERSION); |
616 exit(EXIT_SUCCESS); | 635 exit(EXIT_SUCCESS); |
617 } else if (strcmp(argv[i], "--help") == 0) { | 636 } else if (strcmp(argv[i], "--help") == 0) { |
618 usage(stdout, EXIT_SUCCESS); | 637 usage(stdout, EXIT_SUCCESS); |
619 } | 638 } |
620 while ((c = getopt(argc, argv, "d:l:p:L:vsy:")) != EOF && c != -1) | 639 while ((c = getopt(argc, argv, "d:l:p:L:vsy:")) != EOF && c != -1) |
621 switch (c) { | 640 switch (c) { |
622 default: | 641 default: |
623 usage(stderr, EXIT_FAILURE); | 642 usage(stderr, EXIT_FAILURE); |
624 case 'd': | 643 case 'd': |
625 if (directory == NULL) | 644 if (directory == NULL) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 (void) printf("%s: -s ignored\n", progname); | 697 (void) printf("%s: -s ignored\n", progname); |
679 break; | 698 break; |
680 } | 699 } |
681 if (optind == argc - 1 && strcmp(argv[optind], "=") == 0) | 700 if (optind == argc - 1 && strcmp(argv[optind], "=") == 0) |
682 usage(stderr, EXIT_FAILURE); /* usage message by request */ | 701 usage(stderr, EXIT_FAILURE); /* usage message by request */ |
683 if (directory == NULL) | 702 if (directory == NULL) |
684 directory = TZDIR; | 703 directory = TZDIR; |
685 if (yitcommand == NULL) | 704 if (yitcommand == NULL) |
686 yitcommand = "yearistype"; | 705 yitcommand = "yearistype"; |
687 | 706 |
688 setboundaries(); | |
689 | |
690 if (optind < argc && leapsec != NULL) { | 707 if (optind < argc && leapsec != NULL) { |
691 infile(leapsec); | 708 infile(leapsec); |
692 adjleap(); | 709 adjleap(); |
693 } | 710 } |
694 | 711 |
695 #ifdef ICU | 712 #ifdef ICU |
696 if ((icuFile = fopen(ICU_ZONE_FILE, "w")) == NULL) { | 713 if ((icuFile = fopen(ICU_ZONE_FILE, "w")) == NULL) { |
697 const char *e = strerror(errno); | 714 const char *e = strerror(errno); |
698 (void) fprintf(stderr, _("%s: Can't open %s: %s\n"), | 715 (void) fprintf(stderr, _("%s: Can't open %s: %s\n"), |
699 progname, ICU_ZONE_FILE, e); | 716 progname, ICU_ZONE_FILE, e); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 755 } |
739 #ifdef ICU | 756 #ifdef ICU |
740 for (i=0; i<finalRulesCount; ++i) { | 757 for (i=0; i<finalRulesCount; ++i) { |
741 emit_icu_rule(icuFile, finalRules[i], i); | 758 emit_icu_rule(icuFile, finalRules[i], i); |
742 } | 759 } |
743 #endif /*ICU*/ | 760 #endif /*ICU*/ |
744 return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | 761 return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
745 } | 762 } |
746 | 763 |
747 static void | 764 static void |
748 dolink(fromfield, tofield) | 765 dolink(const char *const fromfield, const char *const tofield) |
749 const char * const» fromfield; | |
750 const char * const» tofield; | |
751 { | 766 { |
752 register char * fromname; | 767 register char * fromname; |
753 register char * toname; | 768 register char * toname; |
754 | 769 |
755 if (fromfield[0] == '/') | 770 if (fromfield[0] == '/') |
756 fromname = ecpyalloc(fromfield); | 771 fromname = ecpyalloc(fromfield); |
757 else { | 772 else { |
758 fromname = ecpyalloc(directory); | 773 fromname = ecpyalloc(directory); |
759 fromname = ecatalloc(fromname, "/"); | 774 fromname = ecatalloc(fromname, "/"); |
760 fromname = ecatalloc(fromname, fromfield); | 775 fromname = ecatalloc(fromname, fromfield); |
761 } | 776 } |
762 if (tofield[0] == '/') | 777 if (tofield[0] == '/') |
763 toname = ecpyalloc(tofield); | 778 toname = ecpyalloc(tofield); |
764 else { | 779 else { |
765 toname = ecpyalloc(directory); | 780 toname = ecpyalloc(directory); |
766 toname = ecatalloc(toname, "/"); | 781 toname = ecatalloc(toname, "/"); |
767 toname = ecatalloc(toname, tofield); | 782 toname = ecatalloc(toname, tofield); |
768 } | 783 } |
769 /* | 784 /* |
770 ** We get to be careful here since | 785 ** We get to be careful here since |
771 ** there's a fair chance of root running us. | 786 ** there's a fair chance of root running us. |
772 */ | 787 */ |
773 if (!itsdir(toname)) | 788 if (!itsdir(toname)) |
774 (void) remove(toname); | 789 (void) remove(toname); |
775 » if (link(fromname, toname) != 0) { | 790 » if (link(fromname, toname) != 0 |
| 791 » && access(fromname, F_OK) == 0 && !itsdir(fromname)) { |
776 int result; | 792 int result; |
777 | 793 |
778 if (mkdirs(toname) != 0) | 794 if (mkdirs(toname) != 0) |
779 exit(EXIT_FAILURE); | 795 exit(EXIT_FAILURE); |
780 | 796 |
781 result = link(fromname, toname); | 797 result = link(fromname, toname); |
782 #if HAVE_SYMLINK | 798 » » if (result != 0) { |
783 » » if (result != 0 && | 799 » » » » const char *s = fromfield; |
784 » » » access(fromname, F_OK) == 0 && | 800 » » » » const char *t; |
785 » » » !itsdir(fromname)) { | |
786 » » » » const char *s = tofield; | |
787 register char * symlinkcontents = NULL; | 801 register char * symlinkcontents = NULL; |
788 | 802 |
789 » » » » while ((s = strchr(s+1, '/')) != NULL) | 803 » » » » do |
| 804 » » » » » t = s; |
| 805 » » » » while ((s = strchr(s, '/')) |
| 806 » » » » && ! strncmp (fromfield, tofield, |
| 807 » » » » » » ++s - fromfield)); |
| 808 |
| 809 » » » » for (s = tofield + (t - fromfield); |
| 810 » » » » (s = strchr(s, '/')); |
| 811 » » » » s++) |
790 symlinkcontents = | 812 symlinkcontents = |
791 ecatalloc(symlinkcontents, | 813 ecatalloc(symlinkcontents, |
792 "../"); | 814 "../"); |
793 » » » » symlinkcontents = | 815 » » » » symlinkcontents = ecatalloc(symlinkcontents, t); |
794 » » » » » ecatalloc(symlinkcontents, | 816 » » » » result = symlink(symlinkcontents, toname); |
795 » » » » » fromname); | |
796 » » » » result = symlink(symlinkcontents, | |
797 » » » » » toname); | |
798 if (result == 0) | 817 if (result == 0) |
799 warning(_("hard link failed, symbolic link used")); | 818 warning(_("hard link failed, symbolic link used")); |
800 » » » » ifree(symlinkcontents); | 819 » » » » free(symlinkcontents); |
801 } | 820 } |
802 #endif /* HAVE_SYMLINK */ | |
803 if (result != 0) { | 821 if (result != 0) { |
804 » » » const char *e = strerror(errno); | 822 » » » FILE *fp, *tp; |
805 | 823 » » » int c; |
806 » » » (void) fprintf(stderr, | 824 » » » fp = fopen(fromname, "rb"); |
807 » » » » _("%s: Can't link from %s to %s: %s\n"), | 825 » » » if (!fp) { |
808 » » » » progname, fromname, toname, e); | 826 » » » » const char *e = strerror(errno); |
| 827 » » » » (void) fprintf(stderr, |
| 828 » » » » » _("%s: Can't read %s: %s\n"), |
| 829 » » » » » progname, fromname, e); |
| 830 » » » » exit(EXIT_FAILURE); |
| 831 » » » } |
| 832 » » » tp = fopen(toname, "wb"); |
| 833 » » » if (!tp) { |
| 834 » » » » const char *e = strerror(errno); |
| 835 » » » » (void) fprintf(stderr, |
| 836 » » » » » _("%s: Can't create %s: %s\n"), |
| 837 » » » » » progname, toname, e); |
| 838 » » » » exit(EXIT_FAILURE); |
| 839 » » » } |
| 840 » » » while ((c = getc(fp)) != EOF) |
| 841 » » » » putc(c, tp); |
| 842 » » » if (ferror(fp) || fclose(fp)) { |
| 843 » » » » (void) fprintf(stderr, |
| 844 » » » » » _("%s: Error reading %s\n"), |
| 845 » » » » » progname, fromname); |
| 846 » » » » exit(EXIT_FAILURE); |
| 847 » » » } |
| 848 » » » if (ferror(tp) || fclose(tp)) { |
| 849 » » » » (void) fprintf(stderr, |
| 850 » » » » » _("%s: Error writing %s\n"), |
| 851 » » » » » progname, toname); |
| 852 » » » » exit(EXIT_FAILURE); |
| 853 » » » } |
| 854 » » » warning(_("link failed, copy used")); |
809 #ifndef ICU_LINKS | 855 #ifndef ICU_LINKS |
810 exit(EXIT_FAILURE); | 856 exit(EXIT_FAILURE); |
811 #endif | 857 #endif |
812 } | 858 } |
813 } | 859 } |
814 » ifree(fromname); | 860 » free(fromname); |
815 » ifree(toname); | 861 » free(toname); |
816 } | 862 } |
817 | 863 |
818 #define TIME_T_BITS_IN_FILE 64 | 864 #define TIME_T_BITS_IN_FILE 64 |
819 | 865 |
820 static void | 866 static const zic_t min_time = (zic_t) -1 << (TIME_T_BITS_IN_FILE - 1); |
821 setboundaries(void) | 867 static const zic_t max_time = -1 - ((zic_t) -1 << (TIME_T_BITS_IN_FILE - 1)); |
822 { | |
823 » register int» i; | |
824 | |
825 » min_time = -1; | |
826 » for (i = 0; i < TIME_T_BITS_IN_FILE - 1; ++i) | |
827 » » min_time *= 2; | |
828 » max_time = -(min_time + 1); | |
829 } | |
830 | 868 |
831 static int | 869 static int |
832 itsdir(name) | 870 itsdir(const char *const name) |
833 const char * const» name; | |
834 { | 871 { |
835 register char * myname; | 872 register char * myname; |
836 register int accres; | 873 register int accres; |
837 | 874 |
838 myname = ecpyalloc(name); | 875 myname = ecpyalloc(name); |
839 myname = ecatalloc(myname, "/."); | 876 myname = ecatalloc(myname, "/."); |
840 accres = access(myname, F_OK); | 877 accres = access(myname, F_OK); |
841 » ifree(myname); | 878 » free(myname); |
842 return accres == 0; | 879 return accres == 0; |
843 } | 880 } |
844 | 881 |
845 /* | 882 /* |
846 ** Associate sets of rules with zones. | 883 ** Associate sets of rules with zones. |
847 */ | 884 */ |
848 | 885 |
849 /* | 886 /* |
850 ** Sort by rule name. | 887 ** Sort by rule name. |
851 */ | 888 */ |
852 | 889 |
853 static int | 890 static int |
854 rcomp(cp1, cp2) | 891 rcomp(const void *cp1, const void *cp2) |
855 const void *» cp1; | |
856 const void *» cp2; | |
857 { | 892 { |
858 return strcmp(((const struct rule *) cp1)->r_name, | 893 return strcmp(((const struct rule *) cp1)->r_name, |
859 ((const struct rule *) cp2)->r_name); | 894 ((const struct rule *) cp2)->r_name); |
860 } | 895 } |
861 | 896 |
862 static void | 897 static void |
863 associate(void) | 898 associate(void) |
864 { | 899 { |
865 register struct zone * zp; | 900 register struct zone * zp; |
866 register struct rule * rp; | 901 register struct rule * rp; |
867 register int base, out; | 902 register int base, out; |
868 register int i, j; | 903 register int i, j; |
869 | 904 |
870 if (nrules != 0) { | 905 if (nrules != 0) { |
871 » » (void) qsort((void *) rules, (size_t) nrules, | 906 » » (void) qsort(rules, nrules, sizeof *rules, rcomp); |
872 » » » (size_t) sizeof *rules, rcomp); | |
873 for (i = 0; i < nrules - 1; ++i) { | 907 for (i = 0; i < nrules - 1; ++i) { |
874 if (strcmp(rules[i].r_name, | 908 if (strcmp(rules[i].r_name, |
875 rules[i + 1].r_name) != 0) | 909 rules[i + 1].r_name) != 0) |
876 continue; | 910 continue; |
877 if (strcmp(rules[i].r_filename, | 911 if (strcmp(rules[i].r_filename, |
878 rules[i + 1].r_filename) == 0) | 912 rules[i + 1].r_filename) == 0) |
879 continue; | 913 continue; |
880 eat(rules[i].r_filename, rules[i].r_linenum); | 914 eat(rules[i].r_filename, rules[i].r_linenum); |
881 warning(_("same rule name in multiple files")); | 915 warning(_("same rule name in multiple files")); |
882 eat(rules[i + 1].r_filename, rules[i + 1].r_linenum); | 916 eat(rules[i + 1].r_filename, rules[i + 1].r_linenum); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 ** Maybe we have a local standard time offset. | 955 ** Maybe we have a local standard time offset. |
922 */ | 956 */ |
923 eat(zp->z_filename, zp->z_linenum); | 957 eat(zp->z_filename, zp->z_linenum); |
924 zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"), | 958 zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"), |
925 TRUE); | 959 TRUE); |
926 /* | 960 /* |
927 ** Note, though, that if there's no rule, | 961 ** Note, though, that if there's no rule, |
928 ** a '%s' in the format is a bad thing. | 962 ** a '%s' in the format is a bad thing. |
929 */ | 963 */ |
930 if (strchr(zp->z_format, '%') != 0) | 964 if (strchr(zp->z_format, '%') != 0) |
931 » » » » error(_("%s in ruleless zone")); | 965 » » » » error("%s", _("%s in ruleless zone")); |
932 } | 966 } |
933 } | 967 } |
934 if (errors) | 968 if (errors) |
935 exit(EXIT_FAILURE); | 969 exit(EXIT_FAILURE); |
936 } | 970 } |
937 | 971 |
938 static void | 972 static void |
939 infile(name) | 973 infile(const char *name) |
940 const char *» name; | |
941 { | 974 { |
942 register FILE * fp; | 975 register FILE * fp; |
943 register char ** fields; | 976 register char ** fields; |
944 register char * cp; | 977 register char * cp; |
945 register const struct lookup * lp; | 978 register const struct lookup * lp; |
946 register int nfields; | 979 register int nfields; |
947 register int wantcont; | 980 register int wantcont; |
948 register int num; | 981 register int num; |
949 char buf[BUFSIZ]; | 982 char buf[BUFSIZ]; |
950 | 983 |
951 if (strcmp(name, "-") == 0) { | 984 if (strcmp(name, "-") == 0) { |
952 name = _("standard input"); | 985 name = _("standard input"); |
953 fp = stdin; | 986 fp = stdin; |
954 } else if ((fp = fopen(name, "r")) == NULL) { | 987 } else if ((fp = fopen(name, "r")) == NULL) { |
955 const char *e = strerror(errno); | 988 const char *e = strerror(errno); |
956 | 989 |
957 (void) fprintf(stderr, _("%s: Can't open %s: %s\n"), | 990 (void) fprintf(stderr, _("%s: Can't open %s: %s\n"), |
958 progname, name, e); | 991 progname, name, e); |
959 exit(EXIT_FAILURE); | 992 exit(EXIT_FAILURE); |
960 } | 993 } |
961 wantcont = FALSE; | 994 wantcont = FALSE; |
962 for (num = 1; ; ++num) { | 995 for (num = 1; ; ++num) { |
963 eat(name, num); | 996 eat(name, num); |
964 » » if (fgets(buf, (int) sizeof buf, fp) != buf) | 997 » » if (fgets(buf, sizeof buf, fp) != buf) |
965 break; | 998 break; |
966 cp = strchr(buf, '\n'); | 999 cp = strchr(buf, '\n'); |
967 if (cp == NULL) { | 1000 if (cp == NULL) { |
968 error(_("line too long")); | 1001 error(_("line too long")); |
969 exit(EXIT_FAILURE); | 1002 exit(EXIT_FAILURE); |
970 } | 1003 } |
971 *cp = '\0'; | 1004 *cp = '\0'; |
972 fields = getfields(buf); | 1005 fields = getfields(buf); |
973 nfields = 0; | 1006 nfields = 0; |
974 while (fields[nfields] != NULL) { | 1007 while (fields[nfields] != NULL) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 else inleap(fields, nfields); | 1039 else inleap(fields, nfields); |
1007 wantcont = FALSE; | 1040 wantcont = FALSE; |
1008 break; | 1041 break; |
1009 default: /* "cannot happen" */ | 1042 default: /* "cannot happen" */ |
1010 (void) fprintf(stderr, | 1043 (void) fprintf(stderr, |
1011 _("%s: panic: Invalid l_value %d\n"), | 1044 _("%s: panic: Invalid l_value %d\n"), |
1012 progname, lp->l_value); | 1045 progname, lp->l_value); |
1013 exit(EXIT_FAILURE); | 1046 exit(EXIT_FAILURE); |
1014 } | 1047 } |
1015 } | 1048 } |
1016 » » ifree((char *) fields); | 1049 » » free(fields); |
1017 } | 1050 } |
1018 if (ferror(fp)) { | 1051 if (ferror(fp)) { |
1019 (void) fprintf(stderr, _("%s: Error reading %s\n"), | 1052 (void) fprintf(stderr, _("%s: Error reading %s\n"), |
1020 progname, filename); | 1053 progname, filename); |
1021 exit(EXIT_FAILURE); | 1054 exit(EXIT_FAILURE); |
1022 } | 1055 } |
1023 if (fp != stdin && fclose(fp)) { | 1056 if (fp != stdin && fclose(fp)) { |
1024 const char *e = strerror(errno); | 1057 const char *e = strerror(errno); |
1025 | 1058 |
1026 (void) fprintf(stderr, _("%s: Error closing %s: %s\n"), | 1059 (void) fprintf(stderr, _("%s: Error closing %s: %s\n"), |
1027 progname, filename, e); | 1060 progname, filename, e); |
1028 exit(EXIT_FAILURE); | 1061 exit(EXIT_FAILURE); |
1029 } | 1062 } |
1030 if (wantcont) | 1063 if (wantcont) |
1031 error(_("expected continuation line not found")); | 1064 error(_("expected continuation line not found")); |
1032 } | 1065 } |
1033 | 1066 |
1034 /* | 1067 /* |
1035 ** Convert a string of one of the forms | 1068 ** Convert a string of one of the forms |
1036 ** h -h hh:mm -hh:mm hh:mm:ss -hh:mm:ss | 1069 ** h -h hh:mm -hh:mm hh:mm:ss -hh:mm:ss |
1037 ** into a number of seconds. | 1070 ** into a number of seconds. |
1038 ** A null string maps to zero. | 1071 ** A null string maps to zero. |
1039 ** Call error with errstring and return zero on errors. | 1072 ** Call error with errstring and return zero on errors. |
1040 */ | 1073 */ |
1041 | 1074 |
1042 static long | 1075 static zic_t |
1043 gethms(string, errstring, signable) | 1076 gethms(const char *string, const char *const errstring, const int signable) |
1044 const char *» » string; | |
1045 const char * const» errstring; | |
1046 const int» » signable; | |
1047 { | 1077 { |
1048 » long» hh; | 1078 » zic_t» hh; |
1049 int mm, ss, sign; | 1079 int mm, ss, sign; |
1050 | 1080 |
1051 if (string == NULL || *string == '\0') | 1081 if (string == NULL || *string == '\0') |
1052 return 0; | 1082 return 0; |
1053 if (!signable) | 1083 if (!signable) |
1054 sign = 1; | 1084 sign = 1; |
1055 else if (*string == '-') { | 1085 else if (*string == '-') { |
1056 sign = -1; | 1086 sign = -1; |
1057 ++string; | 1087 ++string; |
1058 } else sign = 1; | 1088 } else sign = 1; |
1059 » if (sscanf(string, scheck(string, "%ld"), &hh) == 1) | 1089 » if (sscanf(string, scheck(string, "%"SCNdZIC), &hh) == 1) |
1060 mm = ss = 0; | 1090 mm = ss = 0; |
1061 » else if (sscanf(string, scheck(string, "%ld:%d"), &hh, &mm) == 2) | 1091 » else if (sscanf(string, scheck(string, "%"SCNdZIC":%d"), &hh, &mm) == 2) |
1062 ss = 0; | 1092 ss = 0; |
1063 » else if (sscanf(string, scheck(string, "%ld:%d:%d"), | 1093 » else if (sscanf(string, scheck(string, "%"SCNdZIC":%d:%d"), |
1064 &hh, &mm, &ss) != 3) { | 1094 &hh, &mm, &ss) != 3) { |
1065 » » » error(errstring); | 1095 » » » error("%s", errstring); |
1066 return 0; | 1096 return 0; |
1067 } | 1097 } |
1068 if (hh < 0 || | 1098 if (hh < 0 || |
1069 mm < 0 || mm >= MINSPERHOUR || | 1099 mm < 0 || mm >= MINSPERHOUR || |
1070 ss < 0 || ss > SECSPERMIN) { | 1100 ss < 0 || ss > SECSPERMIN) { |
1071 » » » error(errstring); | 1101 » » » error("%s", errstring); |
1072 return 0; | 1102 return 0; |
1073 } | 1103 } |
1074 » if (LONG_MAX / SECSPERHOUR < hh) { | 1104 » if (ZIC_MAX / SECSPERHOUR < hh) { |
1075 error(_("time overflow")); | 1105 error(_("time overflow")); |
1076 return 0; | 1106 return 0; |
1077 } | 1107 } |
1078 if (noise && hh == HOURSPERDAY && mm == 0 && ss == 0) | 1108 if (noise && hh == HOURSPERDAY && mm == 0 && ss == 0) |
1079 warning(_("24:00 not handled by pre-1998 versions of zic")); | 1109 warning(_("24:00 not handled by pre-1998 versions of zic")); |
1080 if (noise && (hh > HOURSPERDAY || | 1110 if (noise && (hh > HOURSPERDAY || |
1081 (hh == HOURSPERDAY && (mm != 0 || ss != 0)))) | 1111 (hh == HOURSPERDAY && (mm != 0 || ss != 0)))) |
1082 warning(_("values over 24 hours not handled by pre-2007 versions of zic")); | 1112 warning(_("values over 24 hours not handled by pre-2007 versions of zic")); |
1083 » return oadd(eitol(sign) * hh * eitol(SECSPERHOUR), | 1113 » return oadd(sign * hh * SECSPERHOUR, |
1084 » » eitol(sign) * (eitol(mm) * eitol(SECSPERMIN) + eitol(ss))); | 1114 » » sign * (mm * SECSPERMIN + ss)); |
1085 } | 1115 } |
1086 | 1116 |
1087 static void | 1117 static void |
1088 inrule(fields, nfields) | 1118 inrule(register char **const fields, const int nfields) |
1089 register char ** const» fields; | |
1090 const int» » nfields; | |
1091 { | 1119 { |
1092 static struct rule r; | 1120 static struct rule r; |
1093 | 1121 |
1094 if (nfields != RULE_FIELDS) { | 1122 if (nfields != RULE_FIELDS) { |
1095 error(_("wrong number of fields on Rule line")); | 1123 error(_("wrong number of fields on Rule line")); |
1096 return; | 1124 return; |
1097 } | 1125 } |
1098 if (*fields[RF_NAME] == '\0') { | 1126 if (*fields[RF_NAME] == '\0') { |
1099 error(_("nameless rule")); | 1127 error(_("nameless rule")); |
1100 return; | 1128 return; |
1101 } | 1129 } |
1102 r.r_filename = filename; | 1130 r.r_filename = filename; |
1103 r.r_linenum = linenum; | 1131 r.r_linenum = linenum; |
1104 r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), TRUE); | 1132 r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), TRUE); |
1105 rulesub(&r, fields[RF_LOYEAR], fields[RF_HIYEAR], fields[RF_COMMAND], | 1133 rulesub(&r, fields[RF_LOYEAR], fields[RF_HIYEAR], fields[RF_COMMAND], |
1106 fields[RF_MONTH], fields[RF_DAY], fields[RF_TOD]); | 1134 fields[RF_MONTH], fields[RF_DAY], fields[RF_TOD]); |
1107 r.r_name = ecpyalloc(fields[RF_NAME]); | 1135 r.r_name = ecpyalloc(fields[RF_NAME]); |
1108 r.r_abbrvar = ecpyalloc(fields[RF_ABBRVAR]); | 1136 r.r_abbrvar = ecpyalloc(fields[RF_ABBRVAR]); |
1109 if (max_abbrvar_len < strlen(r.r_abbrvar)) | 1137 if (max_abbrvar_len < strlen(r.r_abbrvar)) |
1110 max_abbrvar_len = strlen(r.r_abbrvar); | 1138 max_abbrvar_len = strlen(r.r_abbrvar); |
1111 » rules = (struct rule *) (void *) erealloc((char *) rules, | 1139 » rules = growalloc(rules, sizeof *rules, nrules, &nrules_alloc); |
1112 » » (int) ((nrules + 1) * sizeof *rules)); | |
1113 rules[nrules++] = r; | 1140 rules[nrules++] = r; |
1114 } | 1141 } |
1115 | 1142 |
1116 static int | 1143 static int |
1117 inzone(fields, nfields) | 1144 inzone(register char **const fields, const int nfields) |
1118 register char ** const» fields; | |
1119 const int» » nfields; | |
1120 { | 1145 { |
1121 register int i; | 1146 register int i; |
1122 static char * buf; | |
1123 | 1147 |
1124 if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) { | 1148 if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) { |
1125 error(_("wrong number of fields on Zone line")); | 1149 error(_("wrong number of fields on Zone line")); |
1126 return FALSE; | 1150 return FALSE; |
1127 } | 1151 } |
1128 if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) { | 1152 if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) { |
1129 » » buf = erealloc(buf, (int) (132 + strlen(TZDEFAULT))); | 1153 » » error( |
1130 » » (void) sprintf(buf, | |
1131 _("\"Zone %s\" line and -l option are mutually exclusive"), | 1154 _("\"Zone %s\" line and -l option are mutually exclusive"), |
1132 TZDEFAULT); | 1155 TZDEFAULT); |
1133 error(buf); | |
1134 return FALSE; | 1156 return FALSE; |
1135 } | 1157 } |
1136 if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) { | 1158 if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) { |
1137 » » buf = erealloc(buf, (int) (132 + strlen(TZDEFRULES))); | 1159 » » error( |
1138 » » (void) sprintf(buf, | |
1139 _("\"Zone %s\" line and -p option are mutually exclusive"), | 1160 _("\"Zone %s\" line and -p option are mutually exclusive"), |
1140 TZDEFRULES); | 1161 TZDEFRULES); |
1141 error(buf); | |
1142 return FALSE; | 1162 return FALSE; |
1143 } | 1163 } |
1144 for (i = 0; i < nzones; ++i) | 1164 for (i = 0; i < nzones; ++i) |
1145 if (zones[i].z_name != NULL && | 1165 if (zones[i].z_name != NULL && |
1146 strcmp(zones[i].z_name, fields[ZF_NAME]) == 0) { | 1166 strcmp(zones[i].z_name, fields[ZF_NAME]) == 0) { |
1147 » » » » buf = erealloc(buf, (int) (132 + | 1167 » » » » error( |
1148 » » » » » strlen(fields[ZF_NAME]) + | |
1149 » » » » » strlen(zones[i].z_filename))); | |
1150 » » » » (void) sprintf(buf, | |
1151 _("duplicate zone name %s (file \"%s\", line %d)"), | 1168 _("duplicate zone name %s (file \"%s\", line %d)"), |
1152 fields[ZF_NAME], | 1169 fields[ZF_NAME], |
1153 zones[i].z_filename, | 1170 zones[i].z_filename, |
1154 zones[i].z_linenum); | 1171 zones[i].z_linenum); |
1155 error(buf); | |
1156 return FALSE; | 1172 return FALSE; |
1157 } | 1173 } |
1158 return inzsub(fields, nfields, FALSE); | 1174 return inzsub(fields, nfields, FALSE); |
1159 } | 1175 } |
1160 | 1176 |
1161 static int | 1177 static int |
1162 inzcont(fields, nfields) | 1178 inzcont(register char **const fields, const int nfields) |
1163 register char ** const» fields; | |
1164 const int» » nfields; | |
1165 { | 1179 { |
1166 if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) { | 1180 if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) { |
1167 error(_("wrong number of fields on Zone continuation line")); | 1181 error(_("wrong number of fields on Zone continuation line")); |
1168 return FALSE; | 1182 return FALSE; |
1169 } | 1183 } |
1170 return inzsub(fields, nfields, TRUE); | 1184 return inzsub(fields, nfields, TRUE); |
1171 } | 1185 } |
1172 | 1186 |
1173 static int | 1187 static int |
1174 inzsub(fields, nfields, iscont) | 1188 inzsub(register char **const fields, const int nfields, const int iscont) |
1175 register char ** const» fields; | |
1176 const int» » nfields; | |
1177 const int» » iscont; | |
1178 { | 1189 { |
1179 register char * cp; | 1190 register char * cp; |
1180 static struct zone z; | 1191 static struct zone z; |
1181 register int i_gmtoff, i_rule, i_format; | 1192 register int i_gmtoff, i_rule, i_format; |
1182 register int i_untilyear, i_untilmonth; | 1193 register int i_untilyear, i_untilmonth; |
1183 register int i_untilday, i_untiltime; | 1194 register int i_untilday, i_untiltime; |
1184 register int hasuntil; | 1195 register int hasuntil; |
1185 | 1196 |
1186 if (iscont) { | 1197 if (iscont) { |
1187 i_gmtoff = ZFC_GMTOFF; | 1198 i_gmtoff = ZFC_GMTOFF; |
1188 i_rule = ZFC_RULE; | 1199 i_rule = ZFC_RULE; |
1189 i_format = ZFC_FORMAT; | 1200 i_format = ZFC_FORMAT; |
1190 i_untilyear = ZFC_TILYEAR; | 1201 i_untilyear = ZFC_TILYEAR; |
1191 i_untilmonth = ZFC_TILMONTH; | 1202 i_untilmonth = ZFC_TILMONTH; |
1192 i_untilday = ZFC_TILDAY; | 1203 i_untilday = ZFC_TILDAY; |
1193 i_untiltime = ZFC_TILTIME; | 1204 i_untiltime = ZFC_TILTIME; |
1194 z.z_name = NULL; | 1205 z.z_name = NULL; |
1195 } else { | 1206 } else { |
1196 i_gmtoff = ZF_GMTOFF; | 1207 i_gmtoff = ZF_GMTOFF; |
1197 i_rule = ZF_RULE; | 1208 i_rule = ZF_RULE; |
1198 i_format = ZF_FORMAT; | 1209 i_format = ZF_FORMAT; |
1199 i_untilyear = ZF_TILYEAR; | 1210 i_untilyear = ZF_TILYEAR; |
1200 i_untilmonth = ZF_TILMONTH; | 1211 i_untilmonth = ZF_TILMONTH; |
1201 i_untilday = ZF_TILDAY; | 1212 i_untilday = ZF_TILDAY; |
1202 i_untiltime = ZF_TILTIME; | 1213 i_untiltime = ZF_TILTIME; |
1203 z.z_name = ecpyalloc(fields[ZF_NAME]); | 1214 z.z_name = ecpyalloc(fields[ZF_NAME]); |
1204 } | 1215 } |
1205 z.z_filename = filename; | 1216 z.z_filename = filename; |
1206 z.z_linenum = linenum; | 1217 z.z_linenum = linenum; |
1207 » z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UTC offset"), TRUE); | 1218 » z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UT offset"), TRUE); |
1208 if ((cp = strchr(fields[i_format], '%')) != 0) { | 1219 if ((cp = strchr(fields[i_format], '%')) != 0) { |
1209 if (*++cp != 's' || strchr(cp, '%') != 0) { | 1220 if (*++cp != 's' || strchr(cp, '%') != 0) { |
1210 error(_("invalid abbreviation format")); | 1221 error(_("invalid abbreviation format")); |
1211 return FALSE; | 1222 return FALSE; |
1212 } | 1223 } |
1213 } | 1224 } |
1214 z.z_rule = ecpyalloc(fields[i_rule]); | 1225 z.z_rule = ecpyalloc(fields[i_rule]); |
1215 z.z_format = ecpyalloc(fields[i_format]); | 1226 z.z_format = ecpyalloc(fields[i_format]); |
1216 if (max_format_len < strlen(z.z_format)) | 1227 if (max_format_len < strlen(z.z_format)) |
1217 max_format_len = strlen(z.z_format); | 1228 max_format_len = strlen(z.z_format); |
(...skipping 16 matching lines...) Expand all Loading... |
1234 z.z_untiltime < max_time && | 1245 z.z_untiltime < max_time && |
1235 zones[nzones - 1].z_untiltime > min_time && | 1246 zones[nzones - 1].z_untiltime > min_time && |
1236 zones[nzones - 1].z_untiltime < max_time && | 1247 zones[nzones - 1].z_untiltime < max_time && |
1237 zones[nzones - 1].z_untiltime >= z.z_untiltime) { | 1248 zones[nzones - 1].z_untiltime >= z.z_untiltime) { |
1238 error(_( | 1249 error(_( |
1239 "Zone continuation line end time is not after end time of previous line" | 1250 "Zone continuation line end time is not after end time of previous line" |
1240 )); | 1251 )); |
1241 return FALSE; | 1252 return FALSE; |
1242 } | 1253 } |
1243 } | 1254 } |
1244 » zones = (struct zone *) (void *) erealloc((char *) zones, | 1255 » zones = growalloc(zones, sizeof *zones, nzones, &nzones_alloc); |
1245 » » (int) ((nzones + 1) * sizeof *zones)); | |
1246 zones[nzones++] = z; | 1256 zones[nzones++] = z; |
1247 /* | 1257 /* |
1248 ** If there was an UNTIL field on this line, | 1258 ** If there was an UNTIL field on this line, |
1249 ** there's more information about the zone on the next line. | 1259 ** there's more information about the zone on the next line. |
1250 */ | 1260 */ |
1251 return hasuntil; | 1261 return hasuntil; |
1252 } | 1262 } |
1253 | 1263 |
1254 static void | 1264 static void |
1255 inleap(fields, nfields) | 1265 inleap(register char ** const fields, const int nfields) |
1256 register char ** const» fields; | |
1257 const int» » nfields; | |
1258 { | 1266 { |
1259 register const char * cp; | 1267 register const char * cp; |
1260 register const struct lookup * lp; | 1268 register const struct lookup * lp; |
1261 register int i, j; | 1269 register int i, j; |
1262 » int» » » » year, month, day; | 1270 » zic_t» » » » year; |
1263 » long» » » » dayoff, tod; | 1271 » int» » » » month, day; |
| 1272 » zic_t» » » » dayoff, tod; |
1264 zic_t t; | 1273 zic_t t; |
1265 | 1274 |
1266 if (nfields != LEAP_FIELDS) { | 1275 if (nfields != LEAP_FIELDS) { |
1267 error(_("wrong number of fields on Leap line")); | 1276 error(_("wrong number of fields on Leap line")); |
1268 return; | 1277 return; |
1269 } | 1278 } |
1270 dayoff = 0; | 1279 dayoff = 0; |
1271 cp = fields[LP_YEAR]; | 1280 cp = fields[LP_YEAR]; |
1272 » if (sscanf(cp, scheck(cp, "%d"), &year) != 1) { | 1281 » if (sscanf(cp, scheck(cp, "%"SCNdZIC), &year) != 1) { |
1273 /* | 1282 /* |
1274 ** Leapin' Lizards! | 1283 ** Leapin' Lizards! |
1275 */ | 1284 */ |
1276 error(_("invalid leaping year")); | 1285 error(_("invalid leaping year")); |
1277 return; | 1286 return; |
1278 } | 1287 } |
1279 if (!leapseen || leapmaxyear < year) | 1288 if (!leapseen || leapmaxyear < year) |
1280 leapmaxyear = year; | 1289 leapmaxyear = year; |
1281 if (!leapseen || leapminyear > year) | 1290 if (!leapseen || leapminyear > year) |
1282 leapminyear = year; | 1291 leapminyear = year; |
1283 leapseen = TRUE; | 1292 leapseen = TRUE; |
1284 j = EPOCH_YEAR; | 1293 j = EPOCH_YEAR; |
1285 while (j != year) { | 1294 while (j != year) { |
1286 if (year > j) { | 1295 if (year > j) { |
1287 i = len_years[isleap(j)]; | 1296 i = len_years[isleap(j)]; |
1288 ++j; | 1297 ++j; |
1289 } else { | 1298 } else { |
1290 --j; | 1299 --j; |
1291 i = -len_years[isleap(j)]; | 1300 i = -len_years[isleap(j)]; |
1292 } | 1301 } |
1293 » » dayoff = oadd(dayoff, eitol(i)); | 1302 » » dayoff = oadd(dayoff, i); |
1294 } | 1303 } |
1295 if ((lp = byword(fields[LP_MONTH], mon_names)) == NULL) { | 1304 if ((lp = byword(fields[LP_MONTH], mon_names)) == NULL) { |
1296 error(_("invalid month name")); | 1305 error(_("invalid month name")); |
1297 return; | 1306 return; |
1298 } | 1307 } |
1299 month = lp->l_value; | 1308 month = lp->l_value; |
1300 j = TM_JANUARY; | 1309 j = TM_JANUARY; |
1301 while (j != month) { | 1310 while (j != month) { |
1302 i = len_months[isleap(year)][j]; | 1311 i = len_months[isleap(year)][j]; |
1303 » » dayoff = oadd(dayoff, eitol(i)); | 1312 » » dayoff = oadd(dayoff, i); |
1304 ++j; | 1313 ++j; |
1305 } | 1314 } |
1306 cp = fields[LP_DAY]; | 1315 cp = fields[LP_DAY]; |
1307 if (sscanf(cp, scheck(cp, "%d"), &day) != 1 || | 1316 if (sscanf(cp, scheck(cp, "%d"), &day) != 1 || |
1308 day <= 0 || day > len_months[isleap(year)][month]) { | 1317 day <= 0 || day > len_months[isleap(year)][month]) { |
1309 error(_("invalid day of month")); | 1318 error(_("invalid day of month")); |
1310 return; | 1319 return; |
1311 } | 1320 } |
1312 » dayoff = oadd(dayoff, eitol(day - 1)); | 1321 » dayoff = oadd(dayoff, day - 1); |
1313 if (dayoff < 0 && !TYPE_SIGNED(zic_t)) { | 1322 if (dayoff < 0 && !TYPE_SIGNED(zic_t)) { |
1314 error(_("time before zero")); | 1323 error(_("time before zero")); |
1315 return; | 1324 return; |
1316 } | 1325 } |
1317 if (dayoff < min_time / SECSPERDAY) { | 1326 if (dayoff < min_time / SECSPERDAY) { |
1318 error(_("time too small")); | 1327 error(_("time too small")); |
1319 return; | 1328 return; |
1320 } | 1329 } |
1321 if (dayoff > max_time / SECSPERDAY) { | 1330 if (dayoff > max_time / SECSPERDAY) { |
1322 error(_("time too large")); | 1331 error(_("time too large")); |
(...skipping 26 matching lines...) Expand all Loading... |
1349 error(_( | 1358 error(_( |
1350 "illegal Rolling/Stationary field on Leap line" | 1359 "illegal Rolling/Stationary field on Leap line" |
1351 )); | 1360 )); |
1352 return; | 1361 return; |
1353 } | 1362 } |
1354 leapadd(tadd(t, tod), positive, lp->l_value, count); | 1363 leapadd(tadd(t, tod), positive, lp->l_value, count); |
1355 } | 1364 } |
1356 } | 1365 } |
1357 | 1366 |
1358 static void | 1367 static void |
1359 inlink(fields, nfields) | 1368 inlink(register char **const fields, const int nfields) |
1360 register char ** const» fields; | |
1361 const int» » nfields; | |
1362 { | 1369 { |
1363 struct link l; | 1370 struct link l; |
1364 | 1371 |
1365 if (nfields != LINK_FIELDS) { | 1372 if (nfields != LINK_FIELDS) { |
1366 error(_("wrong number of fields on Link line")); | 1373 error(_("wrong number of fields on Link line")); |
1367 return; | 1374 return; |
1368 } | 1375 } |
1369 if (*fields[LF_FROM] == '\0') { | 1376 if (*fields[LF_FROM] == '\0') { |
1370 error(_("blank FROM field on Link line")); | 1377 error(_("blank FROM field on Link line")); |
1371 return; | 1378 return; |
1372 } | 1379 } |
1373 if (*fields[LF_TO] == '\0') { | 1380 if (*fields[LF_TO] == '\0') { |
1374 error(_("blank TO field on Link line")); | 1381 error(_("blank TO field on Link line")); |
1375 return; | 1382 return; |
1376 } | 1383 } |
1377 l.l_filename = filename; | 1384 l.l_filename = filename; |
1378 l.l_linenum = linenum; | 1385 l.l_linenum = linenum; |
1379 l.l_from = ecpyalloc(fields[LF_FROM]); | 1386 l.l_from = ecpyalloc(fields[LF_FROM]); |
1380 l.l_to = ecpyalloc(fields[LF_TO]); | 1387 l.l_to = ecpyalloc(fields[LF_TO]); |
1381 » links = (struct link *) (void *) erealloc((char *) links, | 1388 » links = growalloc(links, sizeof *links, nlinks, &nlinks_alloc); |
1382 » » (int) ((nlinks + 1) * sizeof *links)); | |
1383 links[nlinks++] = l; | 1389 links[nlinks++] = l; |
1384 } | 1390 } |
1385 | 1391 |
1386 static void | 1392 static void |
1387 rulesub(rp, loyearp, hiyearp, typep, monthp, dayp, timep) | 1393 rulesub(register struct rule *const rp, |
1388 register struct rule * const» rp; | 1394 » const char *const loyearp, |
1389 const char * const» » loyearp; | 1395 » const char *const hiyearp, |
1390 const char * const» » hiyearp; | 1396 » const char *const typep, |
1391 const char * const» » typep; | 1397 » const char *const monthp, |
1392 const char * const» » monthp; | 1398 » const char *const dayp, |
1393 const char * const» » dayp; | 1399 » const char *const timep) |
1394 const char * const» » timep; | |
1395 { | 1400 { |
1396 register const struct lookup * lp; | 1401 register const struct lookup * lp; |
1397 register const char * cp; | 1402 register const char * cp; |
1398 register char * dp; | 1403 register char * dp; |
1399 register char * ep; | 1404 register char * ep; |
1400 | 1405 |
1401 if ((lp = byword(monthp, mon_names)) == NULL) { | 1406 if ((lp = byword(monthp, mon_names)) == NULL) { |
1402 error(_("invalid month name")); | 1407 error(_("invalid month name")); |
1403 return; | 1408 return; |
1404 } | 1409 } |
(...skipping 17 matching lines...) Expand all Loading... |
1422 case 'g': /* Greenwich */ | 1427 case 'g': /* Greenwich */ |
1423 case 'u': /* Universal */ | 1428 case 'u': /* Universal */ |
1424 case 'z': /* Zulu */ | 1429 case 'z': /* Zulu */ |
1425 rp->r_todisstd = TRUE; | 1430 rp->r_todisstd = TRUE; |
1426 rp->r_todisgmt = TRUE; | 1431 rp->r_todisgmt = TRUE; |
1427 *ep = '\0'; | 1432 *ep = '\0'; |
1428 break; | 1433 break; |
1429 } | 1434 } |
1430 } | 1435 } |
1431 rp->r_tod = gethms(dp, _("invalid time of day"), FALSE); | 1436 rp->r_tod = gethms(dp, _("invalid time of day"), FALSE); |
1432 » ifree(dp); | 1437 » free(dp); |
1433 /* | 1438 /* |
1434 ** Year work. | 1439 ** Year work. |
1435 */ | 1440 */ |
1436 cp = loyearp; | 1441 cp = loyearp; |
1437 lp = byword(cp, begin_years); | 1442 lp = byword(cp, begin_years); |
1438 rp->r_lowasnum = lp == NULL; | 1443 rp->r_lowasnum = lp == NULL; |
1439 if (!rp->r_lowasnum) switch ((int) lp->l_value) { | 1444 if (!rp->r_lowasnum) switch ((int) lp->l_value) { |
1440 case YR_MINIMUM: | 1445 case YR_MINIMUM: |
1441 » » » rp->r_loyear = INT_MIN; | 1446 » » » rp->r_loyear = ZIC_MIN; |
1442 break; | 1447 break; |
1443 case YR_MAXIMUM: | 1448 case YR_MAXIMUM: |
1444 » » » rp->r_loyear = INT_MAX; | 1449 » » » rp->r_loyear = ZIC_MAX; |
1445 break; | 1450 break; |
1446 default: /* "cannot happen" */ | 1451 default: /* "cannot happen" */ |
1447 (void) fprintf(stderr, | 1452 (void) fprintf(stderr, |
1448 _("%s: panic: Invalid l_value %d\n"), | 1453 _("%s: panic: Invalid l_value %d\n"), |
1449 progname, lp->l_value); | 1454 progname, lp->l_value); |
1450 exit(EXIT_FAILURE); | 1455 exit(EXIT_FAILURE); |
1451 » } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_loyear) != 1) { | 1456 » } else if (sscanf(cp, scheck(cp, "%"SCNdZIC), &rp->r_loyear) != 1) { |
1452 error(_("invalid starting year")); | 1457 error(_("invalid starting year")); |
1453 return; | 1458 return; |
1454 } | 1459 } |
1455 cp = hiyearp; | 1460 cp = hiyearp; |
1456 lp = byword(cp, end_years); | 1461 lp = byword(cp, end_years); |
1457 rp->r_hiwasnum = lp == NULL; | 1462 rp->r_hiwasnum = lp == NULL; |
1458 if (!rp->r_hiwasnum) switch ((int) lp->l_value) { | 1463 if (!rp->r_hiwasnum) switch ((int) lp->l_value) { |
1459 case YR_MINIMUM: | 1464 case YR_MINIMUM: |
1460 » » » rp->r_hiyear = INT_MIN; | 1465 » » » rp->r_hiyear = ZIC_MIN; |
1461 break; | 1466 break; |
1462 case YR_MAXIMUM: | 1467 case YR_MAXIMUM: |
1463 » » » rp->r_hiyear = INT_MAX; | 1468 » » » rp->r_hiyear = ZIC_MAX; |
1464 break; | 1469 break; |
1465 case YR_ONLY: | 1470 case YR_ONLY: |
1466 rp->r_hiyear = rp->r_loyear; | 1471 rp->r_hiyear = rp->r_loyear; |
1467 break; | 1472 break; |
1468 default: /* "cannot happen" */ | 1473 default: /* "cannot happen" */ |
1469 (void) fprintf(stderr, | 1474 (void) fprintf(stderr, |
1470 _("%s: panic: Invalid l_value %d\n"), | 1475 _("%s: panic: Invalid l_value %d\n"), |
1471 progname, lp->l_value); | 1476 progname, lp->l_value); |
1472 exit(EXIT_FAILURE); | 1477 exit(EXIT_FAILURE); |
1473 » } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_hiyear) != 1) { | 1478 » } else if (sscanf(cp, scheck(cp, "%"SCNdZIC), &rp->r_hiyear) != 1) { |
1474 error(_("invalid ending year")); | 1479 error(_("invalid ending year")); |
1475 return; | 1480 return; |
1476 } | 1481 } |
1477 if (rp->r_loyear > rp->r_hiyear) { | 1482 if (rp->r_loyear > rp->r_hiyear) { |
1478 error(_("starting year greater than ending year")); | 1483 error(_("starting year greater than ending year")); |
1479 return; | 1484 return; |
1480 } | 1485 } |
1481 if (*typep == '\0') | 1486 if (*typep == '\0') |
1482 rp->r_yrtype = NULL; | 1487 rp->r_yrtype = NULL; |
1483 else { | 1488 else { |
(...skipping 22 matching lines...) Expand all Loading... |
1506 else if ((ep = strchr(dp, '>')) != 0) | 1511 else if ((ep = strchr(dp, '>')) != 0) |
1507 rp->r_dycode = DC_DOWGEQ; | 1512 rp->r_dycode = DC_DOWGEQ; |
1508 else { | 1513 else { |
1509 ep = dp; | 1514 ep = dp; |
1510 rp->r_dycode = DC_DOM; | 1515 rp->r_dycode = DC_DOM; |
1511 } | 1516 } |
1512 if (rp->r_dycode != DC_DOM) { | 1517 if (rp->r_dycode != DC_DOM) { |
1513 *ep++ = 0; | 1518 *ep++ = 0; |
1514 if (*ep++ != '=') { | 1519 if (*ep++ != '=') { |
1515 error(_("invalid day of month")); | 1520 error(_("invalid day of month")); |
1516 » » » » ifree(dp); | 1521 » » » » free(dp); |
1517 return; | 1522 return; |
1518 } | 1523 } |
1519 if ((lp = byword(dp, wday_names)) == NULL) { | 1524 if ((lp = byword(dp, wday_names)) == NULL) { |
1520 error(_("invalid weekday name")); | 1525 error(_("invalid weekday name")); |
1521 » » » » ifree(dp); | 1526 » » » » free(dp); |
1522 return; | 1527 return; |
1523 } | 1528 } |
1524 rp->r_wday = lp->l_value; | 1529 rp->r_wday = lp->l_value; |
1525 } | 1530 } |
1526 if (sscanf(ep, scheck(ep, "%d"), &rp->r_dayofmonth) != 1 || | 1531 if (sscanf(ep, scheck(ep, "%d"), &rp->r_dayofmonth) != 1 || |
1527 rp->r_dayofmonth <= 0 || | 1532 rp->r_dayofmonth <= 0 || |
1528 (rp->r_dayofmonth > len_months[1][rp->r_month])) { | 1533 (rp->r_dayofmonth > len_months[1][rp->r_month])) { |
1529 error(_("invalid day of month")); | 1534 error(_("invalid day of month")); |
1530 » » » » ifree(dp); | 1535 » » » » free(dp); |
1531 return; | 1536 return; |
1532 } | 1537 } |
1533 } | 1538 } |
1534 » ifree(dp); | 1539 » free(dp); |
1535 } | 1540 } |
1536 | 1541 |
1537 static void | 1542 static void |
1538 convert(val, buf) | 1543 convert(const int_fast32_t val, char *const buf) |
1539 const long» val; | |
1540 char * const» buf; | |
1541 { | 1544 { |
1542 register int i; | 1545 register int i; |
1543 register int shift; | 1546 register int shift; |
| 1547 unsigned char *const b = (unsigned char *) buf; |
1544 | 1548 |
1545 for (i = 0, shift = 24; i < 4; ++i, shift -= 8) | 1549 for (i = 0, shift = 24; i < 4; ++i, shift -= 8) |
1546 » » buf[i] = val >> shift; | 1550 » » b[i] = val >> shift; |
1547 } | 1551 } |
1548 | 1552 |
1549 static void | 1553 static void |
1550 convert64(val, buf) | 1554 convert64(const zic_t val, char *const buf) |
1551 const zic_t» val; | |
1552 char * const» buf; | |
1553 { | 1555 { |
1554 register int i; | 1556 register int i; |
1555 register int shift; | 1557 register int shift; |
| 1558 unsigned char *const b = (unsigned char *) buf; |
1556 | 1559 |
1557 for (i = 0, shift = 56; i < 8; ++i, shift -= 8) | 1560 for (i = 0, shift = 56; i < 8; ++i, shift -= 8) |
1558 » » buf[i] = val >> shift; | 1561 » » b[i] = val >> shift; |
1559 } | 1562 } |
1560 | 1563 |
1561 static void | 1564 static void |
1562 puttzcode(val, fp) | 1565 puttzcode(const int_fast32_t val, FILE *const fp) |
1563 const long» val; | |
1564 FILE * const» fp; | |
1565 { | 1566 { |
1566 char buf[4]; | 1567 char buf[4]; |
1567 | 1568 |
1568 convert(val, buf); | 1569 convert(val, buf); |
1569 » (void) fwrite((void *) buf, (size_t) sizeof buf, (size_t) 1, fp); | 1570 » (void) fwrite(buf, sizeof buf, 1, fp); |
1570 } | 1571 } |
1571 | 1572 |
1572 static void | 1573 static void |
1573 puttzcode64(val, fp) | 1574 puttzcode64(const zic_t val, FILE *const fp) |
1574 const zic_t» val; | |
1575 FILE * const» fp; | |
1576 { | 1575 { |
1577 char buf[8]; | 1576 char buf[8]; |
1578 | 1577 |
1579 convert64(val, buf); | 1578 convert64(val, buf); |
1580 » (void) fwrite((void *) buf, (size_t) sizeof buf, (size_t) 1, fp); | 1579 » (void) fwrite(buf, sizeof buf, 1, fp); |
1581 } | 1580 } |
1582 | 1581 |
1583 static int | 1582 static int |
1584 atcomp(avp, bvp) | 1583 atcomp(const void *avp, const void *bvp) |
1585 const void *» avp; | |
1586 const void *» bvp; | |
1587 { | 1584 { |
1588 const zic_t a = ((const struct attype *) avp)->at; | 1585 const zic_t a = ((const struct attype *) avp)->at; |
1589 const zic_t b = ((const struct attype *) bvp)->at; | 1586 const zic_t b = ((const struct attype *) bvp)->at; |
1590 | 1587 |
1591 return (a < b) ? -1 : (a > b); | 1588 return (a < b) ? -1 : (a > b); |
1592 } | 1589 } |
1593 | 1590 |
1594 static int | 1591 static int |
1595 is32(x) | 1592 is32(const zic_t x) |
1596 const zic_t» x; | |
1597 { | 1593 { |
1598 return INT32_MIN <= x && x <= INT32_MAX; | 1594 return INT32_MIN <= x && x <= INT32_MAX; |
1599 } | 1595 } |
1600 | 1596 |
1601 static void | 1597 static void |
1602 writezone(name, string) | 1598 writezone(const char *const name, const char *const string, char version) |
1603 const char * const» name; | |
1604 const char * const» string; | |
1605 { | 1599 { |
1606 register FILE * fp; | 1600 register FILE * fp; |
1607 register int i, j; | 1601 register int i, j; |
1608 register int leapcnt32, leapi32; | 1602 register int leapcnt32, leapi32; |
1609 register int timecnt32, timei32; | 1603 register int timecnt32, timei32; |
1610 register int pass; | 1604 register int pass; |
1611 static char * fullname; | 1605 static char * fullname; |
1612 static const struct tzhead tzh0; | 1606 static const struct tzhead tzh0; |
1613 static struct tzhead tzh; | 1607 static struct tzhead tzh; |
1614 » zic_t» » » » ats[TZ_MAX_TIMES]; | 1608 » zic_t *ats = emalloc(size_product(timecnt, sizeof *ats + 1)); |
1615 » unsigned char» » » types[TZ_MAX_TIMES]; | 1609 » void *typesptr = ats + timecnt; |
| 1610 » unsigned char *types = typesptr; |
1616 | 1611 |
1617 /* | 1612 /* |
1618 ** Sort. | 1613 ** Sort. |
1619 */ | 1614 */ |
1620 if (timecnt > 1) | 1615 if (timecnt > 1) |
1621 » » (void) qsort((void *) attypes, (size_t) timecnt, | 1616 » » (void) qsort(attypes, timecnt, sizeof *attypes, atcomp); |
1622 » » » (size_t) sizeof *attypes, atcomp); | |
1623 /* | 1617 /* |
1624 ** Optimize. | 1618 ** Optimize. |
1625 */ | 1619 */ |
1626 { | 1620 { |
1627 int fromi; | 1621 int fromi; |
1628 int toi; | 1622 int toi; |
1629 | 1623 |
1630 toi = 0; | 1624 toi = 0; |
1631 fromi = 0; | 1625 fromi = 0; |
1632 while (fromi < timecnt && attypes[fromi].at < min_time) | 1626 while (fromi < timecnt && attypes[fromi].at < min_time) |
1633 ++fromi; | 1627 ++fromi; |
1634 » » if (isdsts[0] == 0) | 1628 » » /* |
1635 » » » while (fromi < timecnt && attypes[fromi].type == 0) | 1629 » » ** Remember that type 0 is reserved. |
| 1630 » » */ |
| 1631 » » if (isdsts[1] == 0) |
| 1632 » » » while (fromi < timecnt && attypes[fromi].type == 1) |
1636 ++fromi; /* handled by default rule */ | 1633 ++fromi; /* handled by default rule */ |
1637 for ( ; fromi < timecnt; ++fromi) { | 1634 for ( ; fromi < timecnt; ++fromi) { |
1638 if (toi != 0 && ((attypes[fromi].at + | 1635 if (toi != 0 && ((attypes[fromi].at + |
1639 gmtoffs[attypes[toi - 1].type]) <= | 1636 gmtoffs[attypes[toi - 1].type]) <= |
1640 (attypes[toi - 1].at + gmtoffs[toi == 1 ? 0 | 1637 (attypes[toi - 1].at + gmtoffs[toi == 1 ? 0 |
1641 : attypes[toi - 2].type]))) { | 1638 : attypes[toi - 2].type]))) { |
1642 attypes[toi - 1].type = | 1639 attypes[toi - 1].type = |
1643 attypes[fromi].type; | 1640 attypes[fromi].type; |
1644 continue; | 1641 continue; |
1645 } | 1642 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 --timecnt32; | 1677 --timecnt32; |
1681 ++timei32; | 1678 ++timei32; |
1682 } | 1679 } |
1683 while (leapcnt32 > 0 && !is32(trans[leapcnt32 - 1])) | 1680 while (leapcnt32 > 0 && !is32(trans[leapcnt32 - 1])) |
1684 --leapcnt32; | 1681 --leapcnt32; |
1685 while (leapcnt32 > 0 && !is32(trans[leapi32])) { | 1682 while (leapcnt32 > 0 && !is32(trans[leapi32])) { |
1686 --leapcnt32; | 1683 --leapcnt32; |
1687 ++leapi32; | 1684 ++leapi32; |
1688 } | 1685 } |
1689 fullname = erealloc(fullname, | 1686 fullname = erealloc(fullname, |
1690 » » (int) (strlen(directory) + 1 + strlen(name) + 1)); | 1687 » » » strlen(directory) + 1 + strlen(name) + 1); |
1691 (void) sprintf(fullname, "%s/%s", directory, name); | 1688 (void) sprintf(fullname, "%s/%s", directory, name); |
1692 /* | 1689 /* |
1693 ** Remove old file, if any, to snap links. | 1690 ** Remove old file, if any, to snap links. |
1694 */ | 1691 */ |
1695 if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) { | 1692 if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) { |
1696 const char *e = strerror(errno); | 1693 const char *e = strerror(errno); |
1697 | 1694 |
1698 (void) fprintf(stderr, _("%s: Can't remove %s: %s\n"), | 1695 (void) fprintf(stderr, _("%s: Can't remove %s: %s\n"), |
1699 progname, fullname, e); | 1696 progname, fullname, e); |
1700 exit(EXIT_FAILURE); | 1697 exit(EXIT_FAILURE); |
1701 } | 1698 } |
1702 if ((fp = fopen(fullname, "wb")) == NULL) { | 1699 if ((fp = fopen(fullname, "wb")) == NULL) { |
1703 if (mkdirs(fullname) != 0) | 1700 if (mkdirs(fullname) != 0) |
1704 exit(EXIT_FAILURE); | 1701 exit(EXIT_FAILURE); |
1705 if ((fp = fopen(fullname, "wb")) == NULL) { | 1702 if ((fp = fopen(fullname, "wb")) == NULL) { |
1706 const char *e = strerror(errno); | 1703 const char *e = strerror(errno); |
1707 | 1704 |
1708 (void) fprintf(stderr, _("%s: Can't create %s: %s\n"), | 1705 (void) fprintf(stderr, _("%s: Can't create %s: %s\n"), |
1709 progname, fullname, e); | 1706 progname, fullname, e); |
1710 exit(EXIT_FAILURE); | 1707 exit(EXIT_FAILURE); |
1711 } | 1708 } |
1712 } | 1709 } |
1713 for (pass = 1; pass <= 2; ++pass) { | 1710 for (pass = 1; pass <= 2; ++pass) { |
1714 register int thistimei, thistimecnt; | 1711 register int thistimei, thistimecnt; |
1715 register int thisleapi, thisleapcnt; | 1712 register int thisleapi, thisleapcnt; |
1716 register int thistimelim, thisleaplim; | 1713 register int thistimelim, thisleaplim; |
1717 » » int» » writetype[TZ_MAX_TIMES]; | 1714 » » int» » writetype[TZ_MAX_TYPES]; |
1718 int typemap[TZ_MAX_TYPES]; | 1715 int typemap[TZ_MAX_TYPES]; |
1719 register int thistypecnt; | 1716 register int thistypecnt; |
1720 char thischars[TZ_MAX_CHARS]; | 1717 char thischars[TZ_MAX_CHARS]; |
1721 char thischarcnt; | 1718 char thischarcnt; |
1722 int indmap[TZ_MAX_CHARS]; | 1719 int indmap[TZ_MAX_CHARS]; |
1723 | 1720 |
1724 if (pass == 1) { | 1721 if (pass == 1) { |
1725 thistimei = timei32; | 1722 thistimei = timei32; |
1726 thistimecnt = timecnt32; | 1723 thistimecnt = timecnt32; |
1727 thisleapi = leapi32; | 1724 thisleapi = leapi32; |
1728 thisleapcnt = leapcnt32; | 1725 thisleapcnt = leapcnt32; |
1729 } else { | 1726 } else { |
1730 thistimei = 0; | 1727 thistimei = 0; |
1731 thistimecnt = timecnt; | 1728 thistimecnt = timecnt; |
1732 thisleapi = 0; | 1729 thisleapi = 0; |
1733 thisleapcnt = leapcnt; | 1730 thisleapcnt = leapcnt; |
1734 } | 1731 } |
1735 thistimelim = thistimei + thistimecnt; | 1732 thistimelim = thistimei + thistimecnt; |
1736 thisleaplim = thisleapi + thisleapcnt; | 1733 thisleaplim = thisleapi + thisleapcnt; |
1737 » » for (i = 0; i < typecnt; ++i) | 1734 » » /* |
| 1735 » » ** Remember that type 0 is reserved. |
| 1736 » » */ |
| 1737 » » writetype[0] = FALSE; |
| 1738 » » for (i = 1; i < typecnt; ++i) |
1738 writetype[i] = thistimecnt == timecnt; | 1739 writetype[i] = thistimecnt == timecnt; |
1739 if (thistimecnt == 0) { | 1740 if (thistimecnt == 0) { |
1740 /* | 1741 /* |
1741 ** No transition times fall in the current | 1742 ** No transition times fall in the current |
1742 ** (32- or 64-bit) window. | 1743 ** (32- or 64-bit) window. |
1743 */ | 1744 */ |
1744 if (typecnt != 0) | 1745 if (typecnt != 0) |
1745 writetype[typecnt - 1] = TRUE; | 1746 writetype[typecnt - 1] = TRUE; |
1746 } else { | 1747 } else { |
1747 for (i = thistimei - 1; i < thistimelim; ++i) | 1748 for (i = thistimei - 1; i < thistimelim; ++i) |
1748 if (i >= 0) | 1749 if (i >= 0) |
1749 writetype[types[i]] = TRUE; | 1750 writetype[types[i]] = TRUE; |
1750 /* | 1751 /* |
1751 ** For America/Godthab and Antarctica/Palmer | 1752 ** For America/Godthab and Antarctica/Palmer |
1752 */ | 1753 */ |
| 1754 /* |
| 1755 ** Remember that type 0 is reserved. |
| 1756 */ |
1753 if (thistimei == 0) | 1757 if (thistimei == 0) |
| 1758 writetype[1] = TRUE; |
| 1759 } |
| 1760 #ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH |
| 1761 /* |
| 1762 ** For some pre-2011 systems: if the last-to-be-written |
| 1763 ** standard (or daylight) type has an offset different from the |
| 1764 ** most recently used offset, |
| 1765 ** append an (unused) copy of the most recently used type |
| 1766 ** (to help get global "altzone" and "timezone" variables |
| 1767 ** set correctly). |
| 1768 */ |
| 1769 { |
| 1770 register int mrudst, mrustd, hidst, histd, type; |
| 1771 |
| 1772 hidst = histd = mrudst = mrustd = -1; |
| 1773 for (i = thistimei; i < thistimelim; ++i) |
| 1774 if (isdsts[types[i]]) |
| 1775 mrudst = types[i]; |
| 1776 else mrustd = types[i]; |
| 1777 for (i = 0; i < typecnt; ++i) |
| 1778 if (writetype[i]) { |
| 1779 if (isdsts[i]) |
| 1780 hidst = i; |
| 1781 else histd = i; |
| 1782 } |
| 1783 if (hidst >= 0 && mrudst >= 0 && hidst != mrudst && |
| 1784 gmtoffs[hidst] != gmtoffs[mrudst]) { |
| 1785 isdsts[mrudst] = -1; |
| 1786 type = addtype(gmtoffs[mrudst], |
| 1787 #ifdef ICU |
| 1788 rawoffs[mrudst], dstoffs[mrudst]
, |
| 1789 #endif |
| 1790 &chars[abbrinds[mrudst]], |
| 1791 TRUE, |
| 1792 ttisstds[mrudst], |
| 1793 ttisgmts[mrudst]); |
| 1794 isdsts[mrudst] = TRUE; |
| 1795 writetype[type] = TRUE; |
| 1796 } |
| 1797 if (histd >= 0 && mrustd >= 0 && histd != mrustd && |
| 1798 gmtoffs[histd] != gmtoffs[mrustd]) { |
| 1799 isdsts[mrustd] = -1; |
| 1800 type = addtype(gmtoffs[mrustd], |
| 1801 #ifdef ICU |
| 1802 rawoffs[mrudst], dstoffs[mrudst]
, |
| 1803 #endif |
| 1804 &chars[abbrinds[mrustd]], |
| 1805 FALSE, |
| 1806 ttisstds[mrustd], |
| 1807 ttisgmts[mrustd]); |
| 1808 isdsts[mrustd] = FALSE; |
| 1809 writetype[type] = TRUE; |
| 1810 } |
| 1811 } |
| 1812 #endif /* !defined LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */ |
| 1813 thistypecnt = 0; |
| 1814 /* |
| 1815 ** Potentially, set type 0 to that of lowest-valued time. |
| 1816 */ |
| 1817 if (thistimei > 0) { |
| 1818 for (i = 1; i < typecnt; ++i) |
| 1819 if (writetype[i] && !isdsts[i]) |
| 1820 break; |
| 1821 if (i != types[thistimei - 1]) { |
| 1822 i = types[thistimei - 1]; |
| 1823 gmtoffs[0] = gmtoffs[i]; |
| 1824 isdsts[0] = isdsts[i]; |
| 1825 ttisstds[0] = ttisstds[i]; |
| 1826 ttisgmts[0] = ttisgmts[i]; |
| 1827 abbrinds[0] = abbrinds[i]; |
1754 writetype[0] = TRUE; | 1828 writetype[0] = TRUE; |
| 1829 writetype[i] = FALSE; |
| 1830 } |
1755 } | 1831 } |
1756 thistypecnt = 0; | |
1757 for (i = 0; i < typecnt; ++i) | 1832 for (i = 0; i < typecnt; ++i) |
1758 » » » typemap[i] = writetype[i] ? thistypecnt++ : -1; | 1833 » » » typemap[i] = writetype[i] ? thistypecnt++ : 0; |
1759 for (i = 0; i < sizeof indmap / sizeof indmap[0]; ++i) | 1834 for (i = 0; i < sizeof indmap / sizeof indmap[0]; ++i) |
1760 indmap[i] = -1; | 1835 indmap[i] = -1; |
1761 thischarcnt = 0; | 1836 thischarcnt = 0; |
1762 for (i = 0; i < typecnt; ++i) { | 1837 for (i = 0; i < typecnt; ++i) { |
1763 register char * thisabbr; | 1838 register char * thisabbr; |
1764 | 1839 |
1765 if (!writetype[i]) | 1840 if (!writetype[i]) |
1766 continue; | 1841 continue; |
1767 if (indmap[abbrinds[i]] >= 0) | 1842 if (indmap[abbrinds[i]] >= 0) |
1768 continue; | 1843 continue; |
1769 thisabbr = &chars[abbrinds[i]]; | 1844 thisabbr = &chars[abbrinds[i]]; |
1770 for (j = 0; j < thischarcnt; ++j) | 1845 for (j = 0; j < thischarcnt; ++j) |
1771 if (strcmp(&thischars[j], thisabbr) == 0) | 1846 if (strcmp(&thischars[j], thisabbr) == 0) |
1772 break; | 1847 break; |
1773 if (j == thischarcnt) { | 1848 if (j == thischarcnt) { |
1774 (void) strcpy(&thischars[(int) thischarcnt], | 1849 (void) strcpy(&thischars[(int) thischarcnt], |
1775 thisabbr); | 1850 thisabbr); |
1776 thischarcnt += strlen(thisabbr) + 1; | 1851 thischarcnt += strlen(thisabbr) + 1; |
1777 } | 1852 } |
1778 indmap[abbrinds[i]] = j; | 1853 indmap[abbrinds[i]] = j; |
1779 } | 1854 } |
1780 #define DO(field)» (void) fwrite((void *) tzh.field, \ | 1855 #define DO(field)» ((void) fwrite(tzh.field, sizeof tzh.field, 1, fp)) |
1781 » » » » (size_t) sizeof tzh.field, (size_t) 1, fp) | |
1782 tzh = tzh0; | 1856 tzh = tzh0; |
1783 #ifdef ICU | 1857 #ifdef ICU |
1784 * (ICUZoneinfoVersion*) &tzh.tzh_reserved = TZ_ICU_VERSION; | 1858 * (ICUZoneinfoVersion*) &tzh.tzh_reserved = TZ_ICU_VERSION; |
1785 (void) strncpy(tzh.tzh_magic, TZ_ICU_MAGIC, sizeof tzh.tzh_magic
); | 1859 (void) strncpy(tzh.tzh_magic, TZ_ICU_MAGIC, sizeof tzh.tzh_magic
); |
1786 #else | 1860 #else |
1787 (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); | 1861 (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); |
1788 #endif | 1862 #endif |
1789 » » tzh.tzh_version[0] = ZIC_VERSION; | 1863 » » tzh.tzh_version[0] = version; |
1790 » » convert(eitol(thistypecnt), tzh.tzh_ttisgmtcnt); | 1864 » » convert(thistypecnt, tzh.tzh_ttisgmtcnt); |
1791 » » convert(eitol(thistypecnt), tzh.tzh_ttisstdcnt); | 1865 » » convert(thistypecnt, tzh.tzh_ttisstdcnt); |
1792 » » convert(eitol(thisleapcnt), tzh.tzh_leapcnt); | 1866 » » convert(thisleapcnt, tzh.tzh_leapcnt); |
1793 » » convert(eitol(thistimecnt), tzh.tzh_timecnt); | 1867 » » convert(thistimecnt, tzh.tzh_timecnt); |
1794 » » convert(eitol(thistypecnt), tzh.tzh_typecnt); | 1868 » » convert(thistypecnt, tzh.tzh_typecnt); |
1795 » » convert(eitol(thischarcnt), tzh.tzh_charcnt); | 1869 » » convert(thischarcnt, tzh.tzh_charcnt); |
1796 DO(tzh_magic); | 1870 DO(tzh_magic); |
1797 DO(tzh_version); | 1871 DO(tzh_version); |
1798 DO(tzh_reserved); | 1872 DO(tzh_reserved); |
1799 DO(tzh_ttisgmtcnt); | 1873 DO(tzh_ttisgmtcnt); |
1800 DO(tzh_ttisstdcnt); | 1874 DO(tzh_ttisstdcnt); |
1801 DO(tzh_leapcnt); | 1875 DO(tzh_leapcnt); |
1802 DO(tzh_timecnt); | 1876 DO(tzh_timecnt); |
1803 DO(tzh_typecnt); | 1877 DO(tzh_typecnt); |
1804 DO(tzh_charcnt); | 1878 DO(tzh_charcnt); |
1805 #undef DO | 1879 #undef DO |
1806 for (i = thistimei; i < thistimelim; ++i) | 1880 for (i = thistimei; i < thistimelim; ++i) |
1807 if (pass == 1) | 1881 if (pass == 1) |
1808 » » » » puttzcode((long) ats[i], fp); | 1882 » » » » puttzcode(ats[i], fp); |
1809 else puttzcode64(ats[i], fp); | 1883 else puttzcode64(ats[i], fp); |
1810 for (i = thistimei; i < thistimelim; ++i) { | 1884 for (i = thistimei; i < thistimelim; ++i) { |
1811 unsigned char uc; | 1885 unsigned char uc; |
1812 | 1886 |
1813 uc = typemap[types[i]]; | 1887 uc = typemap[types[i]]; |
1814 » » » (void) fwrite((void *) &uc, | 1888 » » » (void) fwrite(&uc, sizeof uc, 1, fp); |
1815 » » » » (size_t) sizeof uc, | |
1816 » » » » (size_t) 1, | |
1817 » » » » fp); | |
1818 } | 1889 } |
1819 for (i = 0; i < typecnt; ++i) | 1890 for (i = 0; i < typecnt; ++i) |
1820 if (writetype[i]) { | 1891 if (writetype[i]) { |
1821 #ifdef ICU | 1892 #ifdef ICU |
1822 » » » » puttzcode((long) rawoffs[i], fp); | 1893 » » » » puttzcode(rawoffs[i], fp); |
1823 » » » » puttzcode((long) dstoffs[i], fp); | 1894 » » » » puttzcode(dstoffs[i], fp); |
1824 #else | 1895 #else |
1825 puttzcode(gmtoffs[i], fp); | 1896 puttzcode(gmtoffs[i], fp); |
1826 #endif | 1897 #endif |
1827 (void) putc(isdsts[i], fp); | 1898 (void) putc(isdsts[i], fp); |
1828 (void) putc((unsigned char) indmap[abbrinds[i]],
fp); | 1899 (void) putc((unsigned char) indmap[abbrinds[i]],
fp); |
1829 } | 1900 } |
1830 if (thischarcnt != 0) | 1901 if (thischarcnt != 0) |
1831 » » » (void) fwrite((void *) thischars, | 1902 » » » (void) fwrite(thischars, sizeof thischars[0], |
1832 » » » » (size_t) sizeof thischars[0], | 1903 » » » » thischarcnt, fp); |
1833 » » » » (size_t) thischarcnt, fp); | |
1834 for (i = thisleapi; i < thisleaplim; ++i) { | 1904 for (i = thisleapi; i < thisleaplim; ++i) { |
1835 register zic_t todo; | 1905 register zic_t todo; |
1836 | 1906 |
1837 if (roll[i]) { | 1907 if (roll[i]) { |
1838 if (timecnt == 0 || trans[i] < ats[0]) { | 1908 if (timecnt == 0 || trans[i] < ats[0]) { |
1839 j = 0; | 1909 j = 0; |
1840 while (isdsts[j]) | 1910 while (isdsts[j]) |
1841 if (++j >= typecnt) { | 1911 if (++j >= typecnt) { |
1842 j = 0; | 1912 j = 0; |
1843 break; | 1913 break; |
1844 } | 1914 } |
1845 } else { | 1915 } else { |
1846 j = 1; | 1916 j = 1; |
1847 while (j < timecnt && | 1917 while (j < timecnt && |
1848 trans[i] >= ats[j]) | 1918 trans[i] >= ats[j]) |
1849 ++j; | 1919 ++j; |
1850 j = types[j - 1]; | 1920 j = types[j - 1]; |
1851 } | 1921 } |
1852 todo = tadd(trans[i], -gmtoffs[j]); | 1922 todo = tadd(trans[i], -gmtoffs[j]); |
1853 } else todo = trans[i]; | 1923 } else todo = trans[i]; |
1854 if (pass == 1) | 1924 if (pass == 1) |
1855 » » » » puttzcode((long) todo, fp); | 1925 » » » » puttzcode(todo, fp); |
1856 else puttzcode64(todo, fp); | 1926 else puttzcode64(todo, fp); |
1857 puttzcode(corr[i], fp); | 1927 puttzcode(corr[i], fp); |
1858 } | 1928 } |
1859 for (i = 0; i < typecnt; ++i) | 1929 for (i = 0; i < typecnt; ++i) |
1860 if (writetype[i]) | 1930 if (writetype[i]) |
1861 (void) putc(ttisstds[i], fp); | 1931 (void) putc(ttisstds[i], fp); |
1862 for (i = 0; i < typecnt; ++i) | 1932 for (i = 0; i < typecnt; ++i) |
1863 if (writetype[i]) | 1933 if (writetype[i]) |
1864 (void) putc(ttisgmts[i], fp); | 1934 (void) putc(ttisgmts[i], fp); |
1865 } | 1935 } |
1866 (void) fprintf(fp, "\n%s\n", string); | 1936 (void) fprintf(fp, "\n%s\n", string); |
1867 if (ferror(fp) || fclose(fp)) { | 1937 if (ferror(fp) || fclose(fp)) { |
1868 (void) fprintf(stderr, _("%s: Error writing %s\n"), | 1938 (void) fprintf(stderr, _("%s: Error writing %s\n"), |
1869 progname, fullname); | 1939 progname, fullname); |
1870 exit(EXIT_FAILURE); | 1940 exit(EXIT_FAILURE); |
1871 } | 1941 } |
| 1942 free(ats); |
1872 } | 1943 } |
1873 | 1944 |
1874 static void | 1945 static void |
1875 doabbr(abbr, format, letters, isdst, doquotes) | 1946 doabbr(char *const abbr, const char *const format, const char *const letters, |
1876 char * const» » abbr; | 1947 const int isdst, const int doquotes) |
1877 const char * const» format; | |
1878 const char * const» letters; | |
1879 const int» » isdst; | |
1880 const int» » doquotes; | |
1881 { | 1948 { |
1882 register char * cp; | 1949 register char * cp; |
1883 register char * slashp; | 1950 register char * slashp; |
1884 register int len; | 1951 register int len; |
1885 | 1952 |
1886 slashp = strchr(format, '/'); | 1953 slashp = strchr(format, '/'); |
1887 if (slashp == NULL) { | 1954 if (slashp == NULL) { |
1888 if (letters == NULL) | 1955 if (letters == NULL) |
1889 (void) strcpy(abbr, format); | 1956 (void) strcpy(abbr, format); |
1890 else (void) sprintf(abbr, format, letters); | 1957 else (void) sprintf(abbr, format, letters); |
1891 } else if (isdst) { | 1958 } else if (isdst) { |
1892 (void) strcpy(abbr, slashp + 1); | 1959 (void) strcpy(abbr, slashp + 1); |
1893 } else { | 1960 } else { |
1894 if (slashp > format) | 1961 if (slashp > format) |
1895 » » » (void) strncpy(abbr, format, | 1962 » » » (void) strncpy(abbr, format, slashp - format); |
1896 » » » » (unsigned) (slashp - format)); | |
1897 abbr[slashp - format] = '\0'; | 1963 abbr[slashp - format] = '\0'; |
1898 } | 1964 } |
1899 if (!doquotes) | 1965 if (!doquotes) |
1900 return; | 1966 return; |
1901 for (cp = abbr; *cp != '\0'; ++cp) | 1967 for (cp = abbr; *cp != '\0'; ++cp) |
1902 if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", *cp) == NULL && | 1968 if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", *cp) == NULL && |
1903 strchr("abcdefghijklmnopqrstuvwxyz", *cp) == NULL) | 1969 strchr("abcdefghijklmnopqrstuvwxyz", *cp) == NULL) |
1904 break; | 1970 break; |
1905 len = strlen(abbr); | 1971 len = strlen(abbr); |
1906 if (len > 0 && *cp == '\0') | 1972 if (len > 0 && *cp == '\0') |
1907 return; | 1973 return; |
1908 abbr[len + 2] = '\0'; | 1974 abbr[len + 2] = '\0'; |
1909 abbr[len + 1] = '>'; | 1975 abbr[len + 1] = '>'; |
1910 for ( ; len > 0; --len) | 1976 for ( ; len > 0; --len) |
1911 abbr[len] = abbr[len - 1]; | 1977 abbr[len] = abbr[len - 1]; |
1912 abbr[0] = '<'; | 1978 abbr[0] = '<'; |
1913 } | 1979 } |
1914 | 1980 |
1915 static void | 1981 static void |
1916 updateminmax(x) | 1982 updateminmax(const zic_t x) |
1917 const int» x; | |
1918 { | 1983 { |
1919 if (min_year > x) | 1984 if (min_year > x) |
1920 min_year = x; | 1985 min_year = x; |
1921 if (max_year < x) | 1986 if (max_year < x) |
1922 max_year = x; | 1987 max_year = x; |
1923 } | 1988 } |
1924 | 1989 |
1925 static int | 1990 static int |
1926 stringoffset(result, offset) | 1991 stringoffset(char *result, zic_t offset) |
1927 char *» result; | |
1928 long» offset; | |
1929 { | 1992 { |
1930 register int hours; | 1993 register int hours; |
1931 register int minutes; | 1994 register int minutes; |
1932 register int seconds; | 1995 register int seconds; |
1933 | 1996 |
1934 result[0] = '\0'; | 1997 result[0] = '\0'; |
1935 if (offset < 0) { | 1998 if (offset < 0) { |
1936 (void) strcpy(result, "-"); | 1999 (void) strcpy(result, "-"); |
1937 offset = -offset; | 2000 offset = -offset; |
1938 } | 2001 } |
1939 seconds = offset % SECSPERMIN; | 2002 seconds = offset % SECSPERMIN; |
1940 offset /= SECSPERMIN; | 2003 offset /= SECSPERMIN; |
1941 minutes = offset % MINSPERHOUR; | 2004 minutes = offset % MINSPERHOUR; |
1942 offset /= MINSPERHOUR; | 2005 offset /= MINSPERHOUR; |
1943 hours = offset; | 2006 hours = offset; |
1944 » if (hours >= HOURSPERDAY) { | 2007 » if (hours >= HOURSPERDAY * DAYSPERWEEK) { |
1945 result[0] = '\0'; | 2008 result[0] = '\0'; |
1946 return -1; | 2009 return -1; |
1947 } | 2010 } |
1948 (void) sprintf(end(result), "%d", hours); | 2011 (void) sprintf(end(result), "%d", hours); |
1949 if (minutes != 0 || seconds != 0) { | 2012 if (minutes != 0 || seconds != 0) { |
1950 (void) sprintf(end(result), ":%02d", minutes); | 2013 (void) sprintf(end(result), ":%02d", minutes); |
1951 if (seconds != 0) | 2014 if (seconds != 0) |
1952 (void) sprintf(end(result), ":%02d", seconds); | 2015 (void) sprintf(end(result), ":%02d", seconds); |
1953 } | 2016 } |
1954 return 0; | 2017 return 0; |
1955 } | 2018 } |
1956 | 2019 |
1957 static int | 2020 static int |
1958 stringrule(result, rp, dstoff, gmtoff) | 2021 stringrule(char *result, const struct rule *const rp, const zic_t dstoff, |
1959 char *» » » » result; | 2022 » const zic_t gmtoff) |
1960 const struct rule * const» rp; | |
1961 const long» » » dstoff; | |
1962 const long» » » gmtoff; | |
1963 { | 2023 { |
1964 » register long» tod; | 2024 » register zic_t» tod = rp->r_tod; |
| 2025 » register int» compat = 0; |
1965 | 2026 |
1966 result = end(result); | 2027 result = end(result); |
1967 if (rp->r_dycode == DC_DOM) { | 2028 if (rp->r_dycode == DC_DOM) { |
1968 register int month, total; | 2029 register int month, total; |
1969 | 2030 |
1970 if (rp->r_dayofmonth == 29 && rp->r_month == TM_FEBRUARY) | 2031 if (rp->r_dayofmonth == 29 && rp->r_month == TM_FEBRUARY) |
1971 return -1; | 2032 return -1; |
1972 total = 0; | 2033 total = 0; |
1973 for (month = 0; month < rp->r_month; ++month) | 2034 for (month = 0; month < rp->r_month; ++month) |
1974 total += len_months[0][month]; | 2035 total += len_months[0][month]; |
1975 » » (void) sprintf(result, "J%d", total + rp->r_dayofmonth); | 2036 » » /* Omit the "J" in Jan and Feb, as that's shorter. */ |
| 2037 » » if (rp->r_month <= 1) |
| 2038 » » (void) sprintf(result, "%d", total + rp->r_dayofmonth - 1); |
| 2039 » » else |
| 2040 » » (void) sprintf(result, "J%d", total + rp->r_dayofmonth); |
1976 } else { | 2041 } else { |
1977 register int week; | 2042 register int week; |
| 2043 register int wday = rp->r_wday; |
| 2044 register int wdayoff; |
1978 | 2045 |
1979 if (rp->r_dycode == DC_DOWGEQ) { | 2046 if (rp->r_dycode == DC_DOWGEQ) { |
1980 » » » week = 1 + rp->r_dayofmonth / DAYSPERWEEK; | 2047 » » » wdayoff = (rp->r_dayofmonth - 1) % DAYSPERWEEK; |
1981 » » » if ((week - 1) * DAYSPERWEEK + 1 != rp->r_dayofmonth) | 2048 » » » if (wdayoff) |
1982 » » » » return -1; | 2049 » » » » compat = 2013; |
| 2050 » » » wday -= wdayoff; |
| 2051 » » » tod += wdayoff * SECSPERDAY; |
| 2052 » » » week = 1 + (rp->r_dayofmonth - 1) / DAYSPERWEEK; |
1983 } else if (rp->r_dycode == DC_DOWLEQ) { | 2053 } else if (rp->r_dycode == DC_DOWLEQ) { |
1984 if (rp->r_dayofmonth == len_months[1][rp->r_month]) | 2054 if (rp->r_dayofmonth == len_months[1][rp->r_month]) |
1985 week = 5; | 2055 week = 5; |
1986 else { | 2056 else { |
1987 » » » » week = 1 + rp->r_dayofmonth / DAYSPERWEEK; | 2057 » » » » wdayoff = rp->r_dayofmonth % DAYSPERWEEK; |
1988 » » » » if (week * DAYSPERWEEK - 1 != rp->r_dayofmonth) | 2058 » » » » if (wdayoff) |
1989 » » » » » return -1; | 2059 » » » » » compat = 2013; |
| 2060 » » » » wday -= wdayoff; |
| 2061 » » » » tod += wdayoff * SECSPERDAY; |
| 2062 » » » » week = rp->r_dayofmonth / DAYSPERWEEK; |
1990 } | 2063 } |
1991 } else return -1; /* "cannot happen" */ | 2064 } else return -1; /* "cannot happen" */ |
| 2065 if (wday < 0) |
| 2066 wday += DAYSPERWEEK; |
1992 (void) sprintf(result, "M%d.%d.%d", | 2067 (void) sprintf(result, "M%d.%d.%d", |
1993 » » » rp->r_month + 1, week, rp->r_wday); | 2068 » » » rp->r_month + 1, week, wday); |
1994 } | 2069 } |
1995 tod = rp->r_tod; | |
1996 if (rp->r_todisgmt) | 2070 if (rp->r_todisgmt) |
1997 tod += gmtoff; | 2071 tod += gmtoff; |
1998 if (rp->r_todisstd && rp->r_stdoff == 0) | 2072 if (rp->r_todisstd && rp->r_stdoff == 0) |
1999 tod += dstoff; | 2073 tod += dstoff; |
2000 if (tod < 0) { | |
2001 result[0] = '\0'; | |
2002 return -1; | |
2003 } | |
2004 if (tod != 2 * SECSPERMIN * MINSPERHOUR) { | 2074 if (tod != 2 * SECSPERMIN * MINSPERHOUR) { |
2005 (void) strcat(result, "/"); | 2075 (void) strcat(result, "/"); |
2006 if (stringoffset(end(result), tod) != 0) | 2076 if (stringoffset(end(result), tod) != 0) |
2007 return -1; | 2077 return -1; |
| 2078 if (tod < 0) { |
| 2079 if (compat < 2013) |
| 2080 compat = 2013; |
| 2081 } else if (SECSPERDAY <= tod) { |
| 2082 if (compat < 1994) |
| 2083 compat = 1994; |
| 2084 } |
2008 } | 2085 } |
2009 » return 0; | 2086 » return compat; |
2010 } | 2087 } |
2011 | 2088 |
2012 static void | 2089 static int |
2013 stringzone(result, zpfirst, zonecount) | 2090 rule_cmp(struct rule const *a, struct rule const *b) |
2014 char *» » » » result; | 2091 { |
2015 const struct zone * const» zpfirst; | 2092 » if (!a) |
2016 const int» » » zonecount; | 2093 » » return -!!b; |
| 2094 » if (!b) |
| 2095 » » return 1; |
| 2096 » if (a->r_hiyear != b->r_hiyear) |
| 2097 » » return a->r_hiyear < b->r_hiyear ? -1 : 1; |
| 2098 » if (a->r_month - b->r_month != 0) |
| 2099 » » return a->r_month - b->r_month; |
| 2100 » return a->r_dayofmonth - b->r_dayofmonth; |
| 2101 } |
| 2102 |
| 2103 enum { YEAR_BY_YEAR_ZONE = 1 }; |
| 2104 |
| 2105 static int |
| 2106 stringzone(char *result, const struct zone *const zpfirst, const int zonecount) |
2017 { | 2107 { |
2018 register const struct zone * zp; | 2108 register const struct zone * zp; |
2019 register struct rule * rp; | 2109 register struct rule * rp; |
2020 register struct rule * stdrp; | 2110 register struct rule * stdrp; |
2021 register struct rule * dstrp; | 2111 register struct rule * dstrp; |
2022 register int i; | 2112 register int i; |
2023 register const char * abbrvar; | 2113 register const char * abbrvar; |
| 2114 register int compat = 0; |
| 2115 register int c; |
| 2116 struct rule stdr, dstr; |
2024 | 2117 |
2025 result[0] = '\0'; | 2118 result[0] = '\0'; |
2026 zp = zpfirst + zonecount - 1; | 2119 zp = zpfirst + zonecount - 1; |
2027 stdrp = dstrp = NULL; | 2120 stdrp = dstrp = NULL; |
2028 for (i = 0; i < zp->z_nrules; ++i) { | 2121 for (i = 0; i < zp->z_nrules; ++i) { |
2029 rp = &zp->z_rules[i]; | 2122 rp = &zp->z_rules[i]; |
2030 » » if (rp->r_hiwasnum || rp->r_hiyear != INT_MAX) | 2123 » » if (rp->r_hiwasnum || rp->r_hiyear != ZIC_MAX) |
2031 continue; | 2124 continue; |
2032 if (rp->r_yrtype != NULL) | 2125 if (rp->r_yrtype != NULL) |
2033 continue; | 2126 continue; |
2034 if (rp->r_stdoff == 0) { | 2127 if (rp->r_stdoff == 0) { |
2035 if (stdrp == NULL) | 2128 if (stdrp == NULL) |
2036 stdrp = rp; | 2129 stdrp = rp; |
2037 » » » else» return; | 2130 » » » else» return -1; |
2038 } else { | 2131 } else { |
2039 if (dstrp == NULL) | 2132 if (dstrp == NULL) |
2040 dstrp = rp; | 2133 dstrp = rp; |
2041 » » » else» return; | 2134 » » » else» return -1; |
2042 } | 2135 } |
2043 } | 2136 } |
2044 if (stdrp == NULL && dstrp == NULL) { | 2137 if (stdrp == NULL && dstrp == NULL) { |
2045 /* | 2138 /* |
2046 ** There are no rules running through "max". | 2139 ** There are no rules running through "max". |
2047 » » ** Let's find the latest rule. | 2140 » » ** Find the latest std rule in stdabbrrp |
| 2141 » » ** and latest rule of any type in stdrp. |
2048 */ | 2142 */ |
| 2143 register struct rule *stdabbrrp = NULL; |
2049 for (i = 0; i < zp->z_nrules; ++i) { | 2144 for (i = 0; i < zp->z_nrules; ++i) { |
2050 rp = &zp->z_rules[i]; | 2145 rp = &zp->z_rules[i]; |
2051 » » » if (stdrp == NULL || rp->r_hiyear > stdrp->r_hiyear || | 2146 » » » if (rp->r_stdoff == 0 && rule_cmp(stdabbrrp, rp) < 0) |
2052 » » » » (rp->r_hiyear == stdrp->r_hiyear && | 2147 » » » » stdabbrrp = rp; |
2053 » » » » rp->r_month > stdrp->r_month)) | 2148 » » » if (rule_cmp(stdrp, rp) < 0) |
2054 » » » » » stdrp = rp; | 2149 » » » » stdrp = rp; |
2055 } | 2150 } |
2056 if (stdrp != NULL && stdrp->r_stdoff != 0) | |
2057 return; /* We end up in DST (a POSIX no-no). */ | |
2058 /* | 2151 /* |
2059 ** Horrid special case: if year is 2037, | 2152 ** Horrid special case: if year is 2037, |
2060 ** presume this is a zone handled on a year-by-year basis; | 2153 ** presume this is a zone handled on a year-by-year basis; |
2061 ** do not try to apply a rule to the zone. | 2154 ** do not try to apply a rule to the zone. |
2062 */ | 2155 */ |
2063 if (stdrp != NULL && stdrp->r_hiyear == 2037) | 2156 if (stdrp != NULL && stdrp->r_hiyear == 2037) |
2064 » » » return; | 2157 » » » return YEAR_BY_YEAR_ZONE; |
| 2158 |
| 2159 » » if (stdrp != NULL && stdrp->r_stdoff != 0) { |
| 2160 » » » /* Perpetual DST. */ |
| 2161 » » » dstr.r_month = TM_JANUARY; |
| 2162 » » » dstr.r_dycode = DC_DOM; |
| 2163 » » » dstr.r_dayofmonth = 1; |
| 2164 » » » dstr.r_tod = 0; |
| 2165 » » » dstr.r_todisstd = dstr.r_todisgmt = FALSE; |
| 2166 » » » dstr.r_stdoff = stdrp->r_stdoff; |
| 2167 » » » dstr.r_abbrvar = stdrp->r_abbrvar; |
| 2168 » » » stdr.r_month = TM_DECEMBER; |
| 2169 » » » stdr.r_dycode = DC_DOM; |
| 2170 » » » stdr.r_dayofmonth = 31; |
| 2171 » » » stdr.r_tod = SECSPERDAY + stdrp->r_stdoff; |
| 2172 » » » stdr.r_todisstd = stdr.r_todisgmt = FALSE; |
| 2173 » » » stdr.r_stdoff = 0; |
| 2174 » » » stdr.r_abbrvar |
| 2175 » » » = (stdabbrrp ? stdabbrrp->r_abbrvar : ""); |
| 2176 » » » dstrp = &dstr; |
| 2177 » » » stdrp = &stdr; |
| 2178 » » } |
2065 } | 2179 } |
2066 » if (stdrp == NULL && zp->z_nrules != 0) | 2180 » if (stdrp == NULL && (zp->z_nrules != 0 || zp->z_stdoff != 0)) |
2067 » » return; | 2181 » » return -1; |
2068 abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar; | 2182 abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar; |
2069 doabbr(result, zp->z_format, abbrvar, FALSE, TRUE); | 2183 doabbr(result, zp->z_format, abbrvar, FALSE, TRUE); |
2070 if (stringoffset(end(result), -zp->z_gmtoff) != 0) { | 2184 if (stringoffset(end(result), -zp->z_gmtoff) != 0) { |
2071 result[0] = '\0'; | 2185 result[0] = '\0'; |
2072 » » return; | 2186 » » return -1; |
2073 } | 2187 } |
2074 if (dstrp == NULL) | 2188 if (dstrp == NULL) |
2075 » » return; | 2189 » » return compat; |
2076 doabbr(end(result), zp->z_format, dstrp->r_abbrvar, TRUE, TRUE); | 2190 doabbr(end(result), zp->z_format, dstrp->r_abbrvar, TRUE, TRUE); |
2077 if (dstrp->r_stdoff != SECSPERMIN * MINSPERHOUR) | 2191 if (dstrp->r_stdoff != SECSPERMIN * MINSPERHOUR) |
2078 if (stringoffset(end(result), | 2192 if (stringoffset(end(result), |
2079 -(zp->z_gmtoff + dstrp->r_stdoff)) != 0) { | 2193 -(zp->z_gmtoff + dstrp->r_stdoff)) != 0) { |
2080 result[0] = '\0'; | 2194 result[0] = '\0'; |
2081 » » » » return; | 2195 » » » » return -1; |
2082 } | 2196 } |
2083 (void) strcat(result, ","); | 2197 (void) strcat(result, ","); |
2084 » if (stringrule(result, dstrp, dstrp->r_stdoff, zp->z_gmtoff) != 0) { | 2198 » c = stringrule(result, dstrp, dstrp->r_stdoff, zp->z_gmtoff); |
| 2199 » if (c < 0) { |
2085 result[0] = '\0'; | 2200 result[0] = '\0'; |
2086 » » return; | 2201 » » return -1; |
2087 } | 2202 } |
| 2203 if (compat < c) |
| 2204 compat = c; |
2088 (void) strcat(result, ","); | 2205 (void) strcat(result, ","); |
2089 » if (stringrule(result, stdrp, dstrp->r_stdoff, zp->z_gmtoff) != 0) { | 2206 » c = stringrule(result, stdrp, dstrp->r_stdoff, zp->z_gmtoff); |
| 2207 » if (c < 0) { |
2090 result[0] = '\0'; | 2208 result[0] = '\0'; |
2091 » » return; | 2209 » » return -1; |
2092 } | 2210 } |
| 2211 if (compat < c) |
| 2212 compat = c; |
| 2213 return compat; |
2093 } | 2214 } |
2094 | 2215 |
2095 static void | 2216 static void |
2096 outzone(zpfirst, zonecount) | 2217 outzone(const struct zone * const zpfirst, const int zonecount) |
2097 const struct zone * const» zpfirst; | |
2098 const int» » » zonecount; | |
2099 { | 2218 { |
2100 register const struct zone * zp; | 2219 register const struct zone * zp; |
2101 register struct rule * rp; | 2220 register struct rule * rp; |
2102 register int i, j; | 2221 register int i, j; |
2103 register int usestart, useuntil; | 2222 register int usestart, useuntil; |
2104 register zic_t starttime, untiltime; | 2223 register zic_t starttime, untiltime; |
2105 » register long» » » gmtoff; | 2224 » register zic_t» » » gmtoff; |
2106 » register long» » » stdoff; | 2225 » register zic_t» » » stdoff; |
2107 » register int» » » year; | 2226 » register zic_t» » » year; |
2108 » register long» » » startoff; | 2227 » register zic_t» » » startoff; |
2109 register int startttisstd; | 2228 register int startttisstd; |
2110 register int startttisgmt; | 2229 register int startttisgmt; |
2111 register int type; | 2230 register int type; |
2112 register char * startbuf; | 2231 register char * startbuf; |
2113 register char * ab; | 2232 register char * ab; |
2114 register char * envvar; | 2233 register char * envvar; |
2115 register int max_abbr_len; | 2234 register int max_abbr_len; |
2116 register int max_envvar_len; | 2235 register int max_envvar_len; |
| 2236 register int prodstic; /* all rules are min to max */ |
| 2237 register int compat; |
| 2238 register int do_extend; |
| 2239 register char version; |
2117 #ifdef ICU | 2240 #ifdef ICU |
2118 int finalRuleYear, finalRule
Index; | 2241 int finalRuleYear, finalRule
Index; |
2119 const struct rule* finalRule1; | 2242 const struct rule* finalRule1; |
2120 const struct rule* finalRule2; | 2243 const struct rule* finalRule2; |
2121 #endif | 2244 #endif |
2122 | 2245 |
2123 max_abbr_len = 2 + max_format_len + max_abbrvar_len; | 2246 max_abbr_len = 2 + max_format_len + max_abbrvar_len; |
2124 max_envvar_len = 2 * max_abbr_len + 5 * 9; | 2247 max_envvar_len = 2 * max_abbr_len + 5 * 9; |
2125 startbuf = emalloc(max_abbr_len + 1); | 2248 startbuf = emalloc(max_abbr_len + 1); |
2126 ab = emalloc(max_abbr_len + 1); | 2249 ab = emalloc(max_abbr_len + 1); |
2127 envvar = emalloc(max_envvar_len + 1); | 2250 envvar = emalloc(max_envvar_len + 1); |
2128 INITIALIZE(untiltime); | 2251 INITIALIZE(untiltime); |
2129 INITIALIZE(starttime); | 2252 INITIALIZE(starttime); |
2130 /* | 2253 /* |
2131 ** Now. . .finally. . .generate some useful data! | 2254 ** Now. . .finally. . .generate some useful data! |
2132 */ | 2255 */ |
2133 timecnt = 0; | 2256 timecnt = 0; |
2134 typecnt = 0; | 2257 typecnt = 0; |
2135 charcnt = 0; | 2258 charcnt = 0; |
| 2259 prodstic = zonecount == 1; |
2136 /* | 2260 /* |
2137 ** Thanks to Earl Chew | 2261 ** Thanks to Earl Chew |
2138 ** for noting the need to unconditionally initialize startttisstd. | 2262 ** for noting the need to unconditionally initialize startttisstd. |
2139 */ | 2263 */ |
2140 startttisstd = FALSE; | 2264 startttisstd = FALSE; |
2141 startttisgmt = FALSE; | 2265 startttisgmt = FALSE; |
2142 min_year = max_year = EPOCH_YEAR; | 2266 min_year = max_year = EPOCH_YEAR; |
2143 if (leapseen) { | 2267 if (leapseen) { |
2144 updateminmax(leapminyear); | 2268 updateminmax(leapminyear); |
2145 » » updateminmax(leapmaxyear); | 2269 » » updateminmax(leapmaxyear + (leapmaxyear < ZIC_MAX)); |
2146 } | 2270 } |
| 2271 /* |
| 2272 ** Reserve type 0. |
| 2273 */ |
| 2274 gmtoffs[0] = isdsts[0] = ttisstds[0] = ttisgmts[0] = abbrinds[0] = -1; |
| 2275 typecnt = 1; |
2147 for (i = 0; i < zonecount; ++i) { | 2276 for (i = 0; i < zonecount; ++i) { |
2148 zp = &zpfirst[i]; | 2277 zp = &zpfirst[i]; |
2149 if (i < zonecount - 1) | 2278 if (i < zonecount - 1) |
2150 updateminmax(zp->z_untilrule.r_loyear); | 2279 updateminmax(zp->z_untilrule.r_loyear); |
2151 for (j = 0; j < zp->z_nrules; ++j) { | 2280 for (j = 0; j < zp->z_nrules; ++j) { |
2152 rp = &zp->z_rules[j]; | 2281 rp = &zp->z_rules[j]; |
2153 if (rp->r_lowasnum) | 2282 if (rp->r_lowasnum) |
2154 updateminmax(rp->r_loyear); | 2283 updateminmax(rp->r_loyear); |
2155 if (rp->r_hiwasnum) | 2284 if (rp->r_hiwasnum) |
2156 updateminmax(rp->r_hiyear); | 2285 updateminmax(rp->r_hiyear); |
| 2286 if (rp->r_lowasnum || rp->r_hiwasnum) |
| 2287 prodstic = FALSE; |
2157 } | 2288 } |
2158 } | 2289 } |
2159 /* | 2290 /* |
2160 ** Generate lots of data if a rule can't cover all future times. | 2291 ** Generate lots of data if a rule can't cover all future times. |
2161 */ | 2292 */ |
2162 » stringzone(envvar, zpfirst, zonecount); | 2293 » compat = stringzone(envvar, zpfirst, zonecount); |
2163 » if (noise && envvar[0] == '\0') { | 2294 » version = compat < 2013 ? ZIC_VERSION_PRE_2013 : ZIC_VERSION; |
2164 » » register char *»wp; | 2295 » do_extend = compat < 0 || compat == YEAR_BY_YEAR_ZONE; |
| 2296 #ifdef ICU |
| 2297 » do_extend = 0; |
| 2298 #endif |
| 2299 » if (noise) { |
| 2300 » » if (!*envvar) |
| 2301 » » » warning("%s %s", |
| 2302 » » » » _("no POSIX environment variable for zone"), |
| 2303 » » » » zpfirst->z_name); |
| 2304 » » else if (compat != 0 && compat != YEAR_BY_YEAR_ZONE) { |
| 2305 » » » /* Circa-COMPAT clients, and earlier clients, might |
| 2306 » » » not work for this zone when given dates before |
| 2307 » » » 1970 or after 2038. */ |
| 2308 » » » warning(_("%s: pre-%d clients may mishandle" |
| 2309 » » » » " distant timestamps"), |
| 2310 » » » » zpfirst->z_name, compat); |
| 2311 » » } |
| 2312 » } |
| 2313 » if (do_extend) { |
| 2314 » » /* |
| 2315 » » ** Search through a couple of extra years past the obvious |
| 2316 » » ** 400, to avoid edge cases. For example, suppose a non-POSIX |
| 2317 » » ** rule applies from 2012 onwards and has transitions in March |
| 2318 » » ** and September, plus some one-off transitions in November |
| 2319 » » ** 2013. If zic looked only at the last 400 years, it would |
| 2320 » » ** set max_year=2413, with the intent that the 400 years 2014 |
| 2321 » » ** through 2413 will be repeated. The last transition listed |
| 2322 » » ** in the tzfile would be in 2413-09, less than 400 years |
| 2323 » » ** after the last one-off transition in 2013-11. Two years |
| 2324 » » ** might be overkill, but with the kind of edge cases |
| 2325 » » ** available we're not sure that one year would suffice. |
| 2326 » » */ |
| 2327 » » enum { years_of_observations = YEARSPERREPEAT + 2 }; |
2165 | 2328 |
2166 wp = ecpyalloc(_("no POSIX environment variable for zone")); | 2329 » » if (min_year >= ZIC_MIN + years_of_observations) |
2167 » » wp = ecatalloc(wp, " "); | 2330 » » » min_year -= years_of_observations; |
2168 » » wp = ecatalloc(wp, zpfirst->z_name); | 2331 » » else» min_year = ZIC_MIN; |
2169 » » warning(wp); | 2332 » » if (max_year <= ZIC_MAX - years_of_observations) |
2170 » » ifree(wp); | 2333 » » » max_year += years_of_observations; |
2171 » } | 2334 » » else» max_year = ZIC_MAX; |
2172 » if (envvar[0] == '\0') { | 2335 » » /* |
2173 » » if (min_year >= INT_MIN + YEARSPERREPEAT) | 2336 » » ** Regardless of any of the above, |
2174 » » » min_year -= YEARSPERREPEAT; | 2337 » » ** for a "proDSTic" zone which specifies that its rules |
2175 » » else» min_year = INT_MIN; | 2338 » » ** always have and always will be in effect, |
2176 » » if (max_year <= INT_MAX - YEARSPERREPEAT) | 2339 » » ** we only need one cycle to define the zone. |
2177 » » » max_year += YEARSPERREPEAT; | 2340 » » */ |
2178 » » else» max_year = INT_MAX; | 2341 » » if (prodstic) { |
| 2342 » » » min_year = 1900; |
| 2343 » » » max_year = min_year + years_of_observations; |
| 2344 » » } |
2179 } | 2345 } |
2180 /* | 2346 /* |
2181 ** For the benefit of older systems, | 2347 ** For the benefit of older systems, |
2182 ** generate data from 1900 through 2037. | 2348 ** generate data from 1900 through 2037. |
2183 */ | 2349 */ |
2184 if (min_year > 1900) | 2350 if (min_year > 1900) |
2185 min_year = 1900; | 2351 min_year = 1900; |
2186 if (max_year < 2037) | 2352 if (max_year < 2037) |
2187 max_year = 2037; | 2353 max_year = 2037; |
2188 for (i = 0; i < zonecount; ++i) { | 2354 for (i = 0; i < zonecount; ++i) { |
(...skipping 12 matching lines...) Expand all Loading... |
2201 startoff = zp->z_gmtoff; | 2367 startoff = zp->z_gmtoff; |
2202 #ifdef ICU | 2368 #ifdef ICU |
2203 finalRuleYear = finalRuleIndex = -1; | 2369 finalRuleYear = finalRuleIndex = -1; |
2204 finalRule1 = finalRule2 = NULL; | 2370 finalRule1 = finalRule2 = NULL; |
2205 if (i == (zonecount - 1)) { /* !useuntil */ | 2371 if (i == (zonecount - 1)) { /* !useuntil */ |
2206 /* Look for exactly 2 rules that end at 'max' and | 2372 /* Look for exactly 2 rules that end at 'max' and |
2207 * note them. Determine max(r_loyear) for the 2 of | 2373 * note them. Determine max(r_loyear) for the 2 of |
2208 * them. */ | 2374 * them. */ |
2209 for (j=0; j<zp->z_nrules; ++j) { | 2375 for (j=0; j<zp->z_nrules; ++j) { |
2210 rp = &zp->z_rules[j]; | 2376 rp = &zp->z_rules[j]; |
2211 » » » » if (rp->r_hiyear == INT_MAX) { | 2377 » » » » if (rp->r_hiyear == ZIC_MAX) { |
2212 if (rp->r_loyear > finalRuleYear) { | 2378 if (rp->r_loyear > finalRuleYear) { |
2213 finalRuleYear = rp->r_loyear; | 2379 finalRuleYear = rp->r_loyear; |
2214 } | 2380 } |
2215 if (finalRule1 == NULL) { | 2381 if (finalRule1 == NULL) { |
2216 finalRule1 = rp; | 2382 finalRule1 = rp; |
2217 } else if (finalRule2 == NULL) { | 2383 } else if (finalRule2 == NULL) { |
2218 finalRule2 = rp; | 2384 finalRule2 = rp; |
2219 } else { | 2385 } else { |
2220 error("more than two max rules f
ound (ICU)"); | 2386 error("more than two max rules f
ound (ICU)"); |
2221 exit(EXIT_FAILURE); | 2387 exit(EXIT_FAILURE); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 finalRuleIndex = add_icu_final_r
ules(finalRule1, finalRule2); | 2447 finalRuleIndex = add_icu_final_r
ules(finalRule1, finalRule2); |
2282 } | 2448 } |
2283 } | 2449 } |
2284 } | 2450 } |
2285 } | 2451 } |
2286 #endif | 2452 #endif |
2287 | 2453 |
2288 if (zp->z_nrules == 0) { | 2454 if (zp->z_nrules == 0) { |
2289 stdoff = zp->z_stdoff; | 2455 stdoff = zp->z_stdoff; |
2290 doabbr(startbuf, zp->z_format, | 2456 doabbr(startbuf, zp->z_format, |
2291 » » » » (char *) NULL, stdoff != 0, FALSE); | 2457 » » » NULL, stdoff != 0, FALSE); |
2292 type = addtype(oadd(zp->z_gmtoff, stdoff), | 2458 type = addtype(oadd(zp->z_gmtoff, stdoff), |
2293 #ifdef ICU | 2459 #ifdef ICU |
2294 zp->z_gmtoff, stdoff, | 2460 zp->z_gmtoff, stdoff, |
2295 #endif | 2461 #endif |
2296 startbuf, stdoff != 0, startttisstd, | 2462 startbuf, stdoff != 0, startttisstd, |
2297 startttisgmt); | 2463 startttisgmt); |
2298 if (usestart) { | 2464 if (usestart) { |
2299 addtt(starttime, type); | 2465 addtt(starttime, type); |
2300 usestart = FALSE; | 2466 usestart = FALSE; |
2301 } else if (stdoff != 0) | 2467 } else if (stdoff != 0) |
(...skipping 11 matching lines...) Expand all Loading... |
2313 rp->r_filename, rp->r_linenum); | 2479 rp->r_filename, rp->r_linenum); |
2314 rp->r_todo = year >= rp->r_loyear && | 2480 rp->r_todo = year >= rp->r_loyear && |
2315 year <= rp->r_hiyear && | 2481 year <= rp->r_hiyear && |
2316 yearistype(year, rp->r_yrtype); | 2482 yearistype(year, rp->r_yrtype); |
2317 if (rp->r_todo) | 2483 if (rp->r_todo) |
2318 rp->r_temp = rpytime(rp, year); | 2484 rp->r_temp = rpytime(rp, year); |
2319 } | 2485 } |
2320 for ( ; ; ) { | 2486 for ( ; ; ) { |
2321 register int k; | 2487 register int k; |
2322 register zic_t jtime, ktime; | 2488 register zic_t jtime, ktime; |
2323 » » » » register long» offset; | 2489 » » » » register zic_t» offset; |
2324 | 2490 |
2325 INITIALIZE(ktime); | 2491 INITIALIZE(ktime); |
2326 if (useuntil) { | 2492 if (useuntil) { |
2327 /* | 2493 /* |
2328 » » » » » ** Turn untiltime into UTC | 2494 » » » » » ** Turn untiltime into UT |
2329 ** assuming the current gmtoff and | 2495 ** assuming the current gmtoff and |
2330 ** stdoff values. | 2496 ** stdoff values. |
2331 */ | 2497 */ |
2332 untiltime = zp->z_untiltime; | 2498 untiltime = zp->z_untiltime; |
2333 if (!zp->z_untilrule.r_todisgmt) | 2499 if (!zp->z_untilrule.r_todisgmt) |
2334 untiltime = tadd(untiltime, | 2500 untiltime = tadd(untiltime, |
2335 -gmtoff); | 2501 -gmtoff); |
2336 if (!zp->z_untilrule.r_todisstd) | 2502 if (!zp->z_untilrule.r_todisstd) |
2337 untiltime = tadd(untiltime, | 2503 untiltime = tadd(untiltime, |
2338 -stdoff); | 2504 -stdoff); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2458 if (useuntil) { | 2624 if (useuntil) { |
2459 startttisstd = zp->z_untilrule.r_todisstd; | 2625 startttisstd = zp->z_untilrule.r_todisstd; |
2460 startttisgmt = zp->z_untilrule.r_todisgmt; | 2626 startttisgmt = zp->z_untilrule.r_todisgmt; |
2461 starttime = zp->z_untiltime; | 2627 starttime = zp->z_untiltime; |
2462 if (!startttisstd) | 2628 if (!startttisstd) |
2463 starttime = tadd(starttime, -stdoff); | 2629 starttime = tadd(starttime, -stdoff); |
2464 if (!startttisgmt) | 2630 if (!startttisgmt) |
2465 starttime = tadd(starttime, -gmtoff); | 2631 starttime = tadd(starttime, -gmtoff); |
2466 } | 2632 } |
2467 } | 2633 } |
2468 » writezone(zpfirst->z_name, envvar); | 2634 » if (do_extend) { |
2469 » ifree(startbuf); | 2635 » » /* |
2470 » ifree(ab); | 2636 » » ** If we're extending the explicitly listed observations |
2471 » ifree(envvar); | 2637 » » ** for 400 years because we can't fill the POSIX-TZ field, |
| 2638 » » ** check whether we actually ended up explicitly listing |
| 2639 » » ** observations through that period. If there aren't any |
| 2640 » » ** near the end of the 400-year period, add a redundant |
| 2641 » » ** one at the end of the final year, to make it clear |
| 2642 » » ** that we are claiming to have definite knowledge of |
| 2643 » » ** the lack of transitions up to that point. |
| 2644 » » */ |
| 2645 » » struct rule xr; |
| 2646 » » struct attype *lastat; |
| 2647 » » xr.r_month = TM_JANUARY; |
| 2648 » » xr.r_dycode = DC_DOM; |
| 2649 » » xr.r_dayofmonth = 1; |
| 2650 » » xr.r_tod = 0; |
| 2651 » » for (lastat = &attypes[0], i = 1; i < timecnt; i++) |
| 2652 » » » if (attypes[i].at > lastat->at) |
| 2653 » » » » lastat = &attypes[i]; |
| 2654 » » if (lastat->at < rpytime(&xr, max_year - 1)) { |
| 2655 » » » /* |
| 2656 » » » ** Create new type code for the redundant entry, |
| 2657 » » » ** to prevent it being optimised away. |
| 2658 » » » */ |
| 2659 » » » if (typecnt >= TZ_MAX_TYPES) { |
| 2660 » » » » error(_("too many local time types")); |
| 2661 » » » » exit(EXIT_FAILURE); |
| 2662 » » » } |
| 2663 » » » gmtoffs[typecnt] = gmtoffs[lastat->type]; |
| 2664 » » » isdsts[typecnt] = isdsts[lastat->type]; |
| 2665 » » » ttisstds[typecnt] = ttisstds[lastat->type]; |
| 2666 » » » ttisgmts[typecnt] = ttisgmts[lastat->type]; |
| 2667 » » » abbrinds[typecnt] = abbrinds[lastat->type]; |
| 2668 » » » ++typecnt; |
| 2669 » » » addtt(rpytime(&xr, max_year + 1), typecnt-1); |
| 2670 » » } |
| 2671 » } |
| 2672 » writezone(zpfirst->z_name, envvar, version); |
| 2673 » free(startbuf); |
| 2674 » free(ab); |
| 2675 » free(envvar); |
2472 } | 2676 } |
2473 | 2677 |
2474 static void | 2678 static void |
2475 addtt(starttime, type) | 2679 addtt(const zic_t starttime, int type) |
2476 const zic_t» starttime; | |
2477 int» » type; | |
2478 { | 2680 { |
2479 if (starttime <= min_time || | 2681 if (starttime <= min_time || |
2480 (timecnt == 1 && attypes[0].at < min_time)) { | 2682 (timecnt == 1 && attypes[0].at < min_time)) { |
2481 gmtoffs[0] = gmtoffs[type]; | 2683 gmtoffs[0] = gmtoffs[type]; |
2482 #ifdef ICU | 2684 #ifdef ICU |
2483 rawoffs[0] = rawoffs[type]; | 2685 rawoffs[0] = rawoffs[type]; |
2484 dstoffs[0] = dstoffs[type]; | 2686 dstoffs[0] = dstoffs[type]; |
2485 #endif | 2687 #endif |
2486 isdsts[0] = isdsts[type]; | 2688 isdsts[0] = isdsts[type]; |
2487 ttisstds[0] = ttisstds[type]; | 2689 ttisstds[0] = ttisstds[type]; |
2488 ttisgmts[0] = ttisgmts[type]; | 2690 ttisgmts[0] = ttisgmts[type]; |
2489 if (abbrinds[type] != 0) | 2691 if (abbrinds[type] != 0) |
2490 (void) strcpy(chars, &chars[abbrinds[type]]); | 2692 (void) strcpy(chars, &chars[abbrinds[type]]); |
2491 abbrinds[0] = 0; | 2693 abbrinds[0] = 0; |
2492 charcnt = strlen(chars) + 1; | 2694 charcnt = strlen(chars) + 1; |
2493 typecnt = 1; | 2695 typecnt = 1; |
2494 timecnt = 0; | 2696 timecnt = 0; |
2495 type = 0; | 2697 type = 0; |
2496 } | 2698 } |
2497 » if (timecnt >= TZ_MAX_TIMES) { | 2699 » attypes = growalloc(attypes, sizeof *attypes, timecnt, &timecnt_alloc); |
2498 » » error(_("too many transitions?!")); | |
2499 » » exit(EXIT_FAILURE); | |
2500 » } | |
2501 attypes[timecnt].at = starttime; | 2700 attypes[timecnt].at = starttime; |
2502 attypes[timecnt].type = type; | 2701 attypes[timecnt].type = type; |
2503 ++timecnt; | 2702 ++timecnt; |
2504 } | 2703 } |
2505 | 2704 |
2506 static int | 2705 static int |
2507 #ifdef ICU | 2706 #ifdef ICU |
2508 addtype(gmtoff, rawoff, dstoff, abbr, isdst, ttisstd, ttisgmt) | 2707 addtype(const zic_t gmtoff, const zic_t rawoff, const zic_t dstoff, char *const
abbr, const int isdst, |
2509 const long» » gmtoff; | 2708 » const int ttisstd, const int ttisgmt) |
2510 const long» » rawoff; | |
2511 const long» » dstoff; | |
2512 #else | 2709 #else |
2513 addtype(gmtoff, abbr, isdst, ttisstd, ttisgmt) | 2710 addtype(const zic_t gmtoff, const char *const abbr, const int isdst, |
2514 const long» » gmtoff; | 2711 » const int ttisstd, const int ttisgmt) |
2515 #endif | 2712 #endif |
2516 const char * const abbr; | |
2517 const int isdst; | |
2518 const int ttisstd; | |
2519 const int ttisgmt; | |
2520 { | 2713 { |
2521 register int i, j; | 2714 register int i, j; |
2522 | 2715 |
2523 if (isdst != TRUE && isdst != FALSE) { | 2716 if (isdst != TRUE && isdst != FALSE) { |
2524 error(_("internal error - addtype called with bad isdst")); | 2717 error(_("internal error - addtype called with bad isdst")); |
2525 exit(EXIT_FAILURE); | 2718 exit(EXIT_FAILURE); |
2526 } | 2719 } |
2527 if (ttisstd != TRUE && ttisstd != FALSE) { | 2720 if (ttisstd != TRUE && ttisstd != FALSE) { |
2528 error(_("internal error - addtype called with bad ttisstd")); | 2721 error(_("internal error - addtype called with bad ttisstd")); |
2529 exit(EXIT_FAILURE); | 2722 exit(EXIT_FAILURE); |
2530 } | 2723 } |
2531 if (ttisgmt != TRUE && ttisgmt != FALSE) { | 2724 if (ttisgmt != TRUE && ttisgmt != FALSE) { |
2532 error(_("internal error - addtype called with bad ttisgmt")); | 2725 error(_("internal error - addtype called with bad ttisgmt")); |
2533 exit(EXIT_FAILURE); | 2726 exit(EXIT_FAILURE); |
2534 } | 2727 } |
2535 #ifdef ICU | 2728 #ifdef ICU |
2536 if (isdst != (dstoff != 0)) { | 2729 if (isdst != (dstoff != 0)) { |
2537 error(_("internal error - addtype called with bad isdst/dstoff")
); | 2730 error(_("internal error - addtype called with bad isdst/dstoff")
); |
2538 » » (void) exit(EXIT_FAILURE); | 2731 » » exit(EXIT_FAILURE); |
2539 } | 2732 } |
2540 if (gmtoff != (rawoff + dstoff)) { | 2733 if (gmtoff != (rawoff + dstoff)) { |
2541 error(_("internal error - addtype called with bad gmt/raw/dstoff
")); | 2734 error(_("internal error - addtype called with bad gmt/raw/dstoff
")); |
2542 » » (void) exit(EXIT_FAILURE); | 2735 » » exit(EXIT_FAILURE); |
2543 } | 2736 } |
2544 #endif | 2737 #endif |
2545 /* | 2738 /* |
2546 ** See if there's already an entry for this zone type. | 2739 ** See if there's already an entry for this zone type. |
2547 ** If so, just return its index. | 2740 ** If so, just return its index. |
2548 */ | 2741 */ |
2549 for (i = 0; i < typecnt; ++i) { | 2742 for (i = 0; i < typecnt; ++i) { |
2550 if (gmtoff == gmtoffs[i] && isdst == isdsts[i] && | 2743 if (gmtoff == gmtoffs[i] && isdst == isdsts[i] && |
2551 #ifdef ICU | 2744 #ifdef ICU |
2552 rawoff == rawoffs[i] && dstoff == dstoffs[i] && | 2745 rawoff == rawoffs[i] && dstoff == dstoffs[i] && |
2553 #endif | 2746 #endif |
2554 strcmp(abbr, &chars[abbrinds[i]]) == 0 && | 2747 strcmp(abbr, &chars[abbrinds[i]]) == 0 && |
2555 ttisstd == ttisstds[i] && | 2748 ttisstd == ttisstds[i] && |
2556 ttisgmt == ttisgmts[i]) | 2749 ttisgmt == ttisgmts[i]) |
2557 return i; | 2750 return i; |
2558 } | 2751 } |
2559 /* | 2752 /* |
2560 ** There isn't one; add a new one, unless there are already too | 2753 ** There isn't one; add a new one, unless there are already too |
2561 ** many. | 2754 ** many. |
2562 */ | 2755 */ |
2563 if (typecnt >= TZ_MAX_TYPES) { | 2756 if (typecnt >= TZ_MAX_TYPES) { |
2564 error(_("too many local time types")); | 2757 error(_("too many local time types")); |
2565 exit(EXIT_FAILURE); | 2758 exit(EXIT_FAILURE); |
2566 } | 2759 } |
2567 if (! (-1L - 2147483647L <= gmtoff && gmtoff <= 2147483647L)) { | 2760 if (! (-1L - 2147483647L <= gmtoff && gmtoff <= 2147483647L)) { |
2568 » » error(_("UTC offset out of range")); | 2761 » » error(_("UT offset out of range")); |
2569 exit(EXIT_FAILURE); | 2762 exit(EXIT_FAILURE); |
2570 } | 2763 } |
2571 gmtoffs[i] = gmtoff; | 2764 gmtoffs[i] = gmtoff; |
2572 #ifdef ICU | 2765 #ifdef ICU |
2573 rawoffs[i] = rawoff; | 2766 rawoffs[i] = rawoff; |
2574 dstoffs[i] = dstoff; | 2767 dstoffs[i] = dstoff; |
2575 #endif | 2768 #endif |
2576 isdsts[i] = isdst; | 2769 isdsts[i] = isdst; |
2577 ttisstds[i] = ttisstd; | 2770 ttisstds[i] = ttisstd; |
2578 ttisgmts[i] = ttisgmt; | 2771 ttisgmts[i] = ttisgmt; |
2579 | 2772 |
2580 for (j = 0; j < charcnt; ++j) | 2773 for (j = 0; j < charcnt; ++j) |
2581 if (strcmp(&chars[j], abbr) == 0) | 2774 if (strcmp(&chars[j], abbr) == 0) |
2582 break; | 2775 break; |
2583 if (j == charcnt) | 2776 if (j == charcnt) |
2584 newabbr(abbr); | 2777 newabbr(abbr); |
2585 abbrinds[i] = j; | 2778 abbrinds[i] = j; |
2586 ++typecnt; | 2779 ++typecnt; |
2587 return i; | 2780 return i; |
2588 } | 2781 } |
2589 | 2782 |
2590 static void | 2783 static void |
2591 leapadd(t, positive, rolling, count) | 2784 leapadd(const zic_t t, const int positive, const int rolling, int count) |
2592 const zic_t» t; | |
2593 const int» positive; | |
2594 const int» rolling; | |
2595 int» » count; | |
2596 { | 2785 { |
2597 register int i, j; | 2786 register int i, j; |
2598 | 2787 |
2599 if (leapcnt + (positive ? count : 1) > TZ_MAX_LEAPS) { | 2788 if (leapcnt + (positive ? count : 1) > TZ_MAX_LEAPS) { |
2600 error(_("too many leap seconds")); | 2789 error(_("too many leap seconds")); |
2601 exit(EXIT_FAILURE); | 2790 exit(EXIT_FAILURE); |
2602 } | 2791 } |
2603 for (i = 0; i < leapcnt; ++i) | 2792 for (i = 0; i < leapcnt; ++i) |
2604 if (t <= trans[i]) { | 2793 if (t <= trans[i]) { |
2605 if (t == trans[i]) { | 2794 if (t == trans[i]) { |
2606 error(_("repeated leap second moment")); | 2795 error(_("repeated leap second moment")); |
2607 exit(EXIT_FAILURE); | 2796 exit(EXIT_FAILURE); |
2608 } | 2797 } |
2609 break; | 2798 break; |
2610 } | 2799 } |
2611 do { | 2800 do { |
2612 for (j = leapcnt; j > i; --j) { | 2801 for (j = leapcnt; j > i; --j) { |
2613 trans[j] = trans[j - 1]; | 2802 trans[j] = trans[j - 1]; |
2614 corr[j] = corr[j - 1]; | 2803 corr[j] = corr[j - 1]; |
2615 roll[j] = roll[j - 1]; | 2804 roll[j] = roll[j - 1]; |
2616 } | 2805 } |
2617 trans[i] = t; | 2806 trans[i] = t; |
2618 » » corr[i] = positive ? 1L : eitol(-count); | 2807 » » corr[i] = positive ? 1 : -count; |
2619 roll[i] = rolling; | 2808 roll[i] = rolling; |
2620 ++leapcnt; | 2809 ++leapcnt; |
2621 } while (positive && --count != 0); | 2810 } while (positive && --count != 0); |
2622 } | 2811 } |
2623 | 2812 |
2624 static void | 2813 static void |
2625 adjleap(void) | 2814 adjleap(void) |
2626 { | 2815 { |
2627 register int i; | 2816 register int i; |
2628 » register long» last = 0; | 2817 » register zic_t» last = 0; |
2629 | 2818 |
2630 /* | 2819 /* |
2631 ** propagate leap seconds forward | 2820 ** propagate leap seconds forward |
2632 */ | 2821 */ |
2633 for (i = 0; i < leapcnt; ++i) { | 2822 for (i = 0; i < leapcnt; ++i) { |
2634 trans[i] = tadd(trans[i], last); | 2823 trans[i] = tadd(trans[i], last); |
2635 last = corr[i] += last; | 2824 last = corr[i] += last; |
2636 } | 2825 } |
2637 } | 2826 } |
2638 | 2827 |
2639 static int | 2828 static int |
2640 yearistype(year, type) | 2829 yearistype(const int year, const char *const type) |
2641 const int» » year; | |
2642 const char * const» type; | |
2643 { | 2830 { |
2644 static char * buf; | 2831 static char * buf; |
2645 int result; | 2832 int result; |
2646 | 2833 |
2647 if (type == NULL || *type == '\0') | 2834 if (type == NULL || *type == '\0') |
2648 return TRUE; | 2835 return TRUE; |
2649 » buf = erealloc(buf, (int) (132 + strlen(yitcommand) + strlen(type))); | 2836 » buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type)); |
2650 (void) sprintf(buf, "%s %d %s", yitcommand, year, type); | 2837 (void) sprintf(buf, "%s %d %s", yitcommand, year, type); |
2651 result = system(buf); | 2838 result = system(buf); |
2652 if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { | 2839 if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { |
2653 case 0: | 2840 case 0: |
2654 return TRUE; | 2841 return TRUE; |
2655 case 1: | 2842 case 1: |
2656 return FALSE; | 2843 return FALSE; |
2657 } | 2844 } |
2658 error(_("Wild result from command execution")); | 2845 error(_("Wild result from command execution")); |
2659 (void) fprintf(stderr, _("%s: command was '%s', result was %d\n"), | 2846 (void) fprintf(stderr, _("%s: command was '%s', result was %d\n"), |
2660 progname, buf, result); | 2847 progname, buf, result); |
2661 for ( ; ; ) | 2848 for ( ; ; ) |
2662 exit(EXIT_FAILURE); | 2849 exit(EXIT_FAILURE); |
2663 } | 2850 } |
2664 | 2851 |
2665 static int | 2852 static int |
2666 lowerit(a) | 2853 lowerit(int a) |
2667 int» a; | |
2668 { | 2854 { |
2669 a = (unsigned char) a; | 2855 a = (unsigned char) a; |
2670 return (isascii(a) && isupper(a)) ? tolower(a) : a; | 2856 return (isascii(a) && isupper(a)) ? tolower(a) : a; |
2671 } | 2857 } |
2672 | 2858 |
2673 static int | 2859 /* case-insensitive equality */ |
2674 ciequal(ap, bp)»» /* case-insensitive equality */ | 2860 static ATTRIBUTE_PURE int |
2675 register const char *» ap; | 2861 ciequal(register const char *ap, register const char *bp) |
2676 register const char *» bp; | |
2677 { | 2862 { |
2678 while (lowerit(*ap) == lowerit(*bp++)) | 2863 while (lowerit(*ap) == lowerit(*bp++)) |
2679 if (*ap++ == '\0') | 2864 if (*ap++ == '\0') |
2680 return TRUE; | 2865 return TRUE; |
2681 return FALSE; | 2866 return FALSE; |
2682 } | 2867 } |
2683 | 2868 |
2684 static int | 2869 static ATTRIBUTE_PURE int |
2685 itsabbr(abbr, word) | 2870 itsabbr(register const char *abbr, register const char *word) |
2686 register const char *» abbr; | |
2687 register const char *» word; | |
2688 { | 2871 { |
2689 if (lowerit(*abbr) != lowerit(*word)) | 2872 if (lowerit(*abbr) != lowerit(*word)) |
2690 return FALSE; | 2873 return FALSE; |
2691 ++word; | 2874 ++word; |
2692 while (*++abbr != '\0') | 2875 while (*++abbr != '\0') |
2693 do { | 2876 do { |
2694 if (*word == '\0') | 2877 if (*word == '\0') |
2695 return FALSE; | 2878 return FALSE; |
2696 } while (lowerit(*word++) != lowerit(*abbr)); | 2879 } while (lowerit(*word++) != lowerit(*abbr)); |
2697 return TRUE; | 2880 return TRUE; |
2698 } | 2881 } |
2699 | 2882 |
2700 static const struct lookup * | 2883 static ATTRIBUTE_PURE const struct lookup * |
2701 byword(word, table) | 2884 byword(register const char *const word, |
2702 register const char * const» » word; | 2885 register const struct lookup *const table) |
2703 register const struct lookup * const» table; | |
2704 { | 2886 { |
2705 register const struct lookup * foundlp; | 2887 register const struct lookup * foundlp; |
2706 register const struct lookup * lp; | 2888 register const struct lookup * lp; |
2707 | 2889 |
2708 if (word == NULL || table == NULL) | 2890 if (word == NULL || table == NULL) |
2709 return NULL; | 2891 return NULL; |
2710 /* | 2892 /* |
2711 ** Look for exact match. | 2893 ** Look for exact match. |
2712 */ | 2894 */ |
2713 for (lp = table; lp->l_word != NULL; ++lp) | 2895 for (lp = table; lp->l_word != NULL; ++lp) |
2714 if (ciequal(word, lp->l_word)) | 2896 if (ciequal(word, lp->l_word)) |
2715 return lp; | 2897 return lp; |
2716 /* | 2898 /* |
2717 ** Look for inexact match. | 2899 ** Look for inexact match. |
2718 */ | 2900 */ |
2719 foundlp = NULL; | 2901 foundlp = NULL; |
2720 for (lp = table; lp->l_word != NULL; ++lp) | 2902 for (lp = table; lp->l_word != NULL; ++lp) |
2721 if (itsabbr(word, lp->l_word)) { | 2903 if (itsabbr(word, lp->l_word)) { |
2722 if (foundlp == NULL) | 2904 if (foundlp == NULL) |
2723 foundlp = lp; | 2905 foundlp = lp; |
2724 else return NULL; /* multiple inexact matches */ | 2906 else return NULL; /* multiple inexact matches */ |
2725 } | 2907 } |
2726 return foundlp; | 2908 return foundlp; |
2727 } | 2909 } |
2728 | 2910 |
2729 static char ** | 2911 static char ** |
2730 getfields(cp) | 2912 getfields(register char *cp) |
2731 register char *»cp; | |
2732 { | 2913 { |
2733 register char * dp; | 2914 register char * dp; |
2734 register char ** array; | 2915 register char ** array; |
2735 register int nsubs; | 2916 register int nsubs; |
2736 | 2917 |
2737 if (cp == NULL) | 2918 if (cp == NULL) |
2738 return NULL; | 2919 return NULL; |
2739 » array = (char **) (void *) | 2920 » array = emalloc(size_product(strlen(cp) + 1, sizeof *array)); |
2740 » » emalloc((int) ((strlen(cp) + 1) * sizeof *array)); | |
2741 nsubs = 0; | 2921 nsubs = 0; |
2742 for ( ; ; ) { | 2922 for ( ; ; ) { |
2743 while (isascii((unsigned char) *cp) && | 2923 while (isascii((unsigned char) *cp) && |
2744 isspace((unsigned char) *cp)) | 2924 isspace((unsigned char) *cp)) |
2745 ++cp; | 2925 ++cp; |
2746 if (*cp == '\0' || *cp == '#') | 2926 if (*cp == '\0' || *cp == '#') |
2747 break; | 2927 break; |
2748 array[nsubs++] = dp = cp; | 2928 array[nsubs++] = dp = cp; |
2749 do { | 2929 do { |
2750 if ((*dp = *cp++) != '"') | 2930 if ((*dp = *cp++) != '"') |
(...skipping 10 matching lines...) Expand all Loading... |
2761 } while (*cp != '\0' && *cp != '#' && | 2941 } while (*cp != '\0' && *cp != '#' && |
2762 (!isascii(*cp) || !isspace((unsigned char) *cp))); | 2942 (!isascii(*cp) || !isspace((unsigned char) *cp))); |
2763 if (isascii(*cp) && isspace((unsigned char) *cp)) | 2943 if (isascii(*cp) && isspace((unsigned char) *cp)) |
2764 ++cp; | 2944 ++cp; |
2765 *dp = '\0'; | 2945 *dp = '\0'; |
2766 } | 2946 } |
2767 array[nsubs] = NULL; | 2947 array[nsubs] = NULL; |
2768 return array; | 2948 return array; |
2769 } | 2949 } |
2770 | 2950 |
2771 static long | 2951 static ATTRIBUTE_PURE zic_t |
2772 oadd(t1, t2) | 2952 oadd(const zic_t t1, const zic_t t2) |
2773 const long» t1; | |
2774 const long» t2; | |
2775 { | 2953 { |
2776 » register long» t; | 2954 » if (t1 < 0 ? t2 < ZIC_MIN - t1 : ZIC_MAX - t1 < t2) { |
2777 | |
2778 » t = t1 + t2; | |
2779 » if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) { | |
2780 error(_("time overflow")); | 2955 error(_("time overflow")); |
2781 exit(EXIT_FAILURE); | 2956 exit(EXIT_FAILURE); |
2782 } | 2957 } |
2783 » return t; | 2958 » return t1 + t2; |
2784 } | 2959 } |
2785 | 2960 |
2786 static zic_t | 2961 static ATTRIBUTE_PURE zic_t |
2787 tadd(t1, t2) | 2962 tadd(const zic_t t1, const zic_t t2) |
2788 const zic_t» t1; | |
2789 const long» t2; | |
2790 { | 2963 { |
2791 register zic_t t; | |
2792 | |
2793 if (t1 == max_time && t2 > 0) | 2964 if (t1 == max_time && t2 > 0) |
2794 return max_time; | 2965 return max_time; |
2795 if (t1 == min_time && t2 < 0) | 2966 if (t1 == min_time && t2 < 0) |
2796 return min_time; | 2967 return min_time; |
2797 » t = t1 + t2; | 2968 » if (t1 < 0 ? t2 < min_time - t1 : max_time - t1 < t2) { |
2798 » if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) { | |
2799 error(_("time overflow")); | 2969 error(_("time overflow")); |
2800 exit(EXIT_FAILURE); | 2970 exit(EXIT_FAILURE); |
2801 } | 2971 } |
2802 » return t; | 2972 » return t1 + t2; |
2803 } | 2973 } |
2804 | 2974 |
2805 /* | 2975 /* |
2806 ** Given a rule, and a year, compute the date - in seconds since January 1, | 2976 ** Given a rule, and a year, compute the date - in seconds since January 1, |
2807 ** 1970, 00:00 LOCAL time - in that year that the rule refers to. | 2977 ** 1970, 00:00 LOCAL time - in that year that the rule refers to. |
2808 */ | 2978 */ |
2809 | 2979 |
2810 static zic_t | 2980 static zic_t |
2811 rpytime(rp, wantedy) | 2981 rpytime(register const struct rule *const rp, register const zic_t wantedy) |
2812 register const struct rule * const» rp; | |
2813 register const int» » » wantedy; | |
2814 { | 2982 { |
2815 » register int» y, m, i; | 2983 » register int» m, i; |
2816 » register long» dayoff;»» » /* with a nod to Margaret O. */ | 2984 » register zic_t» dayoff;»» » /* with a nod to Margaret O. */ |
2817 » register zic_t» t; | 2985 » register zic_t» t, y; |
2818 | 2986 |
2819 » if (wantedy == INT_MIN) | 2987 » if (wantedy == ZIC_MIN) |
2820 return min_time; | 2988 return min_time; |
2821 » if (wantedy == INT_MAX) | 2989 » if (wantedy == ZIC_MAX) |
2822 return max_time; | 2990 return max_time; |
2823 dayoff = 0; | 2991 dayoff = 0; |
2824 m = TM_JANUARY; | 2992 m = TM_JANUARY; |
2825 y = EPOCH_YEAR; | 2993 y = EPOCH_YEAR; |
2826 while (wantedy != y) { | 2994 while (wantedy != y) { |
2827 if (wantedy > y) { | 2995 if (wantedy > y) { |
2828 i = len_years[isleap(y)]; | 2996 i = len_years[isleap(y)]; |
2829 ++y; | 2997 ++y; |
2830 } else { | 2998 } else { |
2831 --y; | 2999 --y; |
2832 i = -len_years[isleap(y)]; | 3000 i = -len_years[isleap(y)]; |
2833 } | 3001 } |
2834 » » dayoff = oadd(dayoff, eitol(i)); | 3002 » » dayoff = oadd(dayoff, i); |
2835 } | 3003 } |
2836 while (m != rp->r_month) { | 3004 while (m != rp->r_month) { |
2837 i = len_months[isleap(y)][m]; | 3005 i = len_months[isleap(y)][m]; |
2838 » » dayoff = oadd(dayoff, eitol(i)); | 3006 » » dayoff = oadd(dayoff, i); |
2839 ++m; | 3007 ++m; |
2840 } | 3008 } |
2841 i = rp->r_dayofmonth; | 3009 i = rp->r_dayofmonth; |
2842 if (m == TM_FEBRUARY && i == 29 && !isleap(y)) { | 3010 if (m == TM_FEBRUARY && i == 29 && !isleap(y)) { |
2843 if (rp->r_dycode == DC_DOWLEQ) | 3011 if (rp->r_dycode == DC_DOWLEQ) |
2844 --i; | 3012 --i; |
2845 else { | 3013 else { |
2846 error(_("use of 2/29 in non leap-year")); | 3014 error(_("use of 2/29 in non leap-year")); |
2847 exit(EXIT_FAILURE); | 3015 exit(EXIT_FAILURE); |
2848 } | 3016 } |
2849 } | 3017 } |
2850 --i; | 3018 --i; |
2851 » dayoff = oadd(dayoff, eitol(i)); | 3019 » dayoff = oadd(dayoff, i); |
2852 if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ) { | 3020 if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ) { |
2853 » » register long» wday; | 3021 » » register zic_t» wday; |
2854 | 3022 |
2855 #define LDAYSPERWEEK» ((long) DAYSPERWEEK) | 3023 #define LDAYSPERWEEK» ((zic_t) DAYSPERWEEK) |
2856 » » wday = eitol(EPOCH_WDAY); | 3024 » » wday = EPOCH_WDAY; |
2857 /* | 3025 /* |
2858 ** Don't trust mod of negative numbers. | 3026 ** Don't trust mod of negative numbers. |
2859 */ | 3027 */ |
2860 if (dayoff >= 0) | 3028 if (dayoff >= 0) |
2861 wday = (wday + dayoff) % LDAYSPERWEEK; | 3029 wday = (wday + dayoff) % LDAYSPERWEEK; |
2862 else { | 3030 else { |
2863 wday -= ((-dayoff) % LDAYSPERWEEK); | 3031 wday -= ((-dayoff) % LDAYSPERWEEK); |
2864 if (wday < 0) | 3032 if (wday < 0) |
2865 wday += LDAYSPERWEEK; | 3033 wday += LDAYSPERWEEK; |
2866 } | 3034 } |
2867 » » while (wday != eitol(rp->r_wday)) | 3035 » » while (wday != rp->r_wday) |
2868 if (rp->r_dycode == DC_DOWGEQ) { | 3036 if (rp->r_dycode == DC_DOWGEQ) { |
2869 » » » » dayoff = oadd(dayoff, (long) 1); | 3037 » » » » dayoff = oadd(dayoff, 1); |
2870 if (++wday >= LDAYSPERWEEK) | 3038 if (++wday >= LDAYSPERWEEK) |
2871 wday = 0; | 3039 wday = 0; |
2872 ++i; | 3040 ++i; |
2873 } else { | 3041 } else { |
2874 » » » » dayoff = oadd(dayoff, (long) -1); | 3042 » » » » dayoff = oadd(dayoff, -1); |
2875 if (--wday < 0) | 3043 if (--wday < 0) |
2876 wday = LDAYSPERWEEK - 1; | 3044 wday = LDAYSPERWEEK - 1; |
2877 --i; | 3045 --i; |
2878 } | 3046 } |
2879 if (i < 0 || i >= len_months[isleap(y)][m]) { | 3047 if (i < 0 || i >= len_months[isleap(y)][m]) { |
2880 if (noise) | 3048 if (noise) |
2881 warning(_("rule goes past start/end of month--\ | 3049 warning(_("rule goes past start/end of month--\ |
2882 will not work with pre-2004 versions of zic")); | 3050 will not work with pre-2004 versions of zic")); |
2883 } | 3051 } |
2884 } | 3052 } |
2885 if (dayoff < min_time / SECSPERDAY) | 3053 if (dayoff < min_time / SECSPERDAY) |
2886 return min_time; | 3054 return min_time; |
2887 if (dayoff > max_time / SECSPERDAY) | 3055 if (dayoff > max_time / SECSPERDAY) |
2888 return max_time; | 3056 return max_time; |
2889 t = (zic_t) dayoff * SECSPERDAY; | 3057 t = (zic_t) dayoff * SECSPERDAY; |
2890 return tadd(t, rp->r_tod); | 3058 return tadd(t, rp->r_tod); |
2891 } | 3059 } |
2892 | 3060 |
2893 static void | 3061 static void |
2894 newabbr(string) | 3062 newabbr(const char *const string) |
2895 const char * const» string; | |
2896 { | 3063 { |
2897 register int i; | 3064 register int i; |
2898 | 3065 |
2899 if (strcmp(string, GRANDPARENTED) != 0) { | 3066 if (strcmp(string, GRANDPARENTED) != 0) { |
2900 register const char * cp; | 3067 register const char * cp; |
2901 » » register char *»» wp; | 3068 » » const char *» » mp; |
2902 | 3069 |
2903 /* | 3070 /* |
2904 ** Want one to ZIC_MAX_ABBR_LEN_WO_WARN alphabetics | 3071 ** Want one to ZIC_MAX_ABBR_LEN_WO_WARN alphabetics |
2905 ** optionally followed by a + or - and a number from 1 to 14. | 3072 ** optionally followed by a + or - and a number from 1 to 14. |
2906 */ | 3073 */ |
2907 cp = string; | 3074 cp = string; |
2908 » » wp = NULL; | 3075 » » mp = NULL; |
2909 while (isascii((unsigned char) *cp) && | 3076 while (isascii((unsigned char) *cp) && |
2910 isalpha((unsigned char) *cp)) | 3077 isalpha((unsigned char) *cp)) |
2911 ++cp; | 3078 ++cp; |
2912 if (cp - string == 0) | 3079 if (cp - string == 0) |
2913 wp = _("time zone abbreviation lacks alphabetic at start"); | 3080 mp = _("time zone abbreviation lacks alphabetic at start"); |
2914 » » if (noise && cp - string > 3) | 3081 » » if (noise && cp - string < 3) |
2915 wp = _("time zone abbreviation has more than 3 alphabetics"); | 3082 mp = _("time zone abbreviation has fewer than 3 alphabetics"); |
2916 if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN) | 3083 if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN) |
2917 wp = _("time zone abbreviation has too many alphabetics"); | 3084 mp = _("time zone abbreviation has too many alphabetics"); |
2918 » » if (wp == NULL && (*cp == '+' || *cp == '-')) { | 3085 » » if (mp == NULL && (*cp == '+' || *cp == '-')) { |
2919 ++cp; | 3086 ++cp; |
2920 if (isascii((unsigned char) *cp) && | 3087 if (isascii((unsigned char) *cp) && |
2921 isdigit((unsigned char) *cp)) | 3088 isdigit((unsigned char) *cp)) |
2922 if (*cp++ == '1' && | 3089 if (*cp++ == '1' && |
2923 *cp >= '0' && *cp <= '4') | 3090 *cp >= '0' && *cp <= '4') |
2924 ++cp; | 3091 ++cp; |
2925 } | 3092 } |
2926 if (*cp != '\0') | 3093 if (*cp != '\0') |
2927 wp = _("time zone abbreviation differs from POSIX standard"); | 3094 mp = _("time zone abbreviation differs from POSIX standard"); |
2928 » » if (wp != NULL) { | 3095 » » if (mp != NULL) |
2929 » » » wp = ecpyalloc(wp); | 3096 » » » warning("%s (%s)", mp, string); |
2930 » » » wp = ecatalloc(wp, " ("); | |
2931 » » » wp = ecatalloc(wp, string); | |
2932 » » » wp = ecatalloc(wp, ")"); | |
2933 » » » warning(wp); | |
2934 » » » ifree(wp); | |
2935 » » } | |
2936 } | 3097 } |
2937 i = strlen(string) + 1; | 3098 i = strlen(string) + 1; |
2938 if (charcnt + i > TZ_MAX_CHARS) { | 3099 if (charcnt + i > TZ_MAX_CHARS) { |
2939 error(_("too many, or too long, time zone abbreviations")); | 3100 error(_("too many, or too long, time zone abbreviations")); |
2940 exit(EXIT_FAILURE); | 3101 exit(EXIT_FAILURE); |
2941 } | 3102 } |
2942 (void) strcpy(&chars[charcnt], string); | 3103 (void) strcpy(&chars[charcnt], string); |
2943 » charcnt += eitol(i); | 3104 » charcnt += i; |
2944 } | 3105 } |
2945 | 3106 |
2946 static int | 3107 static int |
2947 mkdirs(argname) | 3108 mkdirs(char *argname) |
2948 char *» » argname; | |
2949 { | 3109 { |
2950 register char * name; | 3110 register char * name; |
2951 register char * cp; | 3111 register char * cp; |
2952 | 3112 |
2953 if (argname == NULL || *argname == '\0') | 3113 if (argname == NULL || *argname == '\0') |
2954 return 0; | 3114 return 0; |
2955 cp = name = ecpyalloc(argname); | 3115 cp = name = ecpyalloc(argname); |
2956 while ((cp = strchr(cp + 1, '/')) != 0) { | 3116 while ((cp = strchr(cp + 1, '/')) != 0) { |
2957 *cp = '\0'; | 3117 *cp = '\0'; |
2958 #ifndef unix | 3118 #ifdef HAVE_DOS_FILE_NAMES |
2959 /* | 3119 /* |
2960 ** DOS drive specifier? | 3120 ** DOS drive specifier? |
2961 */ | 3121 */ |
2962 if (isalpha((unsigned char) name[0]) && | 3122 if (isalpha((unsigned char) name[0]) && |
2963 name[1] == ':' && name[2] == '\0') { | 3123 name[1] == ':' && name[2] == '\0') { |
2964 *cp = '/'; | 3124 *cp = '/'; |
2965 continue; | 3125 continue; |
2966 } | 3126 } |
2967 #endif /* !defined unix */ | 3127 #endif |
2968 if (!itsdir(name)) { | 3128 if (!itsdir(name)) { |
2969 /* | 3129 /* |
2970 ** It doesn't seem to exist, so we try to create it. | 3130 ** It doesn't seem to exist, so we try to create it. |
2971 ** Creation may fail because of the directory being | 3131 ** Creation may fail because of the directory being |
2972 ** created by some other multiprocessor, so we get | 3132 ** created by some other multiprocessor, so we get |
2973 ** to do extra checking. | 3133 ** to do extra checking. |
2974 */ | 3134 */ |
2975 if (mkdir(name, MKDIR_UMASK) != 0) { | 3135 if (mkdir(name, MKDIR_UMASK) != 0) { |
2976 const char *e = strerror(errno); | 3136 const char *e = strerror(errno); |
2977 | 3137 |
2978 if (errno != EEXIST || !itsdir(name)) { | 3138 if (errno != EEXIST || !itsdir(name)) { |
2979 (void) fprintf(stderr, | 3139 (void) fprintf(stderr, |
2980 _("%s: Can't create directory %s: %s\n"), | 3140 _("%s: Can't create directory %s: %s\n"), |
2981 progname, name, e); | 3141 progname, name, e); |
2982 » » » » » ifree(name); | 3142 » » » » » free(name); |
2983 return -1; | 3143 return -1; |
2984 } | 3144 } |
2985 } | 3145 } |
2986 } | 3146 } |
2987 *cp = '/'; | 3147 *cp = '/'; |
2988 } | 3148 } |
2989 » ifree(name); | 3149 » free(name); |
2990 return 0; | 3150 return 0; |
2991 } | 3151 } |
2992 | 3152 |
2993 static long | |
2994 eitol(i) | |
2995 const int i; | |
2996 { | |
2997 long l; | |
2998 | |
2999 l = i; | |
3000 if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) { | |
3001 (void) fprintf(stderr, | |
3002 _("%s: %d did not sign extend correctly\n"), | |
3003 progname, i); | |
3004 exit(EXIT_FAILURE); | |
3005 } | |
3006 return l; | |
3007 } | |
3008 | |
3009 /* | 3153 /* |
3010 ** UNIX was a registered trademark of The Open Group in 2003. | 3154 ** UNIX was a registered trademark of The Open Group in 2003. |
3011 */ | 3155 */ |
OLD | NEW |