Jump to content


Photo

Function Skeleton generator


  • Please log in to reply
2 replies to this topic

#1 daeken

daeken
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationChambersburg, PA

Posted 09 November 2003 - 03:32 AM

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)
Black and white are all I see in my infancy.

#2 daeken

daeken
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationChambersburg, PA

Posted 09 November 2003 - 03:39 AM

Just an example header file and the skeleton code generated:
/*  +----------------------------------------------------------------------+  | PHP Version 4                                                        |  +----------------------------------------------------------------------+  | Copyright (c) 1997-2003 The PHP Group                                |  +----------------------------------------------------------------------+  | This source file is subject to version 2.02 of the PHP license,      |  | that is bundled with this package in the file LICENSE, and is        |  | available at through the world-wide-web at                           |  | http://www.php.net/license/2_02.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.               |  +----------------------------------------------------------------------+  | Author: Cody Brocious                                                |  +----------------------------------------------------------------------+  $Id: header,v 1.10.8.1 2003/07/14 15:59:18 sniper Exp $ */#ifndef PHP_OPENAL_H#define PHP_OPENAL_Hextern zend_module_entry openal_module_entry;#define phpext_openal_ptr &openal_module_entry#ifdef PHP_WIN32#define PHP_OPENAL_API __declspec(dllexport)#else#define PHP_OPENAL_API#endif#ifdef ZTS#include "TSRM.h"#endif#include <AL/al.h>PHP_MINIT_FUNCTION(openal);PHP_MSHUTDOWN_FUNCTION(openal);PHP_RINIT_FUNCTION(openal);PHP_RSHUTDOWN_FUNCTION(openal);PHP_MINFO_FUNCTION(openal);PHP_FUNCTION(alEnable);PHP_FUNCTION(alDisable);PHP_FUNCTION(alIsEnabled);PHP_FUNCTION(alHint);PHP_FUNCTION(alGetBooleanv);PHP_FUNCTION(alGetIntegerv);#ifdef ZTS#define OPENAL_G(v) TSRMG(openal_globals_id, zend_openal_globals *, v)#else#define OPENAL_G(v) (openal_globals.v)#endif#endif	/* PHP_OPENAL_H *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */

Skeleton Code:
function_entry openal_functions[] = {  ZEND_FE(alEnable, NULL)  ZEND_FE(alDisable, NULL)  ZEND_FE(alIsEnabled, NULL)  ZEND_FE(alHint, NULL)  ZEND_FE(alGetBooleanv, NULL)  ZEND_FE(alGetIntegerv, NULL)  {NULL, NULL, NULL}};/* {{{ proto void alEnable()   DESCRIPTION */PHP_FUNCTION(alEnable){}/* }}} *//* {{{ proto void alDisable()   DESCRIPTION */PHP_FUNCTION(alDisable){}/* }}} *//* {{{ proto void alIsEnabled()   DESCRIPTION */PHP_FUNCTION(alIsEnabled){}/* }}} *//* {{{ proto void alHint()   DESCRIPTION */PHP_FUNCTION(alHint){}/* }}} *//* {{{ proto void alGetBooleanv()   DESCRIPTION */PHP_FUNCTION(alGetBooleanv){}/* }}} *//* {{{ proto void alGetIntegerv()   DESCRIPTION */PHP_FUNCTION(alGetIntegerv){}/* }}} */

Black and white are all I see in my infancy.

#3 Derek

Derek
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationTennessee

Posted 09 November 2003 - 03:42 AM

this is EXCELLENT! This\'ll save a lot of time while writing extensions :)
function comment(s)

{

	if (i_know_what_to_do_shut_up_i_dont_need_your_help_mode) {
   return  	} else {    return s  	}  }
ext/skeleton/create_stubs, lines 40-47. - PHP Core




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users