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/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)) {
41 foreach ($r[0] as $opt) {
42 if ($opt[0] == "v" || $opt[0] == "--version") {
43 _Ethna_HandleGateway_ShowVersion();
49 if (count($arg_list) == 0) {
52 $id = array_shift($arg_list);
55 $handler =& $eh->getHandler($id);
57 if (Ethna::isError($handler)) {
58 printf("no such command: %s\n\n", $id);
60 $handler =& $eh->getHandler($id);
62 if (Ethna::isError($handler)) {
63 exit(1); // should not happen.
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') {
79 * fetch options for myself
81 function _Ethna_HandleGateway_SeparateArgList($arg_list)
83 $my_arg_list = array();
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];
96 $arg_list = array_slice($arg_list, $i);
98 return array($my_arg_list, $arg_list);
104 function _Ethna_HandleGateway_ShowVersion()
107 Ethna %s (using PHP %s)
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>
120 printf($version, ETHNA_VERSION, PHP_VERSION, date('Y'));