Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance fixes #2

Merged
merged 6 commits into from Jan 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions CodeGen/PECL/Cli.php 100755 → 100644
Expand Up @@ -14,31 +14,28 @@
$command = new CodeGen_PECL_Command($extension, "pecl-gen");

if ($command->options->have("experimental", "x")) {
echo "the --experimental (-x) option has been deprecated
echo "the --experimental (-x) option has been deprecated

please use the 'version' attribute of the <extension> tag
to select version-specific features
";

exit(3);
}



if ($command->options->have("function"))
{
$command->singleFunction();
exit(0);
$command->singleFunction();
exit(0);
}

// ext_skel compatibility?
if ($command->options->have("extname")) {
$command->extSkelCompat();
exit(0);
}

$command->extSkelCompat();
exit(0);
}

$parser = new CodeGen_PECL_ExtensionParser($extension);

$command->execute($parser);

?>
101 changes: 50 additions & 51 deletions CodeGen/PECL/Command.php
@@ -1,6 +1,6 @@
<?php
/**
* Command wrapper class
* Command wrapper class
*
* PHP versions 5
*
Expand All @@ -27,12 +27,11 @@
require_once "CodeGen/PECL/Extension.php";
require_once "CodeGen/PECL/ExtensionParser.php";


/**
* Command wrapper class
*
* This class wraps up the functionality needed for the
* command line script.
* This class wraps up the functionality needed for the
* command line script.
*
* @category Tools and Utilities
* @package CodeGen
Expand All @@ -53,7 +52,7 @@ class CodeGen_PECL_Command
function __construct(CodeGen_Extension $extension)
{
parent::__construct($extension);

if ($this->options->have("linespecs")) {
$this->extension->setLinespecs(true);
}
Expand All @@ -68,15 +67,15 @@ function commandOptions()
{
list($shortOptions, $longOptions) = parent::commandOptions();

$longOptions= array_merge($longOptions, array("extname=",
"full-xml",
$longOptions= array_merge($longOptions, array("extname=",
"full-xml",
"function=",
"linespecs",
"no-help",
"proto=",
"skel=",
"stubs=",
"xml=="));
"skel=",
"stubs=",
"xml=="));

return array($shortOptions, $longOptions);
}
Expand All @@ -89,13 +88,13 @@ function commandOptions()
function showUsage($message = false)
{
$fp = fopen("php://stderr", "w");

if ($message) fputs($fp, "$message\n\n");

fputs($fp, "Usage:

pecl-gen [-h] [--force] [--experimental] [--version]
[--extname=name] [--proto=file] [--skel=dir] [--stubs=file]
[--extname=name] [--proto=file] [--skel=dir] [--stubs=file]
[--no-help] [--xml[=file]] [--full-xml] [--function=proto] [specfile.xml]

-h|--help this message
Expand All @@ -108,7 +107,7 @@ function showUsage($message = false)
--version show version info

the following options are inherited from ext_skel:
--extname=module module is the name of your extension
--extname=module module is the name of your extension
--proto=file file contains prototypes of functions to create
--xml generate xml documentation to be added to phpdoc-cvs

Expand All @@ -119,20 +118,19 @@ function showUsage($message = false)

these are accepted for backwards compatibility reasons but not used ...
--full-xml generate xml documentation for a self-contained extension
(this was also a no-op in ext_skel)
(this was also a no-op in ext_skel)
--skel=dir path to the skeleton directory
(skeleton stuff is now self-contained)
");

fclose($fp);
}


/**
* Generate just a single function stub file
*
*/
function singleFunction()
function singleFunction()
{
$func = new CodeGen_PECL_Element_Function;

Expand All @@ -141,23 +139,23 @@ function singleFunction()
$err = $func->setProto(trim($this->options->value("function")), $this->extension);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}
}

$err = $this->extension->addFunction($func);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}

echo $this->extension->publicFunctionsC();

echo "\n\n/*----------------------------------------------------------------------*/\n\n";

foreach ($this->extension->getFunctions() as $name => $function) {
echo sprintf("\tPHP_FE(%-20s, NULL)\n", $name);
}

echo "\n\n/*----------------------------------------------------------------------*/\n\n";

foreach ($this->extension->getFunctions() as $name => $function) {
echo "PHP_FUNCTION($name);\n";
}
Expand All @@ -170,96 +168,97 @@ function singleFunction()
function extSkelCompat()
{
$extname = $this->options->value("extname");

$err = $this->extension->setName($extname);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}

if ($this->options->have("proto")) {
$proto_file = $this->options->value("proto");

if (!file_exists($proto_file) || !is_readable($proto_file)) {
$this->terminate("cannot open proto file");
$this->terminate("cannot open proto file");
}

foreach (file($proto_file) as $line) {
$func = new CodeGen_PECL_Element_Function;
$func->setRole("public");
$err = $func->setProto(trim($line));
$err = $func->setProto(trim($line), $this->extension);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}
}

$err = $this->extension->addFunction($func);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}
}
}

if ($this->options->have("stubs")) {
$stubname = $this->options->value("stubs");

if (file_exists("$stubname") && !$this->options->have("f", "force")) {
$this->terminate("'$stubname' already exists (use '--force' to overwrite)");
$this->terminate("'$stubname' already exists (use '--force' to overwrite)");
}

$fp = fopen($stubname, "w");
fputs($fp, $this->extension->publicFunctionsC());

fputs($fp, "\n\n/*----------------------------------------------------------------------*/\n\n");

foreach ($this->extension->functions as $name => $function) {
fputs($fp, sprintf("\tPHP_FE(%-20s, NULL)\n", $name));
}

fputs($fp, "\n\n/*----------------------------------------------------------------------*/\n\n");

foreach ($this->extension->functions as $name => $function) {
fputs($fp, "PHP_FUNCTION($name);\n");
}

fclose($fp);

echo "$stubname successfully written\n";
} else {
if (file_exists("./$extname") && !$this->options->have("f", "force")) {
$this->terminate("'$extname' already exists, can't create directory (use '--force' to override)");
$this->terminate("'$extname' already exists, can't create directory (use '--force' to override)");
}

$err = System::mkdir($extname);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}

$this->extension->dirpath = realpath("./$extname");

$err = $this->extension->generateSource("./$extname");
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}

if ($this->options->have("xml")) {
$manpath = "$extname/manual/". str_replace('_', '-', $extname);

$err = System::mkdir("-p $manpath");
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}

$err = $this->extension->generateDocumentation($manpath);
if (PEAR::isError($err)) {
$this->terminate($err->getMessage());
}
}

$this->extension->writeReadme("./$extname");

if (!$this->options->have("quiet")) {
echo $this->extension->successMsg();
}
}

}
}