20 require_once
'PEAR.php';
21 require_once
'Console/Getopt.php';
71 function _parseArgs($argv, $short_options, $long_options = null)
73 if (!is_array($argv) && $argv !== null) {
74 $argv = preg_split(
'/\s+/', $argv, -1, PREG_SPLIT_NO_EMPTY);
91 $error = $error->getMessage();
93 trigger_error($error, E_USER_WARNING);
124 $struct = array(
'dirs' => array(),
'files' => array());
125 if (($dir = @opendir($sPath)) ===
false) {
132 $struct[
'dirs'][] = $sPath = realpath($sPath);
134 while (
false !== (
$file = readdir($dir))) {
142 if ($aktinst < $maxinst || $maxinst == 0) {
143 foreach ($list as $val) {
144 $path = $sPath . DIRECTORY_SEPARATOR . $val;
147 $struct = array_merge_recursive($struct, $tmp);
149 $struct[
'files'][] =
$path;
167 $struct = array(
'dirs' => array(),
'files' => array());
168 settype($files,
'array');
169 foreach ($files as
$file) {
170 if (is_dir($file) && !is_link($file)) {
172 $struct = array_merge_recursive($tmp, $struct);
174 if (!in_array($file, $struct[
'files'])) {
175 $struct[
'files'][] =
$file;
197 foreach ($opts[0] as $opt) {
198 if ($opt[0] ==
'r') {
199 $do_recursive =
true;
203 if (isset($do_recursive)) {
205 foreach ($struct[
'files'] as
$file) {
206 if (!@unlink($file)) {
211 rsort($struct[
'dirs']);
212 foreach ($struct[
'dirs'] as $dir) {
218 foreach ($opts[1] as
$file) {
219 $delete = (is_dir($file)) ?
'rmdir' :
'unlink';
220 if (!@$delete($file)) {
245 foreach ($opts[0] as $opt) {
246 if ($opt[0] ==
'p') {
247 $create_parents =
true;
248 } elseif ($opt[0] ==
'm') {
251 if (strlen($opt[1]) && $opt[1]{0} ==
'0') {
252 $opt[1] = octdec($opt[1]);
262 if (isset($create_parents)) {
263 foreach ($opts[1] as $dir) {
265 while ((!file_exists($dir) || !is_dir($dir)) &&
266 $dir != DIRECTORY_SEPARATOR) {
267 array_unshift($dirstack, $dir);
268 $dir = dirname($dir);
271 while ($newdir = array_shift($dirstack)) {
272 if (!is_writeable(dirname($newdir))) {
277 if (!mkdir($newdir, $mode)) {
283 foreach($opts[1] as $dir) {
284 if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
312 if (!is_array($args)) {
313 $args = preg_split(
'/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
316 $count_args = count($args);
317 for ($i = 0; $i < $count_args; $i++) {
318 if ($args[$i] ==
'>') {
320 $outputfile = $args[$i+1];
322 } elseif ($args[$i] ==
'>>') {
324 $outputfile = $args[$i+1];
327 $files[] = $args[$i];
332 if (!$outputfd = fopen($outputfile, $mode)) {
338 foreach ($files as
$file) {
339 if (!$fd = fopen($file,
'r')) {
343 while ($cont = fread($fd, 2048)) {
344 if (is_resource($outputfd)) {
345 fwrite($outputfd, $cont);
352 if (is_resource($outputfd)) {
384 static $first_time =
true;
390 foreach ($opts[0] as $opt) {
391 if ($opt[0] ==
'd') {
393 } elseif ($opt[0] ==
't') {
398 $prefix = (isset($opts[1][0])) ? $opts[1][0] :
'tmp';
399 if (!isset($tmpdir)) {
407 $tmp = tempnam($tmpdir, $prefix);
408 if (isset($tmp_is_dir)) {
410 if (!mkdir($tmp, 0700)) {
415 $GLOBALS[
'_System_temp_files'][] = $tmp;
416 if (isset($tmp_is_dir)) {
437 if (count(
$GLOBALS[
'_System_temp_files'])) {
438 $delete =
$GLOBALS[
'_System_temp_files'];
439 array_unshift($delete,
'-r');
441 $GLOBALS[
'_System_temp_files'] = array();
457 if ($var = isset($_ENV[
'TMP']) ? $_ENV[
'TMP'] : getenv(
'TMP')) {
460 if ($var = isset($_ENV[
'TEMP']) ? $_ENV[
'TEMP'] : getenv(
'TEMP')) {
463 if ($var = isset($_ENV[
'USERPROFILE']) ? $_ENV[
'USERPROFILE'] : getenv(
'USERPROFILE')) {
466 if ($var = isset($_ENV[
'windir']) ? $_ENV[
'windir'] : getenv(
'windir')) {
469 return getenv(
'SystemRoot') .
'\temp';
471 if ($var = isset($_ENV[
'TMPDIR']) ? $_ENV[
'TMPDIR'] : getenv(
'TMPDIR')) {
474 return realpath(
'/tmp');
490 if (!is_string($program) ||
'' == $program) {
495 if (basename($program) != $program) {
496 $path_elements[] = dirname($program);
497 $program = basename($program);
500 if (!ini_get(
'safe_mode') || !
$path = ini_get(
'safe_mode_exec_dir')) {
501 $path = getenv(
'PATH');
503 $path = getenv(
'Path');
506 $path_elements = explode(PATH_SEPARATOR,
$path);
510 $exe_suffixes = getenv(
'PATHEXT')
511 ? explode(PATH_SEPARATOR, getenv(
'PATHEXT'))
512 : array(
'.exe',
'.bat',
'.cmd',
'.com');
514 if (strpos($program,
'.') !==
false) {
515 array_unshift($exe_suffixes,
'');
518 $pear_is_executable = (function_exists(
'is_executable')) ?
'is_executable' :
'is_file';
520 $exe_suffixes = array(
'');
521 $pear_is_executable =
'is_executable';
524 foreach ($exe_suffixes as $suff) {
525 foreach ($path_elements as $dir) {
526 $file = $dir . DIRECTORY_SEPARATOR . $program . $suff;
527 if (@$pear_is_executable(
$file)) {
561 if (!is_array($args)) {
562 $args = preg_split(
'/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
564 $dir = realpath(array_shift($args));
570 $do_files = $do_dirs =
true;
571 $args_count = count($args);
572 for ($i = 0; $i < $args_count; $i++) {
575 if (in_array($args[$i+1], array(
'd',
'f'))) {
576 if ($args[$i+1] ==
'd') {
585 $name = preg_quote($args[$i+1],
'#');
588 $name = strtr($name, array(
'\?' =>
'.',
'\*' =>
'.*'));
589 $patterns[] =
'('.$name.
')';
593 $depth = $args[$i+1];
598 if ($do_files && $do_dirs) {
599 $files = array_merge(
$path[
'files'],
$path[
'dirs']);
600 } elseif ($do_dirs) {
601 $files =
$path[
'dirs'];
603 $files =
$path[
'files'];
605 if (count($patterns)) {
606 $dsq = preg_quote(DIRECTORY_SEPARATOR,
'#');
607 $pattern =
'#(^|'.$dsq.
')'.implode(
'|', $patterns).
'($|'.$dsq.
')#';
609 $files_count = count($files);
610 for ($i = 0; $i < $files_count; $i++) {
612 $filepart = basename($files[$i]);
613 if (preg_match($pattern, $filepart)) {