OSDN Git Service

misc :change version number to 2.6
[ethna/ethna.git] / bin / 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$
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/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[0] as $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 function _Ethna_HandleGateway_SeparateArgList($arg_list)
82 {
83     $my_arg_list = array();
84
85     //  はじめの引数に - が含まれていたら、
86     //  それを $my_arg_list に入れる
87     //  これは --version 判定のため 
88     for ($i = 0; $i < count($arg_list); $i++) {
89         if ($arg_list[$i]{0} == '-') {
90             // assume this should be an option for myself
91             $my_arg_list[] = $arg_list[$i];
92         } else {
93             break;
94         }
95     }
96     $arg_list = array_slice($arg_list, $i);
97
98     return array($my_arg_list, $arg_list);
99 }
100
101 /**
102  *  show version
103  */
104 function _Ethna_HandleGateway_ShowVersion()
105 {
106     $version = <<<EOD
107 Ethna %s (using PHP %s)
108
109 Copyright (c) 2004-%s,
110   Masaki Fujimoto <fujimoto@php.net>
111   halt feits <halt.feits@gmail.com>
112   Takuya Ookubo <sfio@sakura.ai.to>
113   nozzzzz <nozzzzz@gmail.com>
114   cocoitiban <cocoiti@comio.info>
115   Yoshinari Takaoka <takaoka@beatcraft.com>
116
117 http://ethna.jp/
118
119 EOD;
120     printf($version, ETHNA_VERSION, PHP_VERSION, date('Y'));
121 }