From 514830cf206c726edbc954daf244b683b4f8a544 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 6 Aug 2010 18:37:55 +0200 Subject: lightning: work on fixlang --- fixlang.php | 292 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100755 fixlang.php (limited to 'fixlang.php') diff --git a/fixlang.php b/fixlang.php new file mode 100755 index 0000000..51ff7d7 --- /dev/null +++ b/fixlang.php @@ -0,0 +1,292 @@ +#!/usr/bin/php +1) echo "+ empty\n"; + } else if ($prev!='comment' && preg_match('/^ *(|)$/', $buf, $res)) { + if ($debug>1) echo "+ Line '".$res[1]."'\n"; + $ind=trim($res[1]); + $tab[$ind] = $res[1].'"'.$res[2].'">'; + $prev=false; + } else if ($prev!='comment' && preg_match('/^1) echo "+ Start '".$res[1]."'\n"; + $ind=trim($res[1]); + $tab[$ind] = $res[1].'"'.$res[2]; + $prev=$ind; + } else if (preg_match('/^$/', $buf, $res)) { + if ($debug>1) echo "+ Comment (".$res[1].")\n"; + } else if (preg_match('/^[[:space:]]*$/', $buf, $res)) { + if ($debug>1) echo "+ End 'License'\n"; + $tab[$prev] .= "\n".$res[1]; + $prev=false; + } else if ($prev=="comment" && preg_match('/^(.*)-->$/', $buf, $res)) { + if ($debug>1) echo "+ End 'Comment'\n"; + unset($tab['comment']); + $prev=false; + } else if ($prev && preg_match('/^(.*)">$/', $buf, $res)) { + if ($debug>1) echo "+ End '".$prev."'\n"; + $tab[$prev] .= "\n".$res[1].'">'; + $prev=false; + } else if ($prev && preg_match('/^(.*)$/', $buf, $res)) { + if ($debug>1) echo "+ Cont. '".$prev."'\n"; + $tab[$prev] .= "\n".$res[1]; + } else { + die("*** - unkonwn ($buf) !\n"); + } + } +} + +function SaveDtd ($locpath, $loc, $ref) { + global $debug; + + $fic=@fopen($locpath, "w"); + if (!$fic) { + die ("*** Cannot create $locpath\n"); + } + if ($debug) echo "\tCreate $locpath\n"; + if (isset($ref['license'])) { + fputs($fic, "\n"); + unset($ref['license']); + } + // print_r($ref); print_r($loc); + foreach($ref as $ind => $line) { + if (isset($loc[$ind])) { + fputs($fic, "1) echo "+ empty\n"; + } else if (preg_match('/^#(.*)$/', $buf, $res)) { + if ($debug>1) echo "+ comments\n"; + $tab['comment'][]=$res[1]; + } else if (preg_match('/^([A-Za-z0-9._{}@-]*)[[:space:]]*=[[:space:]]*(.*)/', $buf, $res)) { + if ($debug>1) echo "+ Value '".$res[1]."'\n"; + $ind=trim($res[1]); + $tab[$ind] = $res[1].'='.$res[2]; + } else { + echo("\tIgnored ($buf) in $file !\n"); + } + } +} + +function SaveProp ($locpath, $loc, $ref) { + global $debug; + + $fic=@fopen($locpath, "w"); + if (!$fic) { + die ("*** Cannot create $locpath\n"); + } + if ($debug) echo "\tCreate $locpath\n"; + if (isset($ref['license'])) { + fputs($fic, "\n"); + unset($ref['license']); + } + foreach($ref['comment'] as $com) { + fputs($fic, "#$com\n"); + } + unset($ref['comment']); + // print_r($ref); print_r($loc); + foreach($ref as $ind => $line) { + if (isset($loc[$ind])) { + fputs($fic, $loc[$ind]."\n"); + } else { + echo "\tAdding missing $ind to $locpath\n"; + fputs($fic, $ref[$ind]."\n"); + } + } + fclose($fic); +} + +function FixProp ($locpath, $refpath) { + global $debug; + static $cache=array(); + + if ($debug) echo "\tCheck Properties: $locpath $refpath\n"; + + $key = basename($locpath); + if (!isset($cache[$key])) { + LoadProp($refpath,$cache[$key]); + } + $ref = $cache[$key]; + $loc = array(); + LoadProp($locpath, $loc); + SaveProp($locpath, $loc, $ref); +} + + +if (!isset($xpi) + || !isset($manifest) || !is_file($manifest) + || !isset($output) || !is_dir($output)) { + echo "xpi=$xpi, ref=$ref\n"; + die("usage php fixlang.php --xpi=pathto.xpi --=pathtorefdir --output=pathtooutputdir --manifest=pathto/chrome.manifest [ --debug=# ]\n"); +} +$zip = new ZipArchive(); +$zip2 = new ZipArchive(); +$zip3 = new ZipArchive(); +if (!$zip->open($xpi)) { + die("*** Can't read $xpi\n"); +} +$ficman=@fopen($manifest, "a"); +if (!$ficman) { + die("*** Can't read $manifest\n"); +} +for ($i=0 ; $i <$zip->numFiles; $i++) { + $file=$zip->statIndex($i); + if (preg_match('/^chrome\/(.*)-([a-z]{2}-[a-zA-Z]{2}).jar$/', $file['name'], $regs)) { + $extn = $regs[1]; + $lang = $regs[2]; + } else if (preg_match('/^chrome\/(.*)-([a-z]{2}).jar$/', $file['name'], $regs)) { + $extn = $regs[1]; + $lang = $regs[2]; + } else { + continue; + } + if (isset($$extn) && is_dir($$extn)) { + $ref=$$extn; + } else { + die("*** Missing --$extn options\n"); + } + if ($lang == 'en-US') { + continue; + } + //if ($lang != 'et') continue; /// for debug + if ($debug) echo "Working on $tmp/chrome/$extn-$lang.jar to $output/chrome/$extn-$lang.jar \n"; + $zip->extractTo($tmp, "chrome/$extn-$lang.jar"); + + if ($zip2->open($zipin="$tmp/chrome/$extn-$lang.jar")!==true) { + die("*** Can't read $zipin\n"); + } + if ($zip3->open($zipout="$output/chrome/$extn-$lang.jar", ZIPARCHIVE::CREATE)!==true) { + die("*** Can't write $zipout=\n"); + } + + for ($j=0 ; $j <$zip2->numFiles; $j++) { + $file=$zip2->statIndex($j); + + $zip2->extractTo($tmp, $file['name']); + if (preg_match('/.dtd$/', $file['name'])) { + $sub = basename(dirname($file['name'])); + if (is_file("$ref/".basename($file['name']))) { + FixDtd("$tmp/".$file['name'], "$ref/".basename($file['name'])); + } else if (is_file("$ref/$sub/".basename($file['name']))) { + FixDtd("$tmp/".$file['name'], "$ref/$sub/".basename($file['name'])); + } else { + echo "\tSkip check of $tmp/".$file['name']." ($sub)\n"; + } + + } else if (preg_match('/.properties$/', $file['name'])) { + $sub = basename(dirname($file['name'])); + if (is_file("$ref/".basename($file['name']))) { + FixProp("$tmp/".$file['name'], "$ref/".basename($file['name'])); + } else if (is_file("$ref/$sub/".basename($file['name']))) { + FixProp("$tmp/".$file['name'], "$ref/$sub/".basename($file['name'])); + } else if (basename($file['name'])=='wcap.properties') { + FixProp("$tmp/".$file['name'], "$ref/providers/wcap/".basename($file['name'])); + } else if (basename($file['name'])=='timezones.properties') { + FixProp("$tmp/".$file['name'], "$ref/../calendar/".basename($file['name'])); + } else { + echo "\tSkip check of $tmp/".$file['name']." ($sub)\n"; + } + } else { + if ($debug) echo "Copy $tmp/".$file['name']."\n"; + } + + if ($zip3->addFile("$tmp/".$file['name'], $file['name'])) { + if ($debug) echo "\tAdd "."$tmp/".$file['name']." in $zipout\n"; + } else { + die ("*** Can't add ".$file['name']." in $zipout\n"); + } + $base = dirname($file['name']); + } + fputs($ficman, "locale\t$extn\t$lang\tjar:chrome/$extn-$lang.jar!/$base/\n"); + $zip2->close(); + $zip3->close(); +} +fclose($ficman); +?> -- cgit