GIF89a;
Mass Deface
getMessage();
$ui->outputData("ERROR: $_file is not a valid config file or is corrupted.");
// We stop, we have no idea where we are :)
exit(1);
}
// this is used in the error handler to retrieve a relative path
$_PEAR_PHPDIR = $config->get('php_dir');
$ui->setConfig($config);
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
$verbose = $config->get("verbose");
$cmdopts = array();
if ($raw) {
if (!$config->isDefinedLayer('user') && !$config->isDefinedLayer('system')) {
$found = false;
foreach ($opts as $opt) {
if ($opt[0] == 'd' || $opt[0] == 'D') {
// the user knows what they are doing, and are setting config values
$found = true;
}
}
if (!$found) {
// no prior runs, try to install PEAR
$parent = dirname(__FILE__);
if (strpos($parent, 'scripts')) {
$grandparent = dirname($parent);
$packagexml = $grandparent . DIRECTORY_SEPARATOR . 'package2.xml';
$pearbase = $grandparent;
} else {
$packagexml = $parent . DIRECTORY_SEPARATOR . 'package2.xml';
$pearbase = $parent;
}
if (file_exists($packagexml)) {
$options[1] = array(
'install',
$packagexml
);
$config->set('php_dir', $pearbase . DIRECTORY_SEPARATOR . 'php');
$config->set('data_dir', $pearbase . DIRECTORY_SEPARATOR . 'data');
$config->set('doc_dir', $pearbase . DIRECTORY_SEPARATOR . 'docs');
$config->set('test_dir', $pearbase . DIRECTORY_SEPARATOR . 'tests');
$config->set(
'ext_dir',
$pearbase . DIRECTORY_SEPARATOR . 'extensions'
);
$config->set('bin_dir', $pearbase);
$config->mergeConfigFile($pearbase . 'pear.ini', false);
$config->store();
$config->set('auto_discover', 1);
}
}
}
}
foreach ($opts as $opt) {
$param = !empty($opt[1]) ? $opt[1] : true;
switch ($opt[0]) {
case 'd':
if ($param === true) {
die(
'Invalid usage of "-d" option, expected -d config_value=value, ' .
'received "-d"' . "\n"
);
}
$possible = explode('=', $param);
if (count($possible) != 2) {
die(
'Invalid usage of "-d" option, expected ' .
'-d config_value=value, received "' . $param . '"' . "\n"
);
}
list($key, $value) = explode('=', $param);
$config->set($key, $value, 'user');
break;
case 'D':
if ($param === true) {
die(
'Invalid usage of "-d" option, expected ' .
'-d config_value=value, received "-d"' . "\n"
);
}
$possible = explode('=', $param);
if (count($possible) != 2) {
die(
'Invalid usage of "-d" option, expected ' .
'-d config_value=value, received "' . $param . '"' . "\n"
);
}
list($key, $value) = explode('=', $param);
$config->set($key, $value, 'system');
break;
case 's':
$store_user_config = true;
break;
case 'S':
$store_system_config = true;
break;
case 'u':
$config->remove($param, 'user');
break;
case 'v':
$config->set('verbose', $config->get('verbose') + 1);
break;
case 'q':
$config->set('verbose', $config->get('verbose') - 1);
break;
case 'V':
usage(null, 'version');
case 'c':
case 'C':
break;
default:
// all non pear params goes to the command
$cmdopts[$opt[0]] = $param;
break;
}
}
if ($store_system_config) {
$config->store('system');
}
if ($store_user_config) {
$config->store('user');
}
$command = (isset($options[1][0])) ? $options[1][0] : null;
if (empty($command) && ($store_user_config || $store_system_config)) {
exit;
}
if ($fetype == 'Gtk2') {
if (!$config->validConfiguration()) {
PEAR::raiseError(
"CRITICAL ERROR: no existing valid configuration files found in " .
"files '$pear_user_config' or '$pear_system_config', " .
"please copy an existing configuration file to one of these " .
"locations, or use the -c and -s options to create one"
);
}
Gtk::main();
} else {
do {
if ($command == 'help') {
usage(null, isset($options[1][1]) ? $options[1][1] : null);
}
if (!$config->validConfiguration()) {
PEAR::raiseError(
"CRITICAL ERROR: no existing valid configuration files found " .
"in files '$pear_user_config' or '$pear_system_config', " .
"please copy an existing configuration file to one of " .
"these locations, or use the -c and -s options to create one"
);
}
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$cmd = PEAR_Command::factory($command, $config);
PEAR::popErrorHandling();
if (PEAR::isError($cmd)) {
usage(null, isset($options[1][0]) ? $options[1][0] : null);
}
$short_args = $long_args = null;
PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
array_shift($options[1]);
$tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
if (PEAR::isError($tmp)) {
break;
}
list($tmpopt, $params) = $tmp;
$opts = array();
foreach ($tmpopt as $foo => $tmp2) {
list($opt, $value) = $tmp2;
if ($value === null) {
$value = true; // options without args
}
if (strlen($opt) == 1) {
$cmdoptions = $cmd->getOptions($command);
foreach ($cmdoptions as $o => $d) {
if (isset($d['shortopt']) && $d['shortopt'] == $opt) {
$opts[$o] = $value;
}
}
} else {
if (substr($opt, 0, 2) == '--') {
$opts[substr($opt, 2)] = $value;
}
}
}
$ok = $cmd->run($command, $opts, $params);
if ($ok === false) {
PEAR::raiseError("unknown command `$command'");
}
if (PEAR::isError($ok)) {
PEAR::setErrorHandling(
PEAR_ERROR_CALLBACK, array($ui, "displayFatalError")
);
PEAR::raiseError($ok);
}
} while (false);
}
// {{{ usage()
/**
* Display usage information
*
* @param mixed $error Optional error message
* @param mixed $helpsubject Optional subject/command to display help for
*
* @return void
*/
function usage($error = null, $helpsubject = null)
{
global $progname, $all_commands;
$stdout = fopen('php://stdout', 'w');
if (PEAR::isError($error)) {
fputs($stdout, $error->getMessage() . "\n");
} elseif ($error !== null) {
fputs($stdout, "$error\n");
}
if ($helpsubject != null) {
$put = cmdHelp($helpsubject);
} else {
$put = "Commands:\n";
$maxlen = max(array_map("strlen", $all_commands));
$formatstr = "%-{$maxlen}s %s\n";
ksort($all_commands);
foreach ($all_commands as $cmd => $class) {
$put .= sprintf($formatstr, $cmd, PEAR_Command::getDescription($cmd));
}
$put .=
"Usage: $progname [options] command [command-options]