]> granicus.if.org Git - php/commitdiff
code for the special functions MINIT, MSHUTDOWN, RINIT, RSHUTDOWN, MINFO
authorHartmut Holzgraefe <hholzgra@php.net>
Wed, 19 Feb 2003 16:02:45 +0000 (16:02 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Wed, 19 Feb 2003 16:02:45 +0000 (16:02 +0000)
and for private internal C helper functions may now be embedded into
the XML specification

scripts/ext_skel_ng/extension.xml
scripts/ext_skel_ng/extension_parser.php
scripts/ext_skel_ng/php_function.php

index 67adaf7a65e0366735c3342526b1c964dd7d101c..65a7cf8a9af2f090fc2162018ae6951a8207ae30 100644 (file)
       </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>
index 63fd644250f6288a160df494494fc71816950ee6..fd3c54531ac3259fe6216b5f70eb76de140d36dc 100644 (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();
                }
 
                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());
index c9abe7303563888346b12a0fc7bfbb4f1f577507..c5df80893fdcebd9da3e490ad14d8a7f7f71d2e0 100644 (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) {
                }
 
                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) {
                        }
                        $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;
                }