1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#!/usr/bin/php -q
<?php
/*
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2004 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Jeroen van Wolffelaar <jeroen@php.net> |
+----------------------------------------------------------------------+
*/
// Sorts the aliases.xml file. This script assumes that </row> and <row> tags
// are not on the same line.
$lang = isset($argv[1]) ? $argv[1] : 'en';
if (@is_dir($lang)) {
$filename = "$lang/appendices/aliases.xml";
} elseif (@is_dir("../$lang")) {
$filename = "../$lang/appendices/aliases.xml";
} else { ?>
Usage: ./scripts/sort_aliases.php [<lang>]
While being in the root of phpdoc.
<?php
exit;
}
echo "File: $filename\n\n";
$lines = file($filename);
if (!$lines) {
echo "Cannot read from file, bailing out...\n";
exit;
}
$out = @fopen("$filename.sorted", 'w');
if (!$out) {
echo "Cannot write to file $filename.sorted, bailing out...\n";
exit;
}
echo "Copying beginning of file...\n";
for ($nr = 0; !ereg('tbody',$lines[$nr]); $nr++) {
fwrite($out, $lines[$nr]);
}
fwrite($out, $lines[$nr++]);
echo "Reading entries... ";
for (; ereg('<row>', $lines[$nr]); $nr++) {
$entry = '';
$key = '';
for (; !ereg('</row>', $lines[$nr]); $nr++) {
$entry .= $lines[$nr];
if (!$key && ereg('<entry>([^<>]*)</entry>', $lines[$nr], $regs)) {
$key = $regs[1];
}
}
$entry .= $lines[$nr];
if (!$key) {
echo "No key found, key: ";
var_dump($key);
echo "entry: ";
var_dump($entry);
exit;
}
if (isset($entries[$key])) {
// duplicate key, in order to get a stable sorting, add NUL byte and
// (line number + 1000000)
$key .= "\0".(1000000+$nr);
}
$entries[$key] = $entry;
}
echo count($entries)." entries found\n";
echo "Sorting entries...\n";
asort($entries);
echo "Writing sorted entries...\n";
foreach ($entries as $entry) {
fwrite($out, $entry);
}
echo "Copying rest of file...\n";
for (;isset($lines[$nr]); $nr++) {
fwrite($out, $lines[$nr]);
}
fclose($out);
?>
Done!
(you you still need to copy <?php echo $filename;?>.sorted
on top of <?php echo $filename;?> after a quick check)
|