diff options
-rw-r--r-- | pear/Console/Getopt.php | 42 | ||||
-rw-r--r-- | pear/System.php | 2 | ||||
-rw-r--r-- | pear/package-Console_Getopt.xml | 13 | ||||
-rw-r--r-- | pear/package-PEAR.xml | 2 | ||||
-rw-r--r-- | pear/scripts/pearcmd.php | 4 |
5 files changed, 53 insertions, 10 deletions
diff --git a/pear/Console/Getopt.php b/pear/Console/Getopt.php index 133a5bf313..ed07753f37 100644 --- a/pear/Console/Getopt.php +++ b/pear/Console/Getopt.php @@ -52,8 +52,12 @@ class Console_Getopt { * Long and short options can be mixed. * * Most of the semantics of this function are based on GNU getopt_long(). + * + * <b>WARNING</b>: this function does not maintain full compatibility with GNU getopt_long(). + * To have full compatibility, use {@link getopt2()} * - * @param array $args an array of command-line arguments + * @param array $args an array of command-line arguments. The first argument + * should be the filename (like $argv[0]), unless it begins with - * @param string $short_options specifies the list of allowed short options * @param array $long_options specifies the list of allowed long options * @@ -72,15 +76,47 @@ class Console_Getopt { if (empty($args)) { return array(array(), array()); } - $opts = array(); - $non_opts = array(); settype($args, 'array'); if ($long_options) { sort($long_options); } + if (isset($args[0]{0}) && $args[0]{0} != '-') { + array_shift($args); + } + return Console_Getopt::doGetopt($args, $short_options, $long_options); + } + /** + * This function expects $args to contain only options and values + * @see getopt() + */ + function getopt2($args, $short_options, $long_options = null) + { + // in case you pass directly readPHPArgv() as the first arg + if (PEAR::isError($args)) { + return $args; + } + if (empty($args)) { + return array(array(), array()); + } + + settype($args, 'array'); + + if ($long_options) { + sort($long_options); + } + return Console_Getopt::doGetopt($args, $short_options, $long_options); + } + + /** + * The meat of {@link getopt()} and {@link getopt2()} + */ + function doGetopt($args, $short_options, $long_options = null) + { + $opts = array(); + $non_opts = array(); reset($args); while (list($i, $arg) = each($args)) { diff --git a/pear/System.php b/pear/System.php index 66f48fe49f..b2b2822588 100644 --- a/pear/System.php +++ b/pear/System.php @@ -68,7 +68,7 @@ class System if (!is_array($argv) && $argv !== null) { $argv = preg_split('/\s+/', $argv); } - return Console_Getopt::getopt($argv, $short_options); + return Console_Getopt::getopt2($argv, $short_options); } /** diff --git a/pear/package-Console_Getopt.xml b/pear/package-Console_Getopt.xml index 73738173c2..6e5f6e1846 100644 --- a/pear/package-Console_Getopt.xml +++ b/pear/package-Console_Getopt.xml @@ -21,11 +21,18 @@ short and long options.</description> <name>Stig Bakken</name> <email>stig@php.net</email> </maintainer> + <maintainer> + <user>cellog</user> + <role>helper</role> + <name>Greg Beaver</name> + <email>cellog@php.net</email> + </maintainer> </maintainers> <release> - <version>2.0</version> - <date>2003-12-06</date> - <notes>Revert of erroneous POSIX compatibility fix (BC break)</notes> + <version>1.2</version> + <date>2003-12-11</date> + <notes>Revert of erroneous POSIX compatibility fix in getopt(). +getopt2() must be used for POSIX compatibility (BC break).</notes> <state>stable</state> <filelist> <dir name="Console"> diff --git a/pear/package-PEAR.xml b/pear/package-PEAR.xml index 2b81e10748..50831ac349 100644 --- a/pear/package-PEAR.xml +++ b/pear/package-PEAR.xml @@ -123,7 +123,7 @@ PEAR Installer: <deps> <dep type="php" rel="ge" version="4.1"/> <dep type="pkg" rel="ge" version="1.1">Archive_Tar</dep> - <dep type="pkg" rel="ge" version="2.0">Console_Getopt</dep> + <dep type="pkg" rel="ge" version="1.2">Console_Getopt</dep> <dep type="pkg" rel="ge" version="1.0.4">XML_RPC</dep> <dep type="ext" rel="has" optional="yes">xmlrpc</dep> <dep type="ext" rel="has">xml</dep> diff --git a/pear/scripts/pearcmd.php b/pear/scripts/pearcmd.php index 09b2e30af9..338ed406c5 100644 --- a/pear/scripts/pearcmd.php +++ b/pear/scripts/pearcmd.php @@ -49,7 +49,7 @@ $all_commands = PEAR_Command::getCommands(); $argv = Console_Getopt::readPHPArgv(); $progname = basename($argv[0]); array_shift($argv); -$options = Console_Getopt::getopt($argv, "c:C:d:D:Gh?sSqu:vV"); +$options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV"); if (PEAR::isError($options)) { usage($options); } @@ -157,7 +157,7 @@ if ($fetype == 'Gtk') { $short_args = $long_args = null; PEAR_Command::getGetoptArgs($command, $short_args, $long_args); array_shift($options[1]); - if (PEAR::isError($tmp = Console_Getopt::getopt($options[1], $short_args, $long_args))) { + if (PEAR::isError($tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args))) { break; } list($tmpopt, $params) = $tmp; |