From c2b7f1552c8329b5e1a6066b8aeae35c714a78b8 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 3 Aug 2013 00:05:10 +0300 Subject: [PATCH] remove unused code --- ipf/cli.php | 17 ++++- ipf/getopt.php | 197 ------------------------------------------------- 2 files changed, 14 insertions(+), 200 deletions(-) delete mode 100644 ipf/getopt.php diff --git a/ipf/cli.php b/ipf/cli.php index ccf42b0..bafdd9d 100644 --- a/ipf/cli.php +++ b/ipf/cli.php @@ -48,14 +48,25 @@ class IPF_Cli print "\n"; } + private function getArgs() + { + global $argv; + if (is_array($argv)) + return $argv; + if (@is_array($_SERVER['argv'])) + return $_SERVER['argv']; + if (@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) + return $GLOBALS['HTTP_SERVER_VARS']['argv']; + throw new IPF_Exception("IPF_Cli: Could not read command arguments (register_argc_argv=Off?)"); + } + public function run() { print "IPF command line tool. Version: ".IPF_Version::$name."\n"; print "Project config: ".IPF::get('settings_file')."\n\n"; - $opt = new IPF_Getopt(); - //$z = $opt->getopt2($opt->readPHPArgv(), array('s',)); //, array('s',)); - $args = $opt->readPHPArgv(); + $args = $this->getArgs(); + if (count($args) < 2) { $this->usage(); return; diff --git a/ipf/getopt.php b/ipf/getopt.php deleted file mode 100644 index 67fae42..0000000 --- a/ipf/getopt.php +++ /dev/null @@ -1,197 +0,0 @@ - 1 && $arg{1} == '-' && !$long_options)) { - $non_opts = array_merge($non_opts, array_slice($args, $i)); - break; - } elseif (strlen($arg) > 1 && $arg{1} == '-') { - $error = IPF_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args); - } elseif ($arg == '-') { - // - is stdin - $non_opts = array_merge($non_opts, array_slice($args, $i)); - break; - } else { - $error = IPF_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args); - } - } - - return array($opts, $non_opts); - } - - /** - * @access private - * - */ - function _parseShortOption($arg, $short_options, &$opts, &$args) - { - for ($i = 0; $i < strlen($arg); $i++) { - $opt = $arg{$i}; - $opt_arg = null; - - /* Try to find the short option in the specifier string. */ - if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') - { - throw new IPF_Exception("IPF_Getopt: unrecognized option -- $opt"); - } - - if (strlen($spec) > 1 && $spec{1} == ':') { - if (strlen($spec) > 2 && $spec{2} == ':') { - if ($i + 1 < strlen($arg)) { - /* Option takes an optional argument. Use the remainder of - the arg string if there is anything left. */ - $opts[] = array($opt, substr($arg, $i + 1)); - break; - } - } else { - /* Option requires an argument. Use the remainder of the arg - string if there is anything left. */ - if ($i + 1 < strlen($arg)) { - $opts[] = array($opt, substr($arg, $i + 1)); - break; - } else if (list(, $opt_arg) = each($args)) { - /* Else use the next argument. */; - if (IPF_Getopt::_isShortOpt($opt_arg) || IPF_Getopt::_isLongOpt($opt_arg)) { - throw new IPF_Exception("IPF_Getopt: option requires an argument -- $opt"); - } - } else { - throw new IPF_Exception("IPF_Getopt: option requires an argument -- $opt"); - } - } - } - - $opts[] = array($opt, $opt_arg); - } - } - - /** - * @access private - * - */ - function _isShortOpt($arg) - { - return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]); - } - - /** - * @access private - * - */ - function _isLongOpt($arg) - { - return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' && - preg_match('/[a-zA-Z]+$/', substr($arg, 2)); - } - - /** - * @access private - * - */ - function _parseLongOption($arg, $long_options, &$opts, &$args) - { - @list($opt, $opt_arg) = explode('=', $arg, 2); - $opt_len = strlen($opt); - - for ($i = 0; $i < count($long_options); $i++) { - $long_opt = $long_options[$i]; - $opt_start = substr($long_opt, 0, $opt_len); - $long_opt_name = str_replace('=', '', $long_opt); - - /* Option doesn't match. Go on to the next one. */ - if ($long_opt_name != $opt) { - continue; - } - - $opt_rest = substr($long_opt, $opt_len); - - /* Check that the options uniquely matches one of the allowed - options. */ - if ($i + 1 < count($long_options)) { - $next_option_rest = substr($long_options[$i + 1], $opt_len); - } else { - $next_option_rest = ''; - } - if ($opt_rest != '' && $opt{0} != '=' && - $i + 1 < count($long_options) && - $opt == substr($long_options[$i+1], 0, $opt_len) && - $next_option_rest != '' && - $next_option_rest{0} != '=') { - throw new IPF_Exception("IPF_Getopt: option --$opt is ambiguous"); - } - - if (substr($long_opt, -1) == '=') { - if (substr($long_opt, -2) != '==') { - /* Long option requires an argument. - Take the next argument if one wasn't specified. */; - if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) { - throw new IPF_Exception("IPF_Getopt: option --$opt requires an argument"); - } - if (IPF_Getopt::_isShortOpt($opt_arg) || IPF_Getopt::_isLongOpt($opt_arg)) { - throw new IPF_Exception("IPF_Getopt: option requires an argument --$opt"); - } - } - } else if ($opt_arg) { - throw new IPF_Exception("IPF_Getopt: option --$opt doesn't allow an argument"); - } - - $opts[] = array('--' . $opt, $opt_arg); - return; - } - throw new IPF_Exception("IPF_Getopt: unrecognized option --$opt"); - } - - function readPHPArgv() - { - global $argv; - if (!is_array($argv)) { - if (!@is_array($_SERVER['argv'])) { - if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) { - throw new IPF_Exception("IPF_Getopt: Could not read cmd args (register_argc_argv=Off?)"); - } - return $GLOBALS['HTTP_SERVER_VARS']['argv']; - } - return $_SERVER['argv']; - } - return $argv; - } -} - -?> -- 2.49.0