OSDN Git Service

Enable to build on FreeBSD (OSDN project server environment)
[pukiwiki/pukiwiki_devel.git] / encls.php
index ebb12ae..42a8152 100755 (executable)
--- a/encls.php
+++ b/encls.php
@@ -1,7 +1,7 @@
 #!/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
 //
@@ -29,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);
 }
 
@@ -95,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;
@@ -118,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();
                }
@@ -138,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";
 }
 ?>