/usr/share/php/PHP/Compat/Function/getopt.php is in php-compat 1.6.0a3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | <?php
define('PHP_COMPAT_GETOPT_NO_VALUE', 0);
define('PHP_COMPAT_GETOPT_VALUE_REQUIRED', 1);
define('PHP_COMPAT_GETOPT_VALUE_OPTIONAL', 2);
/**
* Replace getopt()
*
* @category PHP
* @package PHP_Compat
* @license LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/function.getopt
* @author Jim Wigginton <terrafrost@php.net>
* @version $Revision: 301612 $
* @since PHP 4.3.0
*/
function php_compat_getopt($options, $longopts = NULL)
{
global $argv, $argc;
$output = array();
$opt = '';
if (is_array($options)) {
user_error('getopt() expects parameter 1 to be string, array given', E_USER_WARNING);
return false;
}
for ($i = 1; $i < $argc; $i++) {
switch (true) {
case is_array($longopts) && substr($argv[$i], 0, 2) == '--':
$pos = strpos($argv[$i], '=');
$opt = is_int($pos) ? substr($argv[$i], 2, $pos - 2) : substr($argv[$i], 2);
list($match) = array_values(preg_grep('#^' . preg_quote($opt, '#') . ':{0,2}$#', $longopts));
if (is_null($match)) {
break;
}
$value = $pos === false ? null : substr($argv[$i], $pos + 1);
$type = strlen(substr($match, strlen($opt)));
php_compat_getopt_helper($opt, $value, $type, $output);
break;
case $argv[$i][0] == '-' && preg_match('#' . preg_quote($argv[$i][1], '#') . '(:{0,2})#', $options, $matches):
$opt = $argv[$i][1];
$type = strlen($matches[1]);
$value = substr($argv[$i], 2);
if ($type == 0) {
if ($value) {
$argv[$i] = '-' . $value;
--$i;
}
$value = null;
}
php_compat_getopt_helper($opt, $value, $type, $output);
break;
case !empty($opt):
if (isset($output[$opt]) && is_array($output[$opt])) {
$output[$opt][count($output[$opt]) - 1] = $argv[$i];
} else {
$output[$opt] = $argv[$i];
}
$opt = '';
}
if (!empty($value) || $type == PHP_COMPAT_GETOPT_NO_VALUE) {
$opt = '';
}
}
return $output;
}
function php_compat_getopt_helper($opt, $value, $type, &$output) {
switch ($type) {
case PHP_COMPAT_GETOPT_NO_VALUE:
switch (true) {
case !isset($output[$opt]):
$output[$opt] = false;
break;
case is_array($output[$opt]):
$output[$opt][] = false;
break;
default:
$output[$opt] = array($output[$opt], false);
}
break;
case PHP_COMPAT_GETOPT_VALUE_REQUIRED:
if (!empty($value)) {
switch (true) {
case !isset($output[$opt]):
$output[$opt] = $value;
break;
case is_array($output[$opt]):
$output[$opt][] = $value;
break;
default:
$output[$opt] = array($output[$opt], $value);
}
}
break;
case PHP_COMPAT_GETOPT_VALUE_OPTIONAL:
$value = !empty($value) ? $value : false;
switch (true) {
case !isset($output[$opt]):
$output[$opt] = $value;
break;
case is_array($output[$opt]):
$output[$opt][] = $value;
break;
default:
$output[$opt] = array($output[$opt], $value);
}
}
}
// Define
if (!function_exists('getopt')) {
function getopt($options, $longopts = NULL) {
return php_compat_getopt($options, $longopts);
}
}
?>
|