17,6 → 17,8 |
limitations under the License. |
*/ |
|
// TODO: make use of STDERR and return different exit codes |
|
function testmd5($file) { |
// TODO: warn if an entry is multiple times (with different checksums) in a single file |
if (!file_exists($file)) { |
25,8 → 27,18 |
} |
|
$lines = file($file); |
$is_first_line = true; |
$force_utf8 = false; |
foreach ($lines as $line) { |
$line = str_replace("\xEF\xBB\xBF",'',$line); |
if ($is_first_line) { |
$tmp = 0; |
$line = str_replace("\xEF\xBB\xBF",'',$line,$tmp); |
if ($tmp > 0) $force_utf8 = true; |
$is_first_line = false; |
} |
$is_ansi = strstr(utf8_decode($line),'?') !== false; // Attention: This assumes that '?' is not part of the line! |
if (!$force_utf8 && $is_ansi) $line = utf8_encode($line); |
|
$line = trim($line); |
if ($line == '') continue; |
$line = str_replace('*', ' ', $line); |
41,7 → 53,8 |
if (strtolower($checksum) != strtolower($checksum2)) { |
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n"; |
} else { |
//echo "OK: $origname\n"; |
global $show_verbose; |
if ($show_verbose) echo "OK: $origname\n"; |
} |
} |
// TODO: Also warn about extra files which are not indexed |
49,23 → 62,33 |
} |
|
function _rec($directory) { |
$directory = rtrim($directory, '/\\'); |
|
if (!is_dir($directory)) { |
exit("Invalid directory path $directory\n"); |
} |
|
if ($dont_add_files = count(glob("$directory/*.md5")) == 0) { |
// echo "Directory $directory has no MD5 file. Skipping.\n"; |
global $show_verbose; |
if ($show_verbose) echo "Directory $directory has no MD5 file. Skipping.\n"; |
} else { |
$out = array(); |
|
// echo "Check $directory\n"; |
$md5files = glob('*.md5'); |
global $show_verbose; |
if ($show_verbose) echo "Check directory $directory\n"; |
$md5files = glob($directory.'/*.md5'); |
foreach ($md5files as $md5file) { |
testmd5($md5file); |
} |
} |
|
foreach (scandir($directory) as $file) { |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
return; |
} |
|
foreach ($sd as $file) { |
if ($file !== '.' && $file !== '..') { |
$file = $directory . '/' . $file; |
if (is_dir($file)) { |
78,16 → 101,27 |
|
# --- |
|
if ($argc != 2) { |
echo "Syntax: $argv[0] <directory>\n"; |
$show_verbose = false; |
$dir = ''; |
|
for ($i=1; $i<$argc; $i++) { |
if ($argv[$i] == '-v') { |
$show_verbose = true; |
} else { |
$dir = $argv[$i]; |
} |
} |
|
if (empty($dir)) { |
echo "Syntax: $argv[0] [-v] <directory>\n"; |
exit(2); |
} |
|
if (!is_dir($argv[1])) { |
if (!is_dir($dir)) { |
echo "Directory not found\n"; |
exit(1); |
} |
|
_rec($argv[1]); |
_rec($dir); |
|
echo "Done.\n"; |
if ($show_verbose) echo "Done.\n"; |