diff options
author | Ryan Egesdahl <ryan.egesdahl@mongodb.com> | 2020-06-18 21:21:25 -0700 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-26 17:02:46 +0000 |
commit | 22d98e72ac45cd4e145d6b9b42099c5585727ec7 (patch) | |
tree | 4b8f982350542694eb27ddee799c1b75af148729 /src/third_party/timelib-2018.03/zones/create_dot_h_file.php | |
parent | e976a66489bb0b600d9896bdada5e33e6d885534 (diff) | |
download | mongo-22d98e72ac45cd4e145d6b9b42099c5585727ec7.tar.gz |
SERVER-44278 Upgrade timelib to 2018.03
This is a third-party source upgrade of timelib to version 2018.03.
Diffstat (limited to 'src/third_party/timelib-2018.03/zones/create_dot_h_file.php')
-rw-r--r-- | src/third_party/timelib-2018.03/zones/create_dot_h_file.php | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/third_party/timelib-2018.03/zones/create_dot_h_file.php b/src/third_party/timelib-2018.03/zones/create_dot_h_file.php new file mode 100644 index 00000000000..96154c89876 --- /dev/null +++ b/src/third_party/timelib-2018.03/zones/create_dot_h_file.php @@ -0,0 +1,113 @@ +<?php +$index_data = "/* This is a generated file, do not modify */\n"; +$header_data = ''; +$data = ''; + +/* Grab version info */ +$version_info = file( 'version-info.txt' ); +$version = trim( $version_info[1] ); + +$idx_entries = count( file( 'timezonedb.idx' ) ) - 5; +$index_data .= "const timelib_tzdb_index_entry timezonedb_idx_builtin[{$idx_entries}] = {\n"; +$index_data .= file_get_contents( 'timezonedb.idx' ); +$index_data .= "};\n"; + +$index = include 'timezonedb.idx.php'; +$dta = file_get_contents('timezonedb.dta'); +$dta_l = strlen($dta); +$legacy_dta_l = $dta_l; + +$j = 0; +$ascii = ''; + +for ($i = 0; $i < $dta_l; $i++) +{ + if ( array_key_exists( $i, $index ) ) + { + /* Find marker for V2 fields */ + $v2 = strpos( $dta, "TZif", $i ); + /* Find end of data */ + $endOfData = $i + $index[$i]['v2end']; + + $legacy_dta_l -= ( $endOfData - $v2 ); + + if ( $i != 0 && $ascii !== '' ) + { + $data .= str_repeat( ' ', 6 * ( 16 - ( $j % 16 ) ) ); + $data .= " /* {$ascii} */\n"; + } + $data .= "\n\n/* {$index[$i]['key']} */\n"; + $j = 0; $ascii = ''; + echo "."; + } + if ($j % 16 != 0) { + $data .= " "; + } + $char = ord( $dta[$i] ); + $data .= sprintf( "0x%02X,", $char ); + + if ( isset( $argv[1] ) && $argv[1] == 'debug' ) + { + $ascii .= ($char >= 32 && $char != 47 && $char < 127) ? sprintf( "%c", $char ) : '.'; + } + + if ( $j % 16 == 15 ) + { + if ( $ascii !== '' ) + { + $data .= " /* {$ascii} */\n"; + } + else + { + $data .= "\n"; + } + $ascii = ''; + } + $j++; + + if ( $i + 1 == $v2 ) + { + if ( $ascii !== '' ) + { + $data .= str_repeat( ' ', 6 * ( 16 - ( $j % 16 ) ) ); + $data .= " /* {$ascii} */\n"; + } + else if ( $j % 16 != 0 ) + { + $data .= "\n"; + } + $ascii = ''; + $data .= "#ifdef TIMELIB_SUPPORTS_V2DATA\n"; + $j = 0; + } + if ( $i + 1 == $endOfData ) + { + if ( $ascii !== '' ) + { + $data .= str_repeat( ' ', 6 * ( 16 - ( $j % 16 ) ) ); + $data .= " /* {$ascii} */\n"; + } + else if ( $j % 16 != 0 ) + { + $data .= "\n"; + } + $ascii = ''; + $data .= "#endif\n"; + $j = 0; + } +} +$data .= "};\n"; +echo "\n"; + +$data .= "\n"; + +$header_data .= "#ifdef TIMELIB_SUPPORTS_V2DATA\n" . + "const unsigned char timelib_timezone_db_data_builtin[$dta_l] = {\n" . + "#else\n" . + "const unsigned char timelib_timezone_db_data_builtin[$legacy_dta_l] = {\n" . + "#endif\n"; + +$footer_data .= "const timelib_tzdb timezonedb_builtin = { \"{$version}\", {$idx_entries}, timezonedb_idx_builtin, timelib_timezone_db_data_builtin };\n"; + +file_put_contents( 'timezonedb.h', $index_data . $header_data . $data . $footer_data ); +?> |