getopts: manage correctely the parameters if its value is "" (should not be ignored)
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3699 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
19
getopts.php
19
getopts.php
@@ -200,14 +200,24 @@ class getopts
|
||||
if ($this->simulate !== null)
|
||||
$commandLine = $this->simulate;
|
||||
else
|
||||
$commandLine = implode (" ", $argv);
|
||||
{
|
||||
$args = array ();
|
||||
foreach ($argv as $arg)
|
||||
{
|
||||
if (strpos ($arg, " ") !== false || $arg === "")
|
||||
$args[] = "\"$arg\"";
|
||||
else
|
||||
$args[] = $arg;
|
||||
}
|
||||
$commandLine = implode (" ", $args);
|
||||
}
|
||||
$debug = false;
|
||||
$tokens = array ();
|
||||
$prevToken = "";
|
||||
// Look for sentences in the arguments of the command line
|
||||
$offset = 0;
|
||||
if ($debug) echo "\n012345678901234567890123456789\n$commandLine\n";
|
||||
while ($offset <= mb_strlen ($commandLine))
|
||||
while ($offset < mb_strlen ($commandLine))
|
||||
{
|
||||
if ($debug) echo "OFFSET=$offset\n";
|
||||
$start = strpos ($commandLine, "\"", $offset);
|
||||
@@ -224,7 +234,7 @@ class getopts
|
||||
" with $nbchars chars)\n";
|
||||
$token = substr ($commandLine, $offset + 1, $nbchars);
|
||||
$tokens[] = $token;
|
||||
$offset = $end + 1;
|
||||
$offset = $end + 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -251,8 +261,7 @@ class getopts
|
||||
//if ($this->restOfLine !== null)
|
||||
// $this->restOfLine[] = $token;
|
||||
//elseif (trim ($token) !== "")
|
||||
if (trim ($token) !== "")
|
||||
$tokens[] = $token;
|
||||
$tokens[] = $token;
|
||||
$offset = $end + 1;
|
||||
}
|
||||
if ($debug) print_r ($tokens);
|
||||
|
||||
Reference in New Issue
Block a user