From: <abe...@us...> - 2015-05-20 01:43:14
|
Revision: 7073 http://sourceforge.net/p/astlinux/code/7073 Author: abelbeck Date: 2015-05-20 01:43:11 +0000 (Wed, 20 May 2015) Log Message: ----------- add php-timezonedb scripts Added Paths: ----------- branches/1.0/scripts/php-timezonedb/ branches/1.0/scripts/php-timezonedb/create-entry branches/1.0/scripts/php-timezonedb/create-entry2 branches/1.0/scripts/php-timezonedb/create-entry3 branches/1.0/scripts/php-timezonedb/create_dot_h_file branches/1.0/scripts/php-timezonedb/get-version branches/1.0/scripts/php-timezonedb/makearchive.sh branches/1.0/scripts/php-timezonedb/sort-index Added: branches/1.0/scripts/php-timezonedb/create-entry =================================================================== --- branches/1.0/scripts/php-timezonedb/create-entry (rev 0) +++ branches/1.0/scripts/php-timezonedb/create-entry 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,58 @@ +#!/usr/bin/php -qC +<?php +$zone = $argv[1]; +$path = $argv[2]; + +$dataf = "$path/$zone"; + +// obtain data from tz file +$tzdata = file_get_contents( $dataf, false, NULL, 20 ); + +if (($pos = strrpos($tzdata, 'TZif')) !== FALSE) { + $fdata = substr($tzdata, 0, $pos); +} else { + $fdata = $tzdata; +} + +// process extra info +$f = file( "$path/zone.tab" ); + +$cc = '??'; +$lat = $long = 0; +$desc = ''; + +foreach ( $f as $line ) +{ + $line = trim( $line ); + if ( strlen( $line ) < 5 || $line[0] == '#' ) + { + continue; + } + $parts = explode( "\t", $line ); + if ( $parts[2] == $zone ) + { + // format lang/lat + if ( strlen( $parts[1] ) == 11 ) + { + sscanf( $parts[1], '%c%2d%2d%c%3d%2d', $xSign, $xH, $xM, $ySign, $yH, $yM ); + $xS = $yS = 0; + } + else + { + sscanf( $parts[1], '%c%2d%2d%2d%c%3d%2d%2d', $xSign, $xH, $xM, $xS, $ySign, $yH, $yM, $yS ); + } + $lat = $xH + ( $xM / 60 ) + ( $xS / 3600 ); + $long = $yH + ( $yM / 60 ) + ( $yS / 3600 ); + $lat = $xSign == '+' ? $lat : -$lat; + $long = $ySign == '+' ? $long : -$long; + + $cc = $parts[0]; + $desc = isset( $parts[3] ) ? $parts[3] : ''; + + break; + } +} +//printf( '{ "%2s", %d, %d, "%s" },' . "\n", +// $cc, $lat * 100000, $long * 100000, addslashes( $desc ) ); +echo pack( 'a4ca2a13a*NNNa*', "PHP1", $cc != '??' || $zone == 'UTC', $cc, '', $fdata, ($lat + 90) * 100000, ($long + 180) * 100000, strlen( $desc ), $desc ); +?> Property changes on: branches/1.0/scripts/php-timezonedb/create-entry ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: branches/1.0/scripts/php-timezonedb/create-entry2 =================================================================== --- branches/1.0/scripts/php-timezonedb/create-entry2 (rev 0) +++ branches/1.0/scripts/php-timezonedb/create-entry2 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,7 @@ +#!/usr/bin/php -qC +<?php +$j = $argv[1]; +$l = $argv[2]; + +echo "\t{ ".sprintf('%-36s, 0x%06X', '"'.$j.'"', $l)." },\n"; +?> Property changes on: branches/1.0/scripts/php-timezonedb/create-entry2 ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: branches/1.0/scripts/php-timezonedb/create-entry3 =================================================================== --- branches/1.0/scripts/php-timezonedb/create-entry3 (rev 0) +++ branches/1.0/scripts/php-timezonedb/create-entry3 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,7 @@ +#!/usr/bin/php -qC +<?php +$j = $argv[1]; +$l = $argv[2]; + +echo "\t".sprintf('%s => 0x%06X', '"'.$j.'"', $l).",\n"; +?> Property changes on: branches/1.0/scripts/php-timezonedb/create-entry3 ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: branches/1.0/scripts/php-timezonedb/create_dot_h_file =================================================================== --- branches/1.0/scripts/php-timezonedb/create_dot_h_file (rev 0) +++ branches/1.0/scripts/php-timezonedb/create_dot_h_file 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,25 @@ +#!/usr/bin/php -qC +/* This is a generated file, do not modify */ +<?php + $index = include 'timezonedb.idx.php'; + $dta = file_get_contents('timezonedb.dta'); + $dta_l = strlen($dta); + $j = 0; + + echo "const unsigned char timelib_timezone_db_data_builtin[$dta_l] = {\n"; + for ($i = 0; $i < $dta_l; $i++) { + if (($key = array_search($i, $index)) !== false) { + echo "\n\n/* $key */\n"; + $j = 0; + } + if ($j % 16 != 0) { + echo " "; + } + printf("0x%02X,", ord($dta[$i])); + if ($j % 16 == 15) { + echo "\n"; + } + $j++; + } + echo "};\n"; +?> Property changes on: branches/1.0/scripts/php-timezonedb/create_dot_h_file ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: branches/1.0/scripts/php-timezonedb/get-version =================================================================== --- branches/1.0/scripts/php-timezonedb/get-version (rev 0) +++ branches/1.0/scripts/php-timezonedb/get-version 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,10 @@ +#!/usr/bin/php -qC +<?php +$ver = $argv[1]; + +if (preg_match('@([0-9]{4})([a-z])@', $ver, $a)) { + echo $a[1].'.'.(ord($a[2]) - ord('a') + 1); +} else { + echo $ver; +} +?> Property changes on: branches/1.0/scripts/php-timezonedb/get-version ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: branches/1.0/scripts/php-timezonedb/makearchive.sh =================================================================== --- branches/1.0/scripts/php-timezonedb/makearchive.sh (rev 0) +++ branches/1.0/scripts/php-timezonedb/makearchive.sh 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,77 @@ +#!/bin/bash + +## Generate version "1" PHP timezonedb.h file +## Credit: Derick Rethans +## https://github.com/derickr/timelib/tree/master/zones +## +## Adapted for AstLinux by Lonnie Abelbeck + +SCRIPTS="./scripts/php-timezonedb" + +if [ -n "$1" ]; then + TZDATA="$1" +else + TZDATA="output/target/usr/share/zoneinfo" +fi + +if [ ! -f $TZDATA/.tzversion ]; then + echo "File not found: $TZDATA/.tzversion" + exit 1 +fi +version="$($SCRIPTS/get-version "$(cat $TZDATA/.tzversion)")" + +rm -f timezonedb.idx timezonedb.idx.php timezonedb.dta +touch timezonedb.idx timezonedb.dta + +echo "Building index:" +echo "<?php return array(" >> timezonedb.idx.php +for i in $(find $TZDATA -type f | sort); do + l=$(stat -c "%s" timezonedb.dta) + j=${i#$TZDATA/} + + case $j in + .*|*.tab) + ;; + *) + $SCRIPTS/create-entry $j $TZDATA >> timezonedb.dta + $SCRIPTS/create-entry2 $j $l >> timezonedb.idx + $SCRIPTS/create-entry3 $j $l >> timezonedb.idx.php + echo "- $j" + ;; + esac +done +echo "); ?>" >> timezonedb.idx.php +echo "" + +echo "Sorting index:" +$SCRIPTS/sort-index > timezonedb.idx.tmp +mv timezonedb.idx.tmp timezonedb.idx +echo "" + +echo "Creating .h file:" +echo -n "const timelib_tzdb_index_entry timezonedb_idx_builtin[" > timezonedb.h +echo -n $(cat timezonedb.idx | wc -l ) >> timezonedb.h +echo "] = {" >> timezonedb.h +cat timezonedb.idx >> timezonedb.h +echo "};" >> timezonedb.h + +$SCRIPTS/create_dot_h_file >> timezonedb.h +echo "" >> timezonedb.h +echo -n "const timelib_tzdb timezonedb_builtin = { \"$version\", " >> timezonedb.h +echo -n $(cat timezonedb.idx | wc -l ) >> timezonedb.h +echo ", timezonedb_idx_builtin, timelib_timezone_db_data_builtin };" >> timezonedb.h +echo "" + +echo "Packaging:" +mkdir "timezonedb-$version" +mv timezonedb.h "timezonedb-$version" +tar czvf "timezonedb-$version.tar.gz" "timezonedb-$version" +echo "" + +echo "Cleanup:" +rm -rf "timezonedb-$version" +rm -f timezonedb.idx timezonedb.idx.php timezonedb.dta +echo "" + +echo "Done" + Property changes on: branches/1.0/scripts/php-timezonedb/makearchive.sh ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: branches/1.0/scripts/php-timezonedb/sort-index =================================================================== --- branches/1.0/scripts/php-timezonedb/sort-index (rev 0) +++ branches/1.0/scripts/php-timezonedb/sort-index 2015-05-20 01:43:11 UTC (rev 7073) @@ -0,0 +1,18 @@ +#!/usr/bin/php -qC +<?php + $idx = file("timezonedb.idx"); + usort($idx, 'sortfunc'); + echo implode($idx); + + function sortfunc($a, $b) + { + /* Grep tz names */ + preg_match('@"([^"]+)"@', $a, $ma); + $na = $ma[1]; + preg_match('@"([^"]+)"@', $b, $mb); + $nb = $mb[1]; + + $val = strcasecmp($na, $nb); + return $val; + } +?> Property changes on: branches/1.0/scripts/php-timezonedb/sort-index ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |