code for the special functions MINIT, MSHUTDOWN, RINIT, RSHUTDOWN, MINFO

and for private internal C helper functions may now be embedded into
the XML specification
This commit is contained in:
Hartmut Holzgraefe 2003-02-19 16:02:45 +00:00
parent 397785bdcd
commit 843e3449cf
3 changed files with 108 additions and 20 deletions

View file

@ -106,6 +106,16 @@
</code>
</function>
<function role='private' name='myfunc'>
<code>
<![CDATA[
static int myfunc(void) {
return 23;
}
]]>
</code>
</function>
<function role='public' name='dummy_int'>
<summary>dummy integer conversion</summary>

View file

@ -23,6 +23,8 @@
$this->constants = array();
$this->functions = array();
$this->internal_functions = array();
$this->private_functions = array();
$this->globals = array();
$this->phpini = array();
$this->users = array();
@ -128,7 +130,22 @@
}
function handle_functions_function($attr) {
$this->functions[$attr['name']] = new php_function($attr['name'], $this->func_summary, $this->func_proto, @$this->func_desc, @$this->func_code);
$role = isset($attr['role']) ? $attr['role'] : "public";
$function = new php_function($attr['name'], $this->func_summary, $this->func_proto, @$this->func_desc, @$this->func_code, $role);
switch($role) {
case "internal":
$this->internal_functions[$attr['name']] = $function;
break;
case "private":
$this->private_functions[$attr['name']] = $function;
break;
case "public":
$this->functions[$attr['name']] = $function;
break;
default:
$this->error("function role must be either public, private or internal");
break;
}
unset($this->func_summary);
unset($this->func_proto);
unset($this->func_desc);
@ -477,15 +494,20 @@ PHP_MINIT_FUNCTION({$this->name})
";
if(count($this->globals)) {
$code .= " ZEND_INIT_MODULE_GLOBALS({$this->name}, php_{$this->name}_init_globals, NULL)\n";
$code .= "\tZEND_INIT_MODULE_GLOBALS({$this->name}, php_{$this->name}_init_globals, NULL)\n";
}
if(count($this->phpini)) {
$code .= " REGISTER_INI_ENTRIES();\n";
$code .= "\tREGISTER_INI_ENTRIES();\n";
}
$code .="\n /* add your stuff here */\n";
if(isset($this->internal_functions['MINIT'])) {
if(count($this->globals) || count($this->phpini)) $code .= "\n\t{\n";
$code .= $this->internal_functions['MINIT']->code;
if(count($this->globals) || count($this->phpini)) $code .= "\n\t}\n";
} else {
$code .="\n\t/* add your stuff here */\n";
}
$code .= "
return SUCCESS;
}
@ -500,10 +522,16 @@ PHP_MSHUTDOWN_FUNCTION({$this->name})
";
if(count($this->phpini)) {
$code .= " UNREGISTER_INI_ENTRIES();\n";
$code .= "\tUNREGISTER_INI_ENTRIES();\n";
}
$code .="\n /* add your stuff here */\n";
if(isset($this->internal_functions['MSHUTDOWN'])) {
if(count($this->phpini)) $code .= "\n\t{\n";
$code .= $this->internal_functions['MSHUTDOWN']->code;
if(count($this->phpini)) $code .= "\n\t}\n";
} else {
$code .="\n\t/* add your stuff here */\n";
}
$code .= "
return SUCCESS;
@ -516,9 +544,16 @@ PHP_MSHUTDOWN_FUNCTION({$this->name})
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION({$this->name})
{
/* add your stuff here */
";
return SUCCESS;
if(isset($this->internal_functions['RINIT'])) {
$code .= $this->internal_functions['RINIT']->code;
} else {
$code .= " /* add your stuff here */\n";
}
$code .= "
\treturn SUCCESS;
}
/* }}} */
@ -528,9 +563,16 @@ PHP_RINIT_FUNCTION({$this->name})
/* {{{ PHP_RSHUTDOWN_FUNCTION */
PHP_RSHUTDOWN_FUNCTION({$this->name})
{
/* add your stuff here */
";
return SUCCESS;
if(isset($this->internal_functions['RSHUTDOWN'])) {
$code .= $this->internal_functions['RSHUTDOWN']->code;
} else {
$code .= " /* add your stuff here */\n";
}
$code .= "
\treturn SUCCESS;
}
/* }}} */
@ -540,15 +582,23 @@ PHP_RSHUTDOWN_FUNCTION({$this->name})
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION({$this->name})
{
php_info_print_table_start();
php_info_print_table_header(2, \"{$this->name} support\", \"enabled\");
php_info_print_table_end();
\tphp_info_print_table_start();
\tphp_info_print_table_header(2, \"{$this->name} support\", \"enabled\");
\tphp_info_print_table_end();
/* add your stuff here */
";
if(isset($this->internal_functions['MINFO'])) {
$code .= "\n\t{\n";
$code .= $this->internal_functions['MINFO']->code;
$code .= "\n\t}\n";
} else {
$code .= "\t/* add your stuff here */\n";
}
if(count($this->phpini)) {
$code .= "\n DISPLAY_INI_ENTRIES();";
$code .= "\n\tDISPLAY_INI_ENTRIES();";
}
$code .= "
}
@ -562,6 +612,16 @@ $code .= "
// }}}
function private_functions_c() {
$code = "";
foreach ($this->private_functions as $name => $func) {
$code .= "\n\t/* {{{ $name() */\n{$func->code}\n\t/* }}} */\n\n";
}
return $code;
}
// {{{ public functions
function public_functions_c() {
@ -749,7 +809,7 @@ $code .= "
fputs($fp, "/* {{{ {$this->name}_functions[] */\n");
fputs($fp, "function_entry {$this->name}_functions[] = {\n");
foreach($this->functions as $name => $function) {
fputs($fp, sprintf(" PHP_FE(%-20s, NULL)\n",$name));
fputs($fp, sprintf("\tPHP_FE(%-20s, NULL)\n",$name));
}
fputs($fp, "};\n/* }}} */\n\n");
@ -761,6 +821,8 @@ $code .= "
fputs($fp, $this->internal_functions_c());
fputs($fp, $this->private_functions_c());
fputs($fp, $this->public_functions_c());
fputs($fp, $this->editor_config_c());

View file

@ -2,12 +2,13 @@
class php_function extends php_element {
// all known php types
function php_function($name, $summary, $proto, $desc="", $code="") {
function php_function($name, $summary, $proto, $desc="", $code="", $role="") {
$this->name = $name;
$this->summary = $summary;
$this->parse_proto($proto);
$this->desc = empty($desc) ? "&warn.undocumented.func;" : $desc;
$this->code = $code;
$this->role = empty($role) ? "public" : $role;
if($this->role === "public") $this->parse_proto($proto);
}
function parse_proto($proto) {
@ -76,6 +77,10 @@
}
function c_code() {
$code = "";
switch($this->role) {
case "public":
$code .= "\n/* {{{ proto {$this->returns} {$this->name}(";
if(isset($this->params)) {
foreach($this->params as $param) {
@ -160,7 +165,18 @@
}
$code .= "\tphp_error(E_WARNING, \"{$this->name}: not yet implemented\");\n";
$code .= "}\n/* }}} */\n\n";
break;
case "internal":
if(!empty($this->code)) {
$code .= "\t\t{\n";
$code .= $this->code."\n";
$code .= "\t\t}\n";
}
break;
case "private":
$code .= $this->code."\n";
break;
}
return $code;
}