#!/usr/local/bin/php
<?php
// PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: encls.php,v 1.2 2006/05/14 15:05:19 henoheno Exp $
+// $Id: encls.php,v 1.4 2009/03/22 15:38:02 henoheno Exp $
// Copyright (C) 2006 PukiWiki Developers Team
// License: GPL v2 or (at your option) any later version
//
echo ' --suffix -- Specify suffix (default: .txt)' . "\n";
echo ' --encoding_from -- Specify encoding (default: EUC-JP)' . "\n";
echo ' --encoding_to -- Specify encoding (default: UTF-8)' . "\n";
+ echo ' --nocheck -- Suppress check if the argument is exists as a file' . "\n";
+ echo ' --decode -- Just decode() it' . "\n";
exit(1);
}
// Options
$f_all = FALSE;
$suffix = '.txt';
-$encoding_from = 'EUC-JP';
-$encoding_to = 'UTF-8';
+$encoding_from = 'UTF-8';
+$encoding_to = 'EUC-JP';
foreach ($argv as $key => $value) {
if ($value != '' && $value[0] != '-') break;
$optarg = '';
list($value, $optarg) = explode('=', $value, 2);
switch ($value) {
case '--all' : $f_all = TRUE; break;
+ case '--decode' : $f_decode = TRUE; break;
+ case '--nocheck' : $f_nocheck = TRUE; break;
case '--suffix' : $suffix = $optarg; break;
case '--encoding_from': $encoding_from = $optarg; break;
case '--encoding_to' : $encoding_to = $optarg; break;
$argv = array_keys(get_existpages('.', $suffix));
} else {
foreach ($argv as $arg) {
- if (! file_exists($arg)) {
+ if (! $f_nocheck && ! file_exists($arg)) {
echo 'File not found: ' . $arg . "\n";
usage();
}
$suffix = '';
}
//echo $name . $suffix . "\n"; // As-is
- //echo decode($name) . $suffix . "\n"; // Decorded
- echo encode(mb_convert_encoding(decode($name),
- TARGET_ENCODING, SOURCE_ENCODING)) .
- $suffix . "\n"; // Decord -> convert -> encode
+ if ($f_decode) {
+ // Decord
+ echo decode($name) . $suffix . "\n";
+ } else {
+ // Decord -> convert -> encode
+ echo encode(mb_convert_encoding(decode($name),
+ TARGET_ENCODING, SOURCE_ENCODING)) .
+ $suffix . "\n";
+ }
//echo "\n";
}
?>