cvs: pear /CodeGen/CodeGen Command.php Extension.php ExtensionParser.php Maintainer.php Release.php XmlParser.php /CodeGen/CodeGen/Tools Code.php
Getopt.php Indent.php IndentC.php Outbuf.php
| From: | Hartmut Holzgraefe | Date: | Wed, 11 Oct 2006 10:07:43 +0000 |
| Subject: | cvs: pear /CodeGen/CodeGen Command.php Extension.php ExtensionParser.php Maintainer.php Release.php XmlParser.php /CodeGen/CodeGen/Tools Code.php Getopt.php Indent.php IndentC.php Outbuf.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42491@lists.php.net to get a copy of this message | ||
hholzgra Wed Oct 11 10:07:43 2006 UTC
Modified files:
/pear/CodeGen/CodeGen/Tools Code.php Getopt.php IndentC.php
Indent.php Outbuf.php
/pear/CodeGen/CodeGen Command.php ExtensionParser.php Extension.php
Maintainer.php Release.php XmlParser.php
Log:
CS/WS fixes
http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Code.php?r1=1.5&r2=1.6&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Code.php diff -u pear/CodeGen/CodeGen/Tools/Code.php:1.5 pear/CodeGen/CodeGen/Tools/Code.php:1.6 --- pear/CodeGen/CodeGen/Tools/Code.php:1.5 Sat Jul 8 20:04:37 2006 +++ pear/CodeGen/CodeGen/Tools/Code.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Code.php,v 1.5 2006/07/08 20:04:37 hholzgra Exp $ + * @version CVS: $Id: Code.php,v 1.6 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -23,7 +23,7 @@ * includes */ -require_once("CodeGen/Tools/IndentC.php"); +require_once "CodeGen/Tools/IndentC.php"; // TODO make this configurable by language /** @@ -85,7 +85,8 @@ * @param int indent level * @return string formated code block */ - function block($code, $indent = 1) { + function block($code, $indent = 1) + { return CodeGen_Tools_IndentC::indent($indent*$this->indentSteps, $code); } @@ -97,7 +98,8 @@ * @param int indent level * @return string formated code block */ - function varblock($code, $indent = 1) { + function varblock($code, $indent = 1) + { if ($this->language == 'c') { $head = CodeGen_Tools_IndentC::indent($indent * $this->indentSteps, "do {\n"); $foot = CodeGen_Tools_IndentC::indent($indent * $this->indentSteps, "} while (0);\n"); http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Getopt.php?r1=1.3&r2=1.4&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Getopt.php diff -u pear/CodeGen/CodeGen/Tools/Getopt.php:1.3 pear/CodeGen/CodeGen/Tools/Getopt.php:1.4 --- pear/CodeGen/CodeGen/Tools/Getopt.php:1.3 Fri Feb 17 09:47:00 2006 +++ pear/CodeGen/CodeGen/Tools/Getopt.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2003-2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Getopt.php,v 1.3 2006/02/17 09:47:00 hholzgra Exp $ + * @version CVS: $Id: Getopt.php,v 1.4 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -54,7 +54,7 @@ * @param array long options specification * @param callback error callback, call this and exit on errors if given */ - function __construct ($short_options, $long_options = NULL, $usage = NULL) + function __construct ($short_options, $long_options = null, $usage = null) { // use parent methods for actual parsing, store result internaly $argv = parent::readPHPArgv(); @@ -169,8 +169,7 @@ break; } - foreach ($this->options[0] as $opt) - { + foreach ($this->options[0] as $opt) { if ($opt[0] == $name) { return is_null($opt[1]) ? true : $opt[1]; } http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/IndentC.php?r1=1.2&r2=1.3&diff_format=u Index: pear/CodeGen/CodeGen/Tools/IndentC.php diff -u pear/CodeGen/CodeGen/Tools/IndentC.php:1.2 pear/CodeGen/CodeGen/Tools/IndentC.php:1.3 --- pear/CodeGen/CodeGen/Tools/IndentC.php:1.2 Sat Jul 8 19:58:36 2006 +++ pear/CodeGen/CodeGen/Tools/IndentC.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: IndentC.php,v 1.2 2006/07/08 19:58:36 hholzgra Exp $ + * @version CVS: $Id: IndentC.php,v 1.3 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -51,8 +51,16 @@ */ function indent($level, $text) { - $result = parent::indent($level, $text); + $result = parent::indent($level, $text); - return preg_replace('/^\s+#/m', '#', $result); + return preg_replace('/^\s+#/m', '#', $result); } -} \ No newline at end of file +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */ http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Indent.php?r1=1.4&r2=1.5&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Indent.php diff -u pear/CodeGen/CodeGen/Tools/Indent.php:1.4 pear/CodeGen/CodeGen/Tools/Indent.php:1.5 --- pear/CodeGen/CodeGen/Tools/Indent.php:1.4 Sat Jul 8 21:25:52 2006 +++ pear/CodeGen/CodeGen/Tools/Indent.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Indent.php,v 1.4 2006/07/08 21:25:52 hholzgra Exp $ + * @version CVS: $Id: Indent.php,v 1.5 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -48,9 +48,8 @@ function tabify($text, $tabsize = 4) { return preg_replace_callback("/^(".str_repeat(" ", $tabsize).")+/m", - create_function('$matches','return str_repeat("\t", strlen($matches[0])/'.$tabsize.');'), - $text - ); + create_function('$matches', 'return str_repeat("\t", strlen($matches[0])/'.$tabsize.');'), + $text); } @@ -68,9 +67,8 @@ function untabify($text, $tabsize = 4) { return preg_replace_callback("/^(\t)*/m", - create_function('$matches','return str_repeat(" ", strlen($matches[0])*'.$tabsize.');'), - $text - ); + create_function('$matches', 'return str_repeat(" ", strlen($matches[0])*'.$tabsize.');'), + $text); } /** @@ -101,8 +99,8 @@ $minIndent = min($minIndent, strlen($matches[0])); } - $result = ""; - $find = str_repeat(" ", $minIndent); + $result = ""; + $find = str_repeat(" ", $minIndent); $replace = str_repeat(" ", $level); foreach ($lines as $line) { $result.= self::tabify(preg_replace("|^$find|", $replace, $line)."\n", 4); @@ -121,8 +119,8 @@ */ function linetrim($text) { - $text = preg_replace('|^\s*\n|','', $text); - $text = preg_replace('|\n\s*$|',"\n", $text); + $text = preg_replace('|^\s*\n|', '', $text); + $text = preg_replace('|\n\s*$|', "\n", $text); return $text; } @@ -133,9 +131,17 @@ * @param string unix text * @param string dos/windows text */ - function dosify($text) { + function dosify($text) + { return str_replace("\n", "\r\n", $text); } } +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */ http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Outbuf.php?r1=1.4&r2=1.5&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Outbuf.php diff -u pear/CodeGen/CodeGen/Tools/Outbuf.php:1.4 pear/CodeGen/CodeGen/Tools/Outbuf.php:1.5 --- pear/CodeGen/CodeGen/Tools/Outbuf.php:1.4 Thu Feb 2 22:00:57 2006 +++ pear/CodeGen/CodeGen/Tools/Outbuf.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Outbuf.php,v 1.4 2006/02/02 22:00:57 hholzgra Exp $ + * @version CVS: $Id: Outbuf.php,v 1.5 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -91,8 +91,7 @@ { $stat = true; - if ($this->path) - { + if ($this->path) { $text = ob_get_clean(); $fp = new CodeGen_Tools_FileReplacer($this->path); http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Command.php?r1=1.7&r2=1.8&diff_format=u Index: pear/CodeGen/CodeGen/Command.php diff -u pear/CodeGen/CodeGen/Command.php:1.7 pear/CodeGen/CodeGen/Command.php:1.8 --- pear/CodeGen/CodeGen/Command.php:1.7 Sat Aug 19 00:03:57 2006 +++ pear/CodeGen/CodeGen/Command.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Command.php,v 1.7 2006/08/19 00:03:57 hholzgra Exp $ + * @version CVS: $Id: Command.php,v 1.8 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -223,8 +223,8 @@ $err = $parser->parse(); if (PEAR::isError($err)) { $this->terminate($err->getMessage()." ".$err->getUserInfo()); - } else if(is_string($err)) { - $this->terminate($err); + } else if (is_string($err)) { + $this->terminate($err); } if ($this->options->have("l", "lint")) { http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/ExtensionParser.php?r1=1.16&r2=1.17&diff_format=u Index: pear/CodeGen/CodeGen/ExtensionParser.php diff -u pear/CodeGen/CodeGen/ExtensionParser.php:1.16 pear/CodeGen/CodeGen/ExtensionParser.php:1.17 --- pear/CodeGen/CodeGen/ExtensionParser.php:1.16 Sat Jun 24 12:37:03 2006 +++ pear/CodeGen/CodeGen/ExtensionParser.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: ExtensionParser.php,v 1.16 2006/06/24 12:37:03 hholzgra Exp $ + * @version CVS: $Id: ExtensionParser.php,v 1.17 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -303,7 +303,8 @@ return $this->extension->setLicense($license); } - function tagend_extension_code($attr, $data) { + function tagend_extension_code($attr, $data) + { $err = $this->checkAttributes($attr, array("role", "position")); if (PEAR::isError($err)) { return $err; @@ -322,7 +323,7 @@ function tagstart_deps($attr) { - $err = $this->checkAttributes($attr, array("platform","language")); + $err = $this->checkAttributes($attr, array("platform", "language")); if (PEAR::isError($err)) { return $err; } http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Extension.php?r1=1.24&r2=1.25&diff_format=u Index: pear/CodeGen/CodeGen/Extension.php diff -u pear/CodeGen/CodeGen/Extension.php:1.24 pear/CodeGen/CodeGen/Extension.php:1.25 --- pear/CodeGen/CodeGen/Extension.php:1.24 Mon Oct 2 11:20:52 2006 +++ pear/CodeGen/CodeGen/Extension.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Extension.php,v 1.24 2006/10/02 11:20:52 hholzgra Exp $ + * @version CVS: $Id: Extension.php,v 1.25 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -771,7 +771,7 @@ * vim<600: noet sw=4 ts=4 */ '; - } + } /** * Generate Editor settings block for documentation files http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Maintainer.php?r1=1.5&r2=1.6&diff_format=u Index: pear/CodeGen/CodeGen/Maintainer.php diff -u pear/CodeGen/CodeGen/Maintainer.php:1.5 pear/CodeGen/CodeGen/Maintainer.php:1.6 --- pear/CodeGen/CodeGen/Maintainer.php:1.5 Mon Oct 2 11:20:52 2006 +++ pear/CodeGen/CodeGen/Maintainer.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Maintainer.php,v 1.5 2006/10/02 11:20:52 hholzgra Exp $ + * @version CVS: $Id: Maintainer.php,v 1.6 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -61,14 +61,14 @@ * * @var string */ - protected $role = "developer"; + protected $role = "developer"; /** * First maintainer added? * * @var bool */ - protected static $first = true; + protected static $first = true; /** * Prefix to use in comment headers @@ -86,122 +86,122 @@ * @param string email address * @param string role in this project */ - function __construct($user="unknown", $name="Anonymous Coward", $email="unknown", $role="unknown") - { - $this->user = $user; - $this->name = $name; - $this->email = $email; - $this->role = $role; - - if (self::$first) { - self::$first = false; - } else { - $this->comment_prefix = " "; - } - } - - /** - * Set CVS user name - * - * @access public - * @param string CVS user name - * @return bool true on success - */ - function setUser($name) - { - if (!preg_match('|^[\w-]+$|i', $name)) { - return PEAR::raiseError("'$name' is not a valid CVS user name"); - } - - $this->user = $name; - return true; - } - - /** - * CVS user getter - * - * @access public - * @return string - */ - function getUser() - { - return $this->user; - } - - /** - * Set real user name - * - * @access public - * @param string user name - * @return bool true on success - */ - function setName($name) - { - $this->name = $name; - return true; - } - - /** - * real name getter - * - * @access public - * @return string - */ - function getName() - { - return $this->name; - } - - - /** - * Set email address - * - * @access public - * @param string email address - * @return bool true on success - */ - function setEmail($email) - { - // TODO check for valid address - - $this->email = $email; - return true; - } - - /** - * Set project role - * - * @access public - * @param string project role - * @return bool true on success - */ - function setRole($role) - { - switch ($role) { - case "lead": - case "developer": - case "contributor": - case "helper": - $this->role = $role; - return true; - default: - return PEAR::raiseError("'$role' is not a valid maintainer role"); - } - } - - /** - * Generate a comment header line for this author - * - * @access public - * @return string comment line - */ - function comment() - { - $code = sprintf(" | {$this->comment_prefix} %-59s |\n", "{$this->name} <{$this->email}>"); - $prefix = " "; + function __construct($user="unknown", $name="Anonymous Coward", $email="unknown", $role="unknown") + { + $this->user = $user; + $this->name = $name; + $this->email = $email; + $this->role = $role; + + if (self::$first) { + self::$first = false; + } else { + $this->comment_prefix = " "; + } + } - return $code; - } + /** + * Set CVS user name + * + * @access public + * @param string CVS user name + * @return bool true on success + */ + function setUser($name) + { + if (!preg_match('|^[\w-]+$|i', $name)) { + return PEAR::raiseError("'$name' is not a valid CVS user name"); + } + + $this->user = $name; + return true; + } + + /** + * CVS user getter + * + * @access public + * @return string + */ + function getUser() + { + return $this->user; + } + + /** + * Set real user name + * + * @access public + * @param string user name + * @return bool true on success + */ + function setName($name) + { + $this->name = $name; + return true; + } + + /** + * real name getter + * + * @access public + * @return string + */ + function getName() + { + return $this->name; + } + + + /** + * Set email address + * + * @access public + * @param string email address + * @return bool true on success + */ + function setEmail($email) + { + // TODO check for valid address + + $this->email = $email; + return true; + } + + /** + * Set project role + * + * @access public + * @param string project role + * @return bool true on success + */ + function setRole($role) + { + switch ($role) { + case "lead": + case "developer": + case "contributor": + case "helper": + $this->role = $role; + return true; + default: + return PEAR::raiseError("'$role' is not a valid maintainer role"); + } + } + + /** + * Generate a comment header line for this author + * + * @access public + * @return string comment line + */ + function comment() + { + $code = sprintf(" | {$this->comment_prefix} %-59s |\n", "{$this->name} <{$this->email}>"); + $prefix = " "; + + return $code; + } } /* http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Release.php?r1=1.5&r2=1.6&diff_format=u Index: pear/CodeGen/CodeGen/Release.php diff -u pear/CodeGen/CodeGen/Release.php:1.5 pear/CodeGen/CodeGen/Release.php:1.6 --- pear/CodeGen/CodeGen/Release.php:1.5 Wed Jan 25 21:16:34 2006 +++ pear/CodeGen/CodeGen/Release.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Release.php,v 1.5 2006/01/25 21:16:34 hholzgra Exp $ + * @version CVS: $Id: Release.php,v 1.6 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -132,16 +132,16 @@ function setState($state) { switch ($state) { - case "alpha": - case "beta": - case "stable": - case "snapshot": - case "devel": - $this->state = $state; - return true; - - default: - return PEAR::raiseError("'$state' is not a valid release state'"); + case "alpha": + case "beta": + case "stable": + case "snapshot": + case "devel": + $this->state = $state; + return true; + + default: + return PEAR::raiseError("'$state' is not a valid release state'"); } } http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/XmlParser.php?r1=1.16&r2=1.17&diff_format=u Index: pear/CodeGen/CodeGen/XmlParser.php diff -u pear/CodeGen/CodeGen/XmlParser.php:1.16 pear/CodeGen/CodeGen/XmlParser.php:1.17 --- pear/CodeGen/CodeGen/XmlParser.php:1.16 Mon Oct 2 11:20:52 2006 +++ pear/CodeGen/CodeGen/XmlParser.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: XmlParser.php,v 1.16 2006/10/02 11:20:52 hholzgra Exp $ + * @version CVS: $Id: XmlParser.php,v 1.17 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -46,567 +46,552 @@ * @link http://pear.php.net/package/CodeGen */ - class CodeGen_XmlParser +class CodeGen_XmlParser +{ + /** + * XML parser resource + * + * @var resource + */ + protected $parser = null; + + /** + * Parser stack for <include> management + * + * @var array + */ + protected $parserStack = array(); + + /** + * We collect cData in here + * + * @var string + */ + protected $data = ""; + + /** + * We also try to remember where cData started + * + * @var int + */ + protected $dataLine = 0; + + /** + * We maintain the current tag nesting structure here + * + * @var array + */ + protected $tagStack = array(); + + /** + * We keep track of tag attributes so that we can also provide them to the end tag handlers + * + * @var array + */ + protected $attrStack = array(); + + /** + * There is no clean way to terminate parsing from within a handler ... + * + * @var bool + */ + protected $error = false; + + /** + * Input Filename + * + * @var string + */ + protected $filename = false; + + /** + * Input stream + * + * @var resource + */ + protected $fp = null; + + /** + * Verbatim indicator + * + * @var string + */ + protected $verbatim = false; + + /** + * Verbatim taglevel depth + * + * @var string + */ + protected $verbatimDepth = 0; + + /** + * The constructor + * + */ + function __construct() + { + $this->parser = $this->newParser(); + } + + /** + * Create a new SAX parser and associate it with this XmlParser instance + * + * @void + */ + protected function newParser() + { + $parser = @xml_parser_create_ns(null, ' '); + + if (is_resource($parser)) { + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); + + xml_set_object($parser, $this); + xml_set_element_handler($parser, 'startHandler', 'endHandler'); + xml_set_character_data_handler($parser, 'cDataHandler'); + xml_set_external_entity_ref_handler($parser, 'extEntityHandler'); + xml_set_processing_instruction_handler($parser, 'piHandler'); + } + + return $parser; + } + + /** + * Push current SAX parser instance to the parser stack + * + * @void + */ + protected function pushParser() { - /** - * XML parser resource - * - * @var resource - */ - protected $parser = null; - - /** - * Parser stack for <include> management - * - * @var array - */ - protected $parserStack = array(); - - /** - * We collect cData in here - * - * @var string - */ - protected $data = ""; - - /** - * We also try to remember where cData started - * - * @access private - * @var int - */ - protected $dataLine = 0; - - /** - * We maintain the current tag nesting structure here - * - * @access private - * @var array - */ - protected $tagStack = array(); - - /** - * We keep track of tag attributes so that we can also provide them to the end tag handlers - * - * @access private - * @var array - */ - protected $attrStack = array(); - - /** - * There is no clean way to terminate parsing from within a handler ... - * - * @access private - * @var bool - */ - protected $error = false; - - /** - * Input Filename - * - * @access public - * @var string - */ - protected $filename = false; - - /** - * Input stream - * - * @access public - * @var resource - */ - protected $fp = null; - - /** - * Verbatim indicator - * - * @access public - * @var string - */ - protected $verbatim = false; - - /** - * Verbatim taglevel depth - * - * @access public - * @var string - */ - protected $verbatimDepth = 0; - - /** - * The constructor - * - * @access public - */ - function __construct() - { - $this->parser = $this->newParser(); - } - - /** - * Create a new SAX parser and associate it with this XmlParser instance - * - * @void - */ - private function newParser() - { - $parser = @xml_parser_create_ns(null, ' '); - - if (is_resource($parser)) { - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); - - xml_set_object($parser, $this); - xml_set_element_handler($parser, 'startHandler', 'endHandler'); - xml_set_character_data_handler($parser, 'cDataHandler'); - xml_set_external_entity_ref_handler($parser, 'extEntityHandler'); - xml_set_processing_instruction_handler($parser, 'piHandler'); - } - - return $parser; - } - - /** - * Push current SAX parser instance to the parser stack - * - * @void - */ - private function pushParser() - { - if ($this->parser) { - $entry = array($this->parser, $this->filename, $this->fp); - array_push($this->parserStack, $entry); - } - } - - /** - * Replace current SAX parser with one popped from the parser stack - * - * @void - */ - function popParser() - { - xml_parser_free($this->parser); - list($this->parser, $this->filename, $this->fp) = array_pop($this->parserStack); - } - - /** - * Generate current parse position as string for error messages - * - * @void - * @returns string - */ - private function posString() - { - return "in {$this->filename} on line ". - xml_get_current_line_number($this->parser). - ":". - xml_get_current_column_number($this->parser); + if ($this->parser) { + $entry = array($this->parser, $this->filename, $this->fp); + array_push($this->parserStack, $entry); } + } + + /** + * Replace current SAX parser with one popped from the parser stack + * + * @void + */ + function popParser() + { + xml_parser_free($this->parser); + list($this->parser, $this->filename, $this->fp) = array_pop($this->parserStack); + } + + /** + * Generate current parse position as string for error messages + * + * @void + * @returns string + */ + protected function posString() + { + return "in {$this->filename} on line ". + xml_get_current_line_number($this->parser). + ":". + xml_get_current_column_number($this->parser); + } - /** - * Create a new SAX parser to parse an external entity reference - * - * @void - */ - private function extEntityHandler($parser, $openEntityNames, $base, $systemId, $publicId) { - $this->pushParser(); - $this->parser = $this->newParser(); - $stat = $this->setInputFile($systemId); - if ($stat) { - $this->parse(); - } else { - $this->error = PEAR::raiseError("Can't open system entity file '$systemId' ".$this->posString()); - } - $this->popParser(); - return; + /** + * Create a new SAX parser to parse an external entity reference + * + * @void + */ + protected function extEntityHandler($parser, $openEntityNames, $base, $systemId, $publicId) + { + $this->pushParser(); + $this->parser = $this->newParser(); + $stat = $this->setInputFile($systemId); + if ($stat) { + $this->parse(); + } else { + $this->error = PEAR::raiseError("Can't open system entity file '$systemId' ".$this->posString()); } + $this->popParser(); + return; + } - /** - * Set file to parse - * - * @access public - * @param string - */ - public function setInputFile($filename) - { - $this->filename = $filename; + /** + * Set file to parse + * + * @param string + */ + public function setInputFile($filename) + { + $this->filename = $filename; - $this->fp = @fopen($filename, "r"); + $this->fp = @fopen($filename, "r"); - return is_resource($this->fp); - } + return is_resource($this->fp); + } - /** - * Perform the actual parsing - * - * @return boolean true on success - */ - public function parse() - { - if (!is_resource($this->parser)) { - return PEAR::raiseError("Can't create XML parser"); - } + /** + * Perform the actual parsing + * + * @return boolean true on success + */ + public function parse() + { + if (!is_resource($this->parser)) { + return PEAR::raiseError("Can't create XML parser"); + } - if (!is_resource($this->fp)) { - return PEAR::raiseError("No valid input file"); - } + if (!is_resource($this->fp)) { + return PEAR::raiseError("No valid input file"); + } - while (($data = fread($this->fp, 4096))) { - if (!xml_parse($this->parser, $data, feof($this->fp))) { - $this->error = PEAR::RaiseError(xml_error_string(xml_get_error_code($this->parser))." ".$this->posString()); - } - if ($this->error) { - return $this->error; - } + while (($data = fread($this->fp, 4096))) { + if (!xml_parse($this->parser, $data, feof($this->fp))) { + $this->error = PEAR::RaiseError(xml_error_string(xml_get_error_code($this->parser))." ".$this->posString()); + } + if ($this->error) { + return $this->error; } + } - $stat = $this->error ? $this->error : true; + $stat = $this->error ? $this->error : true; - return $stat; - } + return $stat; + } - /** - * Start verbatim mode - * - */ - protected function verbatim() - { - $this->verbatim = true; - $this->verbatimDepth = 1; - } - - /** - * Try to find best matching tag handler for current tag nesting - * - * @access private - * @param string handler method prefix - * @return string hndler method name or false if no handler found - */ - private function findHandler($prefix) - { - for ($tags = $this->tagStack; count($tags); array_shift($tags)) { - $method = "{$prefix}_".join("_", $tags); - if (method_exists($this, $method)) { - return $method; - } - } + /** + * Start verbatim mode + * + */ + protected function verbatim() + { + $this->verbatim = true; + $this->verbatimDepth = 1; + } - return false; + /** + * Try to find best matching tag handler for current tag nesting + * + * @param string handler method prefix + * @return string hndler method name or false if no handler found + */ + protected function findHandler($prefix) + { + for ($tags = $this->tagStack; count($tags); array_shift($tags)) { + $method = "{$prefix}_".join("_", $tags); + if (method_exists($this, $method)) { + return $method; + } } + return false; + } - /** - * Try to find a tagstart handler for this tag and call it - * - * @access private - * @param resource internal parser handle - * @param string tag name - * @param array tag attributes - */ - private function startHandler($XmlParser, $fulltag, $attr) - { - if ($this->error) return; - $pos = strrpos($fulltag, " "); + /** + * Try to find a tagstart handler for this tag and call it + * + * @param resource internal parser handle + * @param string tag name + * @param array tag attributes + */ + protected function startHandler($XmlParser, $fulltag, $attr) + { + if ($this->error) return; + + $pos = strrpos($fulltag, " "); - $ns = $pos ? substr($fulltag, 0, $pos) : ""; - $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; + $ns = $pos ? substr($fulltag, 0, $pos) : ""; + $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; - // XInclude handling - if ($ns === "http://www.w3.org/2001/XInclude") { - // TODO better error checking - if ($tag === "include") { - $path = isset($attr['href']) ? $attr['href'] : $attr['http://www.w3.org/2001/XInclude href']; - - if (isset($attr["parse"]) && $attr["parse"] == "text") { - if (is_readable($path)) { - $data = file_get_contents($path); - $this->cDataHandler($XmlParser, $data); - } else { - $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); - } + // XInclude handling + if ($ns === "http://www.w3.org/2001/XInclude") { + // TODO better error checking + if ($tag === "include") { + $path = isset($attr['href']) ? $attr['href'] : $attr['http://www.w3.org/2001/XInclude href']; + + if (isset($attr["parse"]) && $attr["parse"] == "text") { + if (is_readable($path)) { + $data = file_get_contents($path); + $this->cDataHandler($XmlParser, $data); } else { - $this->pushParser(); - $this->parser = $this->newParser(); - $stat = $this->setInputFile($path); - if ($stat) { - $this->parse(); - } else { - $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); - } - $this->popParser(); + $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); } + } else { + $this->pushParser(); + $this->parser = $this->newParser(); + $stat = $this->setInputFile($path); + if ($stat) { + $this->parse(); + } else { + $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); + } + $this->popParser(); } - - return; } + + return; + } - // this *has* to be done *after* XInclude processing !!! - array_push($this->tagStack, $tag); - array_push($this->attrStack, $attr); - - if ($this->verbatim) { - $this->verbatimDepth++; - $this->data .= "<$tag"; - foreach ($attr as $key => $value) { - $this->data .= " $key='$value'"; - } - $this->data .= ">"; - return; + // this *has* to be done *after* XInclude processing !!! + array_push($this->tagStack, $tag); + array_push($this->attrStack, $attr); + + if ($this->verbatim) { + $this->verbatimDepth++; + $this->data .= "<$tag"; + foreach ($attr as $key => $value) { + $this->data .= " $key='$value'"; } + $this->data .= ">"; + return; + } - $this->data = ""; - $this->dataLine = 0; + $this->data = ""; + $this->dataLine = 0; - $method = $this->findHandler("tagstart"); - if ($method) { - $err = $this->$method($attr); - if (PEAR::isError($err)) { - $this->error = $err; - $this->error->addUserInfo($this->posString()); - } - } else if (!$this->findHandler("tagend")) { - $this->error = PEAR::raiseError("no matching tag handler for ".join(":",$this->tagStack)); - $this->error->addUserInfo($this->posString()); - } + $method = $this->findHandler("tagstart"); + if ($method) { + $err = $this->$method($attr); + if (PEAR::isError($err)) { + $this->error = $err; + $this->error->addUserInfo($this->posString()); + } + } else if (!$this->findHandler("tagend")) { + $this->error = PEAR::raiseError("no matching tag handler for ".join(":", $this->tagStack)); + $this->error->addUserInfo($this->posString()); } + } - /** - * Try to find a tagend handler for this tag and call it - * - * @access private - * @param resource internal parser handle - * @param string tag name - */ - private function endHandler($XmlParser, $fulltag) - { - if ($this->error) return; + /** + * Try to find a tagend handler for this tag and call it + * + * @param resource internal parser handle + * @param string tag name + */ + protected function endHandler($XmlParser, $fulltag) + { + if ($this->error) return; - $pos = strrpos($fulltag, " "); + $pos = strrpos($fulltag, " "); - $ns = $pos ? substr($fulltag, 0, $pos) : ""; - $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; + $ns = $pos ? substr($fulltag, 0, $pos) : ""; + $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; - // XInclude handling - if ($ns === "http://www.w3.org/2001/XInclude") { - return; - } + // XInclude handling + if ($ns === "http://www.w3.org/2001/XInclude") { + return; + } - // this *has* to be done *before* popping the tag stack!!! - $method = $this->findHandler("tagend"); + // this *has* to be done *before* popping the tag stack!!! + $method = $this->findHandler("tagend"); - $oldtag = array_pop($this->tagStack); - $attr = array_pop($this->attrStack); + $oldtag = array_pop($this->tagStack); + $attr = array_pop($this->attrStack); - if ($this->verbatim) { - if (--$this->verbatimDepth > 0) { - $this->data .= "</$tag>"; - return; - } else { - $this->verbatim = false; - } - } + if ($this->verbatim) { + if (--$this->verbatimDepth > 0) { + $this->data .= "</$tag>"; + return; + } else { + $this->verbatim = false; + } + } - if ($method) { - $err = $this->$method($attr, $this->data, $this->dataLine, $this->filename); - if (PEAR::isError($err)) { - $this->error = $err; - $this->error->addUserInfo($this->posString()); - } + if ($method) { + $err = $this->$method($attr, $this->data, $this->dataLine, $this->filename); + if (PEAR::isError($err)) { + $this->error = $err; + $this->error->addUserInfo($this->posString()); } - $this->data = ""; - $this->dataLine = 0; } + $this->data = ""; + $this->dataLine = 0; + } - /** - * Just collect cData for later use in tag end handlers - * - * @access private - * @param resource internal parser handle - * @param string cData to collect - */ - private function cDataHandler($XmlParser, $data) - { - $this->data.= $this->verbatim ? htmlspecialchars($data) : $data; - if (!$this->dataLine) { - $this->dataLine = xml_get_current_line_number($XmlParser); - } + /** + * Just collect cData for later use in tag end handlers + * + * @param resource internal parser handle + * @param string cData to collect + */ + protected function cDataHandler($XmlParser, $data) + { + $this->data.= $this->verbatim ? htmlspecialchars($data) : $data; + if (!$this->dataLine) { + $this->dataLine = xml_get_current_line_number($XmlParser); } + } - /** - * Delegate processing instructions - * - * @access private - * @param resource internal parser handle - * @param string PI name - * @param string PI content data - */ - private function piHandler($XmlParser, $name, $data) - { - $methodName = $name."PiHandler"; + /** + * Delegate processing instructions + * + * @param resource internal parser handle + * @param string PI name + * @param string PI content data + */ + protected function piHandler($XmlParser, $name, $data) + { + $methodName = $name."PiHandler"; - if (method_exists($this, $methodName)) { - $this->$methodName($XmlParser, $data); - } else { - $this->error = PEAR::raiseError("unknown processing instruction '<$name'"); - } + if (method_exists($this, $methodName)) { + $this->$methodName($XmlParser, $data); + } else { + $this->error = PEAR::raiseError("unknown processing instruction '<$name'"); } + } - /** - * Tread <?data PI sections like <![CDATA[ - * - * @access private - * @param resource internal parser handle - * @param string cData to collect - */ - private function dataPiHandler($XmlParser, $data) - { - $this->cDataHandler($XmlParser, $data); - } - - /** - * A helper stack for collecting stuff - * - * @access private - * @var array - */ - protected $helperStack = array(); - - /** - * The current helper (top of stack) - * - * @access private - * @var mixed - */ - protected $helper = false; - - /** - * The previous helper (top-1 of stack) - * - * @access private - * @var mixed - */ - protected $helperPrev = false; + /** + * Tread <?data PI sections like <![CDATA[ + * + * @param resource internal parser handle + * @param string cData to collect + */ + protected function dataPiHandler($XmlParser, $data) + { + $this->cDataHandler($XmlParser, $data); + } + + /** + * A helper stack for collecting stuff + * + * @var array + */ + protected $helperStack = array(); + + /** + * The current helper (top of stack) + * + * @var mixed + */ + protected $helper = false; + + /** + * The previous helper (top-1 of stack) + * + * @var mixed + */ + protected $helperPrev = false; - /** - * Push something on the helper stack - * - * @access private - * @param mixed - */ - protected function pushHelper($helper) - { - array_push($this->helperStack, $this->helper); - $this->helperPrev = $this->helper; - $this->helper = $helper; - } + /** + * Push something on the helper stack + * + * @param mixed + */ + protected function pushHelper($helper) + { + array_push($this->helperStack, $this->helper); + $this->helperPrev = $this->helper; + $this->helper = $helper; + } - /** - * Pop something from the helper stack - * - * @access private - */ - protected function popHelper() - { - // TODO add optional expectedType parameter? - - $oldHelper = $this->helper; - - $this->helper = array_pop($this->helperStack); - if (count($this->helperStack)) { - end($this->helperStack); - $this->helperPrev = current($this->helperStack); - } else { - $this->helperPrev = false; - } + /** + * Pop something from the helper stack + * + */ + protected function popHelper() + { + // TODO add optional expectedType parameter? + + $oldHelper = $this->helper; - return $oldHelper; + $this->helper = array_pop($this->helperStack); + if (count($this->helperStack)) { + end($this->helperStack); + $this->helperPrev = current($this->helperStack); + } else { + $this->helperPrev = false; } + return $oldHelper; + } + - /** - * accept various truth values - * - * @access public - * @param mixed - * @return bool - */ - protected function toBool($arg) - { - if (is_bool($arg)) { - return $arg; - } - - if (is_numeric($arg)) { - return ($arg != 0); - } - - if (is_string($arg)) { - switch (strtolower($arg)) { - case 'on': - case 'yes': - case 'true': - return true; - default: - return false; - } + /** + * accept various truth values + * + * @param mixed + * @return bool + */ + protected function toBool($arg) + { + if (is_bool($arg)) { + return $arg; + } + + if (is_numeric($arg)) { + return ($arg != 0); + } + + if (is_string($arg)) { + switch (strtolower($arg)) { + case 'on': + case 'yes': + case 'true': + return true; + default: + return false; } + } - return false; + return false; + } + + + /** + * Check that no attributes are given + * + */ + protected function noAttributes($attr) + { + if (!empty($attr)) { + return PEAR::raiseError("<".end($this->tagStack)."> does not allow any attributes"); } + return true; + } - /** - * Check that no attributes are given - * - */ - protected function noAttributes($attr) - { - if (!empty($attr)) { - return PEAR::raiseError("<".end($this->tagStack)."> does not allow any attributes"); - } - - return true; - } - - /** - * Check attributes - * - * @param array actual attribute/value pairs - * @param array optinal attribute names with default values - * @param array required attribute names - */ - protected function checkAttributes(&$attr, $optional, $required = array()) - { - // check for missing required attributes - foreach ($required as $key) { - if (!isset($attr[$key])) { + /** + * Check attributes + * + * @param array actual attribute/value pairs + * @param array optinal attribute names with default values + * @param array required attribute names + */ + protected function checkAttributes(&$attr, $optional, $required = array()) + { + // check for missing required attributes + foreach ($required as $key) { + if (!isset($attr[$key])) { return PEAR::raiseError("required attribute '$key' missing in <".end($this->tagStack)."> "); - } } + } - // add defaults for missing optional arguments - foreach ($optional as $key => $value) { - if (is_numeric($key)) { + // add defaults for missing optional arguments + foreach ($optional as $key => $value) { + if (is_numeric($key)) { $key = $value; $value = null; - } - if (!isset($attr[$key])) { + } + if (!isset($attr[$key])) { $attr[$key] = $value; - } } + } - // check for unknown attributes - foreach ($attr as $key => $value) { - if (!in_array($key, $required) && !in_array($key, $optional)) { - return PEAR::raiseError("'$key' is not a valid attribute for <".end($this->tagStack)."> "); - } + // check for unknown attributes + foreach ($attr as $key => $value) { + if (!in_array($key, $required) && !in_array($key, $optional)) { + return PEAR::raiseError("'$key' is not a valid attribute for <".end($this->tagStack)."> "); } - return true; } + return true; } +} -?> +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */
http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Code.php?r1=1.5&r2=1.6&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Code.php diff -u pear/CodeGen/CodeGen/Tools/Code.php:1.5 pear/CodeGen/CodeGen/Tools/Code.php:1.6 --- pear/CodeGen/CodeGen/Tools/Code.php:1.5 Sat Jul 8 20:04:37 2006 +++ pear/CodeGen/CodeGen/Tools/Code.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Code.php,v 1.5 2006/07/08 20:04:37 hholzgra Exp $ + * @version CVS: $Id: Code.php,v 1.6 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -23,7 +23,7 @@ * includes */ -require_once("CodeGen/Tools/IndentC.php"); +require_once "CodeGen/Tools/IndentC.php"; // TODO make this configurable by language /** @@ -85,7 +85,8 @@ * @param int indent level * @return string formated code block */ - function block($code, $indent = 1) { + function block($code, $indent = 1) + { return CodeGen_Tools_IndentC::indent($indent*$this->indentSteps, $code); } @@ -97,7 +98,8 @@ * @param int indent level * @return string formated code block */ - function varblock($code, $indent = 1) { + function varblock($code, $indent = 1) + { if ($this->language == 'c') { $head = CodeGen_Tools_IndentC::indent($indent * $this->indentSteps, "do {\n"); $foot = CodeGen_Tools_IndentC::indent($indent * $this->indentSteps, "} while (0);\n"); http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Getopt.php?r1=1.3&r2=1.4&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Getopt.php diff -u pear/CodeGen/CodeGen/Tools/Getopt.php:1.3 pear/CodeGen/CodeGen/Tools/Getopt.php:1.4 --- pear/CodeGen/CodeGen/Tools/Getopt.php:1.3 Fri Feb 17 09:47:00 2006 +++ pear/CodeGen/CodeGen/Tools/Getopt.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2003-2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Getopt.php,v 1.3 2006/02/17 09:47:00 hholzgra Exp $ + * @version CVS: $Id: Getopt.php,v 1.4 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -54,7 +54,7 @@ * @param array long options specification * @param callback error callback, call this and exit on errors if given */ - function __construct ($short_options, $long_options = NULL, $usage = NULL) + function __construct ($short_options, $long_options = null, $usage = null) { // use parent methods for actual parsing, store result internaly $argv = parent::readPHPArgv(); @@ -169,8 +169,7 @@ break; } - foreach ($this->options[0] as $opt) - { + foreach ($this->options[0] as $opt) { if ($opt[0] == $name) { return is_null($opt[1]) ? true : $opt[1]; } http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/IndentC.php?r1=1.2&r2=1.3&diff_format=u Index: pear/CodeGen/CodeGen/Tools/IndentC.php diff -u pear/CodeGen/CodeGen/Tools/IndentC.php:1.2 pear/CodeGen/CodeGen/Tools/IndentC.php:1.3 --- pear/CodeGen/CodeGen/Tools/IndentC.php:1.2 Sat Jul 8 19:58:36 2006 +++ pear/CodeGen/CodeGen/Tools/IndentC.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: IndentC.php,v 1.2 2006/07/08 19:58:36 hholzgra Exp $ + * @version CVS: $Id: IndentC.php,v 1.3 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -51,8 +51,16 @@ */ function indent($level, $text) { - $result = parent::indent($level, $text); + $result = parent::indent($level, $text); - return preg_replace('/^\s+#/m', '#', $result); + return preg_replace('/^\s+#/m', '#', $result); } -} \ No newline at end of file +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */ http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Indent.php?r1=1.4&r2=1.5&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Indent.php diff -u pear/CodeGen/CodeGen/Tools/Indent.php:1.4 pear/CodeGen/CodeGen/Tools/Indent.php:1.5 --- pear/CodeGen/CodeGen/Tools/Indent.php:1.4 Sat Jul 8 21:25:52 2006 +++ pear/CodeGen/CodeGen/Tools/Indent.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Indent.php,v 1.4 2006/07/08 21:25:52 hholzgra Exp $ + * @version CVS: $Id: Indent.php,v 1.5 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -48,9 +48,8 @@ function tabify($text, $tabsize = 4) { return preg_replace_callback("/^(".str_repeat(" ", $tabsize).")+/m", - create_function('$matches','return str_repeat("\t", strlen($matches[0])/'.$tabsize.');'), - $text - ); + create_function('$matches', 'return str_repeat("\t", strlen($matches[0])/'.$tabsize.');'), + $text); } @@ -68,9 +67,8 @@ function untabify($text, $tabsize = 4) { return preg_replace_callback("/^(\t)*/m", - create_function('$matches','return str_repeat(" ", strlen($matches[0])*'.$tabsize.');'), - $text - ); + create_function('$matches', 'return str_repeat(" ", strlen($matches[0])*'.$tabsize.');'), + $text); } /** @@ -101,8 +99,8 @@ $minIndent = min($minIndent, strlen($matches[0])); } - $result = ""; - $find = str_repeat(" ", $minIndent); + $result = ""; + $find = str_repeat(" ", $minIndent); $replace = str_repeat(" ", $level); foreach ($lines as $line) { $result.= self::tabify(preg_replace("|^$find|", $replace, $line)."\n", 4); @@ -121,8 +119,8 @@ */ function linetrim($text) { - $text = preg_replace('|^\s*\n|','', $text); - $text = preg_replace('|\n\s*$|',"\n", $text); + $text = preg_replace('|^\s*\n|', '', $text); + $text = preg_replace('|\n\s*$|', "\n", $text); return $text; } @@ -133,9 +131,17 @@ * @param string unix text * @param string dos/windows text */ - function dosify($text) { + function dosify($text) + { return str_replace("\n", "\r\n", $text); } } +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */ http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Tools/Outbuf.php?r1=1.4&r2=1.5&diff_format=u Index: pear/CodeGen/CodeGen/Tools/Outbuf.php diff -u pear/CodeGen/CodeGen/Tools/Outbuf.php:1.4 pear/CodeGen/CodeGen/Tools/Outbuf.php:1.5 --- pear/CodeGen/CodeGen/Tools/Outbuf.php:1.4 Thu Feb 2 22:00:57 2006 +++ pear/CodeGen/CodeGen/Tools/Outbuf.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Outbuf.php,v 1.4 2006/02/02 22:00:57 hholzgra Exp $ + * @version CVS: $Id: Outbuf.php,v 1.5 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -91,8 +91,7 @@ { $stat = true; - if ($this->path) - { + if ($this->path) { $text = ob_get_clean(); $fp = new CodeGen_Tools_FileReplacer($this->path); http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Command.php?r1=1.7&r2=1.8&diff_format=u Index: pear/CodeGen/CodeGen/Command.php diff -u pear/CodeGen/CodeGen/Command.php:1.7 pear/CodeGen/CodeGen/Command.php:1.8 --- pear/CodeGen/CodeGen/Command.php:1.7 Sat Aug 19 00:03:57 2006 +++ pear/CodeGen/CodeGen/Command.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Command.php,v 1.7 2006/08/19 00:03:57 hholzgra Exp $ + * @version CVS: $Id: Command.php,v 1.8 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -223,8 +223,8 @@ $err = $parser->parse(); if (PEAR::isError($err)) { $this->terminate($err->getMessage()." ".$err->getUserInfo()); - } else if(is_string($err)) { - $this->terminate($err); + } else if (is_string($err)) { + $this->terminate($err); } if ($this->options->have("l", "lint")) { http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/ExtensionParser.php?r1=1.16&r2=1.17&diff_format=u Index: pear/CodeGen/CodeGen/ExtensionParser.php diff -u pear/CodeGen/CodeGen/ExtensionParser.php:1.16 pear/CodeGen/CodeGen/ExtensionParser.php:1.17 --- pear/CodeGen/CodeGen/ExtensionParser.php:1.16 Sat Jun 24 12:37:03 2006 +++ pear/CodeGen/CodeGen/ExtensionParser.php Wed Oct 11 10:07:41 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: ExtensionParser.php,v 1.16 2006/06/24 12:37:03 hholzgra Exp $ + * @version CVS: $Id: ExtensionParser.php,v 1.17 2006/10/11 10:07:41 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -303,7 +303,8 @@ return $this->extension->setLicense($license); } - function tagend_extension_code($attr, $data) { + function tagend_extension_code($attr, $data) + { $err = $this->checkAttributes($attr, array("role", "position")); if (PEAR::isError($err)) { return $err; @@ -322,7 +323,7 @@ function tagstart_deps($attr) { - $err = $this->checkAttributes($attr, array("platform","language")); + $err = $this->checkAttributes($attr, array("platform", "language")); if (PEAR::isError($err)) { return $err; } http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Extension.php?r1=1.24&r2=1.25&diff_format=u Index: pear/CodeGen/CodeGen/Extension.php diff -u pear/CodeGen/CodeGen/Extension.php:1.24 pear/CodeGen/CodeGen/Extension.php:1.25 --- pear/CodeGen/CodeGen/Extension.php:1.24 Mon Oct 2 11:20:52 2006 +++ pear/CodeGen/CodeGen/Extension.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Extension.php,v 1.24 2006/10/02 11:20:52 hholzgra Exp $ + * @version CVS: $Id: Extension.php,v 1.25 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -771,7 +771,7 @@ * vim<600: noet sw=4 ts=4 */ '; - } + } /** * Generate Editor settings block for documentation files http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Maintainer.php?r1=1.5&r2=1.6&diff_format=u Index: pear/CodeGen/CodeGen/Maintainer.php diff -u pear/CodeGen/CodeGen/Maintainer.php:1.5 pear/CodeGen/CodeGen/Maintainer.php:1.6 --- pear/CodeGen/CodeGen/Maintainer.php:1.5 Mon Oct 2 11:20:52 2006 +++ pear/CodeGen/CodeGen/Maintainer.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Maintainer.php,v 1.5 2006/10/02 11:20:52 hholzgra Exp $ + * @version CVS: $Id: Maintainer.php,v 1.6 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -61,14 +61,14 @@ * * @var string */ - protected $role = "developer"; + protected $role = "developer"; /** * First maintainer added? * * @var bool */ - protected static $first = true; + protected static $first = true; /** * Prefix to use in comment headers @@ -86,122 +86,122 @@ * @param string email address * @param string role in this project */ - function __construct($user="unknown", $name="Anonymous Coward", $email="unknown", $role="unknown") - { - $this->user = $user; - $this->name = $name; - $this->email = $email; - $this->role = $role; - - if (self::$first) { - self::$first = false; - } else { - $this->comment_prefix = " "; - } - } - - /** - * Set CVS user name - * - * @access public - * @param string CVS user name - * @return bool true on success - */ - function setUser($name) - { - if (!preg_match('|^[\w-]+$|i', $name)) { - return PEAR::raiseError("'$name' is not a valid CVS user name"); - } - - $this->user = $name; - return true; - } - - /** - * CVS user getter - * - * @access public - * @return string - */ - function getUser() - { - return $this->user; - } - - /** - * Set real user name - * - * @access public - * @param string user name - * @return bool true on success - */ - function setName($name) - { - $this->name = $name; - return true; - } - - /** - * real name getter - * - * @access public - * @return string - */ - function getName() - { - return $this->name; - } - - - /** - * Set email address - * - * @access public - * @param string email address - * @return bool true on success - */ - function setEmail($email) - { - // TODO check for valid address - - $this->email = $email; - return true; - } - - /** - * Set project role - * - * @access public - * @param string project role - * @return bool true on success - */ - function setRole($role) - { - switch ($role) { - case "lead": - case "developer": - case "contributor": - case "helper": - $this->role = $role; - return true; - default: - return PEAR::raiseError("'$role' is not a valid maintainer role"); - } - } - - /** - * Generate a comment header line for this author - * - * @access public - * @return string comment line - */ - function comment() - { - $code = sprintf(" | {$this->comment_prefix} %-59s |\n", "{$this->name} <{$this->email}>"); - $prefix = " "; + function __construct($user="unknown", $name="Anonymous Coward", $email="unknown", $role="unknown") + { + $this->user = $user; + $this->name = $name; + $this->email = $email; + $this->role = $role; + + if (self::$first) { + self::$first = false; + } else { + $this->comment_prefix = " "; + } + } - return $code; - } + /** + * Set CVS user name + * + * @access public + * @param string CVS user name + * @return bool true on success + */ + function setUser($name) + { + if (!preg_match('|^[\w-]+$|i', $name)) { + return PEAR::raiseError("'$name' is not a valid CVS user name"); + } + + $this->user = $name; + return true; + } + + /** + * CVS user getter + * + * @access public + * @return string + */ + function getUser() + { + return $this->user; + } + + /** + * Set real user name + * + * @access public + * @param string user name + * @return bool true on success + */ + function setName($name) + { + $this->name = $name; + return true; + } + + /** + * real name getter + * + * @access public + * @return string + */ + function getName() + { + return $this->name; + } + + + /** + * Set email address + * + * @access public + * @param string email address + * @return bool true on success + */ + function setEmail($email) + { + // TODO check for valid address + + $this->email = $email; + return true; + } + + /** + * Set project role + * + * @access public + * @param string project role + * @return bool true on success + */ + function setRole($role) + { + switch ($role) { + case "lead": + case "developer": + case "contributor": + case "helper": + $this->role = $role; + return true; + default: + return PEAR::raiseError("'$role' is not a valid maintainer role"); + } + } + + /** + * Generate a comment header line for this author + * + * @access public + * @return string comment line + */ + function comment() + { + $code = sprintf(" | {$this->comment_prefix} %-59s |\n", "{$this->name} <{$this->email}>"); + $prefix = " "; + + return $code; + } } /* http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/Release.php?r1=1.5&r2=1.6&diff_format=u Index: pear/CodeGen/CodeGen/Release.php diff -u pear/CodeGen/CodeGen/Release.php:1.5 pear/CodeGen/CodeGen/Release.php:1.6 --- pear/CodeGen/CodeGen/Release.php:1.5 Wed Jan 25 21:16:34 2006 +++ pear/CodeGen/CodeGen/Release.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Release.php,v 1.5 2006/01/25 21:16:34 hholzgra Exp $ + * @version CVS: $Id: Release.php,v 1.6 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -132,16 +132,16 @@ function setState($state) { switch ($state) { - case "alpha": - case "beta": - case "stable": - case "snapshot": - case "devel": - $this->state = $state; - return true; - - default: - return PEAR::raiseError("'$state' is not a valid release state'"); + case "alpha": + case "beta": + case "stable": + case "snapshot": + case "devel": + $this->state = $state; + return true; + + default: + return PEAR::raiseError("'$state' is not a valid release state'"); } } http://cvs.php.net/viewvc.cgi/pear/CodeGen/CodeGen/XmlParser.php?r1=1.16&r2=1.17&diff_format=u Index: pear/CodeGen/CodeGen/XmlParser.php diff -u pear/CodeGen/CodeGen/XmlParser.php:1.16 pear/CodeGen/CodeGen/XmlParser.php:1.17 --- pear/CodeGen/CodeGen/XmlParser.php:1.16 Mon Oct 2 11:20:52 2006 +++ pear/CodeGen/CodeGen/XmlParser.php Wed Oct 11 10:07:42 2006 @@ -15,7 +15,7 @@ * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: XmlParser.php,v 1.16 2006/10/02 11:20:52 hholzgra Exp $ + * @version CVS: $Id: XmlParser.php,v 1.17 2006/10/11 10:07:42 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ @@ -46,567 +46,552 @@ * @link http://pear.php.net/package/CodeGen */ - class CodeGen_XmlParser +class CodeGen_XmlParser +{ + /** + * XML parser resource + * + * @var resource + */ + protected $parser = null; + + /** + * Parser stack for <include> management + * + * @var array + */ + protected $parserStack = array(); + + /** + * We collect cData in here + * + * @var string + */ + protected $data = ""; + + /** + * We also try to remember where cData started + * + * @var int + */ + protected $dataLine = 0; + + /** + * We maintain the current tag nesting structure here + * + * @var array + */ + protected $tagStack = array(); + + /** + * We keep track of tag attributes so that we can also provide them to the end tag handlers + * + * @var array + */ + protected $attrStack = array(); + + /** + * There is no clean way to terminate parsing from within a handler ... + * + * @var bool + */ + protected $error = false; + + /** + * Input Filename + * + * @var string + */ + protected $filename = false; + + /** + * Input stream + * + * @var resource + */ + protected $fp = null; + + /** + * Verbatim indicator + * + * @var string + */ + protected $verbatim = false; + + /** + * Verbatim taglevel depth + * + * @var string + */ + protected $verbatimDepth = 0; + + /** + * The constructor + * + */ + function __construct() + { + $this->parser = $this->newParser(); + } + + /** + * Create a new SAX parser and associate it with this XmlParser instance + * + * @void + */ + protected function newParser() + { + $parser = @xml_parser_create_ns(null, ' '); + + if (is_resource($parser)) { + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); + + xml_set_object($parser, $this); + xml_set_element_handler($parser, 'startHandler', 'endHandler'); + xml_set_character_data_handler($parser, 'cDataHandler'); + xml_set_external_entity_ref_handler($parser, 'extEntityHandler'); + xml_set_processing_instruction_handler($parser, 'piHandler'); + } + + return $parser; + } + + /** + * Push current SAX parser instance to the parser stack + * + * @void + */ + protected function pushParser() { - /** - * XML parser resource - * - * @var resource - */ - protected $parser = null; - - /** - * Parser stack for <include> management - * - * @var array - */ - protected $parserStack = array(); - - /** - * We collect cData in here - * - * @var string - */ - protected $data = ""; - - /** - * We also try to remember where cData started - * - * @access private - * @var int - */ - protected $dataLine = 0; - - /** - * We maintain the current tag nesting structure here - * - * @access private - * @var array - */ - protected $tagStack = array(); - - /** - * We keep track of tag attributes so that we can also provide them to the end tag handlers - * - * @access private - * @var array - */ - protected $attrStack = array(); - - /** - * There is no clean way to terminate parsing from within a handler ... - * - * @access private - * @var bool - */ - protected $error = false; - - /** - * Input Filename - * - * @access public - * @var string - */ - protected $filename = false; - - /** - * Input stream - * - * @access public - * @var resource - */ - protected $fp = null; - - /** - * Verbatim indicator - * - * @access public - * @var string - */ - protected $verbatim = false; - - /** - * Verbatim taglevel depth - * - * @access public - * @var string - */ - protected $verbatimDepth = 0; - - /** - * The constructor - * - * @access public - */ - function __construct() - { - $this->parser = $this->newParser(); - } - - /** - * Create a new SAX parser and associate it with this XmlParser instance - * - * @void - */ - private function newParser() - { - $parser = @xml_parser_create_ns(null, ' '); - - if (is_resource($parser)) { - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); - - xml_set_object($parser, $this); - xml_set_element_handler($parser, 'startHandler', 'endHandler'); - xml_set_character_data_handler($parser, 'cDataHandler'); - xml_set_external_entity_ref_handler($parser, 'extEntityHandler'); - xml_set_processing_instruction_handler($parser, 'piHandler'); - } - - return $parser; - } - - /** - * Push current SAX parser instance to the parser stack - * - * @void - */ - private function pushParser() - { - if ($this->parser) { - $entry = array($this->parser, $this->filename, $this->fp); - array_push($this->parserStack, $entry); - } - } - - /** - * Replace current SAX parser with one popped from the parser stack - * - * @void - */ - function popParser() - { - xml_parser_free($this->parser); - list($this->parser, $this->filename, $this->fp) = array_pop($this->parserStack); - } - - /** - * Generate current parse position as string for error messages - * - * @void - * @returns string - */ - private function posString() - { - return "in {$this->filename} on line ". - xml_get_current_line_number($this->parser). - ":". - xml_get_current_column_number($this->parser); + if ($this->parser) { + $entry = array($this->parser, $this->filename, $this->fp); + array_push($this->parserStack, $entry); } + } + + /** + * Replace current SAX parser with one popped from the parser stack + * + * @void + */ + function popParser() + { + xml_parser_free($this->parser); + list($this->parser, $this->filename, $this->fp) = array_pop($this->parserStack); + } + + /** + * Generate current parse position as string for error messages + * + * @void + * @returns string + */ + protected function posString() + { + return "in {$this->filename} on line ". + xml_get_current_line_number($this->parser). + ":". + xml_get_current_column_number($this->parser); + } - /** - * Create a new SAX parser to parse an external entity reference - * - * @void - */ - private function extEntityHandler($parser, $openEntityNames, $base, $systemId, $publicId) { - $this->pushParser(); - $this->parser = $this->newParser(); - $stat = $this->setInputFile($systemId); - if ($stat) { - $this->parse(); - } else { - $this->error = PEAR::raiseError("Can't open system entity file '$systemId' ".$this->posString()); - } - $this->popParser(); - return; + /** + * Create a new SAX parser to parse an external entity reference + * + * @void + */ + protected function extEntityHandler($parser, $openEntityNames, $base, $systemId, $publicId) + { + $this->pushParser(); + $this->parser = $this->newParser(); + $stat = $this->setInputFile($systemId); + if ($stat) { + $this->parse(); + } else { + $this->error = PEAR::raiseError("Can't open system entity file '$systemId' ".$this->posString()); } + $this->popParser(); + return; + } - /** - * Set file to parse - * - * @access public - * @param string - */ - public function setInputFile($filename) - { - $this->filename = $filename; + /** + * Set file to parse + * + * @param string + */ + public function setInputFile($filename) + { + $this->filename = $filename; - $this->fp = @fopen($filename, "r"); + $this->fp = @fopen($filename, "r"); - return is_resource($this->fp); - } + return is_resource($this->fp); + } - /** - * Perform the actual parsing - * - * @return boolean true on success - */ - public function parse() - { - if (!is_resource($this->parser)) { - return PEAR::raiseError("Can't create XML parser"); - } + /** + * Perform the actual parsing + * + * @return boolean true on success + */ + public function parse() + { + if (!is_resource($this->parser)) { + return PEAR::raiseError("Can't create XML parser"); + } - if (!is_resource($this->fp)) { - return PEAR::raiseError("No valid input file"); - } + if (!is_resource($this->fp)) { + return PEAR::raiseError("No valid input file"); + } - while (($data = fread($this->fp, 4096))) { - if (!xml_parse($this->parser, $data, feof($this->fp))) { - $this->error = PEAR::RaiseError(xml_error_string(xml_get_error_code($this->parser))." ".$this->posString()); - } - if ($this->error) { - return $this->error; - } + while (($data = fread($this->fp, 4096))) { + if (!xml_parse($this->parser, $data, feof($this->fp))) { + $this->error = PEAR::RaiseError(xml_error_string(xml_get_error_code($this->parser))." ".$this->posString()); + } + if ($this->error) { + return $this->error; } + } - $stat = $this->error ? $this->error : true; + $stat = $this->error ? $this->error : true; - return $stat; - } + return $stat; + } - /** - * Start verbatim mode - * - */ - protected function verbatim() - { - $this->verbatim = true; - $this->verbatimDepth = 1; - } - - /** - * Try to find best matching tag handler for current tag nesting - * - * @access private - * @param string handler method prefix - * @return string hndler method name or false if no handler found - */ - private function findHandler($prefix) - { - for ($tags = $this->tagStack; count($tags); array_shift($tags)) { - $method = "{$prefix}_".join("_", $tags); - if (method_exists($this, $method)) { - return $method; - } - } + /** + * Start verbatim mode + * + */ + protected function verbatim() + { + $this->verbatim = true; + $this->verbatimDepth = 1; + } - return false; + /** + * Try to find best matching tag handler for current tag nesting + * + * @param string handler method prefix + * @return string hndler method name or false if no handler found + */ + protected function findHandler($prefix) + { + for ($tags = $this->tagStack; count($tags); array_shift($tags)) { + $method = "{$prefix}_".join("_", $tags); + if (method_exists($this, $method)) { + return $method; + } } + return false; + } - /** - * Try to find a tagstart handler for this tag and call it - * - * @access private - * @param resource internal parser handle - * @param string tag name - * @param array tag attributes - */ - private function startHandler($XmlParser, $fulltag, $attr) - { - if ($this->error) return; - $pos = strrpos($fulltag, " "); + /** + * Try to find a tagstart handler for this tag and call it + * + * @param resource internal parser handle + * @param string tag name + * @param array tag attributes + */ + protected function startHandler($XmlParser, $fulltag, $attr) + { + if ($this->error) return; + + $pos = strrpos($fulltag, " "); - $ns = $pos ? substr($fulltag, 0, $pos) : ""; - $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; + $ns = $pos ? substr($fulltag, 0, $pos) : ""; + $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; - // XInclude handling - if ($ns === "http://www.w3.org/2001/XInclude") { - // TODO better error checking - if ($tag === "include") { - $path = isset($attr['href']) ? $attr['href'] : $attr['http://www.w3.org/2001/XInclude href']; - - if (isset($attr["parse"]) && $attr["parse"] == "text") { - if (is_readable($path)) { - $data = file_get_contents($path); - $this->cDataHandler($XmlParser, $data); - } else { - $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); - } + // XInclude handling + if ($ns === "http://www.w3.org/2001/XInclude") { + // TODO better error checking + if ($tag === "include") { + $path = isset($attr['href']) ? $attr['href'] : $attr['http://www.w3.org/2001/XInclude href']; + + if (isset($attr["parse"]) && $attr["parse"] == "text") { + if (is_readable($path)) { + $data = file_get_contents($path); + $this->cDataHandler($XmlParser, $data); } else { - $this->pushParser(); - $this->parser = $this->newParser(); - $stat = $this->setInputFile($path); - if ($stat) { - $this->parse(); - } else { - $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); - } - $this->popParser(); + $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); } + } else { + $this->pushParser(); + $this->parser = $this->newParser(); + $stat = $this->setInputFile($path); + if ($stat) { + $this->parse(); + } else { + $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); + } + $this->popParser(); } - - return; } + + return; + } - // this *has* to be done *after* XInclude processing !!! - array_push($this->tagStack, $tag); - array_push($this->attrStack, $attr); - - if ($this->verbatim) { - $this->verbatimDepth++; - $this->data .= "<$tag"; - foreach ($attr as $key => $value) { - $this->data .= " $key='$value'"; - } - $this->data .= ">"; - return; + // this *has* to be done *after* XInclude processing !!! + array_push($this->tagStack, $tag); + array_push($this->attrStack, $attr); + + if ($this->verbatim) { + $this->verbatimDepth++; + $this->data .= "<$tag"; + foreach ($attr as $key => $value) { + $this->data .= " $key='$value'"; } + $this->data .= ">"; + return; + } - $this->data = ""; - $this->dataLine = 0; + $this->data = ""; + $this->dataLine = 0; - $method = $this->findHandler("tagstart"); - if ($method) { - $err = $this->$method($attr); - if (PEAR::isError($err)) { - $this->error = $err; - $this->error->addUserInfo($this->posString()); - } - } else if (!$this->findHandler("tagend")) { - $this->error = PEAR::raiseError("no matching tag handler for ".join(":",$this->tagStack)); - $this->error->addUserInfo($this->posString()); - } + $method = $this->findHandler("tagstart"); + if ($method) { + $err = $this->$method($attr); + if (PEAR::isError($err)) { + $this->error = $err; + $this->error->addUserInfo($this->posString()); + } + } else if (!$this->findHandler("tagend")) { + $this->error = PEAR::raiseError("no matching tag handler for ".join(":", $this->tagStack)); + $this->error->addUserInfo($this->posString()); } + } - /** - * Try to find a tagend handler for this tag and call it - * - * @access private - * @param resource internal parser handle - * @param string tag name - */ - private function endHandler($XmlParser, $fulltag) - { - if ($this->error) return; + /** + * Try to find a tagend handler for this tag and call it + * + * @param resource internal parser handle + * @param string tag name + */ + protected function endHandler($XmlParser, $fulltag) + { + if ($this->error) return; - $pos = strrpos($fulltag, " "); + $pos = strrpos($fulltag, " "); - $ns = $pos ? substr($fulltag, 0, $pos) : ""; - $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; + $ns = $pos ? substr($fulltag, 0, $pos) : ""; + $tag = $pos ? substr($fulltag, $pos + 1) : $fulltag; - // XInclude handling - if ($ns === "http://www.w3.org/2001/XInclude") { - return; - } + // XInclude handling + if ($ns === "http://www.w3.org/2001/XInclude") { + return; + } - // this *has* to be done *before* popping the tag stack!!! - $method = $this->findHandler("tagend"); + // this *has* to be done *before* popping the tag stack!!! + $method = $this->findHandler("tagend"); - $oldtag = array_pop($this->tagStack); - $attr = array_pop($this->attrStack); + $oldtag = array_pop($this->tagStack); + $attr = array_pop($this->attrStack); - if ($this->verbatim) { - if (--$this->verbatimDepth > 0) { - $this->data .= "</$tag>"; - return; - } else { - $this->verbatim = false; - } - } + if ($this->verbatim) { + if (--$this->verbatimDepth > 0) { + $this->data .= "</$tag>"; + return; + } else { + $this->verbatim = false; + } + } - if ($method) { - $err = $this->$method($attr, $this->data, $this->dataLine, $this->filename); - if (PEAR::isError($err)) { - $this->error = $err; - $this->error->addUserInfo($this->posString()); - } + if ($method) { + $err = $this->$method($attr, $this->data, $this->dataLine, $this->filename); + if (PEAR::isError($err)) { + $this->error = $err; + $this->error->addUserInfo($this->posString()); } - $this->data = ""; - $this->dataLine = 0; } + $this->data = ""; + $this->dataLine = 0; + } - /** - * Just collect cData for later use in tag end handlers - * - * @access private - * @param resource internal parser handle - * @param string cData to collect - */ - private function cDataHandler($XmlParser, $data) - { - $this->data.= $this->verbatim ? htmlspecialchars($data) : $data; - if (!$this->dataLine) { - $this->dataLine = xml_get_current_line_number($XmlParser); - } + /** + * Just collect cData for later use in tag end handlers + * + * @param resource internal parser handle + * @param string cData to collect + */ + protected function cDataHandler($XmlParser, $data) + { + $this->data.= $this->verbatim ? htmlspecialchars($data) : $data; + if (!$this->dataLine) { + $this->dataLine = xml_get_current_line_number($XmlParser); } + } - /** - * Delegate processing instructions - * - * @access private - * @param resource internal parser handle - * @param string PI name - * @param string PI content data - */ - private function piHandler($XmlParser, $name, $data) - { - $methodName = $name."PiHandler"; + /** + * Delegate processing instructions + * + * @param resource internal parser handle + * @param string PI name + * @param string PI content data + */ + protected function piHandler($XmlParser, $name, $data) + { + $methodName = $name."PiHandler"; - if (method_exists($this, $methodName)) { - $this->$methodName($XmlParser, $data); - } else { - $this->error = PEAR::raiseError("unknown processing instruction '<$name'"); - } + if (method_exists($this, $methodName)) { + $this->$methodName($XmlParser, $data); + } else { + $this->error = PEAR::raiseError("unknown processing instruction '<$name'"); } + } - /** - * Tread <?data PI sections like <![CDATA[ - * - * @access private - * @param resource internal parser handle - * @param string cData to collect - */ - private function dataPiHandler($XmlParser, $data) - { - $this->cDataHandler($XmlParser, $data); - } - - /** - * A helper stack for collecting stuff - * - * @access private - * @var array - */ - protected $helperStack = array(); - - /** - * The current helper (top of stack) - * - * @access private - * @var mixed - */ - protected $helper = false; - - /** - * The previous helper (top-1 of stack) - * - * @access private - * @var mixed - */ - protected $helperPrev = false; + /** + * Tread <?data PI sections like <![CDATA[ + * + * @param resource internal parser handle + * @param string cData to collect + */ + protected function dataPiHandler($XmlParser, $data) + { + $this->cDataHandler($XmlParser, $data); + } + + /** + * A helper stack for collecting stuff + * + * @var array + */ + protected $helperStack = array(); + + /** + * The current helper (top of stack) + * + * @var mixed + */ + protected $helper = false; + + /** + * The previous helper (top-1 of stack) + * + * @var mixed + */ + protected $helperPrev = false; - /** - * Push something on the helper stack - * - * @access private - * @param mixed - */ - protected function pushHelper($helper) - { - array_push($this->helperStack, $this->helper); - $this->helperPrev = $this->helper; - $this->helper = $helper; - } + /** + * Push something on the helper stack + * + * @param mixed + */ + protected function pushHelper($helper) + { + array_push($this->helperStack, $this->helper); + $this->helperPrev = $this->helper; + $this->helper = $helper; + } - /** - * Pop something from the helper stack - * - * @access private - */ - protected function popHelper() - { - // TODO add optional expectedType parameter? - - $oldHelper = $this->helper; - - $this->helper = array_pop($this->helperStack); - if (count($this->helperStack)) { - end($this->helperStack); - $this->helperPrev = current($this->helperStack); - } else { - $this->helperPrev = false; - } + /** + * Pop something from the helper stack + * + */ + protected function popHelper() + { + // TODO add optional expectedType parameter? + + $oldHelper = $this->helper; - return $oldHelper; + $this->helper = array_pop($this->helperStack); + if (count($this->helperStack)) { + end($this->helperStack); + $this->helperPrev = current($this->helperStack); + } else { + $this->helperPrev = false; } + return $oldHelper; + } + - /** - * accept various truth values - * - * @access public - * @param mixed - * @return bool - */ - protected function toBool($arg) - { - if (is_bool($arg)) { - return $arg; - } - - if (is_numeric($arg)) { - return ($arg != 0); - } - - if (is_string($arg)) { - switch (strtolower($arg)) { - case 'on': - case 'yes': - case 'true': - return true; - default: - return false; - } + /** + * accept various truth values + * + * @param mixed + * @return bool + */ + protected function toBool($arg) + { + if (is_bool($arg)) { + return $arg; + } + + if (is_numeric($arg)) { + return ($arg != 0); + } + + if (is_string($arg)) { + switch (strtolower($arg)) { + case 'on': + case 'yes': + case 'true': + return true; + default: + return false; } + } - return false; + return false; + } + + + /** + * Check that no attributes are given + * + */ + protected function noAttributes($attr) + { + if (!empty($attr)) { + return PEAR::raiseError("<".end($this->tagStack)."> does not allow any attributes"); } + return true; + } - /** - * Check that no attributes are given - * - */ - protected function noAttributes($attr) - { - if (!empty($attr)) { - return PEAR::raiseError("<".end($this->tagStack)."> does not allow any attributes"); - } - - return true; - } - - /** - * Check attributes - * - * @param array actual attribute/value pairs - * @param array optinal attribute names with default values - * @param array required attribute names - */ - protected function checkAttributes(&$attr, $optional, $required = array()) - { - // check for missing required attributes - foreach ($required as $key) { - if (!isset($attr[$key])) { + /** + * Check attributes + * + * @param array actual attribute/value pairs + * @param array optinal attribute names with default values + * @param array required attribute names + */ + protected function checkAttributes(&$attr, $optional, $required = array()) + { + // check for missing required attributes + foreach ($required as $key) { + if (!isset($attr[$key])) { return PEAR::raiseError("required attribute '$key' missing in <".end($this->tagStack)."> "); - } } + } - // add defaults for missing optional arguments - foreach ($optional as $key => $value) { - if (is_numeric($key)) { + // add defaults for missing optional arguments + foreach ($optional as $key => $value) { + if (is_numeric($key)) { $key = $value; $value = null; - } - if (!isset($attr[$key])) { + } + if (!isset($attr[$key])) { $attr[$key] = $value; - } } + } - // check for unknown attributes - foreach ($attr as $key => $value) { - if (!in_array($key, $required) && !in_array($key, $optional)) { - return PEAR::raiseError("'$key' is not a valid attribute for <".end($this->tagStack)."> "); - } + // check for unknown attributes + foreach ($attr as $key => $value) { + if (!in_array($key, $required) && !in_array($key, $optional)) { + return PEAR::raiseError("'$key' is not a valid attribute for <".end($this->tagStack)."> "); } - return true; } + return true; } +} -?> +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */