I was whipping up a quick OpenAL extension, so I started by writing the php_openal.h file and adding the appropriate PHP_FUNCTION(...); lines... well, soon after I got the idea of taking that header file and generating base code for the extension itself from it. Here\'s what I ended up with:
[php:1:88128bd8ea]
#!/usr/local/bin/php
<?php
if($_SERVER[\'argc\'] < 3)
{
echo \'Usage: \', $_SERVER[\'argv\'][0], \' <extension name> <header file>\', chr(10);
exit;
}
$file = file($_SERVER[\'argv\'][2]);
$funcs = array();
foreach($file as $line)
{
$line = trim($line);
if(substr($line, 0, 13) == \'PHP_FUNCTION(\')
$funcs[] = substr($line, 13, -2);
}
echo \'function_entry \', $_SERVER[\'argv\'][1], \'_functions[] = {\', chr(10);
foreach($funcs as $foo)
echo \' ZEND_FE(\', $foo, \', NULL)\', chr(10);
echo \' {NULL, NULL, NULL}\', chr(10), \'};\', chr(10), chr(10), chr(10);
foreach($funcs as $foo)
echo \'/* {{{ proto void \', $foo, \'()\', chr(10), \' DESCRIPTION */\', chr(10), chr(10), \'PHP_FUNCTION(\', $foo, \')\', chr(10), \'{\', chr(10), \'}\', chr(10), \'/* }}} */\', chr(10), chr(10);
?>
[/php:1:88128bd8ea]
Have fun with it, and as always
Happy hacking,
Lord Daeken M. BlackBlade
(Cody Brocious)