PHP PEAR CVS 31 CVS PEAR PECL GEN CHANGELOG TODO PECL GEN
Date: Wed, 02 Jul 2003 15:59:14 -0000

Subject: cvs: pear /PECL_Gen ChangeLog TODO pecl-gen
From: hholzgra@no-spam (Hartmut Holzgraefe)

hholzgra Wed Jul 2 11:59:14 2003 EDT
Modified files: /pear/PECL_Gen ChangeLog TODO pecl-gen Log:
- addded --function option to create a single function stub - redid the commandline option handling Index: pear/PECL_Gen/ChangeLog diff -u pear/PECL_Gen/ChangeLog:1.3 pear/PECL_Gen/ChangeLog:1.4
--- pear/PECL_Gen/ChangeLog:1.3 Mon Jun 30 10:18:52 2003
+++ pear/PECL_Gen/ChangeLog Wed Jul 2 11:59:14 2003
@@no-spam -1,3 +1,5 @@no-spam +- --function="proto" writes function stub to stdout +
- --stubs=filename now supported in ext_skel BC mode - added --help and --version options Index: pear/PECL_Gen/TODO diff -u pear/PECL_Gen/TODO:1.10 pear/PECL_Gen/TODO:1.11
--- pear/PECL_Gen/TODO:1.10 Mon Jun 30 15:37:48 2003
+++ pear/PECL_Gen/TODO Wed Jul 2 11:59:14 2003
@@no-spam -1,8 +1,6 @@no-spam Milestone 0.7
-------------
-- create just function stubs instead of complete extension - (now only supported in ext_skel compatibility mode)
- README file generation - show verbose message on what to do next like ext_skel did (this is also the README file? or INSTALL?)
Index: pear/PECL_Gen/pecl-gen diff -u pear/PECL_Gen/pecl-gen:1.8 pear/PECL_Gen/pecl-gen:1.9
--- pear/PECL_Gen/pecl-gen:1.8 Mon Jun 30 10:09:43 2003
+++ pear/PECL_Gen/pecl-gen Wed Jul 2 11:59:14 2003
@@no-spam -5,15 +5,15 @@no-spam * Console script to generate PECL extensions from command line *
* @no-spam Hartmut Holzgraefe <hartmut@no-spam>
-* @no-spam $Id: pecl-gen,v 1.8 2003/06/30 14:09:43 hholzgra Exp $
+* @no-spam $Id: pecl-gen,v 1.9 2003/07/02 15:59:14 hholzgra Exp $
*/
// includes require_once 'PEAR.php';
-require_once "Console/Getopt.php";
require_once "PECL/Gen/Extension.php";
require_once "PECL/Gen/ExtensionParser.php";
require_once "PECL/Gen/Element.php";
+require_once "PECL/Gen/Tools/Getopt.php";
// no compromise error_reporting(E_ALL);
@@no-spam -21,46 +21,46 @@no-spam // create extension object $extension = new PECL_Gen_Extension;
-$argv = Console_Getopt::readPHPArgv();
-$options = Console_Getopt::getopt($argv, "hq", +$options = new PECL_Gen_Tools_Getopt( "hq", array( "help",
"extname=", "force",
"full-xml", + "function=",
"no-help",
"proto=",
"quiet", - "skel=", - "stubs=",
- "version",
+ "skel=" , + "stubs=",
+ "version",
"xml==", - ));
-
-
-if (have_option($options, "help", "h")) {
+ ),
+ "usage");
+
+if ($options->have("help", "h")) {
version();
usage();
exit(0);
}
-if (have_option($options, "version")) {
+if ($options->have("version")) {
version();
exit(0);
}
// ext_skel compatibility?
-if (have_option($options, "extname")) {
+if ($options->have("extname")) {
$ext = new PECL_Gen_Extension;
- $extname = get_option_val($options, "extname");
+ $extname = $options->value("extname");

$err = $ext->set_name($extname);
if (PEAR::isError($err)) {
die($err->get_message());
}
- if (have_option($options, "proto")) {
- $proto_file = get_option_val($options, "proto");
+ if ($options->have("proto")) {
+ $proto_file = $options->value("proto");
if (!file_exists($proto_file) || !is_readable($proto_file)) {
die("cannot open proto file");
@@no-spam -81,10 +81,10 @@no-spam }
}
- if (have_option($options, "stubs")) {
- $stubname = get_option_val($options, "stubs");
+ if ($options->have("stubs")) {
+ $stubname = $options->value("stubs");
- if (file_exists("$stubname") && !have_option($options, "force")) {
+ if (file_exists("$stubname") && !$options->have("force")) {
die("'$stubname' already exists (use '--force' to overwrite)"); }
@@no-spam -106,8 +106,8 @@no-spam fclose($fp);
echo "$stubname successfully written\n";
- } else {
- if (file_exists("./$extname") && !have_option($options, "force")) {
+ } else { + if (file_exists("./$extname") && !$options->have("force")) {
die("'$extname' already exists, can't create directory (use '--force' to override)");
}

@@no-spam -121,7 +121,7 @@no-spam die($err->get_message());
}

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

$err = System::mkdir("-p $manpath");
@@no-spam -135,7 +135,7 @@no-spam }
}
- if (!have_option($options, "quiet")) {
+ if (!$options->have("quiet")) {
$ext->success_msg($extname);
}
}
@@no-spam -144,13 +144,49 @@no-spam }
+if ($options->have("function"))
+{
+ $ext = new PECL_Gen_Extension;
+
+ $func = new PECL_Gen_Element_Function;
+ $func->set_role("public");
+ $err = $func->set_proto(trim($options->value("function")));
+ if (PEAR::isError($err)) {
+ die($err->get_message());
+ }
+
+ $err = $ext->add_function($func);
+ if (PEAR::isError($err)) {
+ die($err->get_message());
+ }
+
+ echo $ext->public_functions_c();
+
+ echo "\n\n/*----------------------------------------------------------------------*/\n\n";

+
+ foreach ($ext->functions as $name => $function) {
+ echo sprintf("\tPHP_FE(%-20s, NULL)\n",$name);
+ }
+
+ echo "\n\n/*----------------------------------------------------------------------*/\n\n";

+
+ foreach ($ext->functions as $name => $function) {
+ echo "PHP_FUNCTION($name);\n";
+ }
+
+ exit(0);
+}
+
+
+
// normal operation: read XML file and go with that -if (count($options[1]) != 1) {
+$arguments = $options->arguments();
+if (count($arguments) != 1) {
usage();
exit(3);
}
-$xmlfile = $options[1][0];
+$xmlfile = $arguments[0];
if (!file_exists($xmlfile) || !is_readable($xmlfile)) {
die("Cannot open XML spec file '$xmlfile'");
@@no-spam -170,12 +206,12 @@no-spam }
// and now create the actual PECL extension dir from the collected specs -$err = $extension->create_extension(".", have_option($options, "force"));
+$err = $extension->create_extension(".", $options->have("force"));
if (PEAR::isError($err)) {
die($err->getMessage()." ".$err->getUserInfo());
}
-if (!have_option($options, "quiet")) {
+if (!$options->have("quiet")) {
$ext->success_msg($extname);
}
@@no-spam -226,29 +262,6 @@no-spam ");
fclose($fp);
-}
-
-
-function have_option($options, $name, $char=false)
-{
- foreach ($options[0] as $opt)
- {
- if ($opt[0] == "--$name") return true; - if (is_string($char) && $opt[0]{0} === $char) return true;
- }
-
- return false;
-}
-
-
-function get_option_val($options, $name)
-{
- foreach ($options[0] as $opt)
- {
- if ($opt[0] == "--$name") return $opt[1]; - }
-
- return false;
}
?>