cvs: phd / build.php config.php /include PhDPartialReader.class.php /themes/php phpweb.php
| From: | Hannes Magnusson | Date: | Sat, 03 May 2008 23:33:36 +0000 |
| Subject: | cvs: phd / build.php config.php /include PhDPartialReader.class.php /themes/php phpweb.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-1596@lists.php.net to get a copy of this message | ||
bjori Sat May 3 23:33:36 2008 UTC
Modified files:
/phd config.php build.php
/phd/themes/php phpweb.php
/phd/include PhDPartialReader.class.php
Log:
Improve error/info "logger"
Add "option" to specify a resource for PHP triggered errors, PhD
triggered errors and PhD info messages
# We really need some "config interface", adding all options as
# arguments to
http://cvs.php.net/viewvc.cgi/phd/config.php?r1=1.38&r2=1.39&diff_format=u Index: phd/config.php diff -u phd/config.php:1.38 phd/config.php:1.39 --- phd/config.php:1.38 Mon Apr 7 05:41:44 2008 +++ phd/config.php Sat May 3 23:33:36 2008 @@ -1,24 +1,122 @@ <?php -/* $Id: config.php,v 1.38 2008/04/07 05:41:44 bjori Exp $ */ +/* $Id: config.php,v 1.39 2008/05/03 23:33:36 bjori Exp $ */ -/* {{{ Print messages to stderr: v("printf-format-text", $arg1, ...) */ -function v($msg) { +/* {{{ PhD error & message handler */ + +// FC For PHP5.3 +if (!defined("E_DEPRECATED")) { + define("E_DEPRECATED", E_RECOVERABLE_ERROR << 1); +} + +// 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_ALL', (VERBOSE_CHUNK_WRITING << 1)-1); + + +/* {{{ Print info messages: v("printf-format-text" [, $arg1, ...], $verbose-level) */ +// trigger_error() only accepts E_USER_* errors :( +function v($msg, $errno) { $args = func_get_args(); - $args[0] = date($GLOBALS["OPTIONS"]["date_format"]); - vfprintf(STDERR, "[%s] $msg", $args); + $errno = array_pop($args); + + $msg = vsprintf(array_shift($args), $args); + + $bt = debug_backtrace(); + return errh($errno, $msg, $bt[0]["file"], $bt[0]["line"]); } /* }}} */ -define('VERBOSE_INDEXING', 0x01); -define('VERBOSE_FORMAT_RENDERING', 0x02); -define('VERBOSE_THEME_RENDERING', 0x04); -define('VERBOSE_RENDER_STYLE', 0x08); -define('VERBOSE_PARTIAL_READING', 0x10); -define('VERBOSE_PARTIAL_CHILD_READING', 0x20); -define('VERBOSE_TOC_WRITING', 0x40); -define('VERBOSE_CHUNK_WRITING', 0x80); +/* {{{ The PhD errorhandler */ +function errh($errno, $msg, $file, $line, $ctx = null) { + global $OPTIONS; + 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', + ); + static $recursive = false; + + // Respect the error_reporting setting + if (!(error_reporting() & $errno)) { + return false; + } + + // Recursive protection + if ($recursive) { + // Fallback to the default errorhandler + return false; + } + $recursive = true; + + $time = date($OPTIONS["date_format"]); + switch($errno) { + case VERBOSE_INDEXING: + case VERBOSE_FORMAT_RENDERING: + case VERBOSE_THEME_RENDERING: + case VERBOSE_RENDER_STYLE: + case VERBOSE_PARTIAL_READING: + case VERBOSE_PARTIAL_CHILD_READING: + case VERBOSE_TOC_WRITING: + case VERBOSE_CHUNK_WRITING: + fprintf($OPTIONS["phd_info_output"], "[%s - %s] %s\n", $time, $err[$errno], $msg); + break; + + // User triggered errors + case E_USER_ERROR: + case E_USER_WARNING: + case E_USER_NOTICE: + fprintf($OPTIONS["user_error_output"], "[%s - %s] %s:%d\n\t%s\n", $time, $err[$errno], $file, $line, $msg); + break; + + // PHP triggered errors + case E_DEPRECATED: + case E_RECOVERABLE_ERROR: + case E_STRICT: + case E_WARNING: + case E_NOTICE: + fprintf($OPTIONS["php_error_output"], "[%s - %s] %s:%d\n\t%s\n", $time, $err[$errno], $file, $line, $msg); + break; + + default: + // Unknown error level.. let PHP handle it + $recursive = false; + return false; + } + + // Abort on fatal errors + if ($errno & (E_USER_ERROR|E_RECOVERABLE_ERROR)) { + exit(1); + } -define('VERBOSE_ALL', 0xFF); + $recursive = false; + return true; +} +/* }}} */ +set_error_handler("errh"); +/* }}} */ define("PHD_VERSION", "0.2.4-dev"); @@ -52,9 +150,14 @@ 'skip_ids' => array( ), 'output_dir' => '.', + 'php_error_output' => STDERR, + 'user_error_output' => STDERR, + 'phd_info_output' => STDOUT, ); /* }}} */ +$olderr = error_reporting(); +error_reporting($olderr | $OPTIONS["verbose"]); /* {{{ getopt() options */ $opts = array( @@ -75,8 +178,9 @@ /* {{{ Workaround/fix for Windows prior to PHP5.3 */ if (!function_exists("getopt")) { function getopt($short, $long) { - v("I'm sorry, you are running an operating system that does not support getopt()\n"); - v("Please either upgrade to PHP5.3 or try '%s /path/to/your/docbook.xml'\n", $argv[0]); + 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(); } @@ -85,8 +189,7 @@ $args = getopt(implode("", array_values($opts)), array_keys($opts)); if($args === false) { - v("Something happend with getopt(), please report a bug\n"); - exit(1); + trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR); } $verbose = 0; @@ -98,12 +201,10 @@ case "d": case "docbook": if (is_array($v)) { - v("Can only parse one file at a time\n"); - exit(1); + trigger_error("Can only parse one file at a time", E_USER_ERROR); } if (!file_exists($v) || is_dir($v) || !is_readable($v)) { - v("'%s' is not a readable docbook file\n", $v); - exit(1); + trigger_error(sprintf("'%s' is not a readable docbook file", $v), E_USER_ERROR); } $OPTIONS["xml_root"] = dirname($v); $OPTIONS["xml_file"] = $v; @@ -115,13 +216,11 @@ case "o": case "output": if (is_array($v)) { - v("Only a single location can be supplied\n"); - exit(1); + trigger_error("Only a single output location can be supplied", E_USER_ERROR); } @mkdir($v, 0777, true); if (!is_dir($v) || !is_readable($v)) { - v("'%s' is not a valid directory\n", $v); - exit(1); + trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); } $OPTIONS["output_dir"] = $v; break; @@ -131,8 +230,7 @@ case "f": case "format": if ($v != "xhtml") { - v("Only xhtml is supported at this time\n"); - exit(1); + trigger_error("Only xhtml is supported at this time", E_USER_ERROR); } break; /* }}} */ @@ -141,8 +239,7 @@ case "i": case "index": if (is_array($v)) { - v("You cannot pass %s more than once\n", $k); - exit(1); + trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); } switch ($v) { case "yes": @@ -156,8 +253,7 @@ $OPTIONS["index"] = false; break; default: - v("yes/no || true/false || 1/0 expected\n"); - exit(1); + trigger_error("yes/no || true/false || 1/0 expected", E_USER_ERROR); } break; /* }}} */ @@ -254,8 +350,7 @@ } break; default: - v("Unknown theme '%s'\n", $val); - exit(1); + trigger_error(sprintf("Unknown theme '%s'", $val), E_USER_ERROR); } } break; @@ -270,7 +365,7 @@ } elseif (is_numeric($const)) { $verbose |= (int)$const; } else { - v("Unknown option passed to --$k, $const\n"); + trigger_error("Unknown option passed to --$k, $const", E_USER_ERROR); } } } @@ -292,8 +387,8 @@ /* {{{ Version info */ case "V": case "version": - v("PhD version: %s\n", PHD_VERSION); - v("Copyright (c) 2008 The PHP Documentation Group\n"); + printf("PhD version: %s\n", PHD_VERSION); + printf("Copyright (c) 2008 The PHP Documentation Group\n"); exit(0); /* }}} */ @@ -334,13 +429,13 @@ /* {{{ Unsupported option this should *never* happen */ default: - v("Hmh, something weird has happend, I don't know this option"); var_dump($k, $v); - exit(1); + trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR); /* }}} */ } } +error_reporting($olderr | $OPTIONS["verbose"]); /* {{{ BC for PhD 0.0.* (and PHP5.2 on Windows) i.e. `phd path/to/.manual.xml */ @@ -374,6 +469,7 @@ /* This needs to be done in *all* cases! */ $OPTIONS["output_dir"] = realpath($OPTIONS["output_dir"]) . DIRECTORY_SEPARATOR; +// Those files really should be moved into phd/ $OPTIONS["version_info"] = $OPTIONS["xml_root"]."/phpbook/phpbook-xsl/version.xml"; $OPTIONS["acronyms_file"] = $OPTIONS["xml_root"]."/entities/acronyms.xml"; http://cvs.php.net/viewvc.cgi/phd/build.php?r1=1.51&r2=1.52&diff_format=u Index: phd/build.php diff -u phd/build.php:1.51 phd/build.php:1.52 --- phd/build.php:1.51 Wed Feb 27 21:23:13 2008 +++ phd/build.php Sat May 3 23:33:36 2008 @@ -1,6 +1,6 @@ #!@php_bin@ <?php -/* $Id: build.php,v 1.51 2008/02/27 21:23:13 bjori Exp $ */ +/* $Id: build.php,v 1.52 2008/05/03 23:33:36 bjori Exp $ */ /* {{{ Find the $ROOT directory of PhD @php_dir@ will be replaced by the pear package manager @@ -36,18 +36,15 @@ - refnames_*.ser (containing <refname> => File ID) */ if (!$OPTIONS["index"] && (file_exists($OPTIONS['index_location']) && file_exists($OPTIONS['refnames_location']))) { /* FIXME: Load from sqlite db? */ - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Unserializing cached index files...\n"); - } + v("Unserializing cached index files...", VERBOSE_INDEXING); + $IDs = unserialize(file_get_contents($OPTIONS['index_location'])); $REFS = unserialize(file_get_contents($OPTIONS['refnames_location'])); - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Unserialization done\n"); - } + + v("Unserialization done", VERBOSE_INDEXING); } else { - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Indexing...\n"); - } + v("Indexing...", VERBOSE_INDEXING); + /* This file will "return" an $IDs & $REFS array */ require $ROOT. "/mktoc.php"; @@ -57,19 +54,16 @@ $IDs2 = unserialize($ids); $REFS2 = unserialize($refs); if ($IDs !== $IDs2 || $REFS !== $REFS2) { - v("WARNING: Serialized representation does not match"); + trigger_error("Serialized representation does not match", E_USER_WARNING); } - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Indexing done\n"); - } + v("Indexing done", VERBOSE_INDEXING); } /* }}} */ foreach($OPTIONS["output_format"] as $output_format) { - if ($OPTIONS["verbose"] & VERBOSE_FORMAT_RENDERING) { - v("Starting %s rendering\n", $output_format); - } + v("Starting %s rendering", $output_format, VERBOSE_FORMAT_RENDERING); + switch($output_format) { case "xhtml": $classname = "XHTMLPhDFormat"; @@ -87,9 +81,7 @@ $themes = $elementmaps = $textmaps = array(); foreach($OPTIONS["output_theme"][$output_format] as $theme => $array) { is_dir($ROOT. "/themes/$theme") or die("Can't find the '$theme' theme"); - if ($OPTIONS["verbose"] & VERBOSE_THEME_RENDERING) { - v("Using the %s theme (%s)\n", $theme, join(", ", $array)); - } + v("Using the %s theme (%s)", $theme, join(", ", $array), VERBOSE_THEME_RENDERING); foreach($array as $themename) { $themename = basename($themename); @@ -131,24 +123,21 @@ /* {{{ Initialize the PhD[Partial]Reader */ if (!empty($OPTIONS["render_ids"]) || !empty($OPTIONS["skip_ids"])) { $idlist = $OPTIONS["render_ids"]+$OPTIONS["skip_ids"]; - if ($OPTIONS["verbose"] & VERBOSE_RENDER_STYLE) { - v("Running partial build\n"); - } + + v("Running partial build", VERBOSE_RENDER_STYLE); if (!is_array($idlist)) { $idlist = array($idlist => 1); } foreach($idlist as $id => $notused) { if (!isset($IDs[$id])) { - v("Unknown ID %s, bailing\n", $id); - exit(1); + trigger_error(sprintf("Unknown ID %s, bailing", $id), E_USER_ERROR); } } $reader = new PhDPartialReader($OPTIONS); } else { - if ($OPTIONS["verbose"] & VERBOSE_RENDER_STYLE) { - v("Running full build\n"); - } + v("Running full build", VERBOSE_RENDER_STYLE); + $reader = new PhDReader($OPTIONS); } /* }}} */ @@ -301,9 +290,7 @@ } $reader->close(); - if ($OPTIONS["verbose"] & VERBOSE_FORMAT_RENDERING) { - v("Finished rendering\n"); - } + v("Finished rendering", VERBOSE_FORMAT_RENDERING); } // foreach($OPTIONS["output_thtemes"]) http://cvs.php.net/viewvc.cgi/phd/themes/php/phpweb.php?r1=1.24&r2=1.25&diff_format=u Index: phd/themes/php/phpweb.php diff -u phd/themes/php/phpweb.php:1.24 phd/themes/php/phpweb.php:1.25 --- phd/themes/php/phpweb.php:1.24 Fri Apr 11 21:28:46 2008 +++ phd/themes/php/phpweb.php Sat May 3 23:33:36 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: phpweb.php,v 1.24 2008/04/11 21:28:46 bjori Exp $ */ +/* $Id: phpweb.php,v 1.25 2008/05/03 23:33:36 bjori Exp $ */ require_once $ROOT . '/themes/php/phpdotnet.php'; class phpweb extends phpdotnet { @@ -34,7 +34,7 @@ } else { throw new Exception("Cannot rename $filename to $newfilename"); } - v("WARNING: Chunk without an ID found, TOC will NOT work. Wrote content to $newfilename.\n"); + trigger_error("Chunk without an ID found, TOC will NOT work. Wrote content to $newfilename.", E_USER_WARNING); } else { $filename = $id; } @@ -44,9 +44,7 @@ file_put_contents($this->outputdir . $filename, $stream, FILE_APPEND); file_put_contents($this->outputdir . $filename, $this->footer($id), FILE_APPEND); - if ($GLOBALS["OPTIONS"]["verbose"] & VERBOSE_CHUNK_WRITING) { - v("Wrote %s\n", $this->outputdir . $filename); - } + v("Wrote %s", $this->outputdir . $filename, VERBOSE_CHUNK_WRITING); } public function appendData($data, $isChunk) { switch($isChunk) { @@ -105,9 +103,7 @@ file_put_contents($this->outputdir . $filename, $content); - if ($GLOBALS["OPTIONS"]["verbose"] & VERBOSE_TOC_WRITING) { - v("Wrote TOC (%s)\n", $this->outputdir . $filename); - } + v("Wrote TOC (%s)", $this->outputdir . $filename, VERBOSE_TOC_WRITING); } $incl = 'include_once dirname(__FILE__) ."/toc/' .$parent. '.inc";'; http://cvs.php.net/viewvc.cgi/phd/include/PhDPartialReader.class.php?r1=1.4&r2=1.5&diff_format=u Index: phd/include/PhDPartialReader.class.php diff -u phd/include/PhDPartialReader.class.php:1.4 phd/include/PhDPartialReader.class.php:1.5 --- phd/include/PhDPartialReader.class.php:1.4 Mon Feb 4 23:01:27 2008 +++ phd/include/PhDPartialReader.class.php Sat May 3 23:33:36 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: PhDPartialReader.class.php,v 1.4 2008/02/04 23:01:27 bjori Exp $ */ +/* $Id: PhDPartialReader.class.php,v 1.5 2008/05/03 23:33:36 bjori Exp $ */ class PhDPartialReader extends PhDReader { protected $partial = array(); @@ -37,51 +37,44 @@ $id = $this->getAttributeNs("id", PhDReader::XMLNS_XML); if (isset($this->partial[$id])) { if ($this->isChunk == PhDReader::CLOSE_CHUNK) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("%s done\n", $id); - } + v("%s done", $id, VERBOSE_PARTIAL_READING); + unset($this->partial[$id]); --$seeked; $currently_reading = false; } else { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("Starting %s...\n", $id); - } + v("Starting %s...", $id, VERBOSE_PARTIAL_READING); + $currently_reading = $id; ++$seeked; } return $ret; } elseif (isset($this->skip[$id])) { if ($this->isChunk == PhDReader::CLOSE_CHUNK) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("%s done\n", $id); - } + v("%s done", $id, VERBOSE_PARTIAL_READING); + unset($this->skip[$id]); $currently_skipping = false; $ignore = false; } else { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("Skipping %s...\n", $id); - } + v("Skipping %s...", $id, VERBOSE_PARTIAL_READING); + $currently_skipping = $id; $ignore = true; } } elseif ($currently_skipping && $this->skip[$currently_skipping]) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_CHILD_READING) { - if ($this->isChunk == PhDReader::OPEN_CHUNK) { - v("Skipping child of %s, %s\n", $currently_reading, $id); - } else { - v("%s done\n", $id); - } + if ($this->isChunk == PhDReader::OPEN_CHUNK) { + v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); + } else { + v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); } + $ignore = true; } elseif ($currently_reading && $this->partial[$currently_reading]) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_CHILD_READING) { - if ($this->isChunk == PhDReader::OPEN_CHUNK) { - v("Rendering child of %s, %s\n", $currently_reading, $id); - } else { - v("%s done\n", $id); - } + if ($this->isChunk == PhDReader::OPEN_CHUNK) { + v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); + } else { + v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); } return $ret; } elseif (empty($this->partial)) {
phd is already starting to get messy :(
http://cvs.php.net/viewvc.cgi/phd/config.php?r1=1.38&r2=1.39&diff_format=u Index: phd/config.php diff -u phd/config.php:1.38 phd/config.php:1.39 --- phd/config.php:1.38 Mon Apr 7 05:41:44 2008 +++ phd/config.php Sat May 3 23:33:36 2008 @@ -1,24 +1,122 @@ <?php -/* $Id: config.php,v 1.38 2008/04/07 05:41:44 bjori Exp $ */ +/* $Id: config.php,v 1.39 2008/05/03 23:33:36 bjori Exp $ */ -/* {{{ Print messages to stderr: v("printf-format-text", $arg1, ...) */ -function v($msg) { +/* {{{ PhD error & message handler */ + +// FC For PHP5.3 +if (!defined("E_DEPRECATED")) { + define("E_DEPRECATED", E_RECOVERABLE_ERROR << 1); +} + +// 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_ALL', (VERBOSE_CHUNK_WRITING << 1)-1); + + +/* {{{ Print info messages: v("printf-format-text" [, $arg1, ...], $verbose-level) */ +// trigger_error() only accepts E_USER_* errors :( +function v($msg, $errno) { $args = func_get_args(); - $args[0] = date($GLOBALS["OPTIONS"]["date_format"]); - vfprintf(STDERR, "[%s] $msg", $args); + $errno = array_pop($args); + + $msg = vsprintf(array_shift($args), $args); + + $bt = debug_backtrace(); + return errh($errno, $msg, $bt[0]["file"], $bt[0]["line"]); } /* }}} */ -define('VERBOSE_INDEXING', 0x01); -define('VERBOSE_FORMAT_RENDERING', 0x02); -define('VERBOSE_THEME_RENDERING', 0x04); -define('VERBOSE_RENDER_STYLE', 0x08); -define('VERBOSE_PARTIAL_READING', 0x10); -define('VERBOSE_PARTIAL_CHILD_READING', 0x20); -define('VERBOSE_TOC_WRITING', 0x40); -define('VERBOSE_CHUNK_WRITING', 0x80); +/* {{{ The PhD errorhandler */ +function errh($errno, $msg, $file, $line, $ctx = null) { + global $OPTIONS; + 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', + ); + static $recursive = false; + + // Respect the error_reporting setting + if (!(error_reporting() & $errno)) { + return false; + } + + // Recursive protection + if ($recursive) { + // Fallback to the default errorhandler + return false; + } + $recursive = true; + + $time = date($OPTIONS["date_format"]); + switch($errno) { + case VERBOSE_INDEXING: + case VERBOSE_FORMAT_RENDERING: + case VERBOSE_THEME_RENDERING: + case VERBOSE_RENDER_STYLE: + case VERBOSE_PARTIAL_READING: + case VERBOSE_PARTIAL_CHILD_READING: + case VERBOSE_TOC_WRITING: + case VERBOSE_CHUNK_WRITING: + fprintf($OPTIONS["phd_info_output"], "[%s - %s] %s\n", $time, $err[$errno], $msg); + break; + + // User triggered errors + case E_USER_ERROR: + case E_USER_WARNING: + case E_USER_NOTICE: + fprintf($OPTIONS["user_error_output"], "[%s - %s] %s:%d\n\t%s\n", $time, $err[$errno], $file, $line, $msg); + break; + + // PHP triggered errors + case E_DEPRECATED: + case E_RECOVERABLE_ERROR: + case E_STRICT: + case E_WARNING: + case E_NOTICE: + fprintf($OPTIONS["php_error_output"], "[%s - %s] %s:%d\n\t%s\n", $time, $err[$errno], $file, $line, $msg); + break; + + default: + // Unknown error level.. let PHP handle it + $recursive = false; + return false; + } + + // Abort on fatal errors + if ($errno & (E_USER_ERROR|E_RECOVERABLE_ERROR)) { + exit(1); + } -define('VERBOSE_ALL', 0xFF); + $recursive = false; + return true; +} +/* }}} */ +set_error_handler("errh"); +/* }}} */ define("PHD_VERSION", "0.2.4-dev"); @@ -52,9 +150,14 @@ 'skip_ids' => array( ), 'output_dir' => '.', + 'php_error_output' => STDERR, + 'user_error_output' => STDERR, + 'phd_info_output' => STDOUT, ); /* }}} */ +$olderr = error_reporting(); +error_reporting($olderr | $OPTIONS["verbose"]); /* {{{ getopt() options */ $opts = array( @@ -75,8 +178,9 @@ /* {{{ Workaround/fix for Windows prior to PHP5.3 */ if (!function_exists("getopt")) { function getopt($short, $long) { - v("I'm sorry, you are running an operating system that does not support getopt()\n"); - v("Please either upgrade to PHP5.3 or try '%s /path/to/your/docbook.xml'\n", $argv[0]); + 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(); } @@ -85,8 +189,7 @@ $args = getopt(implode("", array_values($opts)), array_keys($opts)); if($args === false) { - v("Something happend with getopt(), please report a bug\n"); - exit(1); + trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR); } $verbose = 0; @@ -98,12 +201,10 @@ case "d": case "docbook": if (is_array($v)) { - v("Can only parse one file at a time\n"); - exit(1); + trigger_error("Can only parse one file at a time", E_USER_ERROR); } if (!file_exists($v) || is_dir($v) || !is_readable($v)) { - v("'%s' is not a readable docbook file\n", $v); - exit(1); + trigger_error(sprintf("'%s' is not a readable docbook file", $v), E_USER_ERROR); } $OPTIONS["xml_root"] = dirname($v); $OPTIONS["xml_file"] = $v; @@ -115,13 +216,11 @@ case "o": case "output": if (is_array($v)) { - v("Only a single location can be supplied\n"); - exit(1); + trigger_error("Only a single output location can be supplied", E_USER_ERROR); } @mkdir($v, 0777, true); if (!is_dir($v) || !is_readable($v)) { - v("'%s' is not a valid directory\n", $v); - exit(1); + trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); } $OPTIONS["output_dir"] = $v; break; @@ -131,8 +230,7 @@ case "f": case "format": if ($v != "xhtml") { - v("Only xhtml is supported at this time\n"); - exit(1); + trigger_error("Only xhtml is supported at this time", E_USER_ERROR); } break; /* }}} */ @@ -141,8 +239,7 @@ case "i": case "index": if (is_array($v)) { - v("You cannot pass %s more than once\n", $k); - exit(1); + trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); } switch ($v) { case "yes": @@ -156,8 +253,7 @@ $OPTIONS["index"] = false; break; default: - v("yes/no || true/false || 1/0 expected\n"); - exit(1); + trigger_error("yes/no || true/false || 1/0 expected", E_USER_ERROR); } break; /* }}} */ @@ -254,8 +350,7 @@ } break; default: - v("Unknown theme '%s'\n", $val); - exit(1); + trigger_error(sprintf("Unknown theme '%s'", $val), E_USER_ERROR); } } break; @@ -270,7 +365,7 @@ } elseif (is_numeric($const)) { $verbose |= (int)$const; } else { - v("Unknown option passed to --$k, $const\n"); + trigger_error("Unknown option passed to --$k, $const", E_USER_ERROR); } } } @@ -292,8 +387,8 @@ /* {{{ Version info */ case "V": case "version": - v("PhD version: %s\n", PHD_VERSION); - v("Copyright (c) 2008 The PHP Documentation Group\n"); + printf("PhD version: %s\n", PHD_VERSION); + printf("Copyright (c) 2008 The PHP Documentation Group\n"); exit(0); /* }}} */ @@ -334,13 +429,13 @@ /* {{{ Unsupported option this should *never* happen */ default: - v("Hmh, something weird has happend, I don't know this option"); var_dump($k, $v); - exit(1); + trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR); /* }}} */ } } +error_reporting($olderr | $OPTIONS["verbose"]); /* {{{ BC for PhD 0.0.* (and PHP5.2 on Windows) i.e. `phd path/to/.manual.xml */ @@ -374,6 +469,7 @@ /* This needs to be done in *all* cases! */ $OPTIONS["output_dir"] = realpath($OPTIONS["output_dir"]) . DIRECTORY_SEPARATOR; +// Those files really should be moved into phd/ $OPTIONS["version_info"] = $OPTIONS["xml_root"]."/phpbook/phpbook-xsl/version.xml"; $OPTIONS["acronyms_file"] = $OPTIONS["xml_root"]."/entities/acronyms.xml"; http://cvs.php.net/viewvc.cgi/phd/build.php?r1=1.51&r2=1.52&diff_format=u Index: phd/build.php diff -u phd/build.php:1.51 phd/build.php:1.52 --- phd/build.php:1.51 Wed Feb 27 21:23:13 2008 +++ phd/build.php Sat May 3 23:33:36 2008 @@ -1,6 +1,6 @@ #!@php_bin@ <?php -/* $Id: build.php,v 1.51 2008/02/27 21:23:13 bjori Exp $ */ +/* $Id: build.php,v 1.52 2008/05/03 23:33:36 bjori Exp $ */ /* {{{ Find the $ROOT directory of PhD @php_dir@ will be replaced by the pear package manager @@ -36,18 +36,15 @@ - refnames_*.ser (containing <refname> => File ID) */ if (!$OPTIONS["index"] && (file_exists($OPTIONS['index_location']) && file_exists($OPTIONS['refnames_location']))) { /* FIXME: Load from sqlite db? */ - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Unserializing cached index files...\n"); - } + v("Unserializing cached index files...", VERBOSE_INDEXING); + $IDs = unserialize(file_get_contents($OPTIONS['index_location'])); $REFS = unserialize(file_get_contents($OPTIONS['refnames_location'])); - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Unserialization done\n"); - } + + v("Unserialization done", VERBOSE_INDEXING); } else { - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Indexing...\n"); - } + v("Indexing...", VERBOSE_INDEXING); + /* This file will "return" an $IDs & $REFS array */ require $ROOT. "/mktoc.php"; @@ -57,19 +54,16 @@ $IDs2 = unserialize($ids); $REFS2 = unserialize($refs); if ($IDs !== $IDs2 || $REFS !== $REFS2) { - v("WARNING: Serialized representation does not match"); + trigger_error("Serialized representation does not match", E_USER_WARNING); } - if ($OPTIONS["verbose"] & VERBOSE_INDEXING) { - v("Indexing done\n"); - } + v("Indexing done", VERBOSE_INDEXING); } /* }}} */ foreach($OPTIONS["output_format"] as $output_format) { - if ($OPTIONS["verbose"] & VERBOSE_FORMAT_RENDERING) { - v("Starting %s rendering\n", $output_format); - } + v("Starting %s rendering", $output_format, VERBOSE_FORMAT_RENDERING); + switch($output_format) { case "xhtml": $classname = "XHTMLPhDFormat"; @@ -87,9 +81,7 @@ $themes = $elementmaps = $textmaps = array(); foreach($OPTIONS["output_theme"][$output_format] as $theme => $array) { is_dir($ROOT. "/themes/$theme") or die("Can't find the '$theme' theme"); - if ($OPTIONS["verbose"] & VERBOSE_THEME_RENDERING) { - v("Using the %s theme (%s)\n", $theme, join(", ", $array)); - } + v("Using the %s theme (%s)", $theme, join(", ", $array), VERBOSE_THEME_RENDERING); foreach($array as $themename) { $themename = basename($themename); @@ -131,24 +123,21 @@ /* {{{ Initialize the PhD[Partial]Reader */ if (!empty($OPTIONS["render_ids"]) || !empty($OPTIONS["skip_ids"])) { $idlist = $OPTIONS["render_ids"]+$OPTIONS["skip_ids"]; - if ($OPTIONS["verbose"] & VERBOSE_RENDER_STYLE) { - v("Running partial build\n"); - } + + v("Running partial build", VERBOSE_RENDER_STYLE); if (!is_array($idlist)) { $idlist = array($idlist => 1); } foreach($idlist as $id => $notused) { if (!isset($IDs[$id])) { - v("Unknown ID %s, bailing\n", $id); - exit(1); + trigger_error(sprintf("Unknown ID %s, bailing", $id), E_USER_ERROR); } } $reader = new PhDPartialReader($OPTIONS); } else { - if ($OPTIONS["verbose"] & VERBOSE_RENDER_STYLE) { - v("Running full build\n"); - } + v("Running full build", VERBOSE_RENDER_STYLE); + $reader = new PhDReader($OPTIONS); } /* }}} */ @@ -301,9 +290,7 @@ } $reader->close(); - if ($OPTIONS["verbose"] & VERBOSE_FORMAT_RENDERING) { - v("Finished rendering\n"); - } + v("Finished rendering", VERBOSE_FORMAT_RENDERING); } // foreach($OPTIONS["output_thtemes"]) http://cvs.php.net/viewvc.cgi/phd/themes/php/phpweb.php?r1=1.24&r2=1.25&diff_format=u Index: phd/themes/php/phpweb.php diff -u phd/themes/php/phpweb.php:1.24 phd/themes/php/phpweb.php:1.25 --- phd/themes/php/phpweb.php:1.24 Fri Apr 11 21:28:46 2008 +++ phd/themes/php/phpweb.php Sat May 3 23:33:36 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: phpweb.php,v 1.24 2008/04/11 21:28:46 bjori Exp $ */ +/* $Id: phpweb.php,v 1.25 2008/05/03 23:33:36 bjori Exp $ */ require_once $ROOT . '/themes/php/phpdotnet.php'; class phpweb extends phpdotnet { @@ -34,7 +34,7 @@ } else { throw new Exception("Cannot rename $filename to $newfilename"); } - v("WARNING: Chunk without an ID found, TOC will NOT work. Wrote content to $newfilename.\n"); + trigger_error("Chunk without an ID found, TOC will NOT work. Wrote content to $newfilename.", E_USER_WARNING); } else { $filename = $id; } @@ -44,9 +44,7 @@ file_put_contents($this->outputdir . $filename, $stream, FILE_APPEND); file_put_contents($this->outputdir . $filename, $this->footer($id), FILE_APPEND); - if ($GLOBALS["OPTIONS"]["verbose"] & VERBOSE_CHUNK_WRITING) { - v("Wrote %s\n", $this->outputdir . $filename); - } + v("Wrote %s", $this->outputdir . $filename, VERBOSE_CHUNK_WRITING); } public function appendData($data, $isChunk) { switch($isChunk) { @@ -105,9 +103,7 @@ file_put_contents($this->outputdir . $filename, $content); - if ($GLOBALS["OPTIONS"]["verbose"] & VERBOSE_TOC_WRITING) { - v("Wrote TOC (%s)\n", $this->outputdir . $filename); - } + v("Wrote TOC (%s)", $this->outputdir . $filename, VERBOSE_TOC_WRITING); } $incl = 'include_once dirname(__FILE__) ."/toc/' .$parent. '.inc";'; http://cvs.php.net/viewvc.cgi/phd/include/PhDPartialReader.class.php?r1=1.4&r2=1.5&diff_format=u Index: phd/include/PhDPartialReader.class.php diff -u phd/include/PhDPartialReader.class.php:1.4 phd/include/PhDPartialReader.class.php:1.5 --- phd/include/PhDPartialReader.class.php:1.4 Mon Feb 4 23:01:27 2008 +++ phd/include/PhDPartialReader.class.php Sat May 3 23:33:36 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: PhDPartialReader.class.php,v 1.4 2008/02/04 23:01:27 bjori Exp $ */ +/* $Id: PhDPartialReader.class.php,v 1.5 2008/05/03 23:33:36 bjori Exp $ */ class PhDPartialReader extends PhDReader { protected $partial = array(); @@ -37,51 +37,44 @@ $id = $this->getAttributeNs("id", PhDReader::XMLNS_XML); if (isset($this->partial[$id])) { if ($this->isChunk == PhDReader::CLOSE_CHUNK) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("%s done\n", $id); - } + v("%s done", $id, VERBOSE_PARTIAL_READING); + unset($this->partial[$id]); --$seeked; $currently_reading = false; } else { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("Starting %s...\n", $id); - } + v("Starting %s...", $id, VERBOSE_PARTIAL_READING); + $currently_reading = $id; ++$seeked; } return $ret; } elseif (isset($this->skip[$id])) { if ($this->isChunk == PhDReader::CLOSE_CHUNK) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("%s done\n", $id); - } + v("%s done", $id, VERBOSE_PARTIAL_READING); + unset($this->skip[$id]); $currently_skipping = false; $ignore = false; } else { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_READING) { - v("Skipping %s...\n", $id); - } + v("Skipping %s...", $id, VERBOSE_PARTIAL_READING); + $currently_skipping = $id; $ignore = true; } } elseif ($currently_skipping && $this->skip[$currently_skipping]) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_CHILD_READING) { - if ($this->isChunk == PhDReader::OPEN_CHUNK) { - v("Skipping child of %s, %s\n", $currently_reading, $id); - } else { - v("%s done\n", $id); - } + if ($this->isChunk == PhDReader::OPEN_CHUNK) { + v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); + } else { + v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); } + $ignore = true; } elseif ($currently_reading && $this->partial[$currently_reading]) { - if ($this->opts["verbose"] & VERBOSE_PARTIAL_CHILD_READING) { - if ($this->isChunk == PhDReader::OPEN_CHUNK) { - v("Rendering child of %s, %s\n", $currently_reading, $id); - } else { - v("%s done\n", $id); - } + if ($this->isChunk == PhDReader::OPEN_CHUNK) { + v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING); + } else { + v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING); } return $ret; } elseif (empty($this->partial)) {