Jump to content

Function Skeleton generator


daeken

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/1325-function-skeleton-generator/
Share on other sites

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          |

 | [email protected] 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_H



extern 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)

{

}

/* }}} */



Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.