cvs: pear /CodeGen .cvsignore Command.php Element.php Extension.php ExtensionParser.php License.php Maintainer.php Release.php XmlParser.php foo.xml
package.xml /CodeGen/License BSD.php GPL.php LGPL.php PHP.php /CodeGen/Tools Code.php Getopt.php Indent.php Platform.php Tokenizer.php
| From: | Hartmut Holzgraefe | Date: | Mon, 18 Jul 2005 08:06:57 +0000 |
| Subject: | cvs: pear /CodeGen .cvsignore Command.php Element.php Extension.php ExtensionParser.php License.php Maintainer.php Release.php XmlParser.php foo.xml package.xml /CodeGen/License BSD.php GPL.php LGPL.php PHP.php /CodeGen/Tools Code.php Getopt.php Indent.php Platform.php Tokenizer.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-33098@lists.php.net to get a copy of this message | ||
hholzgra Mon Jul 18 04:06:57 2005 EDT
Added files:
/pear/CodeGen .cvsignore Command.php Element.php Extension.php
ExtensionParser.php License.php Maintainer.php
Release.php XmlParser.php foo.xml package.xml
/pear/CodeGen/License BSD.php GPL.php LGPL.php PHP.php
/pear/CodeGen/Tools Code.php Getopt.php Indent.php Platform.php
Tokenizer.php
Log:
Initial commit of CodeGen framework
(formerly part of PECL_Gen)
http://cvs.php.net/co.php/pear/CodeGen/.cvsignore?r=1.1&p=1 Index: pear/CodeGen/.cvsignore +++ pear/CodeGen/.cvsignore *~ PECL_GEN*.tgz dumpster http://cvs.php.net/co.php/pear/CodeGen/Command.php?r=1.1&p=1 Index: pear/CodeGen/Command.php +++ pear/CodeGen/Command.php <?php /** * Command wrapper class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * includes */ require_once 'PEAR.php'; require_once "CodeGen/Tools/Getopt.php"; require_once "CodeGen/Extension.php"; /** * Command wrapper class * * This class wraps up the functionality needed for the * command line script. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Command { /** * The extension the command class is going to work on * * @var object */ var $extension; /** * Command constructor * * @param object Extension to work on */ function __construct(CodeGen_Extension $extension) { $this->extension = $extension; // no compromise error_reporting(E_ALL); // but make sure errors are written to stderr so they can't be collected by ob_* functions set_error_handler(array($this, "errorHandler")); list($shortOptions, $longOptions) = $this->commandOptions(); $this->options = new CodeGen_Tools_Getopt($shortOptions, $longOptions, array($this, "showUsage")); if ($this->options->have("help", "h")) { $this->showVersion(); $this->showUsage(); exit(0); } if ($this->options->have("version")) { $this->showVersion(); exit(0); } } /** * Define the available command line options * * @return array the available short and long options */ function commandOptions() { $shortOptions = "fd=hqx"; $longOptions = array( "help", "dir=", "experimental", "force", "quiet", "version", ); return array($shortOptions, $longOptions); } /** * Show copyright and version info taken from extension class * */ function showVersion() { $fp = fopen("php://stderr", "w"); fputs($fp, basename($_SERVER["argv"][0]) . " ". $this->extension->version() . "," . $this->extension->copyright() . "\n"); fclose($fp); } /** * Show usage/help message * * @param string optional error message to display */ function showUsage($message = false) { $fp = fopen("php://stderr", "w"); if ($message) fputs($fp, "$message\n\n"); fputs($fp, "Usage: ". $_SERVER["argv"][0] ." [-hxf] [-d dir] [--version] specfile.xml -h|--help this message -x|--experimental enable experimental features -f|--force overwrite existing files/directories -d|--dir output directory --version show version info "); fclose($fp); } /** * Show error message and bailout * * @param string error message */ function terminate($msg) { $stderr = @fopen("php://stderr/", "w"); if ($stderr) { fprintf($stderr, "%s\n", $msg); fclose($stderr); } else { echo "$msg\n"; } exit(3); } /** * Error handler callback * * @param int error level number * @param string error message * @param string source file * @param int source line */ function errorHandler($errno, $errstr, $errfile, $errline) { if ($errno & error_reporting()) { $fp = fopen("php://stderr", "w"); switch ($errno) { case E_ERROR : fputs($fp, "Error"); break; case E_WARNING : fputs($fp, "Warning"); break; case E_PARSE : fputs($fp, "Parsing Error"); break; case E_NOTICE : fputs($fp, "Notice"); break; case E_CORE_ERROR : fputs($fp, "Core Error"); break; case E_CORE_WARNING : fputs($fp, "Core Warning"); break; case E_COMPILE_ERROR : fputs($fp, "Compile Error"); break; case E_COMPILE_WARNING : fputs($fp, "Compile Warning"); break; case E_USER_ERROR : fputs($fp, "User Error"); break; case E_USER_WARNING : fputs($fp, "User Warning"); break; case E_USER_NOTICE : fputs($fp, "User Notice"); break; case E_STRICT : fputs($fp, "Runtime Notice"); break; default : fputs($fp, "Unknown Error"); break; } fputs($fp, ": $errstr in $errfile on line $errline\n"); fclose($fp); } } /** * Create extension using the given parser * * @param object Extension parser */ function execute($parser) { // normal operation: read XML file and go with that $arguments = $this->options->arguments(); if (count($arguments) != 1) { $this->showUsage(); exit(3); } $xmlfile = $arguments[0]; if (!file_exists($xmlfile) || !is_readable($xmlfile)) { $this->terminate("Cannot open spec file '$xmlfile'"); } // create parser for extension specs $err = $parser->setInputFile($xmlfile); if (PEAR::isError($err)) { $this->terminate($err->message); } // do the actual parsing $err = $parser->parse(); if (PEAR::isError($err)) { $this->terminate($err->getMessage()." ".$err->getUserInfo()); } else if(is_string($err)) { $this->terminate(""); } // and now create the actual extension from the collected specs $err = $this->extension->createExtension($this->options->value("d", "dir"), $this->options->have("f", "force")); if (PEAR::isError($err)) { $this->terminate($err->getMessage()." ".$err->getUserInfo()); } if (!$this->options->have("q", "quiet")) { echo $this->extension->successMsg($this->extension->name); } } } http://cvs.php.net/co.php/pear/CodeGen/Element.php?r=1.1&p=1 Index: pear/CodeGen/Element.php +++ pear/CodeGen/Element.php <?php /** * Abstract base class for all code elements * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: Element.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Abstract base class for all code elements * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_Element { /** * Checks whether a string is a reserved name * * @access public * @param string name * @return bool true if reserved */ function isKeyword($name) { return false; } /** * Checks whether a string is a valid C name * * @access public * @param string The name to check * @return bool true for valid names, false otherwise */ function isName($name) { if (ereg("^[[:alpha:]_][[:alnum:]_]*$",$name)) { // TODO reserved words return true; } return false; } /** * Generate C code for element * * @access public * @param string Extension name * @return string C code */ function cCode($name) { return ""; } /** * Generate C code header block for all elements of this class * * @access public * @param string Extension name * @return string C code */ static function cCodeHeader($name) { return ""; } /** * Generate C code footer block for all elements of this class * * @access public * @param string Extension name * @return string C code */ static function cCodeFooter($name) { return ""; } /** * Generate C include file definitions for element * * @access public * @return string C header code */ function hCode() { return ""; } /** * Generate Editor settings block for C source files * * @access public * @return string Editor settings comment block */ static function cCodeEditorSettings() { return ""; } /** * Generate documentation code for element * * @access public * @param string id basename for extension * @return string documentation content */ function docEntry($extension) { return ""; } /** * Generate documentation header block for all elements of this class * * @access public * @param string Extension name * @return string documentation fragment */ static function docHeader($name) { return ""; } /** * Generate documentation footer block for all elements of this class * * @access public * @param string Extension name * @return string documentation fragment */ static function docFooter($name) { return ""; } /** * Generate Editor settings block for documentation files * * @access public * @param int Directory nesting depth of target file (default: 3) * @return string Editor settings comment block */ static function docEditorSettings($level=3) { return ""; } } ?> http://cvs.php.net/co.php/pear/CodeGen/Extension.php?r=1.1&p=1 Index: pear/CodeGen/Extension.php +++ pear/CodeGen/Extension.php <?php /** * Extension generator class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * includes */ require_once "CodeGen/Maintainer.php"; require_once "CodeGen/License.php"; require_once "CodeGen/Release.php"; require_once "CodeGen/Tools/Platform.php"; require_once "CodeGen/Tools/Indent.php"; /** * Extension generator class * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_Extension { /** * The extensions basename (C naming rules apply) * * @var string */ var $name = "unknown"; /** * The extensions descriptive name * * @var string */ var $summary = "The unknown extension"; /** * extension description * * @var string * @access private */ var $description; /** * The license for this extension * * @var object */ var $license = NULL; /** * The release info for this extension * * @var object */ var $release = NULL; /** * The implementation language * * Currently we support "c" and "cpp" * * @var string */ var $language = "c"; /** * The target platform for this extension * * Possible values are "unix", "win" and "all" * * @var string */ var $platform = null; /** * The authors contributing to this extension * * @var array */ var $authors = array(); /** * Name prefix for functions etc. * * @var string */ var $prefix = ""; /** * Set extension base name * * @access public * @param string name */ function setName($name) { if (!ereg("^[[:alpha:]_][[:alnum:]_]*$", $name)) { return PEAR::raiseError("'$name' is not a valid extension name"); } $this->name = $name; return true; } /** * Set extension summary text * * @access public * @param string short summary */ function setSummary($text) { $this->summary = $text; return true; } /** * Set extension documentation text * * @access public * @param string long description */ function setDescription($text) { $this->description = $text; return true; } /** * Set the programming language to produce code for * * @access public * @param string programming language name */ function setLanguage($lang) { switch (strtolower($lang)) { case "c": $this->language = "c"; return true; case "cpp": case "cxx": case "c++": $this->language = "cpp"; return true; default: break; } return PEAR::raiseError("'$lang' is not a supported implementation language"); } /** * Set target platform for generated code * * @access public * @param string platform name */ function setPlatform($type) { $this->platform = new CodeGen_Tools_Platform($type); if (PEAR::isError($this->platform)) { return $this->platform; } return true; } /** * Add an author or maintainer to the extension * * @access public * @param object a maintainer object */ function addAuthor($author) { if (!is_a($author, "CodeGen_Maintainer")) { return PEAR::raiseError("argument is not CodeGen_Maintainer"); } $this->authors[$author->user] = $author; return true; } /** * Set release info * * @access public * @var object */ function setRelease($release) { $this->release = $release; return true; } /** * Set license * * @access public * @param object */ function setLicense($license) { if ($license->shortname == "GPL") { return PEAR::raiseError("The GPL is no valid choice for PHP extensions due to license incompatibilities"); } $this->license = $license; return true; } /** * Set extension name prefix (for functions etc.) * * @access public * @param string name */ function setPrefix($prefix) { if (! CodeGen_Element::isName($prefix)) { return PEAR::raiseError("'$name' is not a valid name prefix"); } $this->prefix = $prefix; return true; } } ?> http://cvs.php.net/co.php/pear/CodeGen/ExtensionParser.php?r=1.1&p=1 Index: pear/CodeGen/ExtensionParser.php +++ pear/CodeGen/ExtensionParser.php <?php /** * Parser for XML based extension desription files * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * includes */ require_once "CodeGen/XmlParser.php"; require_once "CodeGen/Tools/Indent.php"; /** * Parser for XML based extension desription files * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_ExtensionParser extends CodeGen_XmlParser { /** * The extension to parse specs into * * @access private * @var object */ var $extension; /** * Constructor * * @access public * @param object the extension to parse specs into */ function __construct($extension) { parent::__construct(); $this->extension = $extension; } /** * Handle <extension> * * @access private * @param array attribute/value pairs * @return bool success status */ function tagstart_extension($attr) { if (!isset($attr["name"])) { return PEAR::raiseError("needed attribute 'name' for <extension> not given"); } $status = $this->extension->setName(trim($attr["name"])); if ($status === true && isset($attr["prefix"])) { $status = $this->extension->setPrefix(trim($attr["prefix"])); } if (isset($attr["version"])) { if (version_compare($attr["version"], $this->extension->version(), ">")) { return PEAR::raiseError("This is ".get_class($this->extension)." ".$this->extension->version().", extension specification requires at least version $attr[version]\n"); } } return $status; } /** * Handle <extension><name> * * @access private * @param array attribute/value pairs * @return bool success status */ function tagstart_extension_name($attr) { return PEAR::raiseError("extension <name> tag is no longer supported, use <extension>s 'name=...' attribute instead"); } /** * Handle <extension></summary> * * @access private * @param array attribute/value pairs * @param array tag data content * @return bool success status */ function tagend_extension_summary($attr, $data) { return $this->extension->setSummary(CodeGen_Tools_Indent::linetrim($data)); } /** * Handle <extension></description> * * @access private * @param array attribute/value pairs * @param array tag data content * @return bool success status */ function tagend_extension_description($attr, $data) { return $this->extension->setDescription(CodeGen_Tools_Indent::linetrim($data)); } function tagstart_maintainer($attr) { $this->pushHelper(new CodeGen_Maintainer); return true; } function tagend_maintainer_user($attr, $data) { return $this->helper->setUser(trim($data)); } function tagend_maintainer_name($attr, $data) { return $this->helper->setName(trim($data)); } function tagend_maintainer_email($attr, $data) { return $this->helper->setEmail(trim($data)); } function tagend_maintainer_role($attr, $data) { return $this->helper->setRole(trim($data)); } function tagend_maintainer($attr, $data) { $err = $this->extension->addAuthor($this->helper); $this->popHelper(); return $err; } function tagend_maintainers($attr, $data) { return true; } function tagstart_extension_release($attr) { $this->pushHelper(new CodeGen_Release); return true; } function tagend_release_version($attr, $data) { return $this->helper->setVersion(trim($data)); } function tagend_release_date($attr, $data) { return $this->helper->setDate(trim($data)); } function tagend_release_state($attr, $data) { return $this->helper->setState(trim($data)); } function tagend_release_notes($attr, $data) { return $this->helper->setNotes(CodeGen_Tools_Indent::linetrim($data)); } function tagend_extension_release($attr, $data) { $err = $this->extension->setRelease($this->helper); $this->popHelper(new CodeGen_Release); return $err; } function tagend_extension_changelog($attr, $data) { return true; } function tagend_license($attr, $data) { $license = CodeGen_License::factory(trim($data)); if (PEAR::isError($license)) { return $err; } return $this->extension->setLicense($license); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode:nil * End: */ ?> http://cvs.php.net/co.php/pear/CodeGen/License.php?r=1.1&p=1 Index: pear/CodeGen/License.php +++ pear/CodeGen/License.php <?php /** * Abstract base class for licenses * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: License.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Abstract base class for licenses * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_License { /** * Constructor * * @access private * @param License options */ function __construct($options = array()) { $this->options = $options; } /** * Takes a License shortname and returns an instantiated object of that license * * @access public * @param string License shortname, e.g. PHP, BSD, LGPL * @param array License options * @returns object License instance */ static function factory($name, $options=array()) { $classname = "CodeGen_License_".strtoupper($name); $classfile = str_replace("_", "/", $classname).".php"; if (!class_exists($classname)) { if (!@include_once "$classfile") PEAR::raiseError("Unknown license type '$name' ", E_USER_WARNING); } return class_exists($classname) ? new $classname($options) : false; } /** * Writes the License text to a file * * @param string Filename to write to (default is ./LICENSE) * @return bool Success state * @access public */ function writeToFile($path = "./LICENSE") { $fp = fopen($path, "w"); if (is_resource($fp)) { fputs($fp, $this->getText()); fclose($fp); return true; } return false; } /** * Returns a string suitable for insertion into comment headers * * @return string License comment * @access public */ abstract function getComment(); /** * Returns the complete license text as string * * @return string License text * @access public */ abstract function getText(); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode:nil * End: */ ?> http://cvs.php.net/co.php/pear/CodeGen/Maintainer.php?r=1.1&p=1 Index: pear/CodeGen/Maintainer.php +++ pear/CodeGen/Maintainer.php <?php /** * A class that describes an extension author or maintainer * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * A class that describes an extension author or maintainer * * This class wraps up the functionality needed for the * command line script. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Maintainer { /** * Users system account name * * @var string */ var $user; /** * Real name * * @var string */ var $name; /** * Email address * * @var string */ var $email; /** * Role in this project * * @var string */ var $role; /** * First maintainer added? * * @var bool */ static $first = true; /** * Prefix to use in comment headers * * @var bool */ var $comment_prefix = "Authors:"; /** * Constructor * * @access public * @param string CVS user name * @param string real name * @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 (!ereg("^[[:alnum:]_-]+$", $name)) { return PEAR::raiseError("'$name' is not a valid CVS user name"); } $this->user = $name; return true; } /** * Set real user name * * @access public * @param string user name * @return bool true on success */ function setName($name) { $this->name = $name; return true; } /** * 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) { // TODO check for valid roles $this->role = $role; return true; } /** * 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; } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode:nil * End: */ ?> http://cvs.php.net/co.php/pear/CodeGen/Release.php?r=1.1&p=1 Index: pear/CodeGen/Release.php +++ pear/CodeGen/Release.php <?php /** * Class collecting release information * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Class collecting release information * * This class wraps up the functionality needed for the * command line script. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Release { /** * The current version number * * @access private * @var string */ var $version = "0.0.1"; /** * Set method for version number * * @access public * @param string version * @return bool true on success */ function setVersion($version) { // TODO check format $this->version = $version; return true; } /** * The release date * * @access private * @var string */ var $date = ""; /** * Set method for release date * * @access public * @param int timestamp * @return bool true on success */ function setDate($date) { // TODO parse date if not numeric // TODO check valid dates $this->date = $date; return true; } /** * The 'state': alpha, beta, stable, dev ... * * @access private * @var string */ var $state = "unknown"; /** * Set method for state * * @access public * @param string state * @return bool true on success */ function setState($state) { // TODO check valid states $this->state = $state; return true; } /** * Release notes * * @access private * @var string */ var $notes = ""; /** * Set method for release notes * * @access public * @param string release notes * @return bool true on success */ function setNotes($notes) { $this->notes = $notes; return true; } /** * Constructor * * @access public */ function __construct() { $this->date = date("Y-m-d"); } } ?> http://cvs.php.net/co.php/pear/CodeGen/XmlParser.php?r=1.1&p=1 Index: pear/CodeGen/XmlParser.php +++ pear/CodeGen/XmlParser.php <?php /** * Yet another XML parsing class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Yet another XML parsing class * * This is similar to the "func" mode of XML_Parser but it borrows * some concepts from DSSSL. * The tag handler method to call is not only determined by the tag * name but also potentially by the name of its parent tags, and the * most specific handler method (that is the one including the * maximum number of matching parent tags in its name) wins. * This way it is possible to have e.g. tagstart_name as a general * handler for a <name> tag while tagstart_function_name handles the * more special case of a <name> tag within a <function> tag. * Character data within a tag is collected and passed to the end * tag handler. * Tag names and attributes are managed using stack arrays. * Attributes are not only passed to both the start and end tag * handlers. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_XmlParser { /** * XML parser resource * * @var resource */ private $parser = NULL; /** * Parser stack for <include> management * * @var array */ private $parserStack = array(); /** * We collect cData in here * * @var string */ private $data = ""; /** * We also try to remember where cData started * * @access private * @var int */ var $dataLine = 0; /** * We maintain the current tag nesting structure here * * @access private * @var array */ var $tagStack = array(); /** * We keep track of tag attributes so that we can also provide them to the end tag handlers * * @access private * @var array */ var $attrStack = array(); /** * There is no clean way to terminate parsing from within a handler ... * * @access private * @var bool */ var $error = false; /** * Input Filename * * @access public * @var string */ var $filename = false; /** * Input stream * * @access public * @var resource */ var $fp = null; /** * Verbatim indicator * * @access public * @var string */ var $verbatim = false; /** * Verbatim taglevel depth * * @access public * @var string */ var $verbatimDepth = 0; /** * The constructor * * @access public */ function __construct() { $this->parser = $this->newParser(); } 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; } function pushParser() { if ($this->parser) { $entry = array($this->parser, $this->filename, $this->fp); array_push($this->parserStack, $entry); } } function popParser() { xml_parser_free($this->parser); list($this->parser, $this->filename, $this->fp) = array_pop($this->parserStack); } function posString() { return "in {$this->filename} on line ". xml_get_current_line_number($this->parser). ":". xml_get_current_column_number($this->parser); } function extEntityHandler($parser, $openEntityNames, $base, $systemId, $publicId) { $this->pushParser(); $this->parser = $this->newParser(); $stat = $this->setInputFile($systemId); if (!$stat) { $this->popParser(); $this->error = PEAR::raiseError("Can't open XInclude file '$systemId' ".$this->posString()); } $this->parse(); $this->popParser(); return; } /** * Set file to parse * * @access public * @param string */ function setInputFile($filename) { $this->filename = $filename; $this->fp = @fopen($filename, "r"); return is_resource($this->fp); } /** * Perform the actual parsing * * @access public * @return boolean true on success */ 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"); } while (($data = fread($this->fp, 4096))) { if (!xml_parse($this->parser, $data, feof($this->fp)) || $this->error) { return $this->error; } } return true; } /** * Start verbatim mode * */ 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 */ 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 */ function startHandler($XmlParser, $tag, $attr) { if ($this->error) return; $pos = strrpos($tag, " "); $ns = $pos ? substr($tag, 0, $pos) : ""; $tag = $pos ? substr($tag, $pos + 1) : $tag; // XInclude handling if ($ns === "http://www.w3.org/2001/XInclude") { // TODO better error checking $path = isset($attr['href']) ? $attr['href'] : $attr['http://www.w3.org/2001/XInclude href']; if ($tag === "include") { if (isset($attr["parse"]) && $attr["parse"] == "text") { $this-cDataHandler($XmlParser, get_file_contents($path)); } else { $this->pushParser(); $this->parser = $this->newParser(); $stat = $this->setInputFile($path); if (!$stat) { $this->popParser(); $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); } $this->parse(); $this->popParser(); return; } } } 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; array_push($this->tagStack, $tag); array_push($this->attrStack, $attr); $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 */ function endHandler($XmlParser, $tag) { if ($this->error) return; $pos = strrpos($tag, " "); $ns = $pos ? substr($tag, 0, $pos) : ""; $tag = $pos ? substr($tag, $pos + 1) : $tag; // XInclude handling if ($ns === "http://www.w3.org/2001/XInclude") { return; } if ($this->verbatim) { if (--$this->verbatimDepth > 0) { $this->data .= "</$tag>"; return; } else { $this->verbatim = false; } } $method = $this->findHandler("tagend"); array_pop($this->tagStack); $attr = array_pop($this->attrStack); 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; } /** * Just collect cData for later use in tag end handlers * * @access private * @param resource internal parser handle * @param string cData to collect */ function cDataHandler($XmlParser, $data) { $this->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 */ 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'"); } } /** * Tread <?data PI sections like <![CDATA[ * * @access private * @param resource internal parser handle * @param string cData to collect */ function dataPiHandler($XmlParser, $data) { $this->cDataHandler($XmlParser, $data); } /** * A helper stack for collecting stuff * * @access private * @var array */ var $helperStack = array(); /** * The current helper (top of stack) * * @access private * @var mixed */ var $helper = false; /** * The previous helper (top-1 of stack) * * @access private * @var mixed */ var $helperPrev = false; /** * Push something on the helper stack * * @access private * @param mixed */ function pushHelper($helper) { array_push($this->helperStack, $this->helper); $this->helperPrev = $this->helper; $this->helper = $helper; } /** * Pop something from the helper stack * * @access private */ function popHelper() { $this->helper = array_pop($this->helperStack); if (count($this->helperStack)) { end($this->helperStack); $this->helperPrev = current($this->helperStack); } else { $this->helperPrev = false; } } } ?> http://cvs.php.net/co.php/pear/CodeGen/foo.xml?r=1.1&p=1 Index: pear/CodeGen/foo.xml +++ pear/CodeGen/foo.xml <extension name="#+-"/> http://cvs.php.net/co.php/pear/CodeGen/package.xml?r=1.1&p=1 Index: pear/CodeGen/package.xml +++ pear/CodeGen/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package> <name>CodeGen</name> <summary>Tool to create Code generaters that operate on XML descriptions</summary> <status>beta</status> <maintainers> <maintainer> <user>hholzgra</user> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> <role>lead</role> </maintainer> </maintainers> <description> testing only </description> <license>PHP</license> <release> <state>alpha</state> <version>0.1</version> <date>2005-06-18</date> <notes> testing only </notes> <deps> <dep type="php" rel="ge" version="5"/> <dep type="pkg" rel="ge" version="1.0">Console_Getopt</dep> </deps> <filelist> <dir name="/" baseinstalldir="CodeGen"> <file role="php">Extension.php</file> <file role="php">XmlParser.php</file> <file role="php">ExtensionParser.php</file> <file role="php">Element.php</file> <file role="php">Release.php</file> <file role="php">Maintainer.php</file> <file role="php">License.php</file> <dir name="License"> <file role="php">PHP.php</file> <file role="php">BSD.php</file> <file role="php">LGPL.php</file> </dir> <file role="php">Command.php</file> <dir name="Tools"> <file role="php">Code.php</file> <file role="php">Getopt.php</file> <file role="php">Platform.php</file> <file role="php">Indent.php</file> <file role="php">Tokenizer.php</file> </dir> </dir> </filelist> </release> </package> http://cvs.php.net/co.php/pear/CodeGen/License/BSD.php?r=1.1&p=1 Index: pear/CodeGen/License/BSD.php +++ pear/CodeGen/License/BSD.php <?php /** * The BSD License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: BSD.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The BSD License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_BSD extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'BSD'; /** * full name * * @access public * @var string */ var $longname = 'BSD style license'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | All rights reserved | | | | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions | | are met: | | | | 1. Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | 2. Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in | | the documentation and/or other materials provided with the | | distribution. | | 3. The names of the authors may not be used to endorse or promote | | products derived from this software without specific prior | | written permission. | | | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | POSSIBILITY OF SUCH DAMAGE. | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { return <<<EOD All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EOD; } } ?> http://cvs.php.net/co.php/pear/CodeGen/License/GPL.php?r=1.1&p=1 Index: pear/CodeGen/License/GPL.php +++ pear/CodeGen/License/GPL.php <?php /** * The GPL License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: GPL.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The GPL License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_GPL extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'GPL'; /** * full name * * @access public * @var string */ var $longname = 'GNU General Public License'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License in the file LICENSE along with this library; | | if not, write to the | | | | Free Software Foundation, Inc., | | 59 Temple Place, Suite 330, | | Boston, MA 02111-1307 USA | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { ob_start(); ?> GNU General Public License ************************** Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble ======== The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a. You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b. You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c. If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a. Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b. Accompany it with a written offer, valid for at least three years, to give any third-party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c. Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs ============================================= If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES. Copyright (C) YYYY NAME OF AUTHOR This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. SIGNATURE OF TY COON, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. <?php $text = ob_get_contents(); ob_end_clean(); return $text; } } ?> http://cvs.php.net/co.php/pear/CodeGen/License/LGPL.php?r=1.1&p=1 Index: pear/CodeGen/License/LGPL.php +++ pear/CodeGen/License/LGPL.php <?php /** * The LGPL License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: LGPL.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The LGPL License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_LGPL extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'LGPL'; /** * full name * * @access public * @var string */ var $longname = 'GNU Lesser General Public License'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | This library is free software; you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation; either | | version 2.1 of the License, or (at your option) any later version. | | | | This library is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | Lesser General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License in the file LICENSE along with this library; | | if not, write to the | | | | Free Software Foundation, Inc., | | 59 Temple Place, Suite 330, | | Boston, MA 02111-1307 USA | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { ob_start(); ?> GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the library's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. <signature of Ty Coon>, 1 April 1990 Ty Coon, President of Vice That's all there is to it! <?php $text = ob_get_contents(); ob_end_clean(); return $text; } } ?> http://cvs.php.net/co.php/pear/CodeGen/License/PHP.php?r=1.1&p=1 Index: pear/CodeGen/License/PHP.php +++ pear/CodeGen/License/PHP.php <?php /** * The PHP License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: PHP.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The PHP License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_PHP extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'PHP'; /** * full name * * @access public * @var string */ var $longname = 'The PHP License'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { return <<<EOD -------------------------------------------------------------------- The PHP License, Version 3.0 Copyright (c) 1999 - 2003 The PHP Group. All rights reserved. -------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without modification, is permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name "PHP" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact group@php.net. 4. Products derived from this software may not be called "PHP", nor may "PHP" appear in their name, without prior written permission from group@php.net. You may indicate that your software works in conjunction with PHP by saying "Foo for PHP" instead of calling it "PHP Foo" or "phpfoo" 5. The PHP Group may publish revised and/or new versions of the license from time to time. Each version will be given a distinguishing version number. Once covered code has been published under a particular version of the license, you may always continue to use it under the terms of that version. You may also choose to use such covered code under the terms of any subsequent version of the license published by the PHP Group. No one other than the PHP Group has the right to modify the terms applicable to covered code created under this License. 6. Redistributions of any form whatsoever must retain the following acknowledgment: "This product includes PHP, freely available from <http://www.php.net/>". THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------- This software consists of voluntary contributions made by many individuals on behalf of the PHP Group. The PHP Group can be contacted via Email at group@php.net. For more information on the PHP Group and the PHP project, please see <http://www.php.net>. This product includes the Zend Engine, freely available at <http://www.zend.com>. EOD; } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Code.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Code.php +++ pear/CodeGen/Tools/Code.php <?php /** * Wrapper class for code block generation * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Wrapper class for code block generation * * all methods are actually static, the class is just needed for * namespace emulation to conform with PEAR naming conventions * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ /** */ require_once("CodeGen/Tools/Indent.php"); class CodeGen_Tools_Code { var $language = 'c'; var $indentSteps = 4; /** * Generate simple indented codeblock * * @param string code * @param int indent level * @return string formated code block */ function block($code, $indent = 1) { return CodeGen_Tools_Indent::indent($indent*$this->indentSteps, $code); } /** * Generate indented codeblock with variable declarations * * @param string code * @param int indent level * @return string formated code block */ function varblock($code, $indent = 1) { if ($this->language == 'c') { $head = CodeGen_Tools_Indent::indent($indent * $this->indentSteps, "do {\n"); $foot = CodeGen_Tools_Indent::indent($indent * $this->indentSteps, "} while (0);\n"); $indent++; } else { $head = $foot = ""; } $code = CodeGen_Tools_Indent::indent($indent * $this->indentSteps, $code); return $head . $code . $foot; } }; http://cvs.php.net/co.php/pear/CodeGen/Tools/Getopt.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Getopt.php +++ pear/CodeGen/Tools/Getopt.php <?php /** * A more convenient command line argument parser class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ require_once "Console/Getopt.php"; /** * A more convenient command line argument parser class * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Getopt extends Console_Getopt { /** * Internal storage for parsed arguments * * @access private * @var array */ private $options = array(); /** * Constructor will parse specified short and long arguments * * @access public * @param string short options specification * @param array long options specification * @param callback error callback, call this and exit on errors if given */ function __construct ($short_options, $long_options = NULL, $usage = NULL) { // use parent methods for actual parsing, store result internaly $argv = parent::readPHPArgv(); $this->options = parent::getopt($argv, $short_options, $long_options); if (PEAR::isError($this->options)) { if (!is_null($usage) && is_callable($usage)) { call_user_func($usage, $this->options->message); exit(3); } } } /** * Check if any of the specified options was given * * @access public * @param string a short or long option name * @param ... * @return bool true if anything found else false */ function have($name /*, ... */) { // foreach argument foreach (func_get_args() as $arg) { // short or long option? switch (strlen($arg)) { case 0: continue(2); case 1: $arg = "$arg"; break; default: $arg = "--$arg"; break; } // search given command line options foreach ($this->options[0] as $opt) { // found? if ($opt[0] == $arg) { return true; } } } // nothing found return false; } /** * Check if all of the specified options were given * * @access public * @param string a short or long option name * @param ... * @return bool true if all found else false */ function haveAll($name /*, ... */) { // foreach argument foreach (func_get_args() as $name) { // short or long option? switch (strlen($name)) { case 0: continue(2); case 1: $name = "-$name"; break; default: $name = "--$name"; break; } // check for this option $found = false; foreach ($this->options[0] as $opt) { if ($opt[0] == $name) { $found = true; } } // not found? -> all fails if (!$found) { return false; } } // all passed return true; } /** * Get argument value for an option * * @access public * @param string $name * @result string option value or true for options without argument */ function value($name, $name2 = false) { foreach (func_get_args() as $name) { switch (strlen($name)) { case 0: return false; case 1: $name = "-$name"; break; default: $name = "--$name"; break; } foreach ($this->options[0] as $opt) { if ($opt[0] == $name) { return is_null($opt[1]) ? true : $opt[1]; } } } // not found return false; } /** * Get all given option names * * @access public * @return array an array of option names */ function options() { $names = array(); foreach ($this->options [0] as $opt) { $names[] = ereg_replace("^-*", "", $opt[0]); } return $names; } /** * Get all additional arguments not bound to options * * @access public * @return array an array of argument string values */ function arguments() { $names = array(); foreach ($this->options[1] as $arg) { $names[] = $arg; } return $names; } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Indent.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Indent.php +++ pear/CodeGen/Tools/Indent.php <?php /** * Wrapper class for whitespace related stuff * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Wrapper class for whitespace related stuff * * all methods are actually static, the class is just needed for * namespace emulation to conform with PEAR naming conventions * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Indent { /** * Replace leading blanks with tabs * * PHP C coding conventions require tab indention * with a tabsize of 4 * * @access public * @param string text to tabify * @param int tab indention level (default: 4 spaces) * @return string tabified text */ 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 ); } /** * Replace leading tabs with blanks * * PEAR PHP coding conventions require blank indention * with a tabsize of 4 * * @access public * @param string text to untabify * @param int tab indention level (default: 4 spaces) * @return string untabified text */ function untabify($text, $tabsize = 4) { return preg_replace_callback("/^(\t)*/m", create_function('$matches','return str_repeat(" ", strlen($matches[0])*'.$tabsize.');'), $text ); } /** * re-indent a block of text * * @access public * @param int number of leading indent spaces * @param string text to reindent * @return string indented text */ function indent($level, $text) { $lines = explode("\n", $text); while (count($lines) && trim(end($lines)) == "") { array_pop($lines); } $maxindent = 999; foreach ($lines as $line) { if (trim($line)=="") continue; ereg("^ *", $line, $matches); $maxindent = min($maxindent, strlen($matches[0])); } $result = ""; $find = str_repeat(" ", $maxindent); $replace = str_repeat(" ", $level); foreach ($lines as $line) { $result.= self::tabify(ereg_replace("^$find", $replace, $line)."\n", 4); } return $result; } /** * Trim of leading and trailing whitespace-only lines * * @access public * @param string text * @return string trimmed text */ function linetrim($text) { $text = preg_replace('|^\s*\n|','', $text); $text = preg_replace('|\n\s*$|',"\n", $text); return $text; } /** * Change to DOS/Windows line terminators * * @access public * @param string unix text * @param string dos/windows text */ function dosify($text) { return str_replace("\n", "\r\n", $text); } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Platform.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Platform.php +++ pear/CodeGen/Tools/Platform.php <?php /** * A helper class for platform management * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: Platform.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * A helper class for platform management * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Platform { /** * The supported platforms are collected here * * @access private * @var array the platform short names */ var $platforms = array(); /** * Constructor gets a list of names or "all" * * @access public * @param string|array names as comma separated string or array */ function __construct($names) { if (is_string($names)) { $names = explode(",", $names); } foreach ($names as $name) { switch (strtolower(trim($name))) { case "all": $this->platforms["win"] = true; $this->platforms["unix"] = true; break; case "win": case "win23": case "windows": case "microsoft": $this->platforms["win"] = true; break; case "unix": case "posix": case "gnu": $this->platforms["unix"] = true; break; default: $this->error = PEAR::raiseError("'$name' is not a supported platform"); break(2); } } } /** * Test for a platform shortname * * @access public * @param string shortname * @return bool true if supported else false */ function test($name) { switch (strtolower(trim($name))) { case "all": return 2 == $this->count(); case "win": case "win32": case "windows": case "microsoft": return isset($this->platforms["win"]); case "unix": case "posix": case "gnu": return isset($this->platforms["unix"]); default: return false; } } /** * Count the number of supported platforms * * @access public * @return int platform count */ function count() { return count($this->platforms()); } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Tokenizer.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Tokenizer.php +++ pear/CodeGen/Tools/Tokenizer.php <?php /** * A simple tokenizer for e.g. proto parsing * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: Tokenizer.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * A simple tokenizer for e.g. proto parsing * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Tokenizer { /** * String to parse * * @var string */ protected $string; /** * Current parsing position * * @var int */ protected $pos; /** * Current token content * * @var string */ public $token; /** * Current token type (name, numeric, string) * * @var string */ public $type; /** * Parsing complete? * * @var bool */ public $done = false; /** * pushback stack for parsed tokens * * @var array */ private $tokenStack = array(); /** * Konstruktor * * @param string String to parse */ public function __construct($string) { $this->string = $string; $this->pos = 0; } /** * get next character to parse * * @return string */ private function pullChar() { if ($this->pos >= strlen($this->string)) { $this->done = true; return ""; } return ($this->string{$this->pos++}); } /** * Push back read character(s) * * @param string characters to pusch back */ private function pushChar($char) { // we just rely on the user not cheating $this->pos -= strlen($char); } /** * Read next token into $this->type, $this->token * * @return bool success? */ public function nextToken() { if (!empty($this->tokenStack)) { list($this->type, $this->token) = array_pop($this->tokenStack); return true; } do { $char = $this->pullChar(); if ($char === "") return false; } while (ctype_space($char)); if (ctype_alnum($char) || $char === "_" || $char === "-") { $this->type = "name"; $this->token = $char; while (true) { $char = $this->pullChar(); if (ctype_alnum($char) || $char === "_") { $this->token .= $char; } else if ($this->token === "array" && $char === "(") { $this->token .= $char; } else if ($this->token === "array(" && $char === ")") { $this->token .= $char; } else { $this->pushChar($char); break; } } if (is_numeric($this->token)) { $this->type = 'numeric'; } } else if ($char == '"' || $char == "'") { $this->type = "string"; $this->token = ""; $quote = $char; $escape = false; while (true) { $char = $this->pullChar(); if ($char === "") { $this->type = false; return false; } if ($escape) { $escape = false; $this->token .= $char; continue; } if ($char === $quote) { break; } if ($char === "\\") { $escape = true; continue; } $this->token .= $char; } } else if ($char === ".") { $ellipse = false; $char2 = $this->pullChar(); if ($char2 === ".") { $char3 = $this->pullChar(); if ($char3 === ".") { $ellipse = true; } else { $this->pushChar($char3); } } else { $this->pushChar($char2); } if ($ellipse) { $this->token = "..."; $this->type = "name"; } else { $this->token = "."; $this->type = "name"; } } else { $this->token = $char; $this->type = "char"; } return true; } /** * Push back a parsed token * */ public function pushToken() { array_push($this->tokenStack, array($this->type, $this->token)); } }
http://cvs.php.net/co.php/pear/CodeGen/.cvsignore?r=1.1&p=1 Index: pear/CodeGen/.cvsignore +++ pear/CodeGen/.cvsignore *~ PECL_GEN*.tgz dumpster http://cvs.php.net/co.php/pear/CodeGen/Command.php?r=1.1&p=1 Index: pear/CodeGen/Command.php +++ pear/CodeGen/Command.php <?php /** * Command wrapper class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * includes */ require_once 'PEAR.php'; require_once "CodeGen/Tools/Getopt.php"; require_once "CodeGen/Extension.php"; /** * Command wrapper class * * This class wraps up the functionality needed for the * command line script. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Command { /** * The extension the command class is going to work on * * @var object */ var $extension; /** * Command constructor * * @param object Extension to work on */ function __construct(CodeGen_Extension $extension) { $this->extension = $extension; // no compromise error_reporting(E_ALL); // but make sure errors are written to stderr so they can't be collected by ob_* functions set_error_handler(array($this, "errorHandler")); list($shortOptions, $longOptions) = $this->commandOptions(); $this->options = new CodeGen_Tools_Getopt($shortOptions, $longOptions, array($this, "showUsage")); if ($this->options->have("help", "h")) { $this->showVersion(); $this->showUsage(); exit(0); } if ($this->options->have("version")) { $this->showVersion(); exit(0); } } /** * Define the available command line options * * @return array the available short and long options */ function commandOptions() { $shortOptions = "fd=hqx"; $longOptions = array( "help", "dir=", "experimental", "force", "quiet", "version", ); return array($shortOptions, $longOptions); } /** * Show copyright and version info taken from extension class * */ function showVersion() { $fp = fopen("php://stderr", "w"); fputs($fp, basename($_SERVER["argv"][0]) . " ". $this->extension->version() . "," . $this->extension->copyright() . "\n"); fclose($fp); } /** * Show usage/help message * * @param string optional error message to display */ function showUsage($message = false) { $fp = fopen("php://stderr", "w"); if ($message) fputs($fp, "$message\n\n"); fputs($fp, "Usage: ". $_SERVER["argv"][0] ." [-hxf] [-d dir] [--version] specfile.xml -h|--help this message -x|--experimental enable experimental features -f|--force overwrite existing files/directories -d|--dir output directory --version show version info "); fclose($fp); } /** * Show error message and bailout * * @param string error message */ function terminate($msg) { $stderr = @fopen("php://stderr/", "w"); if ($stderr) { fprintf($stderr, "%s\n", $msg); fclose($stderr); } else { echo "$msg\n"; } exit(3); } /** * Error handler callback * * @param int error level number * @param string error message * @param string source file * @param int source line */ function errorHandler($errno, $errstr, $errfile, $errline) { if ($errno & error_reporting()) { $fp = fopen("php://stderr", "w"); switch ($errno) { case E_ERROR : fputs($fp, "Error"); break; case E_WARNING : fputs($fp, "Warning"); break; case E_PARSE : fputs($fp, "Parsing Error"); break; case E_NOTICE : fputs($fp, "Notice"); break; case E_CORE_ERROR : fputs($fp, "Core Error"); break; case E_CORE_WARNING : fputs($fp, "Core Warning"); break; case E_COMPILE_ERROR : fputs($fp, "Compile Error"); break; case E_COMPILE_WARNING : fputs($fp, "Compile Warning"); break; case E_USER_ERROR : fputs($fp, "User Error"); break; case E_USER_WARNING : fputs($fp, "User Warning"); break; case E_USER_NOTICE : fputs($fp, "User Notice"); break; case E_STRICT : fputs($fp, "Runtime Notice"); break; default : fputs($fp, "Unknown Error"); break; } fputs($fp, ": $errstr in $errfile on line $errline\n"); fclose($fp); } } /** * Create extension using the given parser * * @param object Extension parser */ function execute($parser) { // normal operation: read XML file and go with that $arguments = $this->options->arguments(); if (count($arguments) != 1) { $this->showUsage(); exit(3); } $xmlfile = $arguments[0]; if (!file_exists($xmlfile) || !is_readable($xmlfile)) { $this->terminate("Cannot open spec file '$xmlfile'"); } // create parser for extension specs $err = $parser->setInputFile($xmlfile); if (PEAR::isError($err)) { $this->terminate($err->message); } // do the actual parsing $err = $parser->parse(); if (PEAR::isError($err)) { $this->terminate($err->getMessage()." ".$err->getUserInfo()); } else if(is_string($err)) { $this->terminate(""); } // and now create the actual extension from the collected specs $err = $this->extension->createExtension($this->options->value("d", "dir"), $this->options->have("f", "force")); if (PEAR::isError($err)) { $this->terminate($err->getMessage()." ".$err->getUserInfo()); } if (!$this->options->have("q", "quiet")) { echo $this->extension->successMsg($this->extension->name); } } } http://cvs.php.net/co.php/pear/CodeGen/Element.php?r=1.1&p=1 Index: pear/CodeGen/Element.php +++ pear/CodeGen/Element.php <?php /** * Abstract base class for all code elements * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: Element.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Abstract base class for all code elements * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_Element { /** * Checks whether a string is a reserved name * * @access public * @param string name * @return bool true if reserved */ function isKeyword($name) { return false; } /** * Checks whether a string is a valid C name * * @access public * @param string The name to check * @return bool true for valid names, false otherwise */ function isName($name) { if (ereg("^[[:alpha:]_][[:alnum:]_]*$",$name)) { // TODO reserved words return true; } return false; } /** * Generate C code for element * * @access public * @param string Extension name * @return string C code */ function cCode($name) { return ""; } /** * Generate C code header block for all elements of this class * * @access public * @param string Extension name * @return string C code */ static function cCodeHeader($name) { return ""; } /** * Generate C code footer block for all elements of this class * * @access public * @param string Extension name * @return string C code */ static function cCodeFooter($name) { return ""; } /** * Generate C include file definitions for element * * @access public * @return string C header code */ function hCode() { return ""; } /** * Generate Editor settings block for C source files * * @access public * @return string Editor settings comment block */ static function cCodeEditorSettings() { return ""; } /** * Generate documentation code for element * * @access public * @param string id basename for extension * @return string documentation content */ function docEntry($extension) { return ""; } /** * Generate documentation header block for all elements of this class * * @access public * @param string Extension name * @return string documentation fragment */ static function docHeader($name) { return ""; } /** * Generate documentation footer block for all elements of this class * * @access public * @param string Extension name * @return string documentation fragment */ static function docFooter($name) { return ""; } /** * Generate Editor settings block for documentation files * * @access public * @param int Directory nesting depth of target file (default: 3) * @return string Editor settings comment block */ static function docEditorSettings($level=3) { return ""; } } ?> http://cvs.php.net/co.php/pear/CodeGen/Extension.php?r=1.1&p=1 Index: pear/CodeGen/Extension.php +++ pear/CodeGen/Extension.php <?php /** * Extension generator class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * includes */ require_once "CodeGen/Maintainer.php"; require_once "CodeGen/License.php"; require_once "CodeGen/Release.php"; require_once "CodeGen/Tools/Platform.php"; require_once "CodeGen/Tools/Indent.php"; /** * Extension generator class * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_Extension { /** * The extensions basename (C naming rules apply) * * @var string */ var $name = "unknown"; /** * The extensions descriptive name * * @var string */ var $summary = "The unknown extension"; /** * extension description * * @var string * @access private */ var $description; /** * The license for this extension * * @var object */ var $license = NULL; /** * The release info for this extension * * @var object */ var $release = NULL; /** * The implementation language * * Currently we support "c" and "cpp" * * @var string */ var $language = "c"; /** * The target platform for this extension * * Possible values are "unix", "win" and "all" * * @var string */ var $platform = null; /** * The authors contributing to this extension * * @var array */ var $authors = array(); /** * Name prefix for functions etc. * * @var string */ var $prefix = ""; /** * Set extension base name * * @access public * @param string name */ function setName($name) { if (!ereg("^[[:alpha:]_][[:alnum:]_]*$", $name)) { return PEAR::raiseError("'$name' is not a valid extension name"); } $this->name = $name; return true; } /** * Set extension summary text * * @access public * @param string short summary */ function setSummary($text) { $this->summary = $text; return true; } /** * Set extension documentation text * * @access public * @param string long description */ function setDescription($text) { $this->description = $text; return true; } /** * Set the programming language to produce code for * * @access public * @param string programming language name */ function setLanguage($lang) { switch (strtolower($lang)) { case "c": $this->language = "c"; return true; case "cpp": case "cxx": case "c++": $this->language = "cpp"; return true; default: break; } return PEAR::raiseError("'$lang' is not a supported implementation language"); } /** * Set target platform for generated code * * @access public * @param string platform name */ function setPlatform($type) { $this->platform = new CodeGen_Tools_Platform($type); if (PEAR::isError($this->platform)) { return $this->platform; } return true; } /** * Add an author or maintainer to the extension * * @access public * @param object a maintainer object */ function addAuthor($author) { if (!is_a($author, "CodeGen_Maintainer")) { return PEAR::raiseError("argument is not CodeGen_Maintainer"); } $this->authors[$author->user] = $author; return true; } /** * Set release info * * @access public * @var object */ function setRelease($release) { $this->release = $release; return true; } /** * Set license * * @access public * @param object */ function setLicense($license) { if ($license->shortname == "GPL") { return PEAR::raiseError("The GPL is no valid choice for PHP extensions due to license incompatibilities"); } $this->license = $license; return true; } /** * Set extension name prefix (for functions etc.) * * @access public * @param string name */ function setPrefix($prefix) { if (! CodeGen_Element::isName($prefix)) { return PEAR::raiseError("'$name' is not a valid name prefix"); } $this->prefix = $prefix; return true; } } ?> http://cvs.php.net/co.php/pear/CodeGen/ExtensionParser.php?r=1.1&p=1 Index: pear/CodeGen/ExtensionParser.php +++ pear/CodeGen/ExtensionParser.php <?php /** * Parser for XML based extension desription files * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * includes */ require_once "CodeGen/XmlParser.php"; require_once "CodeGen/Tools/Indent.php"; /** * Parser for XML based extension desription files * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_ExtensionParser extends CodeGen_XmlParser { /** * The extension to parse specs into * * @access private * @var object */ var $extension; /** * Constructor * * @access public * @param object the extension to parse specs into */ function __construct($extension) { parent::__construct(); $this->extension = $extension; } /** * Handle <extension> * * @access private * @param array attribute/value pairs * @return bool success status */ function tagstart_extension($attr) { if (!isset($attr["name"])) { return PEAR::raiseError("needed attribute 'name' for <extension> not given"); } $status = $this->extension->setName(trim($attr["name"])); if ($status === true && isset($attr["prefix"])) { $status = $this->extension->setPrefix(trim($attr["prefix"])); } if (isset($attr["version"])) { if (version_compare($attr["version"], $this->extension->version(), ">")) { return PEAR::raiseError("This is ".get_class($this->extension)." ".$this->extension->version().", extension specification requires at least version $attr[version]\n"); } } return $status; } /** * Handle <extension><name> * * @access private * @param array attribute/value pairs * @return bool success status */ function tagstart_extension_name($attr) { return PEAR::raiseError("extension <name> tag is no longer supported, use <extension>s 'name=...' attribute instead"); } /** * Handle <extension></summary> * * @access private * @param array attribute/value pairs * @param array tag data content * @return bool success status */ function tagend_extension_summary($attr, $data) { return $this->extension->setSummary(CodeGen_Tools_Indent::linetrim($data)); } /** * Handle <extension></description> * * @access private * @param array attribute/value pairs * @param array tag data content * @return bool success status */ function tagend_extension_description($attr, $data) { return $this->extension->setDescription(CodeGen_Tools_Indent::linetrim($data)); } function tagstart_maintainer($attr) { $this->pushHelper(new CodeGen_Maintainer); return true; } function tagend_maintainer_user($attr, $data) { return $this->helper->setUser(trim($data)); } function tagend_maintainer_name($attr, $data) { return $this->helper->setName(trim($data)); } function tagend_maintainer_email($attr, $data) { return $this->helper->setEmail(trim($data)); } function tagend_maintainer_role($attr, $data) { return $this->helper->setRole(trim($data)); } function tagend_maintainer($attr, $data) { $err = $this->extension->addAuthor($this->helper); $this->popHelper(); return $err; } function tagend_maintainers($attr, $data) { return true; } function tagstart_extension_release($attr) { $this->pushHelper(new CodeGen_Release); return true; } function tagend_release_version($attr, $data) { return $this->helper->setVersion(trim($data)); } function tagend_release_date($attr, $data) { return $this->helper->setDate(trim($data)); } function tagend_release_state($attr, $data) { return $this->helper->setState(trim($data)); } function tagend_release_notes($attr, $data) { return $this->helper->setNotes(CodeGen_Tools_Indent::linetrim($data)); } function tagend_extension_release($attr, $data) { $err = $this->extension->setRelease($this->helper); $this->popHelper(new CodeGen_Release); return $err; } function tagend_extension_changelog($attr, $data) { return true; } function tagend_license($attr, $data) { $license = CodeGen_License::factory(trim($data)); if (PEAR::isError($license)) { return $err; } return $this->extension->setLicense($license); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode:nil * End: */ ?> http://cvs.php.net/co.php/pear/CodeGen/License.php?r=1.1&p=1 Index: pear/CodeGen/License.php +++ pear/CodeGen/License.php <?php /** * Abstract base class for licenses * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: License.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Abstract base class for licenses * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ abstract class CodeGen_License { /** * Constructor * * @access private * @param License options */ function __construct($options = array()) { $this->options = $options; } /** * Takes a License shortname and returns an instantiated object of that license * * @access public * @param string License shortname, e.g. PHP, BSD, LGPL * @param array License options * @returns object License instance */ static function factory($name, $options=array()) { $classname = "CodeGen_License_".strtoupper($name); $classfile = str_replace("_", "/", $classname).".php"; if (!class_exists($classname)) { if (!@include_once "$classfile") PEAR::raiseError("Unknown license type '$name' ", E_USER_WARNING); } return class_exists($classname) ? new $classname($options) : false; } /** * Writes the License text to a file * * @param string Filename to write to (default is ./LICENSE) * @return bool Success state * @access public */ function writeToFile($path = "./LICENSE") { $fp = fopen($path, "w"); if (is_resource($fp)) { fputs($fp, $this->getText()); fclose($fp); return true; } return false; } /** * Returns a string suitable for insertion into comment headers * * @return string License comment * @access public */ abstract function getComment(); /** * Returns the complete license text as string * * @return string License text * @access public */ abstract function getText(); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode:nil * End: */ ?> http://cvs.php.net/co.php/pear/CodeGen/Maintainer.php?r=1.1&p=1 Index: pear/CodeGen/Maintainer.php +++ pear/CodeGen/Maintainer.php <?php /** * A class that describes an extension author or maintainer * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * A class that describes an extension author or maintainer * * This class wraps up the functionality needed for the * command line script. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Maintainer { /** * Users system account name * * @var string */ var $user; /** * Real name * * @var string */ var $name; /** * Email address * * @var string */ var $email; /** * Role in this project * * @var string */ var $role; /** * First maintainer added? * * @var bool */ static $first = true; /** * Prefix to use in comment headers * * @var bool */ var $comment_prefix = "Authors:"; /** * Constructor * * @access public * @param string CVS user name * @param string real name * @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 (!ereg("^[[:alnum:]_-]+$", $name)) { return PEAR::raiseError("'$name' is not a valid CVS user name"); } $this->user = $name; return true; } /** * Set real user name * * @access public * @param string user name * @return bool true on success */ function setName($name) { $this->name = $name; return true; } /** * 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) { // TODO check for valid roles $this->role = $role; return true; } /** * 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; } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode:nil * End: */ ?> http://cvs.php.net/co.php/pear/CodeGen/Release.php?r=1.1&p=1 Index: pear/CodeGen/Release.php +++ pear/CodeGen/Release.php <?php /** * Class collecting release information * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Class collecting release information * * This class wraps up the functionality needed for the * command line script. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Release { /** * The current version number * * @access private * @var string */ var $version = "0.0.1"; /** * Set method for version number * * @access public * @param string version * @return bool true on success */ function setVersion($version) { // TODO check format $this->version = $version; return true; } /** * The release date * * @access private * @var string */ var $date = ""; /** * Set method for release date * * @access public * @param int timestamp * @return bool true on success */ function setDate($date) { // TODO parse date if not numeric // TODO check valid dates $this->date = $date; return true; } /** * The 'state': alpha, beta, stable, dev ... * * @access private * @var string */ var $state = "unknown"; /** * Set method for state * * @access public * @param string state * @return bool true on success */ function setState($state) { // TODO check valid states $this->state = $state; return true; } /** * Release notes * * @access private * @var string */ var $notes = ""; /** * Set method for release notes * * @access public * @param string release notes * @return bool true on success */ function setNotes($notes) { $this->notes = $notes; return true; } /** * Constructor * * @access public */ function __construct() { $this->date = date("Y-m-d"); } } ?> http://cvs.php.net/co.php/pear/CodeGen/XmlParser.php?r=1.1&p=1 Index: pear/CodeGen/XmlParser.php +++ pear/CodeGen/XmlParser.php <?php /** * Yet another XML parsing class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Yet another XML parsing class * * This is similar to the "func" mode of XML_Parser but it borrows * some concepts from DSSSL. * The tag handler method to call is not only determined by the tag * name but also potentially by the name of its parent tags, and the * most specific handler method (that is the one including the * maximum number of matching parent tags in its name) wins. * This way it is possible to have e.g. tagstart_name as a general * handler for a <name> tag while tagstart_function_name handles the * more special case of a <name> tag within a <function> tag. * Character data within a tag is collected and passed to the end * tag handler. * Tag names and attributes are managed using stack arrays. * Attributes are not only passed to both the start and end tag * handlers. * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_XmlParser { /** * XML parser resource * * @var resource */ private $parser = NULL; /** * Parser stack for <include> management * * @var array */ private $parserStack = array(); /** * We collect cData in here * * @var string */ private $data = ""; /** * We also try to remember where cData started * * @access private * @var int */ var $dataLine = 0; /** * We maintain the current tag nesting structure here * * @access private * @var array */ var $tagStack = array(); /** * We keep track of tag attributes so that we can also provide them to the end tag handlers * * @access private * @var array */ var $attrStack = array(); /** * There is no clean way to terminate parsing from within a handler ... * * @access private * @var bool */ var $error = false; /** * Input Filename * * @access public * @var string */ var $filename = false; /** * Input stream * * @access public * @var resource */ var $fp = null; /** * Verbatim indicator * * @access public * @var string */ var $verbatim = false; /** * Verbatim taglevel depth * * @access public * @var string */ var $verbatimDepth = 0; /** * The constructor * * @access public */ function __construct() { $this->parser = $this->newParser(); } 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; } function pushParser() { if ($this->parser) { $entry = array($this->parser, $this->filename, $this->fp); array_push($this->parserStack, $entry); } } function popParser() { xml_parser_free($this->parser); list($this->parser, $this->filename, $this->fp) = array_pop($this->parserStack); } function posString() { return "in {$this->filename} on line ". xml_get_current_line_number($this->parser). ":". xml_get_current_column_number($this->parser); } function extEntityHandler($parser, $openEntityNames, $base, $systemId, $publicId) { $this->pushParser(); $this->parser = $this->newParser(); $stat = $this->setInputFile($systemId); if (!$stat) { $this->popParser(); $this->error = PEAR::raiseError("Can't open XInclude file '$systemId' ".$this->posString()); } $this->parse(); $this->popParser(); return; } /** * Set file to parse * * @access public * @param string */ function setInputFile($filename) { $this->filename = $filename; $this->fp = @fopen($filename, "r"); return is_resource($this->fp); } /** * Perform the actual parsing * * @access public * @return boolean true on success */ 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"); } while (($data = fread($this->fp, 4096))) { if (!xml_parse($this->parser, $data, feof($this->fp)) || $this->error) { return $this->error; } } return true; } /** * Start verbatim mode * */ 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 */ 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 */ function startHandler($XmlParser, $tag, $attr) { if ($this->error) return; $pos = strrpos($tag, " "); $ns = $pos ? substr($tag, 0, $pos) : ""; $tag = $pos ? substr($tag, $pos + 1) : $tag; // XInclude handling if ($ns === "http://www.w3.org/2001/XInclude") { // TODO better error checking $path = isset($attr['href']) ? $attr['href'] : $attr['http://www.w3.org/2001/XInclude href']; if ($tag === "include") { if (isset($attr["parse"]) && $attr["parse"] == "text") { $this-cDataHandler($XmlParser, get_file_contents($path)); } else { $this->pushParser(); $this->parser = $this->newParser(); $stat = $this->setInputFile($path); if (!$stat) { $this->popParser(); $this->error = PEAR::raiseError("Can't open XInclude file '$path' ".$this->posString()); } $this->parse(); $this->popParser(); return; } } } 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; array_push($this->tagStack, $tag); array_push($this->attrStack, $attr); $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 */ function endHandler($XmlParser, $tag) { if ($this->error) return; $pos = strrpos($tag, " "); $ns = $pos ? substr($tag, 0, $pos) : ""; $tag = $pos ? substr($tag, $pos + 1) : $tag; // XInclude handling if ($ns === "http://www.w3.org/2001/XInclude") { return; } if ($this->verbatim) { if (--$this->verbatimDepth > 0) { $this->data .= "</$tag>"; return; } else { $this->verbatim = false; } } $method = $this->findHandler("tagend"); array_pop($this->tagStack); $attr = array_pop($this->attrStack); 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; } /** * Just collect cData for later use in tag end handlers * * @access private * @param resource internal parser handle * @param string cData to collect */ function cDataHandler($XmlParser, $data) { $this->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 */ 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'"); } } /** * Tread <?data PI sections like <![CDATA[ * * @access private * @param resource internal parser handle * @param string cData to collect */ function dataPiHandler($XmlParser, $data) { $this->cDataHandler($XmlParser, $data); } /** * A helper stack for collecting stuff * * @access private * @var array */ var $helperStack = array(); /** * The current helper (top of stack) * * @access private * @var mixed */ var $helper = false; /** * The previous helper (top-1 of stack) * * @access private * @var mixed */ var $helperPrev = false; /** * Push something on the helper stack * * @access private * @param mixed */ function pushHelper($helper) { array_push($this->helperStack, $this->helper); $this->helperPrev = $this->helper; $this->helper = $helper; } /** * Pop something from the helper stack * * @access private */ function popHelper() { $this->helper = array_pop($this->helperStack); if (count($this->helperStack)) { end($this->helperStack); $this->helperPrev = current($this->helperStack); } else { $this->helperPrev = false; } } } ?> http://cvs.php.net/co.php/pear/CodeGen/foo.xml?r=1.1&p=1 Index: pear/CodeGen/foo.xml +++ pear/CodeGen/foo.xml <extension name="#+-"/> http://cvs.php.net/co.php/pear/CodeGen/package.xml?r=1.1&p=1 Index: pear/CodeGen/package.xml +++ pear/CodeGen/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package> <name>CodeGen</name> <summary>Tool to create Code generaters that operate on XML descriptions</summary> <status>beta</status> <maintainers> <maintainer> <user>hholzgra</user> <name>Hartmut Holzgraefe</name> <email>hartmut@php.net</email> <role>lead</role> </maintainer> </maintainers> <description> testing only </description> <license>PHP</license> <release> <state>alpha</state> <version>0.1</version> <date>2005-06-18</date> <notes> testing only </notes> <deps> <dep type="php" rel="ge" version="5"/> <dep type="pkg" rel="ge" version="1.0">Console_Getopt</dep> </deps> <filelist> <dir name="/" baseinstalldir="CodeGen"> <file role="php">Extension.php</file> <file role="php">XmlParser.php</file> <file role="php">ExtensionParser.php</file> <file role="php">Element.php</file> <file role="php">Release.php</file> <file role="php">Maintainer.php</file> <file role="php">License.php</file> <dir name="License"> <file role="php">PHP.php</file> <file role="php">BSD.php</file> <file role="php">LGPL.php</file> </dir> <file role="php">Command.php</file> <dir name="Tools"> <file role="php">Code.php</file> <file role="php">Getopt.php</file> <file role="php">Platform.php</file> <file role="php">Indent.php</file> <file role="php">Tokenizer.php</file> </dir> </dir> </filelist> </release> </package> http://cvs.php.net/co.php/pear/CodeGen/License/BSD.php?r=1.1&p=1 Index: pear/CodeGen/License/BSD.php +++ pear/CodeGen/License/BSD.php <?php /** * The BSD License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: BSD.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The BSD License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_BSD extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'BSD'; /** * full name * * @access public * @var string */ var $longname = 'BSD style license'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | All rights reserved | | | | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions | | are met: | | | | 1. Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | 2. Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in | | the documentation and/or other materials provided with the | | distribution. | | 3. The names of the authors may not be used to endorse or promote | | products derived from this software without specific prior | | written permission. | | | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | POSSIBILITY OF SUCH DAMAGE. | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { return <<<EOD All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EOD; } } ?> http://cvs.php.net/co.php/pear/CodeGen/License/GPL.php?r=1.1&p=1 Index: pear/CodeGen/License/GPL.php +++ pear/CodeGen/License/GPL.php <?php /** * The GPL License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: GPL.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The GPL License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_GPL extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'GPL'; /** * full name * * @access public * @var string */ var $longname = 'GNU General Public License'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License in the file LICENSE along with this library; | | if not, write to the | | | | Free Software Foundation, Inc., | | 59 Temple Place, Suite 330, | | Boston, MA 02111-1307 USA | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { ob_start(); ?> GNU General Public License ************************** Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble ======== The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a. You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b. You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c. If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a. Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b. Accompany it with a written offer, valid for at least three years, to give any third-party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c. Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs ============================================= If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES. Copyright (C) YYYY NAME OF AUTHOR This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. SIGNATURE OF TY COON, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. <?php $text = ob_get_contents(); ob_end_clean(); return $text; } } ?> http://cvs.php.net/co.php/pear/CodeGen/License/LGPL.php?r=1.1&p=1 Index: pear/CodeGen/License/LGPL.php +++ pear/CodeGen/License/LGPL.php <?php /** * The LGPL License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: LGPL.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The LGPL License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_LGPL extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'LGPL'; /** * full name * * @access public * @var string */ var $longname = 'GNU Lesser General Public License'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | This library is free software; you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation; either | | version 2.1 of the License, or (at your option) any later version. | | | | This library is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | Lesser General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License in the file LICENSE along with this library; | | if not, write to the | | | | Free Software Foundation, Inc., | | 59 Temple Place, Suite 330, | | Boston, MA 02111-1307 USA | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { ob_start(); ?> GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the library's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. <signature of Ty Coon>, 1 April 1990 Ty Coon, President of Vice That's all there is to it! <?php $text = ob_get_contents(); ob_end_clean(); return $text; } } ?> http://cvs.php.net/co.php/pear/CodeGen/License/PHP.php?r=1.1&p=1 Index: pear/CodeGen/License/PHP.php +++ pear/CodeGen/License/PHP.php <?php /** * The PHP License * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: PHP.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * The PHP License * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_License_PHP extends CodeGen_License { /** * short name * * @access public * @var string */ var $shortname = 'PHP'; /** * full name * * @access public * @var string */ var $longname = 'The PHP License'; /** * License comment to include in code files * * @access public * @return string comment text */ function getComment() { return <<<EOD | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | EOD; } /** * Complete License Text * * @access public * @return string license text */ function getText() { return <<<EOD -------------------------------------------------------------------- The PHP License, Version 3.0 Copyright (c) 1999 - 2003 The PHP Group. All rights reserved. -------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without modification, is permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name "PHP" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact group@php.net. 4. Products derived from this software may not be called "PHP", nor may "PHP" appear in their name, without prior written permission from group@php.net. You may indicate that your software works in conjunction with PHP by saying "Foo for PHP" instead of calling it "PHP Foo" or "phpfoo" 5. The PHP Group may publish revised and/or new versions of the license from time to time. Each version will be given a distinguishing version number. Once covered code has been published under a particular version of the license, you may always continue to use it under the terms of that version. You may also choose to use such covered code under the terms of any subsequent version of the license published by the PHP Group. No one other than the PHP Group has the right to modify the terms applicable to covered code created under this License. 6. Redistributions of any form whatsoever must retain the following acknowledgment: "This product includes PHP, freely available from <http://www.php.net/>". THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------- This software consists of voluntary contributions made by many individuals on behalf of the PHP Group. The PHP Group can be contacted via Email at group@php.net. For more information on the PHP Group and the PHP project, please see <http://www.php.net>. This product includes the Zend Engine, freely available at <http://www.zend.com>. EOD; } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Code.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Code.php +++ pear/CodeGen/Tools/Code.php <?php /** * Wrapper class for code block generation * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Wrapper class for code block generation * * all methods are actually static, the class is just needed for * namespace emulation to conform with PEAR naming conventions * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ /** */ require_once("CodeGen/Tools/Indent.php"); class CodeGen_Tools_Code { var $language = 'c'; var $indentSteps = 4; /** * Generate simple indented codeblock * * @param string code * @param int indent level * @return string formated code block */ function block($code, $indent = 1) { return CodeGen_Tools_Indent::indent($indent*$this->indentSteps, $code); } /** * Generate indented codeblock with variable declarations * * @param string code * @param int indent level * @return string formated code block */ function varblock($code, $indent = 1) { if ($this->language == 'c') { $head = CodeGen_Tools_Indent::indent($indent * $this->indentSteps, "do {\n"); $foot = CodeGen_Tools_Indent::indent($indent * $this->indentSteps, "} while (0);\n"); $indent++; } else { $head = $foot = ""; } $code = CodeGen_Tools_Indent::indent($indent * $this->indentSteps, $code); return $head . $code . $foot; } }; http://cvs.php.net/co.php/pear/CodeGen/Tools/Getopt.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Getopt.php +++ pear/CodeGen/Tools/Getopt.php <?php /** * A more convenient command line argument parser class * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ require_once "Console/Getopt.php"; /** * A more convenient command line argument parser class * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Getopt extends Console_Getopt { /** * Internal storage for parsed arguments * * @access private * @var array */ private $options = array(); /** * Constructor will parse specified short and long arguments * * @access public * @param string short options specification * @param array long options specification * @param callback error callback, call this and exit on errors if given */ function __construct ($short_options, $long_options = NULL, $usage = NULL) { // use parent methods for actual parsing, store result internaly $argv = parent::readPHPArgv(); $this->options = parent::getopt($argv, $short_options, $long_options); if (PEAR::isError($this->options)) { if (!is_null($usage) && is_callable($usage)) { call_user_func($usage, $this->options->message); exit(3); } } } /** * Check if any of the specified options was given * * @access public * @param string a short or long option name * @param ... * @return bool true if anything found else false */ function have($name /*, ... */) { // foreach argument foreach (func_get_args() as $arg) { // short or long option? switch (strlen($arg)) { case 0: continue(2); case 1: $arg = "$arg"; break; default: $arg = "--$arg"; break; } // search given command line options foreach ($this->options[0] as $opt) { // found? if ($opt[0] == $arg) { return true; } } } // nothing found return false; } /** * Check if all of the specified options were given * * @access public * @param string a short or long option name * @param ... * @return bool true if all found else false */ function haveAll($name /*, ... */) { // foreach argument foreach (func_get_args() as $name) { // short or long option? switch (strlen($name)) { case 0: continue(2); case 1: $name = "-$name"; break; default: $name = "--$name"; break; } // check for this option $found = false; foreach ($this->options[0] as $opt) { if ($opt[0] == $name) { $found = true; } } // not found? -> all fails if (!$found) { return false; } } // all passed return true; } /** * Get argument value for an option * * @access public * @param string $name * @result string option value or true for options without argument */ function value($name, $name2 = false) { foreach (func_get_args() as $name) { switch (strlen($name)) { case 0: return false; case 1: $name = "-$name"; break; default: $name = "--$name"; break; } foreach ($this->options[0] as $opt) { if ($opt[0] == $name) { return is_null($opt[1]) ? true : $opt[1]; } } } // not found return false; } /** * Get all given option names * * @access public * @return array an array of option names */ function options() { $names = array(); foreach ($this->options [0] as $opt) { $names[] = ereg_replace("^-*", "", $opt[0]); } return $names; } /** * Get all additional arguments not bound to options * * @access public * @return array an array of argument string values */ function arguments() { $names = array(); foreach ($this->options[1] as $arg) { $names[] = $arg; } return $names; } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Indent.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Indent.php +++ pear/CodeGen/Tools/Indent.php <?php /** * Wrapper class for whitespace related stuff * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * Wrapper class for whitespace related stuff * * all methods are actually static, the class is just needed for * namespace emulation to conform with PEAR naming conventions * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Indent { /** * Replace leading blanks with tabs * * PHP C coding conventions require tab indention * with a tabsize of 4 * * @access public * @param string text to tabify * @param int tab indention level (default: 4 spaces) * @return string tabified text */ 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 ); } /** * Replace leading tabs with blanks * * PEAR PHP coding conventions require blank indention * with a tabsize of 4 * * @access public * @param string text to untabify * @param int tab indention level (default: 4 spaces) * @return string untabified text */ function untabify($text, $tabsize = 4) { return preg_replace_callback("/^(\t)*/m", create_function('$matches','return str_repeat(" ", strlen($matches[0])*'.$tabsize.');'), $text ); } /** * re-indent a block of text * * @access public * @param int number of leading indent spaces * @param string text to reindent * @return string indented text */ function indent($level, $text) { $lines = explode("\n", $text); while (count($lines) && trim(end($lines)) == "") { array_pop($lines); } $maxindent = 999; foreach ($lines as $line) { if (trim($line)=="") continue; ereg("^ *", $line, $matches); $maxindent = min($maxindent, strlen($matches[0])); } $result = ""; $find = str_repeat(" ", $maxindent); $replace = str_repeat(" ", $level); foreach ($lines as $line) { $result.= self::tabify(ereg_replace("^$find", $replace, $line)."\n", 4); } return $result; } /** * Trim of leading and trailing whitespace-only lines * * @access public * @param string text * @return string trimmed text */ function linetrim($text) { $text = preg_replace('|^\s*\n|','', $text); $text = preg_replace('|\n\s*$|',"\n", $text); return $text; } /** * Change to DOS/Windows line terminators * * @access public * @param string unix text * @param string dos/windows text */ function dosify($text) { return str_replace("\n", "\r\n", $text); } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Platform.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Platform.php +++ pear/CodeGen/Tools/Platform.php <?php /** * A helper class for platform management * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: Platform.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * A helper class for platform management * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Platform { /** * The supported platforms are collected here * * @access private * @var array the platform short names */ var $platforms = array(); /** * Constructor gets a list of names or "all" * * @access public * @param string|array names as comma separated string or array */ function __construct($names) { if (is_string($names)) { $names = explode(",", $names); } foreach ($names as $name) { switch (strtolower(trim($name))) { case "all": $this->platforms["win"] = true; $this->platforms["unix"] = true; break; case "win": case "win23": case "windows": case "microsoft": $this->platforms["win"] = true; break; case "unix": case "posix": case "gnu": $this->platforms["unix"] = true; break; default: $this->error = PEAR::raiseError("'$name' is not a supported platform"); break(2); } } } /** * Test for a platform shortname * * @access public * @param string shortname * @return bool true if supported else false */ function test($name) { switch (strtolower(trim($name))) { case "all": return 2 == $this->count(); case "win": case "win32": case "windows": case "microsoft": return isset($this->platforms["win"]); case "unix": case "posix": case "gnu": return isset($this->platforms["unix"]); default: return false; } } /** * Count the number of supported platforms * * @access public * @return int platform count */ function count() { return count($this->platforms()); } } ?> http://cvs.php.net/co.php/pear/CodeGen/Tools/Tokenizer.php?r=1.1&p=1 Index: pear/CodeGen/Tools/Tokenizer.php +++ pear/CodeGen/Tools/Tokenizer.php <?php /** * A simple tokenizer for e.g. proto parsing * * PHP versions 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Tools and Utilities * @package CodeGen * @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: Tokenizer.php,v 1.1 2005/07/18 08:06:56 hholzgra Exp $ * @link http://pear.php.net/package/CodeGen */ /** * A simple tokenizer for e.g. proto parsing * * @category Tools and Utilities * @package CodeGen * @author Hartmut Holzgraefe <hartmut@php.net> * @copyright 2005 Hartmut Holzgraefe * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/CodeGen */ class CodeGen_Tools_Tokenizer { /** * String to parse * * @var string */ protected $string; /** * Current parsing position * * @var int */ protected $pos; /** * Current token content * * @var string */ public $token; /** * Current token type (name, numeric, string) * * @var string */ public $type; /** * Parsing complete? * * @var bool */ public $done = false; /** * pushback stack for parsed tokens * * @var array */ private $tokenStack = array(); /** * Konstruktor * * @param string String to parse */ public function __construct($string) { $this->string = $string; $this->pos = 0; } /** * get next character to parse * * @return string */ private function pullChar() { if ($this->pos >= strlen($this->string)) { $this->done = true; return ""; } return ($this->string{$this->pos++}); } /** * Push back read character(s) * * @param string characters to pusch back */ private function pushChar($char) { // we just rely on the user not cheating $this->pos -= strlen($char); } /** * Read next token into $this->type, $this->token * * @return bool success? */ public function nextToken() { if (!empty($this->tokenStack)) { list($this->type, $this->token) = array_pop($this->tokenStack); return true; } do { $char = $this->pullChar(); if ($char === "") return false; } while (ctype_space($char)); if (ctype_alnum($char) || $char === "_" || $char === "-") { $this->type = "name"; $this->token = $char; while (true) { $char = $this->pullChar(); if (ctype_alnum($char) || $char === "_") { $this->token .= $char; } else if ($this->token === "array" && $char === "(") { $this->token .= $char; } else if ($this->token === "array(" && $char === ")") { $this->token .= $char; } else { $this->pushChar($char); break; } } if (is_numeric($this->token)) { $this->type = 'numeric'; } } else if ($char == '"' || $char == "'") { $this->type = "string"; $this->token = ""; $quote = $char; $escape = false; while (true) { $char = $this->pullChar(); if ($char === "") { $this->type = false; return false; } if ($escape) { $escape = false; $this->token .= $char; continue; } if ($char === $quote) { break; } if ($char === "\\") { $escape = true; continue; } $this->token .= $char; } } else if ($char === ".") { $ellipse = false; $char2 = $this->pullChar(); if ($char2 === ".") { $char3 = $this->pullChar(); if ($char3 === ".") { $ellipse = true; } else { $this->pushChar($char3); } } else { $this->pushChar($char2); } if ($ellipse) { $this->token = "..."; $this->type = "name"; } else { $this->token = "."; $this->type = "name"; } } else { $this->token = $char; $this->type = "char"; } return true; } /** * Push back a parsed token * */ public function pushToken() { array_push($this->tokenStack, array($this->type, $this->token)); } }