7 * @author Masaki Fujimoto <fujimoto@php.net>
8 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 while (ob_get_level()) {
16 $base = dirname(dirname(dirname(__FILE__)));
17 ini_set('include_path', $base.PATH_SEPARATOR.ini_get('include_path'));
19 require_once 'Ethna/Ethna.php';
20 require_once ETHNA_BASE . '/class/Ethna_Getopt.php';
23 $opt = new Ethna_Getopt();
24 $arg_list = $opt->readPHPArgv();
25 if (Ethna::isError($arg_list)) {
26 echo $arg_list->getMessage()."\n";
29 array_shift($arg_list); // remove "ethna_handle.php"
31 $eh =& new Ethna_Handle();
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 _Ethna_HandleGateway_ShowUsage();
43 foreach ($r[0] as $opt) {
44 if ($opt[0] == "v" || $opt[0] == "--version") {
45 _Ethna_HandleGateway_ShowVersion();
50 if (count($arg_list) == 0) {
51 _Ethna_HandleGateway_ShowUsage();
55 $id = array_shift($arg_list);
57 $handler =& $eh->getHandler($id);
59 if (Ethna::isError($handler)) {
60 printf("no such command: %s\n\n", $id);
61 _Ethna_HandleGateway_ShowUsage();
65 // don't know what will happen:)
66 $handler->setArgList($arg_list);
67 $r = $handler->perform();
68 if (Ethna::isError($r)) {
69 printf("error occured w/ command [%s]\n -> %s\n\n", $id, $r->getMessage());
70 if ($r->getCode() == 'usage') {
79 function _Ethna_HandleGateway_ShowUsage()
82 Type 'ethna help' for usage.
89 * fetch options for myself
91 function _Ethna_HandleGateway_SeparateArgList($arg_list)
93 $my_arg_list = array();
95 // はじめの引数に - が含まれていたら、
96 // それを $my_arg_list に入れる
97 // これは --version 判定のため
98 for ($i = 0; $i < count($arg_list); $i++) {
99 if ($arg_list[$i]{0} == '-') {
100 // assume this should be an option for myself
101 $my_arg_list[] = $arg_list[$i];
106 $arg_list = array_slice($arg_list, $i);
108 return array($my_arg_list, $arg_list);
114 function _Ethna_HandleGateway_ShowVersion()
117 Ethna %s (using PHP %s)
119 Copyright (c) 2004-%s,
120 Masaki Fujimoto <fujimoto@php.net>
121 halt feits <halt.feits@gmail.com>
122 Takuya Ookubo <sfio@sakura.ai.to>
123 nozzzzz <nozzzzz@gmail.com>
124 cocoitiban <cocoiti@comio.info>
125 Yoshinari Takaoka <takaoka@beatcraft.com>
130 printf($version, ETHNA_VERSION, PHP_VERSION, date('Y'));