diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/convert-modules.php | 3 | ||||
-rw-r--r-- | tools/global-candidates.php | 75 | ||||
-rw-r--r-- | tools/jedec.php | 4 |
3 files changed, 78 insertions, 4 deletions
diff --git a/tools/convert-modules.php b/tools/convert-modules.php index f8c7a1a5..1b92490d 100644 --- a/tools/convert-modules.php +++ b/tools/convert-modules.php @@ -78,7 +78,7 @@ foreach ( $exFile = "modules/$module/lang/$lang/template-tags.json"; $existing = @json_decode(@file_get_contents($exFile), true); if (!is_array($existing)) $existing = array(); - $existing = $existing + $old; + $existing += $old; ksort($existing); if (file_put_contents($exFile, json_encode($existing, JSON_PRETTY_PRINT)) > 0) { unlink($path); @@ -181,7 +181,6 @@ echo "Processing\n"; foreach ($messages as $id => $modules) { asort($modules, SORT_NUMERIC); $modules = array_reverse($modules, true); - reset($modules); $topModule = key($modules); $topCount = $modules[$topModule]; $sum = 0; diff --git a/tools/global-candidates.php b/tools/global-candidates.php new file mode 100644 index 00000000..c42a43aa --- /dev/null +++ b/tools/global-candidates.php @@ -0,0 +1,75 @@ +<?php + +$langs = $argc > 1 && $argv[1] ? $argv[1] : 'en'; + +echo "Scanning for $langs... (pass as comma separated list, no spaces)\n"; + +$tags = []; +$strings = []; + +foreach (glob('./modules-available/*/lang/{' . $langs . '}/template-tags.json', GLOB_NOSORT | GLOB_BRACE) as $file) { + preg_match('#modules-available/([^/]+)/lang/(..)#', $file, $out); + $module = $out[1]; + $lang = $out[2]; + $j = json_decode(file_get_contents($file), true); + if (!is_array($j)) continue; + foreach ($j as $k => $v) { + if (!isset($tags[$k])) { + $tags[$k] = ['modules' => [], 'lang' => []]; + } + $tags[$k]['modules'][$module] = true; + if (!isset($tags[$k]['lang'][$lang])) { + $tags[$k]['lang'][$lang] = []; + } + $tags[$k]['lang'][$lang][$v] = true; + if (!isset($strings[$v])) { + $strings[$v] = []; + } + if (!isset($strings[$v][$k])) { + $strings[$v][$k] = []; + } + $strings[$v][$k][$module] = true; + } +} + +if ($argc > 1) { + $find = array_flip(array_slice($argv, 2)); + print_r($find); +} else $find = []; + +echo "\n\nDUPLICATE TAG NAME ACROSS DIFFERENT MODULES:\n"; +foreach ($tags as $k => &$tag) { + if (isset($find[$k])) { + echo "## LOOKUP: '$k'\n"; + print_r($tag['lang']); + } + if (count($tag['modules']) < 4) continue; + $tag['modules'] = array_keys($tag['modules']); + foreach ($tag['lang'] as &$lang) { + $lang = array_keys($lang); + } + unset($lang); + echo "## Common tag '$k'\n"; + echo " In " . count($tag['modules']) . " modules: " . implode(', ', $tag['modules']) . "\n"; + foreach ($tag['lang'] as $lang => $str) { + echo " " . count($str) . " in $lang: '" . implode("', '", $str) . "'\n"; + if (count($str) / count($tag['modules']) < 0.26) { + echo " +++ Possible candidate +++\n"; + } + } +} +unset($tag); + +echo "\n\nDUPLICATE STRINGS WITH DIFFERENT NAMES:\n"; +foreach ($strings as $text => $data) { + if (count($data) < 3) continue; + echo "## '$text' ##\n"; + foreach ($data as $tag => $mods) { + echo " As $tag in"; + foreach($mods as $mod => $count) { + echo " $mod($count) "; + } + echo "\n"; + } +} + diff --git a/tools/jedec.php b/tools/jedec.php index a4df9667..1883abb9 100644 --- a/tools/jedec.php +++ b/tools/jedec.php @@ -13,11 +13,11 @@ $last = 0; $index = 1; $line = file_get_contents('jedec'); -preg_match_all("/^\s*([1-9][0-9]?|1[01][0-9]|12[0-6])\s+([^\r\n]{2,9}(?:[a-z][^\r\n]{0,10}){1,3}[\r\n]?[^\r\n0]{0,31})(?:\s*[\r\n]\s|\s+)((?:[10]\s+){8})([0-9a-f]{2})\s*\$/sim", $line, $oout, PREG_SET_ORDER); +preg_match_all("/^\s*([1-9][0-9]?|1[01][0-9]|12[0-6])\s+([^\r\n]{2,9}(?:[a-z][^\r\n]{0,10}){1,3}[\r\n]?[^\r\n0]{0,31})(?:\s*[\r\n]\s|\s+)((?:[10]\s+){8})([0-9a-f]{2})\s*\$/im", $line, $oout, PREG_SET_ORDER); $output = []; foreach ($oout as $out) { $id = (int)$out[1]; - $name = preg_replace("/[\s\r\n]+/ms", ' ', $out[2]); + $name = preg_replace("/[\s\r\n]+/m", ' ', $out[2]); $bin = $out[3]; $hex = $out[4]; if ($id < $last) { |