OSDN Git Service

Integrate creating upgrade patch to pack.sh
[pukiwiki/pukiwiki_devel.git] / encls.php
index dad3707..42a8152 100755 (executable)
--- a/encls.php
+++ b/encls.php
@@ -1,16 +1,23 @@
 #!/usr/local/bin/php
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: encls.php,v 1.1 2006/05/14 09:24:22 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
 //
 // encoded-EUC-JP.txt -> EUC-JP -> UTF-8 -> encoded-UTF-8.txt
 
+// Error reporting
+error_reporting(0); // Nothing
+//error_reporting(E_ERROR | E_PARSE); // Avoid E_WARNING, E_NOTICE, etc
+//error_reporting(E_ALL); // Debug purpose
+
 // PHP-cli only
 if (php_sapi_name() != 'cli') die('Invalid SAPI');
 if (! isset($argv)) die('PHP too old (Not 4.3.0 of above)');
 
+//////////////////////////////////
+
 $base = basename(array_shift($argv));
 function usage(){
        global $base;
@@ -22,6 +29,8 @@ function usage(){
        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);
 }
 
@@ -88,14 +97,16 @@ if (empty($argv)) usage();
 // 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;
@@ -111,7 +122,7 @@ if ($f_all && empty($argv)) {
        $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();
                }
@@ -131,10 +142,15 @@ foreach ($argv as $arg) {
                $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";
 }
 ?>