/** * @param array $arguments * @access protected */ protected function start($arguments) { $wait = false; $possibleOptions = array('help', 'version', 'wait'); $options = Console_Getopt::getopt($arguments, '', $possibleOptions); foreach ($options[0] as $option) { switch ($option[0]) { case '--help': $this->showHelp(); exit(self::SUCCESS_EXIT); break; case '--version': print PHPUnit2_Runner_Version::getVersionString() . "\n"; exit(self::SUCCESS_EXIT); break; case '--wait': $wait = true; break; } } $test = isset($options[1][0]) ? $options[1][0] : false; if ($test === false) { $this->showHelp(); exit(self::SUCCESS_EXIT); } try { return $this->doRun($this->getTest($test), $wait); } catch (Exception $e) { throw new Exception('Could not create and run test suite: ' . $e->getMessage()); } }
/** * returns the commandline arguments of a function * * @param string $argv the commandline * @param string $short_options the allowed option short-tags * @param string $long_options the allowed option long-tags * @return array the given options and there values * @access private */ function _parseArgs($argv, $short_options, $long_options = null) { if (!is_array($argv) && $argv !== null) { $argv = preg_split('/\\s+/', ': ' . $argv); } return Console_Getopt::getopt($argv, $short_options); }
/** * Constructor will parse specified short and long arguments * * @access public * @param string short options specification * @param array long options specification * @param callback error callback, call this and exit on errors if given */ function __construct($short_options, $long_options = NULL, $usage = NULL) { // use parent methods for actual parsing, store result internaly $argv = parent::readPHPArgv(); $this->options = parent::getopt($argv, $short_options, $long_options); if (PEAR::isError($this->options)) { if (!is_null($usage) && is_callable($usage)) { call_user_func($usage, $this->options->message); exit(3); } } }
function run(&$root_group) { $opt_browse_path = false; $opt_test_path = false; $argv = Console_Getopt::readPHPArgv(); if (PEAR::isError($argv)) { die('Fatal Error: ' . $argv->getMessage()) . "\n"; } $short_opts = 'ht:b:'; $long_opts = array('help', 'test=', 'browse='); $options = Console_Getopt::getopt($argv, $short_opts, $long_opts); if (PEAR::isError($options)) { $this->usage(); } foreach ($options[0] as $option) { switch ($option[0]) { case 'h': case '--help': $this->usage(); break; case 't': case '--test': $opt_test_path = $option[1]; break; case 'b': case '--browse': $opt_browse_path = $option[1]; break; } } if ($opt_browse_path) $this->browse($opt_browse_path, $root_group); if ($opt_test_path) $this->perform($opt_test_path, $root_group); if(!$opt_browse_path && !$opt_test_path) $this->browse('', $root_group); exit(0); }
function parseArgs() { // mapp of keys to values.. $args = Console_Getopt::ReadPHPArgV(); $vals = Console_Getopt::getopt($args, ''); //print_r($vals); $files = $vals[1]; if (!$files) { $this->error(0, "No Files supplied"); } foreach ($files as $file) { $realpath = realpath($file); if (!$realpath) { $this->error(0, "File {$path} Does not exist"); } $this->files[] = $realpath; } }
public static function main() { $options = Console_Getopt::getopt($_SERVER['argv'], '', array('wait')); if (PEAR::isError($options)) { // ... exit; } $test = isset($options[1][0]) ? $options[1][0] : false; $wait = isset($options[0][0][0]) ? true : false; if ($test) { $testRunner = new PHPUnit_TextUI_TestRunner(); try { $result = $testRunner->doRun($testRunner->getTest($test), $wait); } catch (Exception $e) { // ... } } else { // ... } }
protected function parseParams($namespace, $task, $cliParams = array()) { sgAutoloader::loadFile('Console_Getopt', dirname(__FILE__) . '/vendor/Console/Getopt.php'); $arguments = array(); $options = array(); $taskDefinition = self::getTask($namespace, $task); if (isset($taskDefinition['options']) || isset($taskDefinition['arguments'])) { if (!isset($taskDefinition['arguments'])) { $taskDefinition['arguments'] = array(); } if (!isset($taskDefinition['options']['short'])) { $taskDefinition['options']['short'] = null; } if (!isset($taskDefinition['options']['long'])) { $taskDefinition['options']['long'] = array(); } try { $params = Console_Getopt::getopt($cliParams, $taskDefinition['options']['short'], $taskDefinition['options']['long']); if (!empty($taskDefinition['arguments']) && (!isset($params[1]) || count($taskDefinition['arguments']) !== count($params[1]))) { throw new Exception('Missing required argument.'); } $arguments = array(); if (!empty($taskDefinition['arguments'])) { $arguments = array_combine($taskDefinition['arguments'], $params[1]); } $options = array(); foreach ($params[0] as $param) { $options[$param[0]] = $param[1]; } } catch (Exception $e) { $error = array(); $error[] = $e->getMessage(); if (isset($taskDefinition['usage'])) { $error[] = 'Usage: ' . $taskDefinition['usage']; } sgCLI::error($error); return false; } } return array('arguments' => $arguments, 'options' => $options); }
/** * */ public function getParams() { $short_opts = 'hdcsl'; $long_opts = array('help', 'debug', 'compress', 'strict', 'lexdebug'); $console = new Console_Getopt(); $args = $console->readPHPArgv(); $opts = $console->getopt($args, $short_opts, $long_opts); if (PEAR::isError($opts)) { echo $opts->getMessage() . PHP_EOL; $this->usage(1); } foreach ($opts[0] as $opt) { if ($opt[0] === '--help' || $opt[0] === 'h') { $this->usage(); } if ($opt[0] === '--debug' || $opt[0] === 'd') { SmartCSS::$debug = true; } if ($opt[0] === '--compress' || $opt[0] === 'c') { SmartCSS::$compress = true; } if ($opt[0] === '--strict' || $opt[0] === 's') { SmartCSS::$strict = true; } if ($opt[0] === '--lexdebug' || $opt[0] === 'l') { SmartCSS::$lexdebug = true; } } if (empty($opts[1])) { $this->usage(); } $filename = $opts[1][0]; if (empty($filename)) { $this->usage(); } return $filename; }
Usage: docgen.php [options] output-directory Options: --plugin=... build docs for given plugin instead of core ENDOFHELP; define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); set_include_path(INSTALLDIR . DIRECTORY_SEPARATOR . 'extlib' . PATH_SEPARATOR . get_include_path()); $pattern = "*.php *.inc"; $exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*'; $plugin = false; require_once 'Console/Getopt.php'; $parser = new Console_Getopt(); $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions); if (PEAR::isError($result)) { print $result->getMessage() . "\n"; exit(1); } list($options, $args) = $result; foreach ($options as $option) { $arg = $option[0]; if ($arg == '--plugin') { $plugin = $options[1]; } else { if ($arg == 'h' || $arg == '--help') { print $helptext; exit(0); } }
<?php require "Getopt.php"; require "scheme.php"; $result = Console_Getopt::getopt($argv, 'p'); if (!$result || count($result[1]) < 3) { die("usage: php merge-defs.php [-p] generated-defs old-defs\n"); } $merge_params = false; list($opts, $argv) = $result; foreach ($opts as $opt) { if ($opt[0] == 'p') { $merge_params = true; } } class Merge_Parser extends Defs_Parser { function handle_include() { /* pass */ } } $new_defs = new Merge_Parser($argv[1]); $old_defs = new Merge_Parser($argv[2]); $new_defs->start_parsing(); $old_defs->start_parsing(); $new_defs->merge($old_defs, $merge_params); $new_defs->write_defs();
// Use $_SERVER if available. if (isset($_SERVER)) { $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; } else { $argc = $HTTP_SERVER_VARS['argc']; $argv = $HTTP_SERVER_VARS['argv']; } $GLOBALS['docgenstats'] = array('classes' => 0, 'constructors' => 0, 'functions' => 0, 'properties' => 0, 'signals' => 0); /* An ugly hack to counteract PHP's pernicious desire to treat + as an argument separator in command-line version. */ // I don't need this. It causes trouble. // array_walk($argv, create_function('&$x', '$x = urldecode($x);')); // Use PEAR::Console_Getopt to get the arguments from the // command line. $result = Console_Getopt::getopt($argv, 'o:p:r:d:s:l:u'); if (!$result || count($result[1]) < 2) { // Set up the help message. die("Usage: php -q generator.php [OPTION] defsfile [class ...]\n\n" . " -o <file> use overrides in <file>\n" . " -p <prefix> use <prefix> for docs\n" . " -r <file> register types from <file>\n" . " -d <path> output files to this directory\n" . " -s <path> documentation dir\n" . " -l <lang> Language\n" . " -u Update existing docs\n"); } list($opts, $argv) = $result; // Set the default options. $prefix = 'gtk'; $overrides = new Overrides(); $lang = 'en'; $update_docs = FALSE; // Override the defaults with the command line options. foreach ($opts as $opt) { list($opt_spec, $opt_arg) = $opt; if ($opt_spec == 'o') { $overrides = new Overrides($opt_arg);
/** * Get our input parameters... * @return boolean success */ function prepare() { $shortoptions = 'qvh'; $longoptions = array('quiet', 'verbose', 'help', 'skip-config'); $map = array('-s' => 'server', '--server' => 'server', '-p' => 'path', '--path' => 'path', '--sitename' => 'sitename', '--fancy' => 'fancy', '--ssl' => 'ssl', '--dbtype' => 'dbtype', '--host' => 'host', '--database' => 'database', '--username' => 'username', '--password' => 'password', '--admin-nick' => 'adminNick', '--admin-pass' => 'adminPass', '--admin-email' => 'adminEmail', '--site-profile' => 'siteProfile'); foreach ($map as $arg => $target) { if (substr($arg, 0, 2) == '--') { $longoptions[] = substr($arg, 2) . '='; } else { $shortoptions .= substr($arg, 1) . ':'; } } $parser = new Console_Getopt(); $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions); if (PEAR::isError($result)) { $this->warning($result->getMessage()); return false; } list($options, $args) = $result; // defaults $this->dbtype = 'mysql'; $this->verbose = true; // ssl is defaulted in lib/installer.php foreach ($options as $option) { $arg = $option[0]; if (isset($map[$arg])) { $var = $map[$arg]; $this->{$var} = $option[1]; if ($arg == '--fancy') { $this->{$var} = $option[1] != 'false' && $option[1] != 'no'; } } else { if ($arg == '--skip-config') { $this->skipConfig = true; } else { if ($arg == 'q' || $arg == '--quiet') { $this->verbose = false; } else { if ($arg == 'v' || $arg == '--verbose') { $this->verbose = true; } else { if ($arg == 'h' || $arg == '--help') { // will go back to show help return false; } } } } } } $fail = false; if (empty($this->server)) { $this->updateStatus("You must specify a web server for the site.", true); // path is optional though $fail = true; } if (!$this->validateDb()) { $fail = true; } if (!$this->validateAdmin()) { $fail = true; } return !$fail; }
*/ define('AUTH_HANDLER', true); define('HORDE_BASE', __DIR__ . '/../../'); define('BEATNIK_BASE', HORDE_BASE . '/beatnik'); // Do CLI checks and environment setup first. require_once HORDE_BASE . '/lib/core.php'; // Make sure no one runs this from the web. if (!Horde_CLI::runningFromCLI()) { exit("Must be run from the command line\n"); } // Load the CLI environment. $cli = Horde_Cli::init(); // We accept the user name on the command-line. require_once 'Console/Getopt.php'; try { Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:u:p:t:r', array('help', 'username='******'password='******'type=', 'rpc=')); } catch (Exception $e) { $error = _("Couldn't read command-line options."); Horde::log($error, 'DEBUG'); $cli->fatal($error); } // Show help and exit if no arguments were set. list($opts, $args) = $ret; if (!$opts) { showHelp(); exit; } foreach ($opts as $opt) { list($optName, $optValue) = $opt; switch ($optName) { case 'u':
// get log object $oLog = PHP_Beautifier_Common::getLog(); //default_options $aInputFiles = STDIN; $sOutputFile = STDOUT; $sIndentChar = ' '; $iIndentNumber = 4; $aFilters = array(); $bRecursive = false; $sCompress = false; $aFiltersDirectory = array(); $iVerbose = PEAR_LOG_WARNING; //end default_options $argv = Console_Getopt::readPHPArgv(); $aLongOptions = array('input=', 'output=', 'indent_tabs==', 'indent_spaces==', 'filters=', 'directory_filters=', 'recursive', 'help', 'compress==', 'verbose'); $options = Console_Getopt::getopt($argv, "f:o:d:l:t::s::c::r?hv", $aLongOptions); if (PEAR::isError($options)) { usage($options); } foreach ($options[0] as $opt) { $sArgument = str_replace('-', '', $opt[0]); $sParam = $opt[1]; $oLog->log("Arg: " . $sArgument . "[{$sParam}]", PEAR_LOG_DEBUG); switch ($sArgument) { case 'input': case 'f': $aInputFiles = $sParam == '-' ? STDIN : array($sParam); break; case 'output': case 'o': $sOutputFile = $sParam == '-' ? STDOUT : $sParam;
#!/usr/bin/env php <?php $php = "php"; set_include_path("test/framework/external/" . PATH_SEPARATOR . "test/framework/" . get_include_path()); require_once "lib/header.php"; require_once "Console/Getopt.php"; require_once "Reduce.php"; $cg = new Console_Getopt(); $command_line = join(" ", $cg->readPHPArgv()); $opt_result = $cg->getopt($cg->readPHPArgv(), "vhc:rdDf:i:UuF:ZP:m:p:"); if (!is_array($opt_result)) { die($opt_result->message . "\n"); } list($opts, $arguments) = $opt_result; $opt_verbose = 0; $opt_help = false; $opt_command = ""; $opt_main_command = ""; $opt_pass = "******"; $opt_xml = NULL; $opt_interpret = false; $opt_dont_upper = false; $opt_upper = false; $opt_failure = false; $opt_zero = true; $opt_phc_prefix = "."; foreach ($opts as $opt) { switch ($opt[0]) { case 'h': $opt_help = true; break;
/** * * @author Piers Harding piers@catalyst.net.nz * @version 0.0.1 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License, mod/taoresource is a work derived from Moodle mod/resoruce * @package taoresource * */ require '../../../../config.php'; require "../../lib.php"; require $CFG->libdir . '/filelib.php'; include "Console/Getopt.php"; $cg = new Console_Getopt(); $allowedShortOptions = "l:f:"; $args = $cg->readPHPArgv(); $ret = $cg->getopt($args, $allowedShortOptions); if (PEAR::isError($ret)) { die("Error in command line: " . $ret->getMessage() . "\n otpions are: -f<filename> -l<lang>"); } // set the defaults $lang = 'en'; $file = "/home/piers/code/lucene/apache-solr-1.3.0/imsrepo/exampledocs/tao.xml"; // now parse the options array $opts = $ret[0]; if (sizeof($opts) > 0) { foreach ($opts as $o) { switch ($o[0]) { case 'l': $lang = $o[1]; break; case 'f':
/* test options */ $opt_separator = '->'; $opt_list = false; $opt_casefile = false; $opt_groupfile = false; /* only allow cmd line options if PEAR Console_Getopt is available */ require_once 'Console/Getopt.php'; /* PEAR lib */ if (class_exists('Console_Getopt')) { $argv = Console_Getopt::readPHPArgv(); if (PEAR::isError($argv)) { die('Fatal Error: ' . $argv->getMessage()) . "\n"; } $short_opts = "f:g:hls:p:"; $long_opts = array("help", "file=", "group=", "list", "separator=", "path="); $options = Console_Getopt::getopt($argv, $short_opts, $long_opts); if (PEAR::isError($options)) { usage($available_grouptests); } foreach ($options[0] as $option) { switch ($option[0]) { case 'h': case '--help': usage(); break; case 'f': case '--file': $opt_casefile = $option[1]; break; case 'g': case '--group':
<?php require_once 'Console/Getopt.php'; require_once 'DB.php'; function usage() { die("php -q mysql2turbine.php"); } $short = 'u:p:'; $result = Console_Getopt::getopt($argv, $short); if (PEAR::isError($result)) { die($result->getMessage() . "\n"); } list($args, $info) = $result; $argList = array('u' => array('user', 'root'), 'p' => array('pass', '')); $final = array(); while (list($arg, $defaults) = each($argList)) { for ($i = 0; $i < count($args); ++$i) { $var = $args[$i][0]; $val = $args[$i][1]; if ($arg == $var) { $final[$defaults[0]] = $val; } } if (!isset($final[$defaults[0]]) && empty($final[$defaults[0]])) { $final[$defaults[0]] = $defaults[1]; } } $database = $info[0]; $tables = array(); for ($i = 1; $i < count($info); ++$i) {
if (!defined('SQ_SYSTEM_ROOT')) { define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT); } require_once $SYSTEM_ROOT . '/core/include/init.inc'; // firstly let's check that we are OK for the version if (version_compare(PHP_VERSION, SQ_REQUIRED_PHP_VERSION, '<')) { trigger_error('<i>' . SQ_SYSTEM_LONG_NAME . '</i> requires PHP Version ' . SQ_REQUIRED_PHP_VERSION . '.<br/> You may need to upgrade.<br/> Your current version is ' . PHP_VERSION, E_USER_ERROR); } // only use console stuff if we're running from the command line require_once 'Console/Getopt.php'; $shortopt = ''; $longopt = array('package='); $con = new Console_Getopt(); $args = $con->readPHPArgv(); array_shift($args); $options = $con->getopt($args, $shortopt, $longopt); if (is_array($options[0])) { $package_list = get_console_list($options[0]); } // check to see if the default/ tech email in main.inc are provided and are correct // for more info see bug report 5804 Default and Tech Emails shouldnt break install require_once SQ_FUDGE_PATH . '/general/www.inc'; $SQ_CONF_DEFAULT_EMAIL = SQ_CONF_DEFAULT_EMAIL; if (!empty($SQ_CONF_DEFAULT_EMAIL) && !valid_email($SQ_CONF_DEFAULT_EMAIL)) { echo "Value '{$SQ_CONF_DEFAULT_EMAIL}' configued for 'SQ_CONF_DEFAULT_EMAIL' in main.inc is not valid.\nPlease fix it and try running the script again.\n"; exit(1); } $SQ_CONF_TECH_EMAIL = SQ_CONF_TECH_EMAIL; if (!empty($SQ_CONF_TECH_EMAIL) && !valid_email($SQ_CONF_TECH_EMAIL)) { echo "Value '{$SQ_CONF_TECH_EMAIL}' configured for 'SQ_CONF_TECH_EMAIL' in main.inc is not valid.\nPlease fix it and try running the script again.\n"; exit(1);
* * @license http://www.opensource.org/licenses/bsd-license.php The BSD License * @package Ethna * @version $Id: 845f8118f4e604b17227ffeda6cc5faeffe71cdf $ */ require_once 'PEAR.php'; require_once 'Console/Getopt.php'; require_once 'PEAR/PackageFileManager2.php'; require_once 'PEAR/PackageFileManager/File.php'; // avoid bugs // args $arg_list = Console_Getopt::readPHPArgv(); $state = "stable"; $is_old_package = false; $get_version = false; $r = Console_Getopt::getopt($arg_list, "abov", array("alpha", "beta", "old-package", "version")); foreach ($r[0] as $opt) { if ($opt[0] == "a" || $opt[0] == "--alpha") { $state = "alpha"; } if ($opt[0] == "b" || $opt[0] == "--beta") { $state = "beta"; } if ($opt[0] == "o" || $opt[0] == "--old-package") { $is_old_package = true; } if ($opt[0] == "v" || $opt[0] == "--version") { $get_version = true; } } $description = 'Ethna Web Application Framework';
break; default: die("Unknown line ending"); break; } } if ($_SERVER['argc'] > 1) { include "_getopt.php"; if ($windows) { $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex="); } else { $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex="); } $con = new Console_Getopt(); $args = $con->readPHPArgv(); $options = $con->getopt($args, null, $longoptions); if (PEAR::isError($options)) { die($options->getMessage()); } $paths = translateCommandArgs($options); foreach ($paths as $path) { fixPath($path); } } else { printHelp(); die; } print "\rDone!" . str_repeat(" ", 40) . "\n"; if ($saved_bytes > 0) { echo "saved " . $saved_bytes . "B"; } else {
$s = <<<__EOT__ Usage: php {$argv[0]} \t[-h|--host={$host}] \t[-p|--port={$port}] \t[-U|--username={$username}] \t[-P|--password=?] \t[-f|--from={$from}] \t[-s|--subject="{$subject}"] \trecipient-email ... __EOT__; exit($s . "\n"); } //============================================================================== require_once 'Console/Getopt.php'; $argv = Console_Getopt::readPHPArgv(); $options = Console_Getopt::getopt($argv, 'h:p:U:P:f:s:?', array('host=', 'port=', 'username='******'password='******'from=', 'subject=', 'help')); if (PEAR::isError($options)) { exit($options->getMessage() . "\n"); } $opts = $options[0]; foreach ($opts as $opt) { switch ($opt[0]) { case '--host': case 'h': $host = $opt[1]; break; case '--port': case 'p': $port = $opt[1]; break; case '--username':
$randomdata = 0; $dumpconfig = ''; $defines = array(); $daemon = 0; $daemon_args = ""; // ************************************************************************************** // THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE! $rrdtool = "/usr/bin/rrdtool"; // (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example) // ************************************************************************************** // initialize object $cg = new Console_Getopt(); $short_opts = ''; $long_opts = array("version", "help", "image-uri=", "base-href=", "config=", "output=", "debug", "uberdebug", "stats", "define=", "no-data", "randomdata", "htmloutput=", "dumpafter", "bulge", "sizedebug", "dumpconfig=", "daemon="); $args = $cg->readPHPArgv(); $ret = $cg->getopt($args, $short_opts, $long_opts); if (PEAR::isError($ret)) { die("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); } $gopts = $ret[0]; $options_output = array(); if (sizeof($gopts) > 0) { foreach ($gopts as $o) { switch ($o[0]) { case '--config': $configfile = $o[1]; break; case '--htmloutput': $htmlfile = $o[1]; break; case '--dumpafter':
function fatal_error($message) { $fh = fopen("php://stderr", "w"); fwrite($fh, "\n\n\n\n\n======================================================================== \n There was a Serious error with the PHP-GTK generator script\n======================================================================== \n {$message}\n======================================================================== \n You should type this to ensure that the c source is correctly\n generated before attempting to make again.\n \n #find . | grep defs | xargs touch\n\n \n\n\n\n"); fclose($fh); exit(1); } $old_error_reporting = error_reporting(E_ALL); if (!isset($_SERVER['argv'])) { fatal_error("\n Could not read command line arguments for generator.php \n Please ensure that this option is set in your php.ini\n register_argc_argv = On \n "); } if (isset($_SERVER['argc']) && isset($_SERVER['argv'])) { $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; } $result = Console_Getopt::getopt($argv, 'l:o:p:c:r:f:v:'); if (!$result || count($result[1]) < 2) { die("usage: php generator.php [-l logfile] [-o overridesfile] [-p prefix] [-c functionclass ] [-r typesfile] [-f savefile] [-v gtklibversion] defsfile\n"); } list($opts, $argv) = $result; $prefix = 'Gtk'; $function_class = null; $overrides = null; $register_defs = array(); $savefile = 'tmp.c'; $logfile = 'php://stderr'; $gtkversion = '2.6'; foreach ($opts as $opt) { list($opt_spec, $opt_arg) = $opt; if ($opt_spec == 'o') { $overrides = $opt_arg;
/** * Send mail to a user that has new messages * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Duck <*****@*****.**> * @package Folks */ require_once __DIR__ . '/../lib/Application.php'; Horde_Registry::appInit('folks', array('cli' => true, 'no_compress' => true)); // We accept the user name on the command-line. $ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:u:p:dt:f:c:', array('help', 'username='******'password='******'time=', 'from=', 'count=')); if ($ret instanceof PEAR_Error) { $error = _("Couldn't read command-line options."); Horde::log($error, 'DEBUG'); $cli->fatal($error); } // Show help and exit if no arguments were set. list($opts, $args) = $ret; if (!$opts) { showHelp(); exit; } foreach ($opts as $opt) { list($optName, $optValue) = $opt; switch ($optName) { case 'u':
* the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @author Martin Jansen <*****@*****.**> * @copyright 2005 The PEAR Group * @version CVS: $Id: make-partial.php 197121 2005-09-28 15:47:51Z techtonik $ */ // NOTE: originally from peardoc:/make-partial.php ; // these files should be kept in sync if (substr(PHP_VERSION, 0, 1) == "4") { require_once "PHP/Compat.php"; $components = PHP_Compat::loadVersion('5.0.0'); } require_once "Console/Getopt.php"; $console = new Console_Getopt(); $args = $console->getopt($console->readPHPArgv(), array(), array("format=", "include=", "help")); // {{{ gather arguments $format = "html"; $sections = array(); $incflag = false; foreach ($args[0] as $arg) { if ($arg[0] == "--help") { showHelp(); exit(0); } elseif ($arg[0] == "--format") { $format = $arg[1]; } elseif ($arg[0] == '--include') { $sections[] = $arg[1]; $incflag = true; } }
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, @$options[1][0]); } $short_args = $long_args = null; PEAR_Command::getGetoptArgs($command, $short_args, $long_args); if (in_array('getopt2', get_class_methods('Console_Getopt'))) { array_shift($options[1]); $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args); } else { $tmp = Console_Getopt::getopt($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) {
function filenameToFunctionName($filename) { $name = basename($filename); $name = preg_replace('/\\.[^\\.]*$/', '_', $name); $name = preg_replace('/[^a-zA-Z0-9]/', '_', $name); return $name; } function _getopt($opts, $name) { if (array_key_exists($name, $opts)) { return $opts[$name]; } else { return null; } } $res = $o->getopt($argv, 'o:thp:ej:c:', array("disable-lambdas", "disable-indentation", "include-partials", "beautify")); $opts = array(); if (is_a($res, "PEAR_error")) { usage(); die; } foreach ($res[0] as $foo) { $opts[$foo[0]] = $foo[1] === null ? true : $foo[1]; } if (_getopt($opts, "h")) { usage(); die; } $context = array(); if (_getopt($opts, "j")) { $context = json_decode(file_get_contents(_getopt($opts, "j")));
/** * Returns profiling information gathered using APD functions. * Accepts a numerical array of command-line arguments. * * Profiler::get_profiling($args) * Sort options * -a Sort by alphabetic names of subroutines. * -l Sort by number of calls to subroutines * -m Sort by memory used in a function call. * -r Sort by real time spent in subroutines. * -R Sort by real time spent in subroutines (inclusive of child calls). * -s Sort by system time spent in subroutines. * -S Sort by system time spent in subroutines (inclusive of child calls). * -u Sort by user time spent in subroutines. * -U Sort by user time spent in subroutines (inclusive of child calls). * -v Sort by average amount of time spent in subroutines. * -z Sort by user+system time spent in subroutines. (default) * * Display options * -c Display Real time elapsed alongside call tree. * -i Suppress reporting for php builtin functions * -O <cnt> Specifies maximum number of subroutines to display. (default 15) * -t Display compressed call tree. * -T Display uncompressed call tree. * * Example array: array('-a', '-l'); * * @param Array $args * @return String Profiling info */ function get_profiling($args) { $con = new Console_Getopt(); array_shift($args); $shortoptions = 'acg:hiIlmMrRsStTuUO:vzZ'; $retval = $con->getopt($args, $shortoptions); if (is_object($retval)) { usage(); } $opt['O'] = 20; foreach ($retval[0] as $kv_array) { $opt[$kv_array[0]] = $kv_array[1]; } $DATA = Profiler::_get_pprofp(); $cfg = array(); $this->parse_info('HEADER', $DATA, $cfg); $callstack = array(); $calls = array(); $indent_cur = 0; $file_hash = array(); $this->mem = array(); $t_rtime = 0; $t_stime = 0; $t_utime = 0; $c_rtimes = array(); $this->c_stimes = array(); $this->c_utimes = array(); $rtimes = array(); $this->stimes = array(); $this->utimes = array(); $rtotal = 0; $stotal = 0; $utotal = 0; $last_memory = 0; $symbol_hash = array(); $symbol_type = array(); while ($line = fgets($DATA)) { $line = rtrim($line); if (preg_match("/^END_TRACE/", $line)) { break; } list($token, $data) = preg_split("/ /", $line, 2); if ($token == '!') { list($index, $file) = preg_split("/ /", $data, 2); $file_hash[$index] = $file; continue; } if ($token == '&') { list($index, $name, $type) = preg_split("/ /", $data, 3); $symbol_hash[$index] = $name; $symbol_type[$index] = $type; continue; } if ($token == '+') { list($index, $file, $line) = preg_split("/ /", $data, 3); if (array_key_exists('i', $opt) && $symbol_type[$index] == 1) { continue; } $index_cur = $index; $calls[$index_cur]++; array_push($callstack, $index_cur); if (array_key_exists('T', $opt)) { if (array_key_exists('c', $opt)) { $retstring .= sprintf("%2.02f ", $rtotal / 1000000); } $retstring .= str_repeat(" ", $indent_cur) . $symbol_hash[$index_cur] . "\n"; if (array_key_exists('m', $opt)) { $retstring .= str_repeat(" ", $indent_cur) . "C: {$file_hash[$file]}:{$line} M: {$memory}\n"; } } elseif (array_key_exists('t', $opt)) { if ($indent_last == $indent_cur && $index_last == $index_cur) { $repcnt++; } else { if ($repcnt) { $repstr = ' (' . ++$repcnt . 'x)'; } if (array_key_exists('c', $opt)) { $retstring .= sprintf("%2.02f ", $rtotal / 1000000); } $retstring .= str_repeat(" ", $indent_last) . $symbol_hash[$index_last] . $repstr . "\n"; if (array_key_exists('m', $opt)) { $retstring .= str_repeat(" ", $indent_cur) . "C: {$file_hash[$file_last]}:{$line_last} M: {$memory}\n"; } $repstr = ''; $repcnt = 0; $index_last = $index_cur; $indent_last = $indent_cur; $file_last = $file; $line_last = $line; } } $indent_cur++; continue; } if ($token == '@') { list($file_no, $line_no, $ut, $st, $rt) = preg_split("/ /", $data); $top = array_pop($callstack); $this->utimes[$top] += $ut; $utotal += $ut; $this->stimes[$top] += $st; $stotal += $st; $rtimes[$top] += $rt; $rtotal += $rt; array_push($callstack, $top); foreach ($callstack as $stack_element) { $this->c_utimes[$stack_element] += $ut; $this->c_stimes[$stack_element] += $st; $c_rtimes[$stack_element] += $rt; } continue; } if ($token == '-') { list($index, $memory) = preg_split("/ /", $data, 2); if (array_key_exists('i', $opt) && $symbol_type[$index] == 1) { continue; } $this->mem[$index] += $memory - $last_memory; $last_memory = $memory; $indent_cur--; $tmp = array_pop($callstack); continue; } } $this->parse_info('FOOTER', $DATA, $cfg); $sort = 'by_time'; if (array_key_exists('l', $opt)) { $sort = 'by_calls'; } if (array_key_exists('m', $opt)) { $sort = 'by_mem'; } if (array_key_exists('a', $opt)) { $sort = 'by_name'; } if (array_key_exists('v', $opt)) { $sort = 'by_avgcpu'; } if (array_key_exists('r', $opt)) { $sort = 'by_rtime'; } if (array_key_exists('R', $opt)) { $sort = 'by_c_rtime'; } if (array_key_exists('s', $opt)) { $sort = 'by_stime'; } if (array_key_exists('S', $opt)) { $sort = 'by_c_stime'; } if (array_key_exists('u', $opt)) { $sort = 'by_utime'; } if (array_key_exists('U', $opt)) { $sort = 'by_c_utime'; } if (array_key_exists('Z', $opt)) { $sort = 'by_c_time'; } if (!count($symbol_hash)) { continue; } $retstring .= sprintf("\n Trace for %s\n Total Elapsed Time = %4.2f\n Total System Time = %4.2f\n Total User Time = %4.2f\n ", $cfg['caller'], $rtotal / 1000000, $stotal / 1000000, $utotal / 1000000); $retstring .= "\n\n Real User System secs/ cumm\n %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name\n --------------------------------------------------------------------------------------\n"; $l = 0; $itotal = 0; $percall = 0; $cpercall = 0; uksort($symbol_hash, $sort); foreach (array_keys($symbol_hash) as $j) { if (array_key_exists('i', $opt) && $symbol_type[$j] == 1) { continue; } if ($l++ < $opt['O']) { $pcnt = 100 * ($this->stimes[$j] + $this->utimes[$j]) / ($utotal + $stotal + $itotal); $c_pcnt = 100 * ($this->c_stimes[$j] + $this->c_utimes[$j]) / ($utotal + $stotal + $itotal); $rsecs = $rtimes[$j] / 1000000; $ssecs = $this->stimes[$j] / 1000000; $usecs = $this->utimes[$j] / 1000000; $c_rsecs = $c_rtimes[$j] / 1000000; $c_ssecs = $this->c_stimes[$j] / 1000000; $c_usecs = $this->c_utimes[$j] / 1000000; $ncalls = $calls[$j]; if (array_key_exists('z', $opt)) { $percall = ($usecs + $ssecs) / $ncalls; $cpercall = ($c_usecs + $c_ssecs) / $ncalls; if ($utotal + $stotal) { $pcnt = 100 * ($this->stimes[$j] + $this->utimes[$j]) / ($utotal + $stotal); } else { $pcnt = 100; } } if (array_key_exists('Z', $opt)) { $percall = ($usecs + $ssecs) / $ncalls; $cpercall = ($c_usecs + $c_ssecs) / $ncalls; if ($utotal + $stotal) { $pcnt = 100 * ($this->c_stimes[$j] + $this->c_utimes[$j]) / ($utotal + $stotal); } else { $pcnt = 100; } } if (array_key_exists('r', $opt)) { $percall = $rsecs / $ncalls; $cpercall = $c_rsecs / $ncalls; if ($rtotal) { $pcnt = 100 * $rtimes[$j] / $rtotal; } else { $pcnt = 100; } } if (array_key_exists('R', $opt)) { $percall = $rsecs / $ncalls; $cpercall = $c_rsecs / $ncalls; if ($rtotal) { $pcnt = 100 * $c_rtimes[$j] / $rtotal; } else { $pcnt = 100; } } if (array_key_exists('u', $opt)) { $percall = $usecs / $ncalls; $cpercall = $c_usecs / $ncalls; if ($utotal) { $pcnt = 100 * $this->utimes[$j] / $utotal; } else { $pcnt = 100; } } if (array_key_exists('U', $opt)) { $percall = $usecs / $ncalls; $cpercall = $c_usecs / $ncalls; if ($utotal) { $pcnt = 100 * $this->c_utimes[$j] / $utotal; } else { $pcnt = 100; } } if (array_key_exists('s', $opt)) { $percall = $ssecs / $ncalls; $cpercall = $c_ssecs / $ncalls; if ($stotal) { $pcnt = 100 * $this->stimes[$j] / $stotal; } else { $pcnt = 100; } } if (array_key_exists('S', $opt)) { $percall = $ssecs / $ncalls; $cpercall = $c_ssecs / $ncalls; if ($stotal) { $pcnt = 100 * $this->c_stimes[$j] / $stotal; } else { $pcnt = 100; } } // $cpercall = ($c_usecs + $c_ssecs)/$ncalls; $mem_usage = $this->mem[$j]; $name = $symbol_hash[$j]; $retstring .= sprintf("%3.01f %2.02f %2.02f %2.02f %2.02f %2.02f %2.02f %4d %2.04f %2.04f %12d %s\n", $pcnt, $rsecs, $c_rsecs, $usecs, $c_usecs, $ssecs, $c_ssecs, $ncalls, $percall, $cpercall, $mem_usage, $name); return $retstring; } } return $retstring; }
Defaults to "localhost". --mail-user The user name for the mail server. --mail-pass The password for the mail server. --mail-port The mail server port. Defaults to "143". --mail-protocol The mail server protocol. Defaults to "imap/notls". --mail-folder The folder on the mail server. Defaults to "INBOX". EOU; } require_once __DIR__ . '/../lib/Application.php'; Horde_Registry::appInit('folks', array('cli' => true)); // Read command-line parameters. $info = array(); $mail = array('host' => 'localhost', 'pass' => '', 'port' => 143, 'protocol' => 'imap/notls', 'folder' => 'INBOX'); $from_mail = false; $options = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:u', array('help', 'username='******'mail-host=', 'mail-user='******'mail-pass='******'mail-port=', 'mail-protocol=', 'mail-folder=')); if ($options instanceof PEAR_Error) { usage(); $cli->fatal($options->getMessage()); } // Convert options into a hash. This is possible because all options are only // allowed once. $opts_hash = array(); list($opts, $args) = $options; foreach ($opts as $opt) { list($optName, $optValue) = $opt; switch ($optName) { case 'h': $optName = '--help'; break; case 'u':