[git] phd.git branch RESTRUCTURE created. 647f4e6

From: Date: Fri, 02 Mar 2012 14:28:03 +0000
Subject: [git] phd.git branch RESTRUCTURE created. 647f4e6
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9786@lists.php.net to get a copy of this message
The branch, RESTRUCTURE on phd.git has been created at 647f4e68e4730ed7c9b66258e933e64ecdc5dc77 (commit) -- Log ---------------------------------------- commit 647f4e68e4730ed7c9b66258e933e64ecdc5dc77 Author: Gwynne Raskind <gwynne@php.net> Date: Thu Jul 16 08:10:50 2009 +0000 one more attempt at ridding us of some of those annoying mime types commit 3f64725725c2c9bb2fbffc9f41e79a4b31a2e440 Author: Gwynne Raskind <gwynne@php.net> Date: Mon Jul 13 12:15:13 2009 +0000 fix a huge number of wrong MIME types. UGH. commit 86054d0ffd9470e5f4e481dd853ef9cff4b7ac20 Author: Gwynne Raskind <gwynne@php.net> Date: Tue Jul 15 12:38:14 2008 +0000 none of this should be ignored by CVS commit e273f9584213025c195bdfc97d4c476a1572f8b5 Author: Gwynne Raskind <gwynne@php.net> Date: Tue Jul 15 12:36:24 2008 +0000 added defaults for -s and -o, deleted more 5.3 BC, finish preliminary setup.php, make -s a common option for input files, change error handling for more verbose and better defining of new verbosity levels, check that output directory is writeable, fix naming conflicts between options diff --git a/config.php b/config.php index 046d5b4..6ed030a 100644 --- a/config.php +++ b/config.php @@ -35,7 +35,9 @@ class PhDConfig 'skip_ids' => array( ), 'color_output' => false, + 'source_dir' => '.', 'output_dir' => '.', + 'intermediate_output_dir' => '.', 'php_error_output' => NULL, 'php_error_color' => false, 'user_error_output' => NULL, @@ -66,18 +68,6 @@ PhDConfig::set_php_error_output(STDERR); PhDConfig::set_user_error_output(STDERR); PhDConfig::set_phd_info_output(STDOUT); -/* {{{ Workaround/fix for Windows prior to PHP5.3 */ -if (!function_exists("getopt")) { - function getopt($short, $long) { - global $argv; - printf("I'm sorry, you are running an operating system that does not support getopt()\n"); - printf("Please either upgrade to PHP5.3 or try '%s /path/to/your/docbook.xml'\n", $argv[0]); - - return array(); - } -} -/* }}} */ - /* {{{ phd_bool($var) Returns boolean true/false on success, null on failure */ function phd_bool($val) { if (!is_string($val)) { diff --git a/include/PhDCommonOptions.class.php b/include/PhDCommonOptions.class.php index 16d2f57..b469e06 100644 --- a/include/PhDCommonOptions.class.php +++ b/include/PhDCommonOptions.class.php @@ -11,6 +11,7 @@ abstract class PhDCommonOptionsParser extends PhDOptionParser public function getOptionList() { return array( + "source:" => "s:", // Input data "color:" => "c:", // Use color output if possible "verbose:" => "v", // Adjust the verbosity level "version" => "V", // Print out version information @@ -18,6 +19,21 @@ abstract class PhDCommonOptionsParser extends PhDOptionParser ); } + public function option_s($k, $v) + { + $this->option_source($k, $v); + } + public function option_source($k, $v) + { + if (is_array($v)) { + trigger_error("Only a single input location can be supplied", E_USER_ERROR); + } + if (!is_dir($v) || !is_readable($v)) { + trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); + } + PhDConfig::set_source_dir($v); + } + public function option_v($k, $v) { if ($k[0] === 'V') { @@ -101,6 +117,8 @@ abstract class PhDCommonOptionsParser extends PhDOptionParser Copyright (c) 2008 The PHP Documentation Group {$this->getHelpText()} + -s <directory> + --source <directory> The source documentation checkout or build area (default: .) -v --verbose <int> Adjusts the verbosity level -c <bool> diff --git a/include/PhDErrors.php b/include/PhDErrors.php index 43dcdfc..4b0cf43 100644 --- a/include/PhDErrors.php +++ b/include/PhDErrors.php @@ -3,24 +3,38 @@ /* {{{ PhD error & message handler */ -// FC For PHP5.3 -if (!defined("E_DEPRECATED")) { - define("E_DEPRECATED", E_RECOVERABLE_ERROR << 1); +$error_map = array( + E_RECOVERABLE_ERROR => 'PHP Error', + E_WARNING => 'PHP Warning', + E_NOTICE => 'PHP Notice', + E_STRICT => 'PHP Strict Standards Warning', + E_DEPRECATED => 'PHP Deprecated Construct Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', +); + +function define_error($name, $explanation) { + static $lastErrorValue = E_DEPRECATED; + + define($name, $lastErrorValue <<= 1); + $GLOBALS['error_map'][$lastErrorValue] = $explanation; } // PhD verbose flags -define('VERBOSE_INDEXING', E_DEPRECATED << 1); -define('VERBOSE_FORMAT_RENDERING', VERBOSE_INDEXING << 1); -define('VERBOSE_THEME_RENDERING', VERBOSE_FORMAT_RENDERING << 1); -define('VERBOSE_RENDER_STYLE', VERBOSE_THEME_RENDERING << 1); -define('VERBOSE_PARTIAL_READING', VERBOSE_RENDER_STYLE << 1); -define('VERBOSE_PARTIAL_CHILD_READING', VERBOSE_PARTIAL_READING << 1); -define('VERBOSE_TOC_WRITING', VERBOSE_PARTIAL_CHILD_READING << 1); -define('VERBOSE_CHUNK_WRITING', VERBOSE_TOC_WRITING << 1); -define('VERBOSE_NOVERSION', VERBOSE_CHUNK_WRITING << 1); - -define('VERBOSE_ALL', (VERBOSE_NOVERSION << 1)-1); -define('VERBOSE_DEFAULT', (VERBOSE_ALL^(VERBOSE_PARTIAL_CHILD_READING|VERBOSE_CHUNK_WRITING|VERBOSE_NOVERSION))); +define_error('VERBOSE_INDEXING', 'PhD Indexer'); +define_error('VERBOSE_FORMAT_RENDERING', 'PhD Output Format'); +define_error('VERBOSE_THEME_RENDERING', 'PhD Output Theme'); +define_error('VERBOSE_RENDER_STYLE', 'PhD Rendering Style'); +define_error('VERBOSE_PARTIAL_READING', 'PhD Partial Reader'); +define_error('VERBOSE_PARTIAL_CHILD_READING', 'PhD Partial Child Reader'); +define_error('VERBOSE_TOC_WRITING', 'PhD TOC Writer'); +define_error('VERBOSE_CHUNK_WRITING', 'PhD Chunk Writer'); +define_error('VERBOSE_NOVERSION', 'Missing Version Information'); +define_error('VERBOSE_DONE', 'PhD Processing Completion'); + +define('VERBOSE_ALL', (VERBOSE_NOVERSION << 1)-1); +define('VERBOSE_DEFAULT', (VERBOSE_ALL^(VERBOSE_PARTIAL_CHILD_READING|VERBOSE_CHUNK_WRITING|VERBOSE_NOVERSION|VERBOSE_DONE))); $olderrrep = error_reporting(); error_reporting($olderrrep | VERBOSE_DEFAULT); @@ -47,27 +61,6 @@ function term_color($text, $color) /* {{{ The PhD errorhandler */ function errh($errno, $msg, $file, $line, $ctx = null) { - static $err = array( - E_DEPRECATED => 'E_DEPRECATED', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', - E_STRICT => 'E_STRICT', - E_WARNING => 'E_WARNING', - E_NOTICE => 'E_NOTICE', - - E_USER_ERROR => 'E_USER_ERROR', - E_USER_WARNING => 'E_USER_WARNING', - E_USER_NOTICE => 'E_USER_NOTICE', - - VERBOSE_INDEXING => 'VERBOSE_INDEXING', - VERBOSE_FORMAT_RENDERING => 'VERBOSE_FORMAT_RENDERING', - VERBOSE_THEME_RENDERING => 'VERBOSE_THEME_RENDERING', - VERBOSE_RENDER_STYLE => 'VERBOSE_RENDER_STYLE', - VERBOSE_PARTIAL_READING => 'VERBOSE_PARTIAL_READING', - VERBOSE_PARTIAL_CHILD_READING => 'VERBOSE_PARTIAL_CHILD_READING', - VERBOSE_TOC_WRITING => 'VERBOSE_TOC_WRITING', - VERBOSE_CHUNK_WRITING => 'VERBOSE_CHUNK_WRITING', - VERBOSE_NOVERSION => 'VERBOSE_NOVERSION', - ); static $recursive = false; // Respect the error_reporting setting @@ -93,6 +86,7 @@ function errh($errno, $msg, $file, $line, $ctx = null) { case VERBOSE_TOC_WRITING: case VERBOSE_CHUNK_WRITING: case VERBOSE_NOVERSION: + case VERBOSE_DONE: $color = PhDConfig::phd_info_color(); $output = PhDConfig::phd_info_output(); $data = $msg; @@ -123,7 +117,7 @@ function errh($errno, $msg, $file, $line, $ctx = null) { return false; } - $timestamp = term_color(sprintf("[%s - %s]", $time, $err[$errno]), $color); + $timestamp = term_color(sprintf("[%s - %s]", $time, $GLOBALS['error_map'][$errno]), $color); fprintf($output, "%s %s\n", $timestamp, $data); // Abort on fatal errors diff --git a/include/PhDRenderOptions.class.php b/include/PhDRenderOptions.class.php index 214210a..b30a481 100644 --- a/include/PhDRenderOptions.class.php +++ b/include/PhDRenderOptions.class.php @@ -14,7 +14,7 @@ class PhDRenderOptionsParser extends PhDCommonOptionsParser "docbook:" => "d:", // The Docbook XML file to render from (.manual.xml) "output:" => "o:", // The output directory "partial:" => "p:", // The ID to render (optionally ignoring its children) - "skip:" => "s:", // The ID to skip (optionally skipping its children too) + "skip:" => "k:", // The ID to skip (optionally skipping its children too) )); } @@ -90,7 +90,7 @@ class PhDRenderOptionsParser extends PhDCommonOptionsParser PhDConfig::set_render_ids($render_ids); } - public function option_s($k, $v) + public function option_k($k, $v) { $this->option_skip($k, $v); } diff --git a/include/PhDSetupOptions.class.php b/include/PhDSetupOptions.class.php index 681145d..b1d25b4 100644 --- a/include/PhDSetupOptions.class.php +++ b/include/PhDSetupOptions.class.php @@ -11,8 +11,7 @@ class PhDSetupOptionsParser extends PhDCommonOptionsParser "format:" => "f:", // The format to render (xhtml, pdf...) "theme:" => "t:", // The theme to render (phpweb, bightml..) "list::" => "l::", // List supported themes/formats - "source:" => "s:", // Input phpdoc checkout - "output:" => "o:", // Output directory or file + "output:" => "o:", // Intermediate output directory )); } @@ -26,7 +25,7 @@ class PhDSetupOptionsParser extends PhDCommonOptionsParser trigger_error("Only a single output location can be supplied", E_USER_ERROR); } @mkdir($v, 0777, true); - if (!is_dir($v) || !is_readable($v)) { + if (!is_dir($v) || !is_readable($v) || !is_writable($v)) { trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); } PhDConfig::set_intermediate_output_dir($v); @@ -138,8 +137,6 @@ class PhDSetupOptionsParser extends PhDCommonOptionsParser protected function getHelpText() { return <<<'ENDBLOB' - -s <directory> - --source <directory> The source documentation checkout (default: .) -o <directory> --output <directory> The output directory for intermediate build files (default: .) -f <formatname> diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php index 046d5b4..6ed030a 100644 --- a/phpdotnet/phd/Config.php +++ b/phpdotnet/phd/Config.php @@ -35,7 +35,9 @@ class PhDConfig 'skip_ids' => array( ), 'color_output' => false, + 'source_dir' => '.', 'output_dir' => '.', + 'intermediate_output_dir' => '.', 'php_error_output' => NULL, 'php_error_color' => false, 'user_error_output' => NULL, @@ -66,18 +68,6 @@ PhDConfig::set_php_error_output(STDERR); PhDConfig::set_user_error_output(STDERR); PhDConfig::set_phd_info_output(STDOUT); -/* {{{ Workaround/fix for Windows prior to PHP5.3 */ -if (!function_exists("getopt")) { - function getopt($short, $long) { - global $argv; - printf("I'm sorry, you are running an operating system that does not support getopt()\n"); - printf("Please either upgrade to PHP5.3 or try '%s /path/to/your/docbook.xml'\n", $argv[0]); - - return array(); - } -} -/* }}} */ - /* {{{ phd_bool($var) Returns boolean true/false on success, null on failure */ function phd_bool($val) { if (!is_string($val)) { diff --git a/phpdotnet/phd/functions.php b/phpdotnet/phd/functions.php index 43dcdfc..4b0cf43 100644 --- a/phpdotnet/phd/functions.php +++ b/phpdotnet/phd/functions.php @@ -3,24 +3,38 @@ /* {{{ PhD error & message handler */ -// FC For PHP5.3 -if (!defined("E_DEPRECATED")) { - define("E_DEPRECATED", E_RECOVERABLE_ERROR << 1); +$error_map = array( + E_RECOVERABLE_ERROR => 'PHP Error', + E_WARNING => 'PHP Warning', + E_NOTICE => 'PHP Notice', + E_STRICT => 'PHP Strict Standards Warning', + E_DEPRECATED => 'PHP Deprecated Construct Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', +); + +function define_error($name, $explanation) { + static $lastErrorValue = E_DEPRECATED; + + define($name, $lastErrorValue <<= 1); + $GLOBALS['error_map'][$lastErrorValue] = $explanation; } // PhD verbose flags -define('VERBOSE_INDEXING', E_DEPRECATED << 1); -define('VERBOSE_FORMAT_RENDERING', VERBOSE_INDEXING << 1); -define('VERBOSE_THEME_RENDERING', VERBOSE_FORMAT_RENDERING << 1); -define('VERBOSE_RENDER_STYLE', VERBOSE_THEME_RENDERING << 1); -define('VERBOSE_PARTIAL_READING', VERBOSE_RENDER_STYLE << 1); -define('VERBOSE_PARTIAL_CHILD_READING', VERBOSE_PARTIAL_READING << 1); -define('VERBOSE_TOC_WRITING', VERBOSE_PARTIAL_CHILD_READING << 1); -define('VERBOSE_CHUNK_WRITING', VERBOSE_TOC_WRITING << 1); -define('VERBOSE_NOVERSION', VERBOSE_CHUNK_WRITING << 1); - -define('VERBOSE_ALL', (VERBOSE_NOVERSION << 1)-1); -define('VERBOSE_DEFAULT', (VERBOSE_ALL^(VERBOSE_PARTIAL_CHILD_READING|VERBOSE_CHUNK_WRITING|VERBOSE_NOVERSION))); +define_error('VERBOSE_INDEXING', 'PhD Indexer'); +define_error('VERBOSE_FORMAT_RENDERING', 'PhD Output Format'); +define_error('VERBOSE_THEME_RENDERING', 'PhD Output Theme'); +define_error('VERBOSE_RENDER_STYLE', 'PhD Rendering Style'); +define_error('VERBOSE_PARTIAL_READING', 'PhD Partial Reader'); +define_error('VERBOSE_PARTIAL_CHILD_READING', 'PhD Partial Child Reader'); +define_error('VERBOSE_TOC_WRITING', 'PhD TOC Writer'); +define_error('VERBOSE_CHUNK_WRITING', 'PhD Chunk Writer'); +define_error('VERBOSE_NOVERSION', 'Missing Version Information'); +define_error('VERBOSE_DONE', 'PhD Processing Completion'); + +define('VERBOSE_ALL', (VERBOSE_NOVERSION << 1)-1); +define('VERBOSE_DEFAULT', (VERBOSE_ALL^(VERBOSE_PARTIAL_CHILD_READING|VERBOSE_CHUNK_WRITING|VERBOSE_NOVERSION|VERBOSE_DONE))); $olderrrep = error_reporting(); error_reporting($olderrrep | VERBOSE_DEFAULT); @@ -47,27 +61,6 @@ function term_color($text, $color) /* {{{ The PhD errorhandler */ function errh($errno, $msg, $file, $line, $ctx = null) { - static $err = array( - E_DEPRECATED => 'E_DEPRECATED', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', - E_STRICT => 'E_STRICT', - E_WARNING => 'E_WARNING', - E_NOTICE => 'E_NOTICE', - - E_USER_ERROR => 'E_USER_ERROR', - E_USER_WARNING => 'E_USER_WARNING', - E_USER_NOTICE => 'E_USER_NOTICE', - - VERBOSE_INDEXING => 'VERBOSE_INDEXING', - VERBOSE_FORMAT_RENDERING => 'VERBOSE_FORMAT_RENDERING', - VERBOSE_THEME_RENDERING => 'VERBOSE_THEME_RENDERING', - VERBOSE_RENDER_STYLE => 'VERBOSE_RENDER_STYLE', - VERBOSE_PARTIAL_READING => 'VERBOSE_PARTIAL_READING', - VERBOSE_PARTIAL_CHILD_READING => 'VERBOSE_PARTIAL_CHILD_READING', - VERBOSE_TOC_WRITING => 'VERBOSE_TOC_WRITING', - VERBOSE_CHUNK_WRITING => 'VERBOSE_CHUNK_WRITING', - VERBOSE_NOVERSION => 'VERBOSE_NOVERSION', - ); static $recursive = false; // Respect the error_reporting setting @@ -93,6 +86,7 @@ function errh($errno, $msg, $file, $line, $ctx = null) { case VERBOSE_TOC_WRITING: case VERBOSE_CHUNK_WRITING: case VERBOSE_NOVERSION: + case VERBOSE_DONE: $color = PhDConfig::phd_info_color(); $output = PhDConfig::phd_info_output(); $data = $msg; @@ -123,7 +117,7 @@ function errh($errno, $msg, $file, $line, $ctx = null) { return false; } - $timestamp = term_color(sprintf("[%s - %s]", $time, $err[$errno]), $color); + $timestamp = term_color(sprintf("[%s - %s]", $time, $GLOBALS['error_map'][$errno]), $color); fprintf($output, "%s %s\n", $timestamp, $data); // Abort on fatal errors diff --git a/setup.php b/setup.php index 3fa7a67..aaa58bd 100644 --- a/setup.php +++ b/setup.php @@ -15,4 +15,44 @@ if ($ROOT == "@php_dir"."@/phd") { require_once $ROOT . "/config.php"; require_once $ROOT . "/include/PhDSetupOptions.class.php"; +// We assume that the code in the option processors has checked for most of the obvious crap +if (!file_exists(PhDConfig::source_dir() . DIRECTORY_SEPARATOR . "manual.xml")) { + trigger_error("The source directory has no manual.xml file. It can not be used with PhD.", E_USER_ERROR); +} + +$saved_options = array( + 'output_format' => PhDConfig::output_format(), + 'output_theme' => PhDConfig::output_theme(), + 'intermediate_output_dir' => realpath(PhDConfig::intermediate_output_dir()), + 'source_dir' => realpath(PhDConfig::source_dir()), + 'date_format' => PhDConfig::date_format(), +); +$now = date(DATE_RFC2822); + +$options_file = <<<BLOB +<?php +/* This file was automatically generated by phd-setup at {$now}. Do not edit it by hand. */ + +BLOB; + +foreach ($saved_options as $option_name => $option_value) { + $v = var_export($option_value, 1); + $options_file .= <<<BLOB +PhDConfig::set_{$option_name}({$v}); + +BLOB; +} + +$options_file .= <<<BLOB +?> +BLOB; + +$config_file_path = PhDConfig::intermediate_output_dir() . DIRECTORY_SEPARATOR . "phd-config.php"; + +if (file_put_contents($config_file_path, $options_file) === FALSE) { + trigger_error("Unable to write the configuration file to the output directory.", E_USER_ERROR); +} + +v("Configuration successfully written to " . $config_file_path, VERBOSE_DONE); + ?> commit d312311773760b971c768875d6c9fc7f6f70a611 Author: Gwynne Raskind <gwynne@php.net> Date: Thu Jul 10 17:06:58 2008 +0000 several options that belong to setup moved there. and let's keep our quote styles straight diff --git a/include/PhDCompileOptions.class.php b/include/PhDCompileOptions.class.php index dfd2fa9..cc7ba05 100644 --- a/include/PhDCompileOptions.class.php +++ b/include/PhDCompileOptions.class.php @@ -8,10 +8,8 @@ class PhDCompileOptionsParser extends PhDCommonOptionsParser public function getOptionList() { return array_merge(parent::getOptionList(), array( - 'output:' => 'o:', // Output directory or file - 'source:' => 's:', // Input phpdoc checkout - 'force:' => 'f:', // Force DOM save on validation fail - 'partial:' => 'p:', // Root ID + "force:" => "f:", // Force DOM save on validation fail + "partial:" => "p:", // Root ID )); } @@ -23,10 +21,6 @@ class PhDCompileOptionsParser extends PhDCommonOptionsParser protected function getHelpText() { return <<<'ENDBLOB' - -o <file/directory> - --output <file/directory> The output directory or file (default: ./.manual.xml) - -s <directory> - --source <directory> The source documentation checkout (default: .) -f <bool> --force <bool> Save (true) invalid XML with errors or discard (default). -p <id> diff --git a/include/PhDRenderOptions.class.php b/include/PhDRenderOptions.class.php index 0430491..214210a 100644 --- a/include/PhDRenderOptions.class.php +++ b/include/PhDRenderOptions.class.php @@ -10,55 +10,14 @@ class PhDRenderOptionsParser extends PhDCommonOptionsParser public function getOptionList() { return array_merge(parent::getOptionList(), array( - "format:" => "f:", // The format to render (xhtml, pdf...) - "theme:" => "t:", // The theme to render (phpweb, bightml..) "index:" => "i:", // Re-index or load from cache "docbook:" => "d:", // The Docbook XML file to render from (.manual.xml) "output:" => "o:", // The output directory "partial:" => "p:", // The ID to render (optionally ignoring its children) "skip:" => "s:", // The ID to skip (optionally skipping its children too) - "list::" => "l::", // List supported themes/formats )); } - public function option_f($k, $v) - { - $this->option_format($k, $v); - } - public function option_format($k, $v) - { - if ($v != "xhtml") { - trigger_error("Only xhtml is supported at this time", E_USER_ERROR); - } - } - - public function option_t($k, $v) - { - $this->option_theme($k, $v); - } - public function option_theme($k, $v) - { - /* Remove the default themes */ - $themes = PhDConfig::output_theme(); - $themes['xhtml']['php'] = array(); - - foreach((array)$v as $i => $val) { - switch($val) { - case "phpweb": - case "chunkedhtml": - case "bightml": - case "chmsource": - if (!in_array($val, $themes["xhtml"]["php"])) { - $themes["xhtml"]["php"][] = $val; - } - break; - default: - trigger_error(sprintf("Unknown theme '%s'", $val), E_USER_ERROR); - } - } - PhDConfig::set_output_theme($themes); - } - public function option_i($k, $v) { $this->option_index($k, $v); @@ -153,66 +112,6 @@ class PhDRenderOptionsParser extends PhDCommonOptionsParser PhDConfig::set_skip_ids($skip_ids); } - public function option_l($k, $v) - { - $this->option_list($k, $v); - } - public function option_list($k, $v) - { - static $formatList = NULL; - static $themeList = NULL; - - if (is_null($formatList)) { - $formatList = array(); - foreach (glob($GLOBALS['ROOT'] . "/formats/*.php") as $item) { - $formatList[] = substr(basename($item), 0, -4); - } - } - if (is_null($themeList)) { - $themeList = array(); - foreach (glob($GLOBALS['ROOT'] . "/themes/*", GLOB_ONLYDIR) as $item) { - if (!in_array(basename($item), array('CVS', '.', '..'))) { - $maintheme = basename($item); - $subthemes = array(); - foreach (glob($item . "/*.php") as $subitem) { - $subthemes[] = substr(basename($subitem), 0, -4); - } - $themeList[$maintheme] = $subthemes; - } - } - } - - if ($v === false) { - $v = array('f', 't'); - } - - foreach((array)$v as $val) { - switch($val) { - case "f": - case "format": - case "formats": { - echo "Supported formats:\n"; - echo "\t" . implode("\n\t", $formatList) . "\n"; - break; - } - - case "t": - case "theme": - case "themes": - echo "Supported themes:\n"; - foreach ($themeList as $theme => $subthemes) { - echo "\t" . $theme . "\n\t\t" . implode("\n\t\t", $subthemes) . "\n"; - } - break; - - default: - echo "Unknown list type '$val'\n"; - break; - } - } - exit(0); - } - protected function getTitleText() { return "PhD Renderer"; @@ -221,10 +120,6 @@ class PhDRenderOptionsParser extends PhDCommonOptionsParser protected function getHelpText() { return <<<'ENDBLOB' - -f <formatname> - --format <formatname> The build format to use - -t <themename> - --theme <themename> The theme to use -i <bool> --index <bool> Index before rendering (default) or load from cache (false) -d <filename> @@ -233,10 +128,8 @@ class PhDRenderOptionsParser extends PhDCommonOptionsParser --partial <id[=bool]> The ID to render, optionally skipping its children chunks (default to true; render children) -s <id[=bool]> --skip <id[=bool]> The ID to skip, optionally skipping its children chunks (default to true; skip children) - -l <formats/themes> - --list <formats/themes> Print out the supported formats/themes (default: both) -o <directory> - --output <directory> The output directory (default: .) + --output <directory> The output directory for final generated files (default: .) ENDBLOB; } } diff --git a/include/PhDSetupOptions.class.php b/include/PhDSetupOptions.class.php index 54aae7f..681145d 100644 --- a/include/PhDSetupOptions.class.php +++ b/include/PhDSetupOptions.class.php @@ -8,10 +8,128 @@ class PhDSetupOptionsParser extends PhDCommonOptionsParser public function getOptionList() { return array_merge(parent::getOptionList(), array( -// 'output:' => 'o:', // Output directory or file + "format:" => "f:", // The format to render (xhtml, pdf...) + "theme:" => "t:", // The theme to render (phpweb, bightml..) + "list::" => "l::", // List supported themes/formats + "source:" => "s:", // Input phpdoc checkout + "output:" => "o:", // Output directory or file )); } + public function option_o($k, $v) + { + $this->option_output($k, $v); + } + public function option_output($k, $v) + { + if (is_array($v)) { + trigger_error("Only a single output location can be supplied", E_USER_ERROR); + } + @mkdir($v, 0777, true); + if (!is_dir($v) || !is_readable($v)) { + trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); + } + PhDConfig::set_intermediate_output_dir($v); + } + + public function option_f($k, $v) + { + $this->option_format($k, $v); + } + public function option_format($k, $v) + { + if ($v != "xhtml") { + trigger_error("Only xhtml is supported at this time", E_USER_ERROR); + } + } + + public function option_t($k, $v) + { + $this->option_theme($k, $v); + } + public function option_theme($k, $v) + { + /* Remove the default themes */ + $themes = PhDConfig::output_theme(); + $themes['xhtml']['php'] = array(); + + foreach((array)$v as $i => $val) { + switch($val) { + case "phpweb": + case "chunkedhtml": + case "bightml": + case "chmsource": + if (!in_array($val, $themes["xhtml"]["php"])) { + $themes["xhtml"]["php"][] = $val; + } + break; + default: + trigger_error(sprintf("Unknown theme '%s'", $val), E_USER_ERROR); + } + } + PhDConfig::set_output_theme($themes); + } + + public function option_l($k, $v) + { + $this->option_list($k, $v); + } + public function option_list($k, $v) + { + static $formatList = NULL; + static $themeList = NULL; + + if (is_null($formatList)) { + $formatList = array(); + foreach (glob($GLOBALS['ROOT'] . "/formats/*.php") as $item) { + $formatList[] = substr(basename($item), 0, -4); + } + } + if (is_null($themeList)) { + $themeList = array(); + foreach (glob($GLOBALS['ROOT'] . "/themes/*", GLOB_ONLYDIR) as $item) { + if (!in_array(basename($item), array('CVS', '.', '..'))) { + $maintheme = basename($item); + $subthemes = array(); + foreach (glob($item . "/*.php") as $subitem) { + $subthemes[] = substr(basename($subitem), 0, -4); + } + $themeList[$maintheme] = $subthemes; + } + } + } + + if ($v === false) { + $v = array('f', 't'); + } + + foreach((array)$v as $val) { + switch($val) { + case "f": + case "format": + case "formats": { + echo "Supported formats:\n"; + echo "\t" . implode("\n\t", $formatList) . "\n"; + break; + } + + case "t": + case "theme": + case "themes": + echo "Supported themes:\n"; + foreach ($themeList as $theme => $subthemes) { + echo "\t" . $theme . "\n\t\t" . implode("\n\t\t", $subthemes) . "\n"; + } + break; + + default: + echo "Unknown list type '$val'\n"; + break; + } + } + exit(0); + } + protected function getTitleText() { return "PhD Setup"; @@ -19,10 +137,18 @@ class PhDSetupOptionsParser extends PhDCommonOptionsParser protected function getHelpText() { - return '';/*<<<'ENDBLOB' - -o <file/directory> - --output <file/directory> The output directory or file (default: ./.manual.xml) -ENDBLOB;*/ + return <<<'ENDBLOB' + -s <directory> + --source <directory> The source documentation checkout (default: .) + -o <directory> + --output <directory> The output directory for intermediate build files (default: .) + -f <formatname> + --format <formatname> The output format to use + -t <themename> + --theme <themename> The theme to use + -l <formats/themes> + --list <formats/themes> Print out the supported formats/themes (default: both) +ENDBLOB; } } commit ecb9be6ee9f3174472172bacef0f01616744a01b Author: Gwynne Raskind <gwynne@php.net> Date: Thu Jul 10 16:56:45 2008 +0000 My face is red. $ only works in SVN. $ works in both. diff --git a/compile.php b/compile.php index 42fe1de..e7eefa0 100644 --- a/compile.php +++ b/compile.php @@ -1,7 +1,7 @@ #!@php_bin@ <?php /* $Id$ */ -$base_revision = '$Rev$'; +$base_revision = '$Revision$'; /* {{{ Find the $ROOT directory of PhD. @php_dir@ will be replaced by the PEAR package manager. If for some reaosn this hasn't happened, fallback to the diff --git a/include/PhDCommonOptions.class.php b/include/PhDCommonOptions.class.php index 564a05c..16d2f57 100644 --- a/include/PhDCommonOptions.class.php +++ b/include/PhDCommonOptions.class.php @@ -82,7 +82,7 @@ abstract class PhDCommonOptionsParser extends PhDOptionParser { $color = PhDConfig::phd_info_color(); $output = PhDConfig::phd_info_output(); - $rev = preg_replace('/\$Re[v](: ([\d.]+) ?)?\$$/e', "'\\1' == '' ? '??' : '\\2'", $GLOBALS['base_revision']); + $rev = preg_replace('/\$Re[v](?:ision)?(: ([\d.]+) ?)?\$$/e', "'\\1' == '' ? '??' : '\\2'", $GLOBALS['base_revision']); fprintf($output, "%s\n", term_color($this->getTitleText(), $color)); fprintf($output, "%s\n", term_color("PhD Version: " . PHD_VERSION . " (" . $rev . ")", $color)); fprintf($output, "%s\n", term_color("Copyright(c) 2008 The PHP Documentation Group", $color)); diff --git a/render.php b/render.php index 401206d..a939e54 100644 --- a/render.php +++ b/render.php @@ -1,7 +1,7 @@ #!@php_bin@ <?php /* $Id$ */ -$base_revision = '$Rev$'; +$base_revision = '$Revision$'; /* {{{ Find the $ROOT directory of PhD @php_dir@ will be replaced by the pear package manager diff --git a/setup.php b/setup.php index 87f6af0..3fa7a67 100644 --- a/setup.php +++ b/setup.php @@ -1,7 +1,7 @@ #!@php_bin@ <?php /* $Id$ */ -$base_revision = '$Rev$'; +$base_revision = '$Revision$'; /* {{{ Find the $ROOT directory of PhD. @php_dir@ will be replaced by the PEAR package manager. If for some reaosn this hasn't happened, fallback to the commit e3ccfd697538e4fde66d5275b8d323a2845d3058 Author: Gwynne Raskind <gwynne@php.net> Date: Thu Jul 10 16:51:28 2008 +0000 fixed the way configs are included, added redesign notes, start phd-setup diff --git a/README.REDESIGN b/README.REDESIGN new file mode 100644 index 0000000..953268c --- /dev/null +++ b/README.REDESIGN @@ -0,0 +1,38 @@ +The redesign affects both PhD itself and the phpdoc/ checkout structure. The +changes in phpdoc/ and their reasons are listed here. + +- Pregenerated files like functable.xml removed from CVS + These can be one-timed from phd-setup as necessitated by the php.net theme + selection. + +- Intermediate manual.xml completely removed + phd-compile only needs this internally; generating it isn't time-consuming + enough to warrant a permanent file. Because it's changed on a per-language + basis, and language is determined by phd-compile, phd-setup should not + pregenerate it. + +- Remove install-win.xml and install-unix.xml + Easily generated by phd-compile --partial=install.windows or similar. + +- Remove htmlhelp/ + Replaced by CHM output format in PhD. + +- phpdoc-howto really should be its own CVS/SVN module + +- phpbook/ and docbook/ removed, replaced by docbook-xml/ + No longer necessary or used, especially not DSSSL or XSL. Only docbook-xml/ + is used by PhD for DTD validation of manual.xml. + +- PhD, all three phases, must support saving *all* output outside a CVS/SVN + checkout. PhD should not depend on the presence of any files inside a CVS/SVN + checkout save manual.xml, and allow manual.xml and specific output themes to + define anything else. PhD may also depend on the use of language + subdirectories according to theme settings. + +- Output format and theme should be defined and saved by phd-setup, but *not* + language! Also under phd-setup's responsibility are: + - input checkout directory (though it should not have to be a CVS/SVN + checkout!), + - output directory for build files + - list of available themes/formats + - *not* output directory for final results diff --git a/compile.php b/compile.php index 4997c9a..42fe1de 100644 --- a/compile.php +++ b/compile.php @@ -12,9 +12,7 @@ if ($ROOT == "@php_dir"."@/phd") { } /* }}} */ -require_once ($ROOT . "/config.php"); - -(include $ROOT . "/include/PhDCompileOptions.class.php") - or die("Invalid configuration.\nThis should never happen, did you edit config.php yourself?\nRe-run phd-setup.\n"); +require_once $ROOT . "/config.php"; +require_once $ROOT . "/include/PhDCompileOptions.class.php"; ?> diff --git a/include/PhDSetupOptions.class.php b/include/PhDSetupOptions.class.php new file mode 100644 index 0000000..54aae7f --- /dev/null +++ b/include/PhDSetupOptions.class.php @@ -0,0 +1,32 @@ +<?php +/* $Id$ */ + +require 'PhDCommonOptions.class.php'; + +class PhDSetupOptionsParser extends PhDCommonOptionsParser +{ + public function getOptionList() + { + return array_merge(parent::getOptionList(), array( +// 'output:' => 'o:', // Output directory or file + )); + } + + protected function getTitleText() + { + return "PhD Setup"; + } + + protected function getHelpText() + { + return '';/*<<<'ENDBLOB' + -o <file/directory> + --output <file/directory> The output directory or file (default: ./.manual.xml) +ENDBLOB;*/ + } +} + +$optParser = new PhDSetupOptionsParser; +$optParser->getopt(); + +?> diff --git a/render.php b/render.php index 3b9b8a9..401206d 100644 --- a/render.php +++ b/render.php @@ -13,10 +13,10 @@ if ($ROOT == "@php_dir"."@/phd") { } /* }}} */ -require_once ($ROOT . "/config.php"); +require_once $ROOT . "/config.php"; +require_once $ROOT . "/include/PhDRenderOptions.class.php"; -(include $ROOT . "/include/PhDRenderOptions.class.php") - && is_array(PhDConfig::output_theme()) +is_array(PhDConfig::output_theme()) or trigger_error("Invalid configuration. This should never happen, was config.php edited manually? Please re-run phd-setup.", E_USER_ERROR); /* If no docbook file was passed, die */ diff --git a/compile.php b/setup.php similarity index 62% copy from compile.php copy to setup.php index 4997c9a..87f6af0 100644 --- a/compile.php +++ b/setup.php @@ -12,9 +12,7 @@ if ($ROOT == "@php_dir"."@/phd") { } /* }}} */ -require_once ($ROOT . "/config.php"); - -(include $ROOT . "/include/PhDCompileOptions.class.php") - or die("Invalid configuration.\nThis should never happen, did you edit config.php yourself?\nRe-run phd-setup.\n"); +require_once $ROOT . "/config.php"; +require_once $ROOT . "/include/PhDSetupOptions.class.php"; ?> commit 0cd25c369ed01b0bdd2d8df82cafec94999c07e6 Author: Gwynne Raskind <gwynne@php.net> Date: Thu Jul 10 12:35:59 2008 +0000 added Rev tags to the program scripts, colorized version output, added Revision to version output, added compile options diff --git a/compile.php b/compile.php index b758603..4997c9a 100644 --- a/compile.php +++ b/compile.php @@ -1,6 +1,7 @@ #!@php_bin@ <?php /* $Id$ */ +$base_revision = '$Rev$'; /* {{{ Find the $ROOT directory of PhD. @php_dir@ will be replaced by the PEAR package manager. If for some reaosn this hasn't happened, fallback to the diff --git a/include/PhDCommonOptions.class.php b/include/PhDCommonOptions.class.php index 525decc..564a05c 100644 --- a/include/PhDCommonOptions.class.php +++ b/include/PhDCommonOptions.class.php @@ -80,9 +80,12 @@ abstract class PhDCommonOptionsParser extends PhDOptionParser public function option_version($k, $v) { - printf("%s\n", $this->getTitleText()); - printf("PhD version: %s\n", PHD_VERSION); - printf("Copyright (c) 2008 The PHP Documentation Group\n"); + $color = PhDConfig::phd_info_color(); + $output = PhDConfig::phd_info_output(); + $rev = preg_replace('/\$Re[v](: ([\d.]+) ?)?\$$/e', "'\\1' == '' ? '??' : '\\2'", $GLOBALS['base_revision']); + fprintf($output, "%s\n", term_color($this->getTitleText(), $color)); + fprintf($output, "%s\n", term_color("PhD Version: " . PHD_VERSION . " (" . $rev . ")", $color)); + fprintf($output, "%s\n", term_color("Copyright(c) 2008 The PHP Documentation Group", $color)); exit(0); } diff --git a/include/PhDCompileOptions.class.php b/include/PhDCompileOptions.class.php index a96ddba..dfd2fa9 100644 --- a/include/PhDCompileOptions.class.php +++ b/include/PhDCompileOptions.class.php @@ -8,7 +8,10 @@ class PhDCompileOptionsParser extends PhDCommonOptionsParser public function getOptionList() { return array_merge(parent::getOptionList(), array( -// "??????:" => "?:", // ????? + 'output:' => 'o:', // Output directory or file + 'source:' => 's:', // Input phpdoc checkout + 'force:' => 'f:', // Force DOM save on validation fail + 'partial:' => 'p:', // Root ID )); } @@ -22,6 +25,12 @@ class PhDCompileOptionsParser extends PhDCommonOptionsParser return <<<'ENDBLOB' -o <file/directory> --output <file/directory> The output directory or file (default: ./.manual.xml) + -s <directory> + --source <directory> The source documentation checkout (default: .) + -f <bool> + --force <bool> Save (true) invalid XML with errors or discard (default). + -p <id> + --partial <id> The root ID to render (default all). ENDBLOB; } } diff --git a/render.php b/render.php index e543970..3b9b8a9 100644 --- a/render.php +++ b/render.php @@ -1,6 +1,7 @@ #!@php_bin@ <?php /* $Id$ */ +$base_revision = '$Rev$'; /* {{{ Find the $ROOT directory of PhD @php_dir@ will be replaced by the pear package manager commit df111fd180660a1e62a4d44cd2cb27c08bdf2d0f Author: Gwynne Raskind <gwynne@php.net> Date: Wed Jul 9 12:14:11 2008 +0000 restructure. Fixes several spelling errors, removes pre-5.3 compatability, refactors options processing (again), removes vim cruft which prevents proper \?> syntax, fixed how config is included, use trigger_error() for config errors diff --git a/compile.php b/compile.php new file mode 100644 index 0000000..b758603 --- /dev/null +++ b/compile.php @@ -0,0 +1,19 @@ +#!@php_bin@ +<?php +/* $Id$ */ + +/* {{{ Find the $ROOT directory of PhD. @php_dir@ will be replaced by the PEAR + package manager. If for some reaosn this hasn't happened, fallback to the + dir containing this file */ +$ROOT = "@php_dir@/phd"; +if ($ROOT == "@php_dir"."@/phd") { + $ROOT = dirname(__FILE__); +} +/* }}} */ + +require_once ($ROOT . "/config.php"); + +(include $ROOT . "/include/PhDCompileOptions.class.php") + or die("Invalid configuration.\nThis should never happen, did you edit config.php yourself?\nRe-run phd-setup.\n"); + +?> diff --git a/config.php b/config.php index a89e95c..046d5b4 100644 --- a/config.php +++ b/config.php @@ -138,14 +138,12 @@ abstract class PhDOptionParser } } -/* {{{ Can't function_call()['key'], so val(function_call(), 'key') */ +/* {{{ Can't function_call()['key'], so val(function_call(), 'key') + See <http://wiki.php.net/rfc/functionarraydereferencing> */ function val($a, $k) { return $a[$k]; } /* }}} */ -/* -* vim600: sw=4 ts=4 syntax=php et -* vim<600: sw=4 ts=4 -*/ +?> diff --git a/include/PhDCommonOptions.class.php b/include/PhDCommonOptions.class.php new file mode 100644 index 0000000..525decc --- /dev/null +++ b/include/PhDCommonOptions.class.php @@ -0,0 +1,117 @@ +<?php +/* $Id$ */ + +abstract class PhDCommonOptionsParser extends PhDOptionParser +{ + public $verbose = 0; + + abstract protected function getTitleText(); + abstract protected function getHelpText(); + + public function getOptionList() + { + return array( + "color:" => "c:", // Use color output if possible + "verbose:" => "v", // Adjust the verbosity level + "version" => "V", // Print out version information + "help" => "h", // Print out help + ); + } + + public function option_v($k, $v) + { + if ($k[0] === 'V') { + $this->option_version($k, $v); + return; + } + + if (is_array($v)) { + foreach($v as $i => $val) { + $this->verbose |= pow(2, $i); + } + } else { + $this->verbose |= 1; + } + PhDConfig::set_verbose($this->verbose); + error_reporting($GLOBALS['olderrrep'] | $this->verbose); + } + + public function option_verbose($k, $v) + { + foreach((array)$v as $i => $val) { + foreach(explode("|", $val) as $const) { + if (defined($const)) { + $this->verbose |= (int)constant($const); + } elseif (is_numeric($const)) { + $this->verbose |= (int)$const; + } else { + trigger_error("Unknown option passed to --$k, $const", E_USER_ERROR); + } + } + } + PhDConfig::set_verbose($this->verbose); + error_reporting($GLOBALS['olderrrep'] | $this->verbose); + } + + public function option_c($k, $v) + { + $this->option_color($k, $v); + } + public function option_color($k, $v) + { + if (is_array($v)) { + trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); + } + $val = phd_bool($v); + if (is_bool($val)) { + if ($val && function_exists('posix_isatty')) { + PhDConfig::set_phd_info_color(posix_isatty(PhDConfig::phd_info_output()) ? '01;32' : false); // Bright (bold) green + PhDConfig::set_user_error_color(posix_isatty(PhDConfig::user_error_output()) ? '01;33' : false); // Bright (bold) yellow + PhDConfig::set_php_error_color(posix_isatty(PhDConfig::php_error_output()) ? '01;31' : false); // Bright (bold) red + } else { + PhDConfig::set_phd_info_color(false); + PhDConfig::set_user_error_color(false); + PhDConfig::set_php_error_color(false); + } + } else { + trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); + } + } + + public function option_version($k, $v) + { + printf("%s\n", $this->getTitleText()); + printf("PhD version: %s\n", PHD_VERSION); + printf("Copyright (c) 2008 The PHP Documentation Group\n"); + exit(0); + } + + public function option_h($k, $v) + { + $this->option_help($k, $v); + } + public function option_help($k, $v) + { + echo $this->getTitleText() . "\n"; + echo "PhD version: " . PHD_VERSION . "\n"; + echo <<<ENDBLOB +Copyright (c) 2008 The PHP Documentation Group + +{$this->getHelpText()} + -v + --verbose <int> Adjusts the verbosity level + -c <bool> + --color <bool> Enable color output when output is to a terminal (default: false) + -V + --version Print the PhD version information + -h + --help This help + +Most options can be passed multiple times for greater effect. + +ENDBLOB; + exit(0); + } +} + +?> diff --git a/include/PhDCompileOptions.class.php b/include/PhDCompileOptions.class.php new file mode 100644 index 0000000..a96ddba --- /dev/null +++ b/include/PhDCompileOptions.class.php @@ -0,0 +1,32 @@ +<?php +/* $Id$ */ + +require 'PhDCommonOptions.class.php'; + +class PhDCompileOptionsParser extends PhDCommonOptionsParser +{ + public function getOptionList() + { + return array_merge(parent::getOptionList(), array( +// "??????:" => "?:", // ????? + )); + } + + protected function getTitleText() + { + return "PhD XML Compiler"; + } + + protected function getHelpText() + { + return <<<'ENDBLOB' + -o <file/directory> + --output <file/directory> The output directory or file (default: ./.manual.xml) +ENDBLOB; + } +} + +$optParser = new PhDCompileOptionsParser; +$optParser->getopt(); + +?> diff --git a/include/PhDBuildOptions.class.php b/include/PhDRenderOptions.class.php similarity index 68% rename from include/PhDBuildOptions.class.php rename to include/PhDRenderOptions.class.php index 3a7f42c..0430491 100644 --- a/include/PhDBuildOptions.class.php +++ b/include/PhDRenderOptions.class.php @@ -1,14 +1,15 @@ <?php /* $Id$ */ -class PhDBuildOptionsParser extends PhDOptionParser +require 'PhDCommonOptions.class.php'; + +class PhDRenderOptionsParser extends PhDCommonOptionsParser { public $docbook = false; - public $verbose = 0; public function getOptionList() { - return array( + return array_merge(parent::getOptionList(), array( "format:" => "f:", // The format to render (xhtml, pdf...) "theme:" => "t:", // The theme to render (phpweb, bightml..) "index:" => "i:", // Re-index or load from cache @@ -16,12 +17,8 @@ class PhDBuildOptionsParser extends PhDOptionParser "output:" => "o:", // The output directory "partial:" => "p:", // The ID to render (optionally ignoring its children) "skip:" => "s:", // The ID to skip (optionally skipping its children too) - "verbose:" => "v", // Adjust the verbosity level "list::" => "l::", // List supported themes/formats - "color:" => "c:", // Use color output if possible - "version" => "V", // Print out version information - "help" => "h", // Print out help - ); + )); } public function option_f($k, $v) @@ -156,41 +153,6 @@ class PhDBuildOptionsParser extends PhDOptionParser PhDConfig::set_skip_ids($skip_ids); } - public function option_v($k, $v) - { - if ($k[0] === 'V') { - $this->option_version($k, $v); - return; - } - - if (is_array($v)) { - foreach($v as $i => $val) { - $this->verbose |= pow(2, $i); - } - } else { - $this->verbose |= 1; - } - PhDConfig::set_verbose($this->verbose); - error_reporting($GLOBALS['olderrrep'] | $this->verbose); - } - - public function option_verbose($k, $v) - { - foreach((array)$v as $i => $val) { - foreach(explode("|", $val) as $const) { - if (defined($const)) { - $this->verbose |= (int)constant($const); - } elseif (is_numeric($const)) { - $this->verbose |= (int)$const; - } else { - trigger_error("Unknown option passed to --$k, $const", E_USER_ERROR); - } - } - } - PhDConfig::set_verbose($this->verbose); - error_reporting($GLOBALS['olderrrep'] | $this->verbose); - } - public function option_l($k, $v) { $this->option_list($k, $v); @@ -251,48 +213,14 @@ class PhDBuildOptionsParser extends PhDOptionParser exit(0); } - public function option_c($k, $v) - { - $this->option_color($k, $v); - } - public function option_color($k, $v) - { - if (is_array($v)) { - trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); - } - $val = phd_bool($v); - if (is_bool($val)) { - if ($val && function_exists('posix_isatty')) { - PhDConfig::set_phd_info_color(posix_isatty(PhDConfig::phd_info_output()) ? '01;32' : false); // Bright (bold) green - PhDConfig::set_user_error_color(posix_isatty(PhDConfig::user_error_output()) ? '01;33' : false); // Bright (bold) yellow - PhDConfig::set_php_error_color(posix_isatty(PhDConfig::php_error_output()) ? '01;31' : false); // Bright (bold) red - } else { - PhDConfig::set_phd_info_color(false); - PhDConfig::set_user_error_color(false); - PhDConfig::set_php_error_color(false); - } - } else { - trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); - } - } - - public function option_version($k, $v) + protected function getTitleText() { - printf("PhD version: %s\n", PHD_VERSION); - printf("Copyright (c) 2008 The PHP Documentation Group\n"); - exit(0); + return "PhD Renderer"; } - public function option_h($k, $v) + protected function getHelpText() { - $this->option_help($k, $v); - } - public function option_help($k, $v) - { - echo "PhD version: " .PHD_VERSION; - echo "\nCopyright (c) 2008 The PHP Documentation Group\n - -v - --verbose <int> Adjusts the verbosity level + return <<<'ENDBLOB' -f <formatname> --format <formatname> The build format to use -t <themename> @@ -309,20 +237,11 @@ class PhDBuildOptionsParser extends PhDOptionParser --list <formats/themes> Print out the supported formats/themes (default: both) -o <directory> --output <directory> The output directory (default: .) - -c <bool> - --color <bool> Enable color output when output is to a terminal (default: false) - -V - --version Print the PhD version information - -h - --help This help - -Most options can be passed multiple times for greater affect. -NOTE: Long options are only supported using PHP5.3\n"; - exit(0); +ENDBLOB; } } -$optParser = new PhDBuildOptionsParser; +$optParser = new PhDRenderOptionsParser; $optParser->getopt(); ?> diff --git a/phpdotnet/phd/BuildOptionsParser.php b/phpdotnet/phd/BuildOptionsParser.php deleted file mode 100644 index 3a7f42c..0000000 --- a/phpdotnet/phd/BuildOptionsParser.php +++ /dev/null @@ -1,328 +0,0 @@ -<?php -/* $Id$ */ - -class PhDBuildOptionsParser extends PhDOptionParser -{ - public $docbook = false; - public $verbose = 0; - - public function getOptionList() - { - return array( - "format:" => "f:", // The format to render (xhtml, pdf...) - "theme:" => "t:", // The theme to render (phpweb, bightml..) - "index:" => "i:", // Re-index or load from cache - "docbook:" => "d:", // The Docbook XML file to render from (.manual.xml) - "output:" => "o:", // The output directory - "partial:" => "p:", // The ID to render (optionally ignoring its children) - "skip:" => "s:", // The ID to skip (optionally skipping its children too) - "verbose:" => "v", // Adjust the verbosity level - "list::" => "l::", // List supported themes/formats - "color:" => "c:", // Use color output if possible - "version" => "V", // Print out version information - "help" => "h", // Print out help - ); - } - - public function option_f($k, $v) - { - $this->option_format($k, $v); - } - public function option_format($k, $v) - { - if ($v != "xhtml") { - trigger_error("Only xhtml is supported at this time", E_USER_ERROR); - } - } - - public function option_t($k, $v) - { - $this->option_theme($k, $v); - } - public function option_theme($k, $v) - { - /* Remove the default themes */ - $themes = PhDConfig::output_theme(); - $themes['xhtml']['php'] = array(); - - foreach((array)$v as $i => $val) { - switch($val) { - case "phpweb": - case "chunkedhtml": - case "bightml": - case "chmsource": - if (!in_array($val, $themes["xhtml"]["php"])) { - $themes["xhtml"]["php"][] = $val; - } - break; - default: - trigger_error(sprintf("Unknown theme '%s'", $val), E_USER_ERROR); - } - } - PhDConfig::set_output_theme($themes); - } - - public function option_i($k, $v) - { - $this->option_index($k, $v); - } - public function option_index($k, $v) - { - if (is_array($v)) { - trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); - } - $val = phd_bool($v); - if (is_bool($val)) { - PhDConfig::set_index($val); - } else { - trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); - } - } - - public function option_d($k, $v) - { - $this->option_docbook($k, $v); - } - public function option_docbook($k, $v) - { - if (is_array($v)) { - trigger_error("Can only parse one file at a time", E_USER_ERROR); - } - if (!file_exists($v) || is_dir($v) || !is_readable($v)) { - trigger_error(sprintf("'%s' is not a readable docbook file", $v), E_USER_ERROR); - } - PhDConfig::set_xml_root(dirname($v)); - PhDConfig::set_xml_file($v); - $this->docbook = true; - } - - public function option_o($k, $v) - { - $this->option_output($k, $v); - } - public function option_output($k, $v) - { - if (is_array($v)) { - trigger_error("Only a single output location can be supplied", E_USER_ERROR); - } - @mkdir($v, 0777, true); - if (!is_dir($v) || !is_readable($v)) { - trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); - } - PhDConfig::set_output_dir($v); - } - - public function option_p($k, $v) - { - $this->option_partial($k, $v); - } - public function option_partial($k, $v) - { - $render_ids = PhDConfig::render_ids(); - foreach((array)$v as $i => $val) { - $recursive = true; - if (strpos($val, "=") !== false) { - list($val, $recursive) = explode("=", $val); - - if (!is_numeric($recursive) && defined($recursive)) { - $recursive = constant($recursive); - } - $recursive = (bool) $recursive; - } - $render_ids[$val] = $recursive; - } - PhDConfig::set_render_ids($render_ids); - } - - public function option_s($k, $v) - { - $this->option_skip($k, $v); - } - public function option_skip($k, $v) - { - $skip_ids = PhDConfig::skip_ids(); - foreach((array)$v as $i => $val) { - $recursive = true; - if (strpos($val, "=") !== false) { - list($val, $recursive) = explode("=", $val); - - if (!is_numeric($recursive) && defined($recursive)) { - $recursive = constant($recursive); - } - $recursive = (bool) $recursive; - } - $skip_ids[$val] = $recursive; - } - PhDConfig::set_skip_ids($skip_ids); - } - - public function option_v($k, $v) - { - if ($k[0] === 'V') { - $this->option_version($k, $v); - return; - } - - if (is_array($v)) { - foreach($v as $i => $val) { - $this->verbose |= pow(2, $i); - } - } else { - $this->verbose |= 1; - } - PhDConfig::set_verbose($this->verbose); - error_reporting($GLOBALS['olderrrep'] | $this->verbose); - } - - public function option_verbose($k, $v) - { - foreach((array)$v as $i => $val) { - foreach(explode("|", $val) as $const) { - if (defined($const)) { - $this->verbose |= (int)constant($const); - } elseif (is_numeric($const)) { - $this->verbose |= (int)$const; - } else { - trigger_error("Unknown option passed to --$k, $const", E_USER_ERROR); - } - } - } - PhDConfig::set_verbose($this->verbose); - error_reporting($GLOBALS['olderrrep'] | $this->verbose); - } - - public function option_l($k, $v) - { - $this->option_list($k, $v); - } - public function option_list($k, $v) - { - static $formatList = NULL; - static $themeList = NULL; - - if (is_null($formatList)) { - $formatList = array(); - foreach (glob($GLOBALS['ROOT'] . "/formats/*.php") as $item) { - $formatList[] = substr(basename($item), 0, -4); - } - } - if (is_null($themeList)) { - $themeList = array(); - foreach (glob($GLOBALS['ROOT'] . "/themes/*", GLOB_ONLYDIR) as $item) { - if (!in_array(basename($item), array('CVS', '.', '..'))) { - $maintheme = basename($item); - $subthemes = array(); - foreach (glob($item . "/*.php") as $subitem) { - $subthemes[] = substr(basename($subitem), 0, -4); - } - $themeList[$maintheme] = $subthemes; - } - } - } - - if ($v === false) { - $v = array('f', 't'); - } - - foreach((array)$v as $val) { - switch($val) { - case "f": - case "format": - case "formats": { - echo "Supported formats:\n"; - echo "\t" . implode("\n\t", $formatList) . "\n"; - break; - } - - case "t": - case "theme": - case "themes": - echo "Supported themes:\n"; - foreach ($themeList as $theme => $subthemes) { - echo "\t" . $theme . "\n\t\t" . implode("\n\t\t", $subthemes) . "\n"; - } - break; - - default: - echo "Unknown list type '$val'\n"; - break; - } - } - exit(0); - } - - public function option_c($k, $v) - { - $this->option_color($k, $v); - } - public function option_color($k, $v) - { - if (is_array($v)) { - trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); - } - $val = phd_bool($v); - if (is_bool($val)) { - if ($val && function_exists('posix_isatty')) { - PhDConfig::set_phd_info_color(posix_isatty(PhDConfig::phd_info_output()) ? '01;32' : false); // Bright (bold) green - PhDConfig::set_user_error_color(posix_isatty(PhDConfig::user_error_output()) ? '01;33' : false); // Bright (bold) yellow - PhDConfig::set_php_error_color(posix_isatty(PhDConfig::php_error_output()) ? '01;31' : false); // Bright (bold) red - } else { - PhDConfig::set_phd_info_color(false); - PhDConfig::set_user_error_color(false); - PhDConfig::set_php_error_color(false); - } - } else { - trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); - } - } - - public function option_version($k, $v) - { - printf("PhD version: %s\n", PHD_VERSION); - printf("Copyright (c) 2008 The PHP Documentation Group\n"); - exit(0); - } - - public function option_h($k, $v) - { - $this->option_help($k, $v); - } - public function option_help($k, $v) - { - echo "PhD version: " .PHD_VERSION; - echo "\nCopyright (c) 2008 The PHP Documentation Group\n - -v - --verbose <int> Adjusts the verbosity level - -f <formatname> - --format <formatname> The build format to use - -t <themename> - --theme <themename> The theme to use - -i <bool> - --index <bool> Index before rendering (default) or load from cache (false) - -d <filename> - --docbook <filename> The Docbook file to render from - -p <id[=bool]> - --partial <id[=bool]> The ID to render, optionally skipping its children chunks (default to true; render children) - -s <id[=bool]> - --skip <id[=bool]> The ID to skip, optionally skipping its children chunks (default to true; skip children) - -l <formats/themes> - --list <formats/themes> Print out the supported formats/themes (default: both) - -o <directory> - --output <directory> The output directory (default: .) - -c <bool> - --color <bool> Enable color output when output is to a terminal (default: false) - -V - --version Print the PhD version information - -h - --help This help - -Most options can be passed multiple times for greater affect. -NOTE: Long options are only supported using PHP5.3\n"; - exit(0); - } -} - -$optParser = new PhDBuildOptionsParser; -$optParser->getopt(); - -?> diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php index a89e95c..046d5b4 100644 --- a/phpdotnet/phd/Config.php +++ b/phpdotnet/phd/Config.php @@ -138,14 +138,12 @@ abstract class PhDOptionParser } } -/* {{{ Can't function_call()['key'], so val(function_call(), 'key') */ +/* {{{ Can't function_call()['key'], so val(function_call(), 'key') + See <http://wiki.php.net/rfc/functionarraydereferencing> */ function val($a, $k) { return $a[$k]; } /* }}} */ -/* -* vim600: sw=4 ts=4 syntax=php et -* vim<600: sw=4 ts=4 -*/ +?> diff --git a/build.php b/render.php similarity index 89% rename from build.php rename to render.php index 639507f..e543970 100644 --- a/build.php +++ b/render.php @@ -12,41 +12,16 @@ if ($ROOT == "@php_dir"."@/phd") { } /* }}} */ -(include $ROOT . "/config.php") - or die("Configuration file not found.\nRe-run phd-setup.\n"); +require_once ($ROOT . "/config.php"); -(include $ROOT . "/include/PhDBuildOptions.class.php") +(include $ROOT . "/include/PhDRenderOptions.class.php") && is_array(PhDConfig::output_theme()) - or die("Invalid configuration.\nThis should never happen, did you edit config.php yourself?\nRe-run phd-setup.\n"); - -/* {{{ BC for PhD 0.0.* (and PHP5.2 on Windows) - i.e. `phd path/to/.manual.xml */ -if (!$optParser->docbook && $argc > 1) { - $arg = $argv[$argc-1]; - if (is_dir($arg)) { - PhDConfig::set_xml_root($arg); - PhDConfig::set_xml_file($arg . DIRECTORY_SEPARATOR . ".manual.xml"); - } elseif (is_file($arg)) { - PhDConfig::set_xml_root(dirname($arg)); - PhDConfig::set_xml_file($arg); - } -} -/* }}} */ + or trigger_error("Invalid configuration. This should never happen, was config.php edited manually? Please re-run phd-setup.", E_USER_ERROR); -/* {{{ If no docbook file was passed, ask for it - This loop should be removed in PhD 0.3.0, and replaced with a fatal errormsg */ -while (!is_dir(PhDConfig::xml_root()) || !is_file(PhDConfig::xml_file())) { - print "I need to know where you keep your '.manual.xml' file (I didn't find it in " . PhDConfig::xml_root() . "): "; - $root = trim(fgets(STDIN)); - if (is_file($root)) { - PhDConfig::set_xml_file($root); - PhDConfig::set_xml_root(dirname($root)); - } else { - PhDConfig::set_xml_file($root . "/.manual.xml"); - PhDConfig::set_xml_root($root); - } +/* If no docbook file was passed, die */ +if (!is_dir(PhDConfig::xml_root()) || !is_file(PhDConfig::xml_file())) { + trigger_error("No '.manual.xml' file was given. Specify it on the command line with --docbook.", E_USER_ERROR); } -/* }}} */ /* This needs to be done in *all* cases! */ PhDConfig::set_output_dir(realpath(PhDConfig::output_dir()) . DIRECTORY_SEPARATOR); @@ -332,8 +307,4 @@ foreach(PhDConfig::output_format() as $output_format) { } // foreach(PhDConfig::output_themes()) -/* -* vim600: sw=4 ts=4 syntax=php et -* vim<600: sw=4 ts=4 -*/ - +?> commit 40bc17f9c570c634a04d6a981514c269c49a08c0 Author: Gwynne Raskind <gwynne@php.net> Date: Wed Jul 9 11:33:33 2008 +0000 whitespace consistency diff --git a/config.php b/config.php index 9d6079e..a89e95c 100644 --- a/config.php +++ b/config.php @@ -85,22 +85,22 @@ function phd_bool($val) { } switch ($val) { - case "on": - case "yes": - case "true": - case "1": - return true; - break; + case "on": + case "yes": + case "true": + case "1": + return true; + break; - case "off": - case "no": - case "false": - case "0": - return false; - break; + case "off": + case "no": + case "false": + case "0": + return false; + break; - default: - return null; + default: + return null; } } /* }}} */ diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php index 9d6079e..a89e95c 100644 --- a/phpdotnet/phd/Config.php +++ b/phpdotnet/phd/Config.php @@ -85,22 +85,22 @@ function phd_bool($val) { } switch ($val) { - case "on": - case "yes": - case "true": - case "1": - return true; - break; + case "on": + case "yes": + case "true": + case "1": + return true; + break; - case "off": - case "no": - case "false": - case "0": - return false; - break; + case "off": + case "no": + case "false": + case "0": + return false; + break; - default: - return null; + default: + return null; } } /* }}} */ commit c867e82cdebbdc724b1d3d0606262ac2d09533a2 Author: Gwynne Raskind <gwynne@php.net> Date: Wed Jul 9 11:32:54 2008 +0000 fix spelling error diff --git a/config.php b/config.php index 1fc01b7..9d6079e 100644 --- a/config.php +++ b/config.php @@ -123,7 +123,7 @@ abstract class PhDOptionParser $opts = $this->getOptionList(); $args = getopt(implode("", array_values($opts)), array_keys($opts)); if ($args === false) { - trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR); + trigger_error("Something happened with getopt(), please report a bug", E_USER_ERROR); } foreach ($args as $k => $v) { @@ -132,7 +132,7 @@ abstract class PhDOptionParser call_user_func($handler, $k, $v); } else { var_dump($k, $v); - trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR); + trigger_error("Hmh, something weird has happened, I don't know this option", E_USER_ERROR); } } } diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php index 1fc01b7..9d6079e 100644 --- a/phpdotnet/phd/Config.php +++ b/phpdotnet/phd/Config.php @@ -123,7 +123,7 @@ abstract class PhDOptionParser $opts = $this->getOptionList(); $args = getopt(implode("", array_values($opts)), array_keys($opts)); if ($args === false) { - trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR); + trigger_error("Something happened with getopt(), please report a bug", E_USER_ERROR); } foreach ($args as $k => $v) { @@ -132,7 +132,7 @@ abstract class PhDOptionParser call_user_func($handler, $k, $v); } else { var_dump($k, $v); - trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR); + trigger_error("Hmh, something weird has happened, I don't know this option", E_USER_ERROR); } } } commit 6a9f32f7d943bd619aaa94b9699d5e0fa5b57b8f Author: SVN Migration <svn@php.net> Date: Sat Jul 5 19:53:37 2008 +0000 This commit was manufactured by cvs2svn to create branch 'RESTRUCTURE'. Thank you for your contribution.

« previous php.doc.cvs (#9786) next »