49 #if defined (SUPPRESS_STRLEN_WARNING) 50 #define strlen(s1) ((int) strlen(s1)) 53 #define TZ_FILENAME_MAX_LEN 17 54 #define TZ_MAX_LINE_LEN 512 55 #define TZ_OFFRULE_PREFIX_TAB_COUNT 3 57 #define TZ_COORDINATES_MAX_SIZE 16 58 #define TZ_COMMENTS_MAX_SIZE 92 59 #define TZ_RULE_LETTER_ABBREV_MAX_SIZE 8 60 #define TZ_RULE_TYPE_MAX_SIZE 4 62 #if defined(_WIN32) || defined(WINDOWS) || defined(WIN64) 63 #define PATH_PARTIAL_TIMEZONES_FILE "timezones\\tzlib\\timezones.c" 65 #define PATH_PARTIAL_TIMEZONES_FILE "timezones/tzlib/timezones.c" 80 TZF_WINDOWS_IANA_ZONES_MAP
117 {TZF_WINDOWS_IANA_ZONES_MAP,
"windowsZones.xml"}
205 char current_file[PATH_MAX];
238 #define TZ_CAL_ABBREV_SIZE 4 240 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 243 {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" };
245 #define STR_SKIP_LEADING_SPACES(str) \ 246 while ((str) != NULL && *(str) == ' ') \ 260 #define TZC_ERR_GENERIC -1 261 #define TZC_ERR_INVALID_PACKAGE -2 262 #define TZC_ERR_BAD_TZ_LINK -3 263 #define TZC_ERR_OUT_OF_MEMORY -4 264 #define TZC_ERR_INVALID_VALUE -5 265 #define TZC_ERR_INVALID_TIME -6 266 #define TZC_ERR_ZONE_RULE_UNORDERED -7 267 #define TZC_ERR_INVALID_DATETIME -8 268 #define TZC_ERR_INVALID_DS_RULE -9 269 #define TZC_ERR_CANT_READ_VALUE -10 270 #define TZC_ERR_PARSING_FAILED -11 271 #define TZC_ERR_DS_INVALID_DATE -12 272 #define TZC_ERR_FILE_NOT_ACCESSIBLE -13 273 #define TZC_ERR_INVALID_COUNTRY -14 274 #define TZC_ERR_INVALID_ZONE -15 275 #define TZC_ERR_ADD_ZONE -16 276 #define TZC_ERR_LINKING_TRUE_ZONES -17 277 #define TZC_ERR_LAST_ERROR -18 283 "Error encountered when %s %s!",
285 "Invalid timezone package! File %s not found in folder %s.",
287 "Invalid link definition (s1: %s, s2: %s). " "Format error or invalid data encountered.",
289 "Memory exhausted when allocating %d items of type '%s'.",
291 "Invalid %s. Value %s is empty or invalid.",
293 "Invalid or empty time value %s found in %s.",
295 "Timezone offset rules are not fully sorted. Rule %s is out of order. %s",
297 "Invalid datetime value %s found in %s.",
299 "Invalid daylight saving rule found: %s %s",
301 "Unable to read %s value. Context: %s.",
303 "Error encountered when parsing %. Context: %s.",
305 "Invalid %d. The resulting date is not valid in the given context (%s).",
307 "The file at %s is missing or not accessible for %s.",
309 "Invalid line for country definition:%s. %s",
311 "Invalid line for zone definition. Line: %s. Values: %s",
313 "Error encountered when adding zone %s %s",
315 "Error! Found a link between %s and %s, which are fully defined timezones." 323 #define LOG_TZC_SET_CURRENT_CONTEXT(tzd_raw, f, l) \ 325 strcpy (tzd_raw->context.current_file, f); \ 326 tzd_raw->context.current_line = l; \ 329 #define TZC_ERR_MSG_MAX_SIZE 512 331 #define TZC_CONTEXT(tzd_raw) (&((tzd_raw)->context)) 333 #define TZC_LOG_ERROR_1ARG(context, err_code, s1) \ 334 tzc_log_error ((context), (err_code), (s1), "") 336 #define TZC_LOG_ERROR_2ARG(context, err_code, s1, s2) \ 337 tzc_log_error ((context), (err_code), (s1), (s2)) 339 #define DUPLICATE_STR(a, b) \ 343 err_status = ER_OUT_OF_VIRTUAL_MEMORY; \ 344 er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, err_status, 1, (size_t) 0); \ 349 #define INIT_COUNTRY(dst, src) \ 351 strcpy ((dst)->code, (src)->code); \ 352 strcpy ((dst)->full_name, (src)->full_name); \ 355 #define PRINT_STRING_TO_C_FILE(fp, val, len) \ 358 fprintf (fp, "\""); \ 359 for (istr = 0; istr < len; istr++) \ 361 fprintf (fp, "\\x%02X", (unsigned char) val[istr]); \ 363 fprintf (fp, "\""); \ 366 #define PRINT_STRING_VAR_TO_C_FILE(fp, valname, val) \ 368 fprintf (fp, "\n" SHLIB_EXPORT_PREFIX "const char " valname "[] = "); \ 369 PRINT_STRING_TO_C_FILE (fp, val, strlen (val)); \ 370 fprintf (fp, ";\n"); \ 373 #define BUF_PUT_INT32(buf,v) \ 375 unsigned int nv = htonl(v); \ 376 *((unsigned char *) (buf)) = ((unsigned char *) &nv)[3]; \ 377 buf = (char *) (buf) + 1; \ 378 *((unsigned char *) (buf)) = ((unsigned char *) &nv)[2]; \ 379 buf = (char *) (buf) + 1; \ 380 *((unsigned char *) (buf)) = ((unsigned char *) &nv)[1]; \ 381 buf = (char *) (buf) + 1; \ 382 *((unsigned char *) (buf)) = ((unsigned char *) &nv)[0]; \ 383 buf = (char *) (buf) + 1; \ 386 #define BUF_PUT_INT16(buf,v) \ 388 unsigned short nv = htons(v); \ 389 *((unsigned char *) (buf)) = ((unsigned char *) &nv)[1];\ 390 buf = (char *) (buf) + 1; \ 391 *((unsigned char *) (buf)) = ((unsigned char *) &nv)[0];\ 392 buf = (char *) (buf) + 1; \ 402 static int tzc_add_zone (
const char *zone,
const char *coord,
const char *code,
const char *comments,
407 unsigned char sec,
bool corr_minus,
bool leap_is_rolling);
411 static bool tzc_is_valid_date (
const int day,
const int month,
const int year_start,
const int year_end);
427 static int str_month_to_int (
const char *month,
int *month_num,
const char **str_next);
428 static int str_day_to_int (
const char *str_in,
int *day_num,
const char **str_next);
429 static int str_read_day_var (
const char *str,
const int month,
int *
type,
int *day,
int *bound,
const char **str_next);
450 static void tzc_build_filepath (
char *path,
size_t size,
const char *dir,
const char *filename);
471 static int tzc_extend (
TZ_DATA * tzd);
476 #if defined (SA_MODE) 481 static int comp_func_tz_windows_zones (
const void *arg1,
const void *arg2);
482 static int xml_start_mapZone (
void *data,
const char **attr);
484 static int tzc_load_windows_iana_map (
TZ_DATA *
tz_data,
const char *input_folder);
490 XML_ELEMENT_DEF windows_zones_elem_windowsZones = {
"supplementalData windowsZones", 2,
NULL,
494 XML_ELEMENT_DEF windows_zones_elem_mapTimezones = {
"supplementalData windowsZones mapTimezones", 3,
NULL,
498 XML_ELEMENT_DEF windows_zones_elem_mapZone = {
"supplementalData windowsZones mapTimezones mapZone", 4,
504 &windows_zones_elem_supplementalData,
505 &windows_zones_elem_windowsZones,
506 &windows_zones_elem_mapTimezones,
507 &windows_zones_elem_mapZone
527 #if !defined(WINDOWS) 528 if (snprintf (path, size - 1,
"%s/%s", dir, filename) < 0)
533 if (snprintf (path, size - 1,
"%s\\%s", dir, filename) < 0)
562 sharp = strchr (str,
'#');
569 for (i = str_len - 1; i >= 0 &&
char_isspace (str[i]); i--)
589 char temp_path[PATH_MAX];
612 #if defined (SA_MODE) 628 const char *timezones_dot_c_filepath,
char *checksum)
633 bool write_checksum =
false;
634 char default_output_file_path[PATH_MAX] = { 0 };
636 memset (&tzd, 0,
sizeof (tzd));
637 memset (&tzd_raw, 0,
sizeof (tzd_raw));
681 err_status = tzc_load_windows_iana_map (&tzd, input_folder);
691 write_checksum =
true;
692 err_status = tzc_extend (&tzd);
719 if (timezones_dot_c_filepath ==
NULL)
722 timezones_dot_c_filepath = default_output_file_path;
730 if (write_checksum ==
true)
838 if (tzd->windows_iana_map !=
NULL)
840 free (tzd->windows_iana_map);
845 memset (&tzd, 0,
sizeof (tzd));
965 for (j = 0; j < tzd_raw->
zone_count && !found; j++)
967 zone = &(tzd_raw->
zones[j]);
982 while (i < tzd_raw->ruleset_count)
986 if (i < tzd_raw->ruleset_count - 1)
1005 if (ruleset ==
NULL)
1038 snprintf (err_msg,
sizeof (err_msg) - 1,
"UPDATE OPTION NOT IMPLEMENTED!");
1065 int i, file_index = -1;
1066 char country_filepath[PATH_MAX] = { 0 };
1068 char *str_country_name;
1077 assert (file_index == -1);
1083 assert (file_index != -1);
1085 tzc_build_filepath (country_filepath,
sizeof (country_filepath), input_folder, tz_Files[file_index].
name);
1086 fp =
fopen_ex (country_filepath,
"rt");
1100 while (fgets (str,
sizeof (str), fp))
1111 str_country_name = strchr (str,
'\t');
1112 if (str_country_name ==
NULL ||
strlen (str_country_name + 1) == 0
1123 if (temp_tz_country ==
NULL)
1137 memset (temp_tz_country, 0,
sizeof (temp_tz_country[0]));
1141 temp_tz_country->
id = -1;
1164 int i, file_index = -1;
1165 char zone_filepath[PATH_MAX] = { 0 };
1169 char *col_code, *col_coord, *col_tz_name, *col_comments;
1171 col_code = col_coord = col_tz_name = col_comments =
NULL;
1178 assert (file_index == -1);
1184 assert (file_index != -1);
1187 fp =
fopen_ex (zone_filepath,
"rt");
1201 while (fgets (str,
sizeof (str), fp))
1213 col_code = strtok (str,
"\t");
1214 col_coord = strtok (
NULL,
"\t");
1215 col_tz_name = strtok (
NULL,
"\t");
1216 col_comments = strtok (
NULL,
"\t");
1225 sprintf (temp_msg,
"code: %s, coordinates: %s, name: %s, comments: %s", col_code ==
NULL ?
"null" : col_code,
1226 col_coord ==
NULL ?
"null" : col_coord, col_tz_name ==
NULL ?
"null" : col_tz_name,
1227 col_comments ==
NULL ?
"null/empty" : col_comments);
1234 err_status =
tzc_add_zone (col_tz_name, col_code, col_coord, col_comments, tzd_raw, &temp_zone_info);
1265 char filepath[PATH_MAX] = { 0 };
1268 char *entry_type_str =
NULL;
1270 char *next_token =
NULL;
1271 bool check_zone =
false;
1290 while (fgets (str,
sizeof (str), fp))
1303 if (str[0] ==
'\t' && str[1] ==
'\t' && str[2] ==
'\t')
1318 entry_type_str = strtok (str,
" \t");
1320 if (strcmp (entry_type_str,
"Link") == 0)
1322 char *zone_name =
NULL, *alias =
NULL;
1324 zone_name = strtok (
NULL,
" \t");
1325 alias = strtok (
NULL,
"\t");
1341 else if (strcmp (entry_type_str,
"Zone") == 0)
1343 next_token = strtok (
NULL,
" \t");
1350 err_status =
tzc_get_zone (tzd_raw, next_token, &last_zone);
1361 if (last_zone ==
NULL)
1376 else if (strcmp (entry_type_str,
"Rule") == 0)
1417 int i, file_index = -1;
1418 char filepath[PATH_MAX] = { 0 };
1421 char *entry_type_str =
NULL;
1422 char *next_token =
NULL, *zone_name =
NULL, *alias =
NULL;
1435 assert (file_index != -1);
1449 while (fgets (str,
sizeof (str), fp))
1460 entry_type_str = strtok (str,
"\t");
1462 assert (entry_type_str !=
NULL && strcmp (entry_type_str,
"Link") == 0);
1464 next_token = str +
strlen (entry_type_str) + 1;
1465 zone_name = strtok (next_token,
"\t");
1473 next_token = zone_name +
strlen (zone_name) + 1;
1474 while (*next_token ==
'\t')
1478 alias = strtok (next_token,
"\t");
1514 int i, file_index = -1, leap_year, leap_month_num, leap_day_num;
1515 int leap_time_h, leap_time_m, leap_time_s;
1516 char filepath[PATH_MAX] = { 0 };
1519 const char *next_token, *str_next, *entry_type_str;
1520 bool leap_corr_minus =
false;
1521 bool leap_is_rolling =
false;
1526 next_token = str_next = entry_type_str =
NULL;
1527 leap_year = leap_month_num = leap_day_num = -1;
1528 leap_time_h = leap_time_m = leap_time_s = -1;
1538 assert (file_index != -1);
1555 while (fgets (str,
sizeof (str), fp))
1557 const char *str_end;
1566 str_end = str +
strlen (str);
1568 entry_type_str = strtok (str,
"\t");
1569 assert (entry_type_str !=
NULL && strcmp (entry_type_str,
"Leap") == 0);
1571 next_token = strtok (
NULL,
"\t");
1576 next_token ==
NULL ?
"" : next_token);
1580 next_token = strtok (
NULL,
"\t");
1585 next_token ==
NULL ?
"" : next_token);
1589 next_token = strtok (
NULL,
"\t");
1594 next_token ==
NULL ?
"" : next_token);
1598 next_token = strtok (
NULL,
"\t");
1599 if (
tz_str_read_time (next_token, str_end,
false,
true, &leap_time_h, &leap_time_m, &leap_time_s, &str_next) !=
1604 next_token ==
NULL ?
"" : next_token);
1608 next_token = strtok (
NULL,
"\t");
1609 if (strlen (next_token) != 1 || ((*next_token !=
'+') && (*next_token !=
'-')))
1613 next_token ==
NULL ?
"" : next_token);
1616 if (*next_token ==
'-')
1618 leap_corr_minus =
true;
1621 next_token = strtok (
NULL,
"\t");
1622 if (strlen (next_token) != 1 || ((*next_token !=
'R') && (*next_token !=
'S')))
1626 next_token ==
NULL ?
"" : next_token);
1629 if (*next_token ==
'R')
1631 leap_is_rolling =
true;
1634 if (
tzc_add_leap_sec (tzd_raw, leap_year, leap_month_num, leap_day_num, leap_time_h, leap_time_m, leap_time_s,
1635 leap_corr_minus, leap_is_rolling) !=
NO_ERROR)
1674 if (temp_link ==
NULL)
1678 sprintf (err_msg,
"%d", tzd_raw->
link_count + 1);
1684 tzd_raw->
links = temp_link;
1687 memset (temp_link, 0,
sizeof (temp_link[0]));
1689 strcpy (temp_link->
name, zone);
1690 strcpy (temp_link->
alias, alias);
1707 unsigned char sec,
bool corr_minus,
bool leap_is_rolling)
1719 if (temp_leap_sec ==
NULL)
1732 memset (temp_leap_sec, 0,
sizeof (temp_leap_sec[0]));
1735 temp_leap_sec->
year = (
unsigned short) year;
1736 temp_leap_sec->
month = (
unsigned char) month;
1737 temp_leap_sec->
day = (
unsigned char) day;
1739 if (hour != 23 || min != 59 || sec != 60)
1747 temp_leap_sec->
corr_negative = (
unsigned char) (corr_minus ? 1 : 0);
1748 temp_leap_sec->
is_rolling = (
unsigned char) (leap_is_rolling ? 1 : 0);
1779 if (temp_zone_info ==
NULL)
1783 sprintf (err_msg,
"%d", tzd_raw->
zone_count + 1);
1788 tzd_raw->
zones = temp_zone_info;
1793 memset (temp_zone_info, 0,
sizeof (temp_zone_info[0]));
1798 strcpy (temp_zone_info->
code, code);
1802 temp_zone_info->
code[0] =
'\0';
1813 strcpy (temp_zone_info->
full_name, zone);
1815 if (comments !=
NULL)
1817 strcpy (temp_zone_info->
comments, comments);
1821 temp_zone_info->
comments[0] =
'\0';
1824 temp_zone_info->
id = -1;
1826 *new_zone = temp_zone_info;
1851 *zone = &(tzd_raw->
zones[
i]);
1874 const char *str_dummy =
NULL;
1875 char *rule_text_end;
1876 int gmt_off_num = 0;
1877 bool is_numeric_gmt_off =
false;
1881 rule_text_end = rule_text +
strlen (rule_text);
1883 gmt_off = strtok (rule_text,
"\t ");
1893 if (strcmp (gmt_off,
"0") == 0)
1895 is_numeric_gmt_off =
true;
1898 else if (strchr (gmt_off,
':') ==
NULL)
1901 err_status =
tz_str_read_number (gmt_off, rule_text_end,
true,
true, &gmt_off_num, &str_dummy);
1907 is_numeric_gmt_off =
true;
1909 rules = strtok (
NULL,
" \t");
1910 format = strtok (
NULL,
" \t");
1919 until = strtok (
NULL,
"\t");
1932 if (temp_rule ==
NULL)
1945 memset (temp_rule, 0,
sizeof (temp_rule[0]));
1947 if (is_numeric_gmt_off)
1949 temp_rule->
gmt_off = gmt_off_num * 3600;
1964 strcpy (temp_rule->
format, format);
2011 *next = (
char *) str + 1;
2030 char *col_name, *col_from, *col_to, *col_type, *col_in, *col_on, *col_at;
2031 char *col_save, *col_letters;
2032 const char *str_cursor =
NULL;
2033 const char *rule_text_end;
2037 rule_text_end = rule_text +
strlen (rule_text);
2039 col_name = strtok (rule_text,
" \t");
2040 col_from = strtok (
NULL,
" \t");
2041 col_to = strtok (
NULL,
" \t");
2042 col_type = strtok (
NULL,
" \t");
2043 col_in = strtok (
NULL,
" \t");
2044 col_on = strtok (
NULL,
" \t");
2045 col_at = strtok (
NULL,
" \t");
2046 col_save = strtok (
NULL,
" \t");
2047 col_letters = strtok (
NULL,
" \t");
2057 "NAME: '%s', FROM: '%s', TO: '%s', TYPE: '%s', " 2058 "IN: '%s', ON: '%s', AT: '%s', SAVE: '%s', LETTER/S: '%s'", col_name ==
NULL ?
"" : col_name,
2059 col_from ==
NULL ?
"" : col_from, col_to ==
NULL ?
"" : col_to, col_type ==
NULL ?
"" : col_type,
2060 col_in ==
NULL ?
"" : col_in, col_on ==
NULL ?
"" : col_on, col_at ==
NULL ?
"" : col_at,
2061 col_save ==
NULL ?
"" : col_save, col_letters ==
NULL ?
"" : col_letters);
2087 if (ds_ruleset ==
NULL)
2093 if (ds_ruleset ==
NULL)
2106 memset (ds_ruleset, 0,
sizeof (ds_ruleset[0]));
2107 strcpy (ds_ruleset->
name, col_name);
2114 if (ds_rule ==
NULL)
2118 sprintf (err_msg,
"%d", ds_ruleset->
rule_count + 1);
2124 ds_ruleset->
rules = ds_rule;
2127 memset (ds_rule, 0,
sizeof (ds_rule[0]));
2141 if (strcmp (col_to,
"only") == 0)
2145 else if (strcmp (col_to,
"max") == 0)
2157 ds_rule->
to_year = (short) val_read;
2161 strcpy (ds_rule->
type, col_type);
2170 if (val_read < TZ_MON_JAN || val_read >
TZ_MON_DEC)
2174 sprintf (temp_msg,
"found value: %d", val_read);
2179 ds_rule->
in_month = (
unsigned char) val_read;
2188 if (strcmp (col_at,
"0") == 0)
2208 if (strlen (col_save) == 1)
2247 int type = -1, bound = -1;
2248 const char *str_cursor =
NULL;
2267 if (day_num < 0 || day_num > 30)
2271 sprintf (temp_msg,
"found value: %d", day_num);
2283 sprintf (temp_msg,
"Day: %d, Month: %d, Year: %d", day_num, dest->
in_month, dest->
from_year);
2329 if (day < 0 || day > 30 || month < TZ_MON_JAN || month >
TZ_MON_DEC || year_start < 0 || year_end <= year_start
2337 for (year = year_start; year < year_end; year++)
2367 if (tzd_raw ==
NULL)
2393 zone = &(tzd_raw->
zones[
i]);
2434 int i, j, tz_name_index, tz_alias_index;
2440 tz_link = &(tzd_raw->
links[
i]);
2442 tz_alias_index = -1;
2443 for (j = 0; j < tzd_raw->
zone_count && (tz_name_index == -1 || tz_alias_index == -1); j++)
2445 tz_zone = &(tzd_raw->
zones[j]);
2449 assert (tz_name_index != tz_alias_index);
2454 assert (tz_name_index != tz_alias_index);
2458 if (tz_name_index != -1 && tz_alias_index != -1)
2462 bool remove_link =
false;
2463 tz_zone = &(tzd_raw->
zones[tz_name_index]);
2486 if (i < tzd_raw->link_count - 1)
2488 tz_link = &(tzd_raw->
links[
i]);
2495 if (tz_link ==
NULL)
2499 sprintf (err_msg,
"%d", tzd_raw->
link_count - 1);
2504 tzd_raw->
links = tz_link;
2509 free (tzd_raw->
links);
2635 if (cur_id < tzd_raw->countries[i].
id)
2652 if (cur_id < tzd_raw->zones[i].
id)
2660 if (tzd_raw->
zones[i].
id == -1)
2685 char **temp_aliases =
NULL;
2718 zone = &(tzd_raw->
zones[j]);
2726 alias = link->
alias;
2734 temp_aliases = (
char **) realloc (zone->
aliases, (zone->
alias_count + 1) *
sizeof (
char *));
2736 if (temp_aliases ==
NULL)
2767 zone = &(tzd_raw->
zones[
i]);
2775 zone_search = &(tzd_raw->
zones[j]);
2802 if (*((
int *) a) == *((
int *) b))
2806 else if (*((
int *) a) < *((
int *) b))
2826 #define ABS(i) ((i) >= 0 ? (i) : -(i)) 2827 #define MAX_DS_CHANGES_YEAR 1000 2828 int start_year, end_year, year;
2831 int last_ds_change_julian_date;
2835 *ds_changes_cnt = 0;
2837 for (i = 0; i < ds_rule_set->
count; i++)
2856 end_year = start_year;
2858 end_year = end_year + 1;
2860 if (end_year < 2038)
2866 for (year = start_year; year < end_year; year++)
2870 for (i = 0; i < ds_rule_set->
count; i++)
2873 int ds_change_julian_date, first_day_year_julian, last_day_year_julian;
2877 if (year >= ds_rule->
from_year && year <= ds_rule->to_year)
2899 all_ds_changes_julian_date[(*ds_changes_cnt)++] = ds_change_julian_date;
2904 if (
ABS (ds_change_julian_date - first_day_year_julian) <= 1
2905 ||
ABS (ds_change_julian_date - last_day_year_julian) <= 1)
2907 printf (
"DS ruleset: %s, Year: %d, Change on : %s \n", ds_rule_set->
ruleset_name, year,
2914 printf (
"DS ruleset: %s, Year: %d, found %d matching rules\n", ds_rule_set->
ruleset_name, year, count);
2918 qsort (all_ds_changes_julian_date, *ds_changes_cnt,
sizeof (
int),
compare_ints);
2919 last_ds_change_julian_date = all_ds_changes_julian_date[0];
2920 for (i = 1; i < *ds_changes_cnt; i++)
2923 int month1, day1, year1;
2924 int month2, day2, year2;
2926 date_diff = all_ds_changes_julian_date[
i] - last_ds_change_julian_date;
2933 printf (
"DS ruleset: %s, DS change after %d days, Date1: %d-%d-%d," "Date1: %d-%d-%d\n",
2934 ds_rule_set->
ruleset_name, date_diff, day1, month1, year1, day2, month2, year2);
2938 printf (
"Ruleset %s , total changes : %d (%d - %d)\n", ds_rule_set->
ruleset_name, *ds_changes_cnt, start_year,
2957 int alias_count, offset_rule_id;
3062 if (strstr (raw_offrule->
format,
"%s") !=
NULL)
3081 save_format = strchr (raw_offrule->
format,
'/');
3083 if (save_format !=
NULL)
3085 *save_format =
'\0';
3100 if (save_format !=
NULL)
3107 sprintf (err_msg,
"%d",
strlen (save_format));
3136 const char *dummy =
NULL;
3193 int zone_id = tzd_raw->
zones[
i].
id;
3274 int total_ds_changes = 0;
3275 int max_ds_changes = 0;
3281 if (ds_changes > max_ds_changes)
3283 max_ds_changes = ds_changes;
3285 total_ds_changes += ds_changes;
3287 printf (
"Total DS changes: %d; maximum changes in a ruleset :%d\n", total_ds_changes, max_ds_changes);
3321 int i, j, cur_rule_index = 0;
3365 int to_year_max = 0;
3366 bool has_default_abbrev =
true;
3367 const char *prev_letter_abbrev =
NULL;
3383 for (j = 0; j < ruleset->
count; j++)
3385 rule = &(tzd->
ds_rules[cur_rule_index]);
3403 if (has_default_abbrev ==
true && rule_raw->
save_time == 0)
3407 || (prev_letter_abbrev !=
NULL && strcmp (rule->
letter_abbrev, prev_letter_abbrev) != 0))
3409 has_default_abbrev =
false;
3419 if (rule->
to_year > to_year_max)
3427 const char empty[2] = {
'-', 0 };
3428 if (has_default_abbrev ==
true && prev_letter_abbrev !=
NULL)
3434 prev_letter_abbrev = empty;
3441 sprintf (err_msg,
"%d",
strlen (prev_letter_abbrev));
3467 const char *str_cursor;
3468 const char *str_next;
3469 const char *str_end;
3471 int type = -1, day = -1, bound = -1;
3472 int hour = 0,
min = 0, sec = 0;
3484 str_end = str +
strlen (str);
3486 str_cursor = strtok (str,
" ");
3496 offset_rule->
until_year = (
unsigned short) val_read;
3508 str_cursor = strtok (
NULL,
" ");
3520 if (val_read < TZ_MON_JAN || val_read >
TZ_MON_DEC)
3524 sprintf (temp_msg,
"%d", val_read);
3529 offset_rule->
until_mon = (
unsigned char) val_read;
3532 str_cursor = strtok (
NULL,
" ");
3553 sprintf (temp_msg,
"Day: %d, Month: %d, Year: %d", day, offset_rule->
until_mon, offset_rule->
until_year);
3569 sprintf (temp_msg,
"Day: %d, Month: %d, Year: %d", month_day, offset_rule->
until_mon,
3584 int max_days_in_month;
3595 bound = max_days_in_month - 1;
3604 sprintf (temp_msg,
"Day: %d, Month: %d, Year: %d", month_day, offset_rule->
until_mon,
3620 offset_rule->
until_day = (
unsigned char) day;
3623 str_cursor = strtok (
NULL,
" ");
3635 sprintf (temp_msg,
"[hour: %d, min: %d, sec: %d]", hour,
min, sec);
3641 str_cursor = str_next;
3648 offset_rule->
until_hour = (
unsigned char) hour;
3650 offset_rule->
until_sec = (
unsigned char) sec;
3693 if (i >= TZ_MON_COUNT)
3745 if (i >= TZ_WEEK_DAY_COUNT)
3782 char str_last[5] =
"last";
3783 const char *str_cursor;
3784 const char *str_end;
3785 const int days_of_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3791 str_end = str +
strlen (str);
3805 if (*str_next != str)
3814 if (strncmp (str, str_last, strlen (str_last)) == 0)
3816 str_cursor = str +
strlen (str_last);
3827 sprintf (temp_msg,
"%d", day_num);
3835 *bound = days_of_month[month] - 1;
3848 assert (*(str_cursor + 1) ==
'=');
3849 if (*str_cursor ==
'>')
3853 else if (*str_cursor ==
'<')
3873 *bound = day_num - 1;
3900 if (c1->
id == -1 && c2->
id == -1)
3907 if (c1->
id != -1 && c2->
id != -1)
3909 return (c1->
id < c2->
id) ? -1 : 1;
3941 if (zone1->
id == -1 && zone2->
id == -1)
3948 if (zone1->
id != -1 && zone2->
id != -1)
3950 return (zone1->
id < zone2->
id) ? -1 : 1;
3999 int r1_until, r2_until;
4019 if (r1_until == r2_until)
4029 if (r1_until < r2_until)
4033 else if (r1_until > r2_until)
4063 return strcmp (rs1->
name, rs2->
name);
4077 int ds_rule_month = rule->
in_month;
4085 int ds_rule_weekday, day_month_bound;
4134 return day1 < day2 ? -1 : 1;
4155 return strcmp (name1->
name, name2->
name);
4172 printf (
"%02d", (
int) (seconds / 3600));
4174 printf (
":%02d", (
int) (seconds / 60));
4178 printf (
":%02d", seconds);
4191 char tz_cub_path[PATH_MAX] = { 0 };
4214 fp =
fopen_ex (timezones_dot_c_filepath,
"wt");
4221 #if defined(WINDOWS) 4222 fprintf (fp,
"#include <stdio.h>\n");
4224 fprintf (fp,
"#include <stddef.h>\n");
4226 fprintf (fp,
"#include \"timezone_lib_common.h\"\n\n");
4236 fprintf (fp,
"};\n\n");
4244 fprintf (fp,
"};\n\n");
4255 fprintf (fp,
"};\n\n");
4270 fprintf (fp,
"\t{%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, ", offrule->
gmt_off, offrule->
ds_ruleset,
4276 fprintf (fp,
"NULL, ");
4280 fprintf (fp,
"\"%s\", ", offrule->
std_format);
4285 fprintf (fp,
"NULL, ");
4294 fprintf (fp,
"NULL }");
4298 fprintf (fp,
"\"%s\" }", offrule->
var_format);
4301 if (i < tzd->offset_rule_count - 1)
4303 fprintf (fp,
",\n");
4306 fprintf (fp,
"};\n\n");
4316 fprintf (fp,
"};\n\n");
4327 fprintf (fp,
"};\n\n");
4335 fprintf (fp,
"\t{%d, %d, %d, {%d, %d, %d}, %d, %d, %d, \"%s\"}%s\n", rule->
from_year, rule->
to_year,
4340 fprintf (fp,
"};\n\n");
4348 fprintf (fp,
"\t{%d, %d, %d, %d, %d}%s\n", leap_sec->
year, leap_sec->
month, leap_sec->
day,
4351 fprintf (fp,
"};\n\n");
4353 #if defined(WINDOWS) 4355 fprintf (fp,
"%s const int windows_iana_map_count = %d;\n",
SHLIB_EXPORT_PREFIX, tzd->windows_iana_map_count);
4356 fprintf (fp,
"%s const TZ_WINDOWS_IANA_MAP windows_iana_map[] = {\n",
SHLIB_EXPORT_PREFIX);
4358 for (i = 0; i < tzd->windows_iana_map_count; i++)
4360 fprintf (fp,
"\t{\"%s\", \"%s\", %d}%s\n", tzd->windows_iana_map[i].windows_zone,
4361 tzd->windows_iana_map[i].territory, tzd->windows_iana_map[i].iana_zone_id,
4362 (i == tzd->windows_iana_map_count - 1) ?
"" :
",");
4364 fprintf (fp,
"};\n\n");
4388 int ruleset_id = -1;
4389 int index_bot, index_top;
4393 index_top = ds_ruleset_count - 1;
4395 while (index_bot <= index_top)
4397 ruleset_id = (index_bot + index_top) / 2;
4398 cmp_res = strcmp (ruleset, ds_rulesets[ruleset_id].ruleset_name);
4403 else if (cmp_res < 0)
4405 index_top = ruleset_id - 1;
4409 index_bot = ruleset_id + 1;
4428 int *temp_array =
NULL;
4440 temp_array = (
int *) realloc (*aliases, ((*alias_count) + 1) *
sizeof (int));
4441 if (temp_array ==
NULL)
4445 sprintf (err_msg,
"%d", (*alias_count) + 1);
4450 *aliases = temp_array;
4451 (*aliases)[*alias_count] =
i;
4516 printf (
" %d", offset_rule->
until_day + 1);
4527 printf (
":%02d", offset_rule->
until_sec);
4544 int i, start_index, end_index;
4546 assert (ruleset_id >= 0 && ruleset_id < tzd->ds_ruleset_count);
4549 printf (
"\nDaylight saving ruleset : %s", ruleset->
ruleset_name);
4552 end_index = start_index + ruleset->
count;
4554 for (i = start_index; i < end_index; i++)
4571 printf (
"%d\t", rule->
to_year);
4621 printf (
"\n Summary");
4627 printf (
"\n No. of daylight saving rules: %d", tzd->
ds_rule_count);
4678 int *zone_aliases =
NULL;
4679 int *ds_rulesets_used =
NULL;
4680 int count_ds_rulesets_used = 0;
4681 int *temp_int_array;
4682 int alias_count = 0, start_index = 0;
4683 bool is_first =
true, found;
4697 if (alias_count > 0)
4699 printf (
" Aliases (%d): ", alias_count);
4701 for (j = 0; j < alias_count; j++)
4713 printf (
"%s", tz_name->
name);
4715 if (alias_count > 0)
4727 printf (
"\n Offset rules: \n");
4742 for (j = 0; j < count_ds_rulesets_used && !found; j++)
4744 if (ds_rulesets_used[j] == offset_rule->
ds_ruleset)
4753 (
int *) realloc (ds_rulesets_used, (count_ds_rulesets_used + 1) *
sizeof (ds_rulesets_used[0]));
4754 if (temp_int_array ==
NULL)
4756 printf (
"\nOUT OF MEMORY!\n");
4759 ds_rulesets_used = temp_int_array;
4760 ds_rulesets_used[count_ds_rulesets_used] = offset_rule->
ds_ruleset;
4761 count_ds_rulesets_used++;
4765 printf (
"\n Found %d daylight saving ruleset(s) used by offset rules\n", count_ds_rulesets_used);
4766 for (i = 0; i < count_ds_rulesets_used; i++)
4772 if (ds_rulesets_used !=
NULL)
4774 free (ds_rulesets_used);
4776 if (zone_aliases !=
NULL)
4778 free (zone_aliases);
4795 printf (
"\n# Leap\tYEAR\tMONTH\tDAY\tHH:MM:SS\tCORR\tR/S\n");
4821 *err_msg_temp =
'\0';
4828 strcat (err_msg, err_msg_temp);
4830 *err_msg_temp =
'\0';
4832 strcat (err_msg, err_msg_temp);
4833 strcat (err_msg,
"\n");
4842 int max_len, temp_len;
4843 int max_len2, temp_len2;
4847 printf (
" COUNTRY MAX NAME LEN: ");
4852 if (temp_len > max_len)
4857 printf (
"%d\n", max_len);
4859 printf (
" DS RULES & RULESETS\n");
4867 if (temp_len > max_len)
4876 if (temp_len > max_len2)
4878 max_len2 = temp_len;
4882 printf (
" DS RULESET MAX NAME LEN: %d\n", max_len);
4883 printf (
" DS RULE MAX LETTER_ABBREV LEN: %d\n\n", max_len2);
4885 printf (
" TIMEZONE\n");
4892 if (temp_len > max_len)
4899 if (temp_len > max_len2)
4901 max_len2 = temp_len;
4907 if (temp_len > max_len3)
4909 max_len3 = temp_len;
4913 printf (
" MAX NAME LEN: %d", max_len);
4914 printf (
" MAX comments LEN: %d", max_len2);
4915 printf (
" MAX coordinates LEN: %d\n", max_len3);
4917 printf (
" TZ_NAMES (timezone names and aliases) MAX NAME LEN: ");
4922 if (temp_len > max_len)
4927 printf (
"%d\n", max_len);
4929 printf (
" TZ_RW_LINKS : \n");
4935 if (temp_len > max_len)
4940 if (temp_len2 > max_len2)
4942 max_len2 = temp_len2;
4945 printf (
" MAX NAME LEN: %d", max_len);
4946 printf (
" MAX ALIAS LEN: %d\n", max_len2);
4949 printf (
" TZ_RAW_OFFSET_RULES : \n");
4960 if (temp_len > max_len)
4965 if (temp_len > max_len2)
4967 max_len2 = temp_len;
4971 printf (
" MAX rules LEN: %d", max_len);
4972 printf (
" MAX format LEN: %d\n", max_len2);
4975 #if defined(WINDOWS) 4984 comp_func_tz_windows_zones (
const void *arg1,
const void *arg2)
5015 xml_start_mapZone (
void *data,
const char **attr)
5019 char *windows_zone =
NULL;
5020 char *iana_zone =
NULL;
5021 char *territory =
NULL;
5023 int len_windows_zone;
5025 int iana_zone_id = -1;
5036 if (tz->windows_iana_map !=
NULL 5037 && strcmp (windows_zone, tz->windows_iana_map[tz->windows_iana_map_count - 1].windows_zone) == 0)
5048 sprintf (err_msg,
"%d", tz->windows_iana_map_count + 1);
5053 len_windows_zone =
strlen (windows_zone);
5054 len_territory =
strlen (territory);
5058 if (temp !=
nullptr)
5065 memmove (temp[tz->windows_iana_map_count].
windows_zone, windows_zone, len_windows_zone);
5066 temp[tz->windows_iana_map_count].
windows_zone[len_windows_zone] =
'\0';
5067 memmove (temp[tz->windows_iana_map_count].
territory, territory, len_territory);
5068 temp[tz->windows_iana_map_count].
territory[len_territory] =
'\0';
5072 if (strcmp (iana_zone, tz->
names[i].
name) == 0)
5079 temp[tz->windows_iana_map_count].
iana_zone_id = iana_zone_id;
5080 tz->windows_iana_map = temp;
5081 tz->windows_iana_map_count++;
5097 tzc_load_windows_iana_map (
TZ_DATA *
tz_data,
const char *input_folder)
5100 char filepath[PATH_MAX] = { 0 };
5109 if (tz_Files[i].
type == TZF_WINDOWS_IANA_ZONES_MAP)
5115 assert (i < tz_File_count);
5118 tz_data->windows_iana_map_count = 0;
5119 tz_data->windows_iana_map =
NULL;
5120 windows_zones_parser.
ud = tz_data;
5123 xml_init_parser (&windows_zones_parser, filepath,
"UTF-8", windows_zones_elements,
5134 qsort (tz_data->windows_iana_map, tz_data->windows_iana_map_count, sizeof (
TZ_WINDOWS_IANA_MAP),
5135 comp_func_tz_windows_zones);
5153 int index_bot, index_top;
5159 while (index_bot <= index_top)
5161 int mid = index_bot + (index_top - index_bot) / 2;
5162 cmp_res = strcmp (timezone_name, tzd->
names[mid].
name);
5167 else if (cmp_res < 0)
5169 index_top = mid - 1;
5173 index_bot = mid + 1;
5191 int index_bot, index_top;
5195 index_top = country_count - 1;
5197 while (index_bot <= index_top)
5199 int mid = index_bot + (index_top - index_bot) / 2;
5201 cmp_res = strcmp (country_name, countries[mid].full_name);
5206 else if (cmp_res < 0)
5208 index_top = mid - 1;
5212 index_bot = mid + 1;
5410 #if defined (SA_MODE) 5430 int all_timezones_count = 0;
5431 int all_timezones_and_aliases_count = 0;
5432 char **all_timezone_names =
NULL;
5433 int start_timezones, start_names, start;
5434 int gmt_off_rule_start, prev_gmt_off_rule_start;
5435 char *timezone_name;
5438 int all_offset_rule_count = 0;
5439 int start_gmt_old, start_gmt_new;
5440 int all_ds_ruleset_count = 0;
5442 char *mark_ruleset =
NULL;
5444 int prev_start_ds_rule = 0, start_ds_rule = 0;
5446 int all_ds_rule_count = 0;
5449 const char *ruleset_name;
5450 bool is_compat =
true;
5451 int start_ds_ruleset_old = 0, start_ds_ruleset_new = 0;
5454 int all_country_count = 0;
5456 char *country_name =
NULL;
5459 bool found_duplicate =
false;
5462 int old_tzd_map_count = 0, tzd_map_count = 0;
5465 char timezone_library_path[PATH_MAX] = { 0 };
5482 if (names[i].is_alias == 0)
5484 all_timezones_count++;
5486 all_timezones_and_aliases_count++;
5490 all_timezones_and_aliases_count += old_tzd.
name_count;
5498 if (country_id == -1)
5500 all_country_count++;
5506 if (all_countries ==
NULL)
5513 all_timezone_names = (
char **) calloc (all_timezones_count,
sizeof (
char *));
5514 if (all_timezone_names ==
NULL)
5522 if (all_timezones ==
NULL)
5529 all_names = (
TZ_NAME *) calloc (all_timezones_and_aliases_count,
sizeof (
TZ_NAME));
5530 if (all_names ==
NULL)
5539 if (old_tzd_offset_rule_map ==
NULL)
5548 if (tzd_offset_rule_map ==
NULL)
5557 if (mark_ruleset ==
NULL)
5571 i = 0, j = 0, k = 0;
5582 else if (comp_res < 0)
5602 while (j < tzd->country_count)
5609 assert (k == all_country_count);
5621 err_status =
init_tz_name (&all_names[start_names], &names[i]);
5626 if (names[i].is_alias == 0)
5628 DUPLICATE_STR (all_timezone_names[start_timezones], names[i].name);
5629 all_timezones[start_timezones] = timezones[names[
i].
zone_id];
5630 all_timezones[start_timezones].
zone_id = start_timezones;
5631 all_names[start_names].
zone_id = start_timezones;
5635 if (is_compat ==
true)
5643 for (i = old_tzd.
name_count; i < all_timezones_and_aliases_count; i++)
5645 if (all_names[i].is_alias == 1)
5659 if (strcmp (timezone_name, all_timezone_names[j]) == 0)
5669 for (i = 0; i < all_timezones_count; i++)
5671 found_duplicate =
false;
5677 for (j = i - 1; j >= 0; j--)
5680 if (temp_zone_id == -1 && all_timezones[i].gmt_off_rule_start == all_timezones[j].gmt_off_rule_start
5681 && all_timezones[i].gmt_off_rule_count == all_timezones[j].gmt_off_rule_count)
5683 found_duplicate =
true;
5687 if (found_duplicate ==
true)
5696 for (j = i - 1; j >= 0; j--)
5700 if (temp_zone_id != -1
5701 && timezones[zone_id].gmt_off_rule_start == timezones[temp_zone_id].gmt_off_rule_start
5702 && timezones[zone_id].gmt_off_rule_count == timezones[temp_zone_id].gmt_off_rule_count)
5704 found_duplicate =
true;
5708 if (found_duplicate ==
true)
5713 all_offset_rule_count += timezones[zone_id].gmt_off_rule_count;
5718 if (all_offset_rules ==
NULL)
5725 gmt_off_rule_start = 0;
5734 for (i = 0; i < all_timezones_count; i++)
5736 prev_gmt_off_rule_start = gmt_off_rule_start;
5739 country_name =
NULL;
5751 for (j = 0; j < old_tzd_map_count; j++)
5753 if (old_tzd_offset_rule_map[j].original_offset_rule_start == start
5754 && old_tzd_offset_rule_map[j].len == cnt)
5764 old_tzd_offset_rule_map[old_tzd_map_count].
len = cnt;
5766 gmt_off_rule_start += cnt;
5780 start = timezones[zone_id].gmt_off_rule_start;
5781 cnt = timezones[zone_id].gmt_off_rule_count;
5783 for (j = 0; j < tzd_map_count; j++)
5785 if (tzd_offset_rule_map[j].original_offset_rule_start == start && tzd_offset_rule_map[j].len == cnt)
5795 tzd_offset_rule_map[tzd_map_count].
len = cnt;
5797 gmt_off_rule_start += cnt;
5816 int tzd_offset_rule_idx = start_gmt_new + j - start_gmt_old;
5854 if (country_name !=
NULL)
5866 for (j = prev_gmt_off_rule_start; j < gmt_off_rule_start; j++)
5868 int offset_rule_index = start + j - prev_gmt_off_rule_start;
5871 err_status =
copy_offset_rule (&all_offset_rules[j], &old_tzd, offset_rule_index);
5885 err_status =
copy_offset_rule (&all_offset_rules[j], tzd, offset_rule_index);
5899 if (ruleset_id == -1 && mark_ruleset[i] == 1)
5901 all_ds_ruleset_count++;
5909 if (all_ds_rulesets ==
NULL)
5917 if (all_ds_rules ==
NULL)
5926 i = 0, j = 0, k = 0;
5929 prev_start_ds_rule = start_ds_rule;
5930 tzd_or_old_tzd =
NULL;
5935 err_status =
init_ds_ruleset (&all_ds_rulesets[k], tzd, j, prev_start_ds_rule);
5940 tzd_or_old_tzd = tzd;
5949 else if (comp_res < 0)
5951 if (mark_ruleset[i] == 1)
5954 err_status =
init_ds_ruleset (&all_ds_rulesets[k], &old_tzd, i, prev_start_ds_rule);
5959 tzd_or_old_tzd = &old_tzd;
5974 if (comp_res >= 0 || (comp_res < 0 && mark_ruleset[i - 1] == 1))
5980 if (tzd_or_old_tzd !=
NULL)
5987 for (l = prev_start_ds_rule; l < start_ds_rule; l++)
5989 err_status =
copy_ds_rule (&all_ds_rules[l], tzd_or_old_tzd, start + l - prev_start_ds_rule);
5998 old_ds_rule = &old_tzd.
ds_rules[start_ds_ruleset_old + l - prev_start_ds_rule];
5999 new_ds_rule = &tzd->
ds_rules[start_ds_ruleset_new + l - prev_start_ds_rule];
6012 prev_start_ds_rule = start_ds_rule;
6014 if (mark_ruleset[i] == 1)
6017 err_status =
init_ds_ruleset (&all_ds_rulesets[k], &old_tzd, i, prev_start_ds_rule);
6026 for (l = prev_start_ds_rule; l < start_ds_rule; l++)
6028 err_status =
copy_ds_rule (&all_ds_rules[l], &old_tzd, start + l - prev_start_ds_rule);
6037 while (j < tzd->ds_ruleset_count)
6049 assert (k == all_ds_ruleset_count);
6050 for (i = 0; i < all_ds_ruleset_count; i++)
6052 if (all_ds_rulesets[i].index_start < 0)
6054 prev_start_ds_rule = start_ds_rule;
6057 start_ds_rule += all_ds_rulesets[
i].
count;
6060 for (j = prev_start_ds_rule; j < start_ds_rule; j++)
6062 err_status =
copy_ds_rule (&all_ds_rules[j], tzd, start + j - prev_start_ds_rule);
6072 for (i = 0; i < all_timezones_count; i++)
6079 tzd_or_old_tzd = &old_tzd;
6083 start = timezones[zone_id].gmt_off_rule_start;
6084 tzd_or_old_tzd = tzd;
6097 ruleset_name =
NULL;
6100 if (ruleset_name !=
NULL)
6114 if (mark_ruleset !=
NULL)
6118 if (old_tzd_offset_rule_map !=
NULL)
6122 if (tzd_offset_rule_map !=
NULL)
6133 tzd->
names = all_names;
6134 tzd->
name_count = all_timezones_and_aliases_count;
6144 old_names = old_tzd.
names;
6151 tz_Is_backward_compatible_timezone[
i] =
true;
6157 int old_start, old_count;
6158 int new_start, new_count;
6163 assert (tzd_zone_id != -1);
6165 if (old_timezones[old_names[i].zone_id].gmt_off_rule_count != timezones[tzd_zone_id].gmt_off_rule_count)
6167 tz_Is_backward_compatible_timezone[
i] =
false;
6171 old_start = old_timezones[old_names[
i].zone_id].gmt_off_rule_start;
6172 new_start = timezones[tzd_zone_id].gmt_off_rule_start;
6173 old_count = old_timezones[old_names[
i].zone_id].gmt_off_rule_count;
6174 new_count = timezones[tzd_zone_id].gmt_off_rule_count;
6176 for (j = old_start, k = new_start; j < old_start + old_count && k < new_start + new_count; j++, k++)
6185 tz_Is_backward_compatible_timezone[
i] =
false;
6191 tz_Is_backward_compatible_timezone[
i] =
false;
6201 int rule1_index = ds_rule1_start;
6202 int rule2_index = ds_rule2_start;
6207 tz_Is_backward_compatible_timezone[
i] =
false;
6211 if (ds_rule1_count != ds_rule2_count)
6213 tz_Is_backward_compatible_timezone[
i] =
false;
6217 while ((rule1_index < ds_rule1_start + ds_rule1_count)
6218 && (rule2_index < ds_rule2_start + ds_rule2_count))
6227 rule1_index++, rule2_index++;
6230 if (rule1_index < ds_rule1_start + ds_rule1_count)
6232 tz_Is_backward_compatible_timezone[
i] =
false;
6238 tz_Is_backward_compatible_timezone[
i] =
false;
6244 if (is_compat ==
false)
6246 printf (
"Updating data in the tables containing timezone data types...\n");
6356 input_buf = (
char *) calloc (size,
sizeof (
char));
6357 if (input_buf ==
NULL)
6481 #if defined (SA_MODE) 6498 if (session ==
NULL)
6516 if (session !=
NULL)
6535 #define TABLE_NAME_MAX_SIZE 256 6536 #define QUERY_BUF_MAX_SIZE 4096 6538 char query_buf[2 * QUERY_BUF_MAX_SIZE];
6539 char update_query[QUERY_BUF_MAX_SIZE];
6540 char where_query[QUERY_BUF_MAX_SIZE];
6546 bool need_db_shutdown =
false;
6548 const char *table_name =
NULL;
6549 bool is_first_column =
true;
6550 bool has_timezone_column;
6557 tz_Compare_datetimetz_tz_id =
true;
6558 tz_Compare_timestamptz_tz_id =
true;
6568 for (db_info_p = dir; db_info_p !=
NULL; db_info_p = db_info_p->
next)
6570 if (database_name !=
NULL && strcmp (db_info_p->
name, database_name) != 0)
6575 printf (
"Opening database %s\n", db_info_p->
name);
6580 printf (
"Error while opening database %s\n", db_info_p->
name);
6581 need_db_shutdown =
true;
6584 printf (
"Updating database %s...\n", db_info_p->
name);
6586 memset (query_buf, 0,
sizeof (query_buf));
6587 strcat (query_buf,
"show tables");
6592 printf (
"Error while executing show tables query\n");
6593 need_db_shutdown =
true;
6604 need_db_shutdown =
true;
6612 need_db_shutdown =
true;
6617 char table_name_buf[TABLE_NAME_MAX_SIZE];
6622 memset (query_buf, 0,
sizeof (query_buf));
6623 memset (table_name_buf, 0,
sizeof (table_name_buf));
6624 strcat (table_name_buf,
"'");
6625 strcat (table_name_buf, table_name);
6626 strcat (table_name_buf,
"'");
6628 snprintf (query_buf,
sizeof (query_buf) - 1,
6629 "select attr_name, data_type from _db_attribute where class_of.class_name = %s",
6634 printf (
"Error while listing column names and types for table %s\n", table_name);
6635 need_db_shutdown =
true;
6638 printf (
"Updating table %s...\n", table_name);
6644 memset (query_buf, 0,
sizeof (query_buf));
6645 memset (update_query, 0,
sizeof (update_query));
6646 memset (where_query, 0,
sizeof (where_query));
6648 strcpy (update_query,
"UPDATE [");
6649 strcat (update_query, table_name);
6650 strcat (update_query,
"] SET ");
6651 strcpy (where_query,
" WHERE ");
6653 is_first_column =
true;
6654 has_timezone_column =
false;
6656 printf (
"We will update the following columns:\n");
6659 const char *column_name =
NULL;
6660 int column_type = 0;
6667 need_db_shutdown =
true;
6676 need_db_shutdown =
true;
6689 has_timezone_column =
true;
6691 if (is_first_column ==
true)
6693 is_first_column =
false;
6697 strcat (update_query,
", ");
6698 strcat (where_query,
" OR ");
6701 strcat (update_query,
"[");
6702 strcat (update_query, column_name);
6703 strcat (update_query,
"]");
6704 strcat (update_query,
"=");
6705 strcat (update_query,
"conv_tz([");
6706 strcat (update_query, column_name);
6707 strcat (update_query,
"])");
6709 strcat (where_query,
"[");
6710 strcat (where_query, column_name);
6711 strcat (where_query,
"]");
6712 strcat (where_query,
"!=");
6713 strcat (where_query,
"conv_tz([");
6714 strcat (where_query, column_name);
6715 strcat (where_query,
"])");
6717 printf (
"%s ", column_name);
6724 if (has_timezone_column ==
true)
6726 strcpy (query_buf, update_query);
6727 strcat (query_buf, where_query);
6732 printf (
"Error while updating table %s\n", table_name);
6734 need_db_shutdown =
true;
6739 printf (
"Finished updating table %s\n", table_name);
6746 printf (
"Finished updating database %s\n", db_info_p->
name);
6747 printf (
"Shutting down database %s...\n", db_info_p->
name);
6758 if (need_db_shutdown ==
true)
6763 tz_Compare_datetimetz_tz_id =
false;
6764 tz_Compare_timestamptz_tz_id =
false;
6768 #undef TABLE_NAME_MAX_SIZE 6769 #undef QUERY_BUF_MAX_SIZE int julian_encode(int m, int d, int y)
#define TZC_LOG_ERROR_1ARG(context, err_code, s1)
#define TZC_CONTEXT(tzd_raw)
#define TZ_RULE_LETTER_ABBREV_MAX_SIZE
static int tzc_check_ds_ruleset(const TZ_DATA *tzd, const TZ_DS_RULESET *ds_rule_set, int *ds_changes_cnt)
int db_execute_statement_local(DB_SESSION *session, int stmt, DB_QUERY_RESULT **result)
TZ_DS_RULESET * ds_rulesets
static int tzc_add_leap_sec(TZ_RAW_DATA *tzd_raw, int year, int month, int day, unsigned char hour, unsigned char min, unsigned char sec, bool corr_minus, bool leap_is_rolling)
#define TZ_OFFRULE_PREFIX_TAB_COUNT
#define DUPLICATE_STR(a, b)
char full_name[TZ_COUNTRY_NAME_SIZE]
static int tzc_index_data(TZ_RAW_DATA *tzd_raw, const TZ_GEN_TYPE mode)
static int comp_func_raw_ds_rulesets(const void *arg1, const void *arg2)
static int tzc_get_ds_ruleset_by_name(const TZ_DS_RULESET *ds_rulesets, int ds_ruleset_count, const char *ruleset)
void db_set_client_type(int client_type)
static int comp_func_raw_links(const void *arg1, const void *arg2)
static int comp_func_raw_zones(const void *arg1, const void *arg2)
#define TZC_ERR_INVALID_PACKAGE
static int tzc_import_old_data(TZ_RAW_DATA *tzd_raw, const TZ_GEN_TYPE mode)
void tzc_dump_countries(const TZ_DATA *tzd)
static int tzc_add_zone(const char *zone, const char *coord, const char *code, const char *comments, TZ_RAW_DATA *tzd_raw, TZ_RAW_ZONE_INFO **new_zone)
#define TZC_ERR_LAST_ERROR
struct tz_windows_iana_map TZ_WINDOWS_IANA_MAP
int db_login(const char *name, const char *password)
static int copy_ds_rule(TZ_DS_RULE *dst, const TZ_DATA *tzd, const int index)
int execute_query(const XASL_ID *xasl_id, QUERY_ID *query_idp, int var_cnt, const DB_VALUE *varptr, QFILE_LIST_ID **list_idp, QUERY_FLAG flag, CACHE_TIME *clt_cache_time, CACHE_TIME *srv_cache_time)
void tzc_dump_leap_sec(const TZ_DATA *tzd)
static bool comp_offset_rules(const TZ_OFFSET_RULE *rule1, const TZ_OFFSET_RULE *rule2)
static int tzc_load_backward_zones(TZ_RAW_DATA *tzd_raw, const char *input_folder)
void tzc_dump_one_timezone(const TZ_DATA *tzd, const int zone_id)
char code[TZ_COUNTRY_CODE_SIZE]
static int tzc_compute_timezone_checksum(TZ_DATA *tzd, TZ_GEN_TYPE type)
int db_get_int(const DB_VALUE *value)
#define AU_DISABLE_PASSWORDS
static bool comp_ds_rules(const TZ_DS_RULE *rule1, const TZ_DS_RULE *rule2)
static void tzc_build_filepath(char *path, size_t size, const char *dir, const char *filename)
TZ_DS_CHANGE_ON change_on
struct tz_raw_link TZ_RAW_LINK
char type[TZ_RULE_TYPE_MAX_SIZE]
#define TZ_COORDINATES_MAX_SIZE
const char * letter_abbrev
#define TZC_ERR_MSG_MAX_SIZE
int db_query_end(DB_QUERY_RESULT *result)
#define assert_release(e)
static void print_seconds_as_time_hms_var(int seconds)
static int tzc_get_timezone_aliases(const TZ_DATA *tzd, const int zone_id, int **aliases, int *alias_count)
int tz_load_with_library_path(TZ_DATA *tzd, const char *timezone_library_path)
char * envvar_libdir_file(char *path, size_t size, const char *filename)
#define PATH_PARTIAL_TIMEZONES_FILE
static int tzc_find_timezone_names(const TZ_DATA *tzd, const char *timezone_name)
char code[TZ_COUNTRY_CODE_SIZE]
#define TZ_COUNTRY_CODE_SIZE
static void tzc_dump_one_offset_rule(const TZ_DATA *tzd, const TZ_OFFSET_RULE *offset_rule)
static int compare_ints(const void *a, const void *b)
int(* ELEM_START_FUNC)(void *, const char **)
struct tz_raw_country TZ_RAW_COUNTRY
TZ_TIME_TYPE at_time_type
XML_Parser xml_init_parser(void *data, const char *xml_file, const char *encoding, XML_ELEMENT_DEF **element_array, const int count)
static int tzc_find_country_names(const TZ_COUNTRY *countries, const int country_count, const char *country_name)
char current_file[PATH_MAX]
static void tzc_index_raw_data(TZ_RAW_DATA *tzd_raw)
#define LOG_TZC_SET_CURRENT_CONTEXT(tzd_raw, f, l)
char comments[TZ_COMMENTS_MAX_SIZE]
void tzc_dump_summary(const TZ_DATA *tzd)
TZ_TIME_TYPE until_time_type
char letter_abbrev[TZ_RULE_LETTER_ABBREV_MAX_SIZE]
#define XML_USER_DATA(xml)
static int comp_func_tz_names(const void *arg1, const void *arg2)
unsigned short until_year
struct tz_raw_ds_rule TZ_RAW_DS_RULE
#define TZ_GENERIC_NAME_SIZE
static int tzc_read_time_type(const char *str, const char **next, TZ_TIME_TYPE *time_type)
static int tzc_load_rule_file(TZ_RAW_DATA *tzd_raw, const int file_index, const char *input_folder)
#define TZ_COMMENTS_MAX_SIZE
int tz_str_read_number(const char *str, const char *str_end, const bool strict, const bool read_sign, int *val, const char **str_next)
static const char * tzc_Err_messages[]
#define TZ_CAL_ABBREV_SIZE
#define TZC_ERR_OUT_OF_MEMORY
struct tz_raw_ds_ruleset TZ_RAW_DS_RULESET
TZ_TIME_TYPE until_time_type
#define INIT_COUNTRY(dst, src)
int db_restart(const char *program, int print_version, const char *volume)
static int str_day_to_int(const char *str_in, int *day_num, const char **str_next)
struct tz_raw_zone_info TZ_RAW_ZONE_INFO
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
char ds_ruleset_name[TZ_DS_RULESET_NAME_SIZE]
char checksum[TZ_CHECKSUM_SIZE+1]
char name[TZ_DS_RULESET_NAME_SIZE]
int tz_str_read_time(const char *str, const char *str_end, bool need_minutes, bool allow_sec60, int *hour, int *min, int *sec, const char **str_next)
#define TZC_ERR_INVALID_TIME
char format[TZ_MAX_FORMAT_SIZE]
#define ER_OUT_OF_VIRTUAL_MEMORY
#define TZC_ERR_INVALID_DS_RULE
#define TZC_ERR_INVALID_ZONE
#define TZC_ERR_INVALID_COUNTRY
#define TZC_ERR_DS_INVALID_DATE
void xml_parser_exec(XML_PARSER_DATA *pd)
#define BUF_PUT_INT32(buf, v)
int tz_str_to_seconds(const char *str, const char *str_end, int *seconds, const char **str_next, const bool is_offset)
int tz_get_ds_change_julian_date_diff(const int src_julian_date, const TZ_DS_RULE *ds_rule, const int year, int *ds_rule_julian_date, full_date_t *date_diff)
struct tz_leap_sec TZ_LEAP_SEC
#define ER_TZ_COMPILE_ERROR
TZ_RAW_COUNTRY * countries
#define MAX_DS_CHANGES_YEAR
static int comp_func_raw_ds_rules(const void *arg1, const void *arg2)
static int tzc_add_offset_rule(TZ_RAW_ZONE_INFO *zone, char *rule_text)
static enum scanner_mode mode
static int tzc_del_unused_raw_data(TZ_RAW_DATA *tzd_raw)
int final_offset_rule_start
#define TZC_ERR_LINKING_TRUE_ZONES
#define TZC_ERR_ZONE_RULE_UNORDERED
static int tzc_get_zone(const TZ_RAW_DATA *tzd_raw, const char *zone_name, TZ_RAW_ZONE_INFO **zone)
static int str_month_to_int(const char *month, int *month_num, const char **str_next)
static int tzc_add_ds_rule(TZ_RAW_DATA *tzd_raw, char *rule_text)
TZ_RAW_OFFSET_RULE * offset_rules
#define TZ_FILENAME_MAX_LEN
int db_abort_transaction(void)
TZ_DS_CHANGE_ON change_on
char name[TZ_FILENAME_MAX_LEN]
static int tzc_load_zone_names(TZ_RAW_DATA *tzd_raw, const char *input_folder)
#define strncpy_bufsize(buf, str)
#define PRINT_STRING_VAR_TO_C_FILE(fp, valname, val)
DB_SESSION * db_open_buffer(const char *buffer)
int db_compile_statement(DB_SESSION *session)
static void tzc_get_timezones_dot_c_filepath(size_t size, char *timezones_dot_c_file_path)
unsigned short until_year
void db_close_session(DB_SESSION *session)
static int init_tz_name(TZ_NAME *dst, TZ_NAME *src)
static const TZ_FILE_DESCRIPTOR tz_Files[]
int crypt_md5_buffer_hex(const char *buffer, size_t len, char *resblock)
char full_name[TZ_GENERIC_NAME_SIZE]
static void tzc_dump_ds_ruleset(const TZ_DATA *tzd, const int ruleset_id)
#define TZC_ERR_BAD_TZ_LINK
unsigned char day_of_month
void tz_set_new_timezone_data(const TZ_DATA *data)
TZ_TIME_TYPE at_time_type
#define TZC_ERR_FILE_NOT_ACCESSIBLE
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
#define TZ_RULE_TYPE_MAX_SIZE
static int tzc_load_countries(TZ_RAW_DATA *tzd_raw, const char *input_folder)
char code[TZ_COUNTRY_CODE_SIZE]
static int tzc_check_links_raw_data(TZ_RAW_DATA *tzd_raw)
#define STR_SKIP_LEADING_SPACES(str)
FILE * fopen_ex(const char *filename, const char *type)
static void trim_comments_whitespaces(char *str)
#define TZ_DS_RULESET_NAME_SIZE
static int tzc_add_link(TZ_RAW_DATA *tzd_raw, const char *zone, const char *alias)
const char * ruleset_name
static void error(const char *msg)
unsigned char day_of_week
static int str_to_offset_rule_until(TZ_RAW_OFFSET_RULE *offset_rule, char *str)
static bool tzc_is_valid_date(const int day, const int month, const int year_start, const int year_end)
const char * tz_timezone_names[]
int db_query_next_tuple(DB_QUERY_RESULT *result)
static void tzc_sort_raw_data(TZ_RAW_DATA *tzd_raw)
static char database_name[MAX_HA_DBINFO_LENGTH]
#define snprintf_dots_truncate(dest, max_len,...)
int tz_get_first_weekday_around_date(const int year, const int month, const int weekday, const int ref_day, const bool before)
static int tzc_load_leap_secs(TZ_RAW_DATA *tzd_raw, const char *input_folder)
static int tz_data_partial_clone(char **timezone_names, TZ_TIMEZONE *timezones, TZ_NAME *names, const TZ_DATA *tzd)
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
static void tzc_free_tz_data(TZ_DATA *tzd, bool full)
void julian_decode(int jul, int *monthp, int *dayp, int *yearp, int *weekp)
#define free_and_init(ptr)
static int tzc_export_timezone_dot_c(const TZ_DATA *tzd, const char *tz_C_filepath)
static int tzc_load_raw_data(TZ_RAW_DATA *tzd_raw, const char *input_folder)
const char * default_abrev
static void tzc_free_raw_data(TZ_RAW_DATA *tzd_raw)
static void tzc_log_error(const TZ_RAW_CONTEXT *context, const int code, const char *msg1, const char *msg2)
static int init_ds_ruleset(TZ_DS_RULESET *dst_ruleset, const TZ_DATA *tzd, const int index, const int start)
static int get_day_of_week_for_raw_rule(const TZ_RAW_DS_RULE *rule, const int year)
char coordinates[TZ_COORDINATES_MAX_SIZE]
#define DB_CURSOR_SUCCESS
int original_offset_rule_start
void xml_destroy_parser(void *data)
char full_name[TZ_COUNTRY_NAME_SIZE]
char territory[TZ_COUNTRY_CODE_SIZE+1]
#define TZ_WINDOWS_ZONE_NAME_SIZE
#define TZC_ERR_CANT_READ_VALUE
static int copy_offset_rule(TZ_OFFSET_RULE *dst, const TZ_DATA *tzd, const int index)
#define DB_VALUE_TYPE(value)
#define BUF_PUT_INT16(buf, v)
static int comp_func_raw_countries(const void *arg1, const void *arg2)
#define TZ_MAX_FORMAT_SIZE
#define DB_IS_NULL(value)
static const char DAY_NAMES_ABBREV[TZ_WEEK_DAY_COUNT][TZ_CAL_ABBREV_SIZE]
char * strdup(const char *str)
char windows_zone[TZ_WINDOWS_ZONE_NAME_SIZE+1]
int db_query_get_tuple_value(DB_QUERY_RESULT *result, int index, DB_VALUE *value)
#define TZ_COUNTRY_CODE_LEN
const TZ_COUNTRY tz_countries[]
static int tzc_index_raw_subdata(TZ_RAW_DATA *tzd_raw, const TZ_GEN_TYPE mode)
static int str_read_day_var(const char *str, const int month, int *type, int *day, int *bound, const char **str_next)
#define TZC_ERR_INVALID_VALUE
static int tzc_index_raw_data_w_static(TZ_RAW_DATA *tzd_raw, const TZ_GEN_TYPE mode)
TZ_RAW_DS_RULESET * ds_rulesets
int xml_get_att_value(const char **attrs, const char *att_name, char **p_att_value)
static const int tzc_Err_message_count
TZ_LEAP_SEC * ds_leap_sec
const char * program_name
#define TZC_LOG_ERROR_2ARG(context, err_code, s1, s2)
struct tz_raw_offset_rule TZ_RAW_OFFSET_RULE
#define SHLIB_EXPORT_PREFIX
char * envvar_cubrid_dir(char *path, size_t size)
void tzc_dump_timezones(const TZ_DATA *tzd)
char name[TZ_GENERIC_NAME_SIZE]
char alias[TZ_GENERIC_NAME_SIZE]
#define TZ_COUNTRY_NAME_SIZE
static int comp_func_raw_offset_rules(const void *arg1, const void *arg2)
static int tzc_check_new_package_validity(const char *input_folder)
char clone_of[TZ_GENERIC_NAME_SIZE]
static void tzc_summary(TZ_RAW_DATA *tzd_raw, TZ_DATA *tzd)
TZ_OFFSET_RULE * offset_rules
void cfg_free_directory(DB_INFO *databases)
static int tzc_compile_ds_rules(TZ_RAW_DATA *tzd_raw, TZ_DATA *tzd)
DB_CONST_C_CHAR db_get_string(const DB_VALUE *value)
enum tz_until_flag TZ_UNTIL_FLAG
int db_commit_transaction(void)
static int tzc_parse_ds_change_on(TZ_RAW_DS_RULE *dest, const char *str)
unsigned char corr_negative
static const char MONTH_NAMES_ABBREV[TZ_MON_COUNT][TZ_CAL_ABBREV_SIZE]
static int tzc_compile_data(TZ_RAW_DATA *tzd_raw, TZ_DATA *tzd)