Source for file ethna_handle.php

Documentation is available at ethna_handle.php

  1. <?php
  2. /**
  3.  *  ethna_handle.php
  4.  *
  5.  *  Ethna Handle Gateway
  6.  *
  7.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  8.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  9.  *  @package    Ethna
  10.  *  @version    $Id: 9afd4dfc63d5ff6211e7a09327f4c53dc6fa8300 $
  11.  */
  12. while (ob_get_level()) {
  13.     ob_end_clean();
  14. }
  15.  
  16. $base dirname(dirname(dirname(__FILE__)));
  17. ini_set('include_path'$base.PATH_SEPARATOR.ini_get('include_path'));
  18.  
  19. require_once 'Ethna/Ethna.php';
  20. require_once ETHNA_BASE '/class/Ethna_Getopt.php';
  21.  
  22. // fetch arguments
  23. $opt new Ethna_Getopt();
  24. $arg_list $opt->readPHPArgv();
  25. if (Ethna::isError($arg_list)) {
  26.     echo $arg_list->getMessage()."\n";
  27.     exit(2);
  28. }
  29. array_shift($arg_list);  // remove "ethna_handle.php"
  30.  
  31. $eh =new Ethna_Handle();
  32.  
  33. //  はじめの引数に - が含まれていればそれを分離する
  34. //  含まれていた場合、それは -v|--version でなければならない
  35. list($my_arg_list$arg_list_Ethna_HandleGateway_SeparateArgList($arg_list);
  36. $r $opt->getopt($my_arg_list"v"array("version"));
  37. if (Ethna::isError($r)) {
  38.     $id 'help';
  39. else {
  40.     // ad-hoc:(
  41.     foreach ($r[0as $opt{
  42.         if ($opt[0== "v" || $opt[0== "--version"{
  43.             _Ethna_HandleGateway_ShowVersion();
  44.             exit(2);
  45.         }
  46.     }
  47. }
  48.  
  49. if (count($arg_list== 0{
  50.     $id 'help';
  51. else {
  52.     $id array_shift($arg_list);
  53. }
  54.  
  55. $handler =$eh->getHandler($id);
  56. $handler->eh =$eh;
  57. if (Ethna::isError($handler)) {
  58.     printf("no such command: %s\n\n"$id);
  59.     $id 'help';
  60.     $handler =$eh->getHandler($id);
  61.     $handler->eh =$eh;
  62.     if (Ethna::isError($handler)) {
  63.        exit(1);  //  should not happen.
  64.     
  65. }
  66.  
  67. // don't know what will happen:)
  68. $handler->setArgList($arg_list);
  69. $r $handler->perform();
  70. if (Ethna::isError($r)) {
  71.     printf("error occured w/ command [%s]\n  -> %s\n\n"$id$r->getMessage());
  72.     if ($r->getCode(== 'usage'{
  73.         $handler->usage();
  74.     }
  75.     exit(1);
  76. }
  77.  
  78. /**
  79.  *  fetch options for myself
  80.  */
  81. {
  82.     $my_arg_list array();
  83.  
  84.     //  はじめの引数に - が含まれていたら、
  85.     //  それを $my_arg_list に入れる
  86.     //  これは --version 判定のため 
  87.     for ($i 0$i count($arg_list)$i++{
  88.         if ($arg_list[$i]{0== '-'{
  89.             // assume this should be an option for myself
  90.             $my_arg_list[$arg_list[$i];
  91.         else {
  92.             break;
  93.         }
  94.     }
  95.     $arg_list array_slice($arg_list$i);
  96.  
  97.     return array($my_arg_list$arg_list);
  98. }
  99.  
  100. /**
  101.  *  show version
  102.  */
  103. {
  104.     $version = <<<EOD
  105. Ethna %s (using PHP %s)
  106.  
  107. Copyright (c) 2004-%s,
  108.   Masaki Fujimoto <fujimoto@php.net>
  109.   halt feits <halt.feits@gmail.com>
  110.   Takuya Ookubo <sfio@sakura.ai.to>
  111.   nozzzzz <nozzzzz@gmail.com>
  112.   cocoitiban <cocoiti@comio.info>
  113.   Yoshinari Takaoka <takaoka@beatcraft.com>
  114.  
  115. http://ethna.jp/
  116.  
  117. EOD;
  118.     printf($versionETHNA_VERSIONPHP_VERSIONdate('Y'));
  119. }
  120. ?>

Documentation generated on Fri, 11 Nov 2011 03:59:45 +0900 by phpDocumentor 1.4.3