cvs: php-gtk /generator Getopt.php gdk.overrides generator.php gtk.defs gtk.overrides make_reg_items.php templates.php
| From: | Andrei Zmievski | Date: | Tue, 13 Mar 2001 05:48:58 +0000 |
| Subject: | cvs: php-gtk /generator Getopt.php gdk.overrides generator.php gtk.defs gtk.overrides make_reg_items.php templates.php | ||
| Groups: | php.gtk | ||
| Request: | Send a blank email to php-gtk+get-752@lists.php.net to get a copy of this message | ||
andrei Mon Mar 12 21:48:58 2001 EDT
Added files:
/php-gtk/generator Getopt.php gdk.overrides make_reg_items.php
Modified files:
/php-gtk/generator generator.php gtk.defs gtk.overrides
templates.php
Log:
Generalized the generator system:
* removed all static content into templates
* everything is now generated just from defs, overrides, and prefix
* removed byref parsing, since it will be transformed into something new
* added ability to specify defs files to register types from
* split out gdk part of overrides into gdk.overrides
Basically, all the generation is based on a concept of a module. For each
module there is .defs file and .overrides file. The generated file is
php_gtk_<module>.c. There are a couple more generated files that get
included by the main source in order to declare class entries, and
register classes and constants.
Also, made Gdk::input_add() work with PHP file resources.
Index: php-gtk/generator/generator.php diff -u php-gtk/generator/generator.php:1.17 php-gtk/generator/generator.php:1.18 --- php-gtk/generator/generator.php:1.17 Thu Mar 8 22:56:31 2001 +++ php-gtk/generator/generator.php Mon Mar 12 21:48:58 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: generator.php,v 1.17 2001/03/09 06:56:31 fmk Exp $ */ +/* $Id: generator.php,v 1.18 2001/03/13 05:48:58 andrei Exp $ */ /* * Significant portions of this generator are based on the pygtk code generator @@ -29,6 +29,7 @@ set_time_limit(300); +require "Getopt.php"; require "arg_types.php"; require "override.php"; require "scheme.php"; @@ -39,14 +40,12 @@ var $overrides = null; var $prefix = null; - var $constants = "/* Generated from gtk.defs */\n\n"; + var $constants = ''; + var $register_classes = ''; + var $class_entries = array(); - var $function_entry = "\nstatic function_entry %s_functions[] = {\n"; - var $function_entry_end = "\t{NULL, NULL, NULL}\n};\n\n"; - var $register_classes = "\nvoid php_gtk_register_classes(void)\n{\n\tzend_class_entry ce;\n"; + var $functions_decl_end = "\t{NULL, NULL, NULL}\n};\n\n"; - var $byref_def = array(); - function Generator(&$parser, &$overrides, $prefix) { $this->parser = &$parser; @@ -54,14 +53,17 @@ $this->prefix = $prefix; } - function register_types() + function register_types($parser = null) { global $matcher; - foreach ($this->parser->objects as $object) + if (!$parser) + $parser = $this->parser; + + foreach ($parser->objects as $object) $matcher->register_object($object->c_name); - foreach ($this->parser->enums as $enum) { + foreach ($parser->enums as $enum) { if ($enum->def_type == 'flags') $matcher->register_flag($enum->c_name); else @@ -69,22 +71,9 @@ } } - function parse_byref($parse_type) - { - $byref_name = "NULL"; - if (trim(implode('', $parse_type))) { - $byref_name = str_replace(' ', 'A', implode('', $parse_type)); - if (!isset($this->byref_def[$byref_name])) { - $this->byref_def[$byref_name] = sprintf("unsigned char byref_" . $byref_name . "[] = {%d, %s};\n", sizeof($parse_type), str_replace(' ', 'BYREF_NONE', str_replace('F', 'BYREF_FORCE', implode(',', $parse_type)))); - } - $byref_name = "byref_$byref_name"; - } - return $byref_name; - } - function write_constants($fp) { - fwrite($fp, "\nvoid php_gtk_register_constants(int module_number ELS_DC)\n"); + fwrite($fp, "\nvoid php_". $this->prefix . "_register_constants(int module_number ELS_DC)\n"); fwrite($fp, "{\n"); foreach ($this->parser->enums as $enum) { if ($this->overrides->is_ignored($enum->c_name)) continue; @@ -149,7 +138,7 @@ $ret_handler = &$matcher->get($method->return_type); if ($ret_handler === null) { error_log("Could not write function $method->name (return type $method->return_type)"); - return; + return false; } $return_tpl = $ret_handler->write_return($method->return_type, $var_list); $return_code = sprintf($return_tpl, @@ -166,7 +155,7 @@ fwrite($fp, $method_code); - return $this->parse_byref($parse_type); + return true; } function write_constructor($fp, $obj_name, $constructor) @@ -191,7 +180,7 @@ $handler = &$matcher->get($param_type); if ($handler === null) { error_log("Could not write constructor $constructor->name (parameter type $param_type)"); - return; + return false; } $specs .= $handler->write_param($param_type, $param_name, @@ -224,8 +213,8 @@ $obj_name); fwrite($fp, $constructor_code); - - return $this->parse_byref($parse_type); + + return true; } function write_function($fp, $function) @@ -254,7 +243,7 @@ $handler = &$matcher->get($param_type); if ($handler === null) { error_log("Could not write function $function->name (parameter type $param_type)"); - return; + return false; } $specs .= $handler->write_param($param_type, $param_name, @@ -297,7 +286,7 @@ fwrite($fp, $function_code); - return $this->parse_byref($parse_type); + return true; } function write_prop_getter($fp, $object) @@ -342,17 +331,13 @@ $prop_checks)); } - function write_static_vars($fp) { - fwrite($fp, "\n/* static variables */\n"); - foreach ($this->parser->objects as $object) - fwrite($fp, "static zend_class_entry *$object->ce;\n"); - } - function write_objects($fp) { global $function_entry_tpl, + $functions_decl_tpl, $register_getter_tpl, $init_class_tpl, + $register_class_tpl, $get_type_tpl; foreach ($this->parser->objects as $object) { @@ -362,41 +347,48 @@ fwrite($fp, "\n/* object $object->c_name */\n"); $this->register_classes .= sprintf($init_class_tpl, $object_module . $object_lname, - 'php_' . $object_module . '_' . $object_lname, + $object_module . '_' . $object_lname, count($object->fields) ? 'php_gtk_get_property' : 'NULL'); - if ($object->parent == null) - $this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; + if ($object->parent === null) + $this->register_classes .= sprintf($register_class_tpl, + $object->ce, + 'NULL'); else { - $parent_obj = $this->parser->find_parent($object); - $this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, $parent_obj->ce, NULL);\n" . - "\tg_hash_table_insert(php_gtk_class_hash, g_strdup(\"Gtk$object->name\"), $object->ce);\n"; + if ($object->parent[1] === null) + $parent_ce = strtolower($object->parent[0]) . '_ce'; + else + $parent_ce = strtolower($object->parent[1] . '_' . $object->parent[0]) . '_ce'; + $this->register_classes .= sprintf($register_class_tpl, + $object->ce, + $parent_ce); + $this->register_classes .= "\tg_hash_table_insert(php_gtk_class_hash, g_strdup(\"Gtk$object->name\"), $object->ce);\n"; } if (count($object->fields)) { $this->register_classes .= sprintf($register_getter_tpl, $object->ce, $object_module . '_' . $object_lname); } - $function_entry = sprintf($this->function_entry, $this->prefix . "_" . $object_lname); + $functions_decl = sprintf($functions_decl_tpl, $object_module . '_' . $object_lname); $constructor = $this->parser->find_constructor($object); if (!$constructor || $this->overrides->is_ignored($constructor->c_name)) { - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($object->c_name), 'no_constructor', 'NULL'); } else if ($this->overrides->is_overriden($constructor->c_name)) { list(, $constructor_override) = $this->overrides->get_override($constructor->c_name); fwrite($fp, $constructor_override . "\n"); - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($constructor->is_constructor_of), strtolower($constructor->c_name), 'NULL'); } else if (!$this->overrides->is_ignored($constructor->c_name)) { - if ($byref = $this->write_constructor($fp, $object->c_name, $constructor)) { - $function_entry .= sprintf($function_entry_tpl, + if ($this->write_constructor($fp, $object->c_name, $constructor)) { + $functions_decl .= sprintf($function_entry_tpl, strtolower($constructor->is_constructor_of), strtolower($constructor->c_name), - $byref); + 'NULL'); } else { - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($constructor->is_constructor_of), 'no_constructor', 'NULL'); } @@ -404,7 +396,7 @@ /* insert get_type() as class method */ $lclass = strtolower(substr(convert_typename($object->c_name), 1)); - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, 'get_type', $lclass . '_get_type', 'NULL'); @@ -416,17 +408,17 @@ fwrite($fp, $method_override . "\n"); if (!isset($method_name)) $method_name = $method->name; - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($method->name), strtolower($method->c_name), 'NULL'); } else if (!$this->overrides->is_ignored($method->c_name)) { - if ($byref = $this->write_method($fp, $object->c_name, $method)) { - $function_entry .= sprintf($function_entry_tpl, + if ($this->write_method($fp, $object->c_name, $method)) { + $functions_decl .= sprintf($function_entry_tpl, strtolower($method->name), strtolower($method->c_name), - $byref); + 'NULL'); } } @@ -438,118 +430,124 @@ fwrite($fp, $method_override . "\n"); if (!isset($method_name)) $method_name = $method_cname; - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($method_name), strtolower($method_cname), 'NULL'); } } - $function_entry .= $this->function_entry_end; - fwrite($fp, $function_entry); + $functions_decl .= $this->functions_decl_end; + fwrite($fp, $functions_decl); if (count($object->fields)) $this->write_prop_getter($fp, $object); } + + $this->register_classes .= "\n" . implode("\n", $this->overrides->get_register_classes()); } function write_functions($fp) { - global $function_entry_tpl; + global $function_entry_tpl, + $functions_decl_tpl, + $init_class_tpl, + $register_class_tpl; - fwrite($fp, "\n/* object Gtk */\n"); - fwrite($fp, "static zend_class_entry *gdk_ce;\n"); - fwrite($fp, "static zend_class_entry *gtk_ce;\n"); - fwrite($fp, "static zend_class_entry *gtk_box_child_ce;\n"); - $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gdk\", php_gdk_functions);\n" - . "\tgdk_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; - $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gtk\", php_gtk_functions);\n" - . "\tgtk_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; - $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gtkboxchild\", NULL);\n" - . "\tgtk_box_child_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; - $function_entry["gdk"] = sprintf($this->function_entry, 'php_gdk'); - $function_entry["gtk"] = sprintf($this->function_entry, $this->prefix); + $this->register_classes .= sprintf($init_class_tpl, + $this->prefix, + $this->prefix, + 'NULL'); + $this->register_classes .= sprintf($register_class_tpl, + $this->prefix . '_ce', + 'NULL'); + $functions_decl = sprintf($functions_decl_tpl, $this->prefix); foreach ($this->parser->functions as $function) { if ($this->overrides->is_overriden($function->c_name)) { list($function_name, $function_override) = $this->overrides->get_override($function->c_name); fwrite($fp, $function_override . "\n"); if ($function->name == $function->c_name) - $function_name = substr($function->name, 4); + $function_name = substr($function->name, strlen($this->prefix) + 1); else $function_name = $function->name; - $function_entry[substr($function->c_name, 0, 3)] .= sprintf($function_entry_tpl, - strtolower($function_name), - strtolower($function->c_name), - 'NULL'); + $functions_decl .= sprintf($function_entry_tpl, + strtolower($function_name), + strtolower($function->c_name), + 'NULL'); } else if (!$this->overrides->is_ignored($function->c_name)) { - if ($byref = $this->write_function($fp, $function)) { + if ($this->write_function($fp, $function)) { if ($function->name == $function->c_name) - $function_name = substr($function->name, 4); + $function_name = substr($function->name, strlen($this->prefix) + 1); else $function_name = $function->name; - $function_entry[substr($function->c_name, 0, 3)] .= sprintf($function_entry_tpl, - $function_name, - strtolower($function->c_name), - $byref); + $functions_decl .= sprintf($function_entry_tpl, + $function_name, + strtolower($function->c_name), + 'NULL'); } } } - $function_entry["gdk"] .= $this->function_entry_end; - $function_entry["gtk"] .= $this->function_entry_end; - fwrite($fp, $function_entry["gdk"]); - fwrite($fp, $function_entry["gtk"]); + $functions_decl .= $this->functions_decl_end; + fwrite($fp, $functions_decl); } + + function write_class_entries($fp) + { + global $class_entry_tpl; - function write_no_constructor($fp) - { - fwrite($fp, "PHP_FUNCTION(wrap_no_constructor)\n" . - "{\n" . - " php_error(E_WARNING, \"%s: An abstract or unimplemented class\", get_active_function_name());\n" . - " php_gtk_invalidate(this_ptr);\n" . - "}\n\n"); + fwrite($fp, sprintf($class_entry_tpl, $this->prefix . '_ce')); + foreach ($this->parser->objects as $object) + fwrite($fp, sprintf($class_entry_tpl, $object->ce)); + foreach ($this->overrides->get_register_classes() as $ce => $rest) + fwrite($fp, sprintf($class_entry_tpl, $ce)); } function create_source() { - /* Rename to php_gtk_gen.c */ - if ($fp = fopen("../src/php_gtk_gen.c", "w")) { - fwrite($fp, "\n#include \"php_gtk.h\"\n"); - fwrite($fp, "\n#if HAVE_PHP_GTK\n"); - fwrite($fp, "\n#include \"php_gtk_gen.h\"\n"); - $this->write_constants($fp); - $this->write_static_vars($fp); - $this->write_functions($fp); - $this->write_no_constructor($fp); - $this->write_objects($fp); - fwrite($fp, $this->register_classes . "}\n"); - fwrite($fp, "\n#endif HAVE_PHP_GTK\n"); - fclose($fp); - } + global $register_classes_tpl; - if ($fp = fopen("../src/php_gtk_gen.h", "w")) { - fwrite($fp, implode('', $this->byref_def)); - fclose($fp); - } + $fp = fopen('../src/php_gtk_gen_' . $this->prefix . '.c', 'w'); + fwrite($fp, "#include \"php_gtk.h\""); + fwrite($fp, "\n#if HAVE_PHP_GTK\n"); + fwrite($fp, $this->overrides->get_headers()); + $this->write_constants($fp); + $this->write_class_entries($fp); + $this->write_functions($fp); + $this->write_objects($fp); + fwrite($fp, sprintf($register_classes_tpl, + $this->prefix, + $this->register_classes)); + fwrite($fp, "\n#endif /* HAVE_PHP_GTK */\n"); + fclose($fp); } } $argc = $HTTP_SERVER_VARS['argc']; $argv = $HTTP_SERVER_VARS['argv']; -if ($argc < 2) - die("usage: php -q generator.php defsfile [overridesfile [prefix]]\n"); - -if ($argc > 2) { - $overrides = new Overrides($argv[2]); - if ($argc > 3) - $prefix = $argv[3]; - else - $prefix = 'php_gtk'; +$result = Console_Getopt::getopt($argv, 'o:p:r:'); +if (!$result || count($result[1]) < 2) + die("usage: php -q generator.php [-o overridesfile] [-p prefix] [-r typesfile] defsfile\n"); + +list($opts, $argv) = $result; + +$prefix = 'gtk'; +$overrides = new Overrides(); + +foreach ($opts as $opt) { + list($opt_spec, $opt_arg) = $opt; + if ($opt_spec == 'o') { + $overrides = new Overrides($opt_arg); + } else if ($opt_spec == 'p') { + $prefix = $opt_arg; + } else if ($opt_spec == 'r') { + $type_parser = new Defs_Parser($opt_arg); + $type_parser->start_parsing(); + Generator::register_types($type_parser); + } } -else - $overrides = new Overrides(); $parser = new Defs_Parser($argv[1]); $generator = new Generator($parser, $overrides, $prefix); Index: php-gtk/generator/gtk.defs diff -u php-gtk/generator/gtk.defs:1.6 php-gtk/generator/gtk.defs:1.7 --- php-gtk/generator/gtk.defs:1.6 Fri Mar 9 11:43:59 2001 +++ php-gtk/generator/gtk.defs Mon Mar 12 21:48:58 2001 @@ -1,7 +1,5 @@ ;; -*- scheme -*- -(include "gdk.defs") - ; object definitions ... (object Object (in-module Gtk) Index: php-gtk/generator/gtk.overrides diff -u php-gtk/generator/gtk.overrides:1.29 php-gtk/generator/gtk.overrides:1.30 --- php-gtk/generator/gtk.overrides:1.29 Thu Mar 8 20:33:35 2001 +++ php-gtk/generator/gtk.overrides Mon Mar 12 21:48:58 2001 @@ -145,8 +145,6 @@ %% ignore GtkPrivateFlags - GdkDebugFlag - GdkColorInfoFlags %% ignore gtk_container_dequeue_resize_handler @@ -168,6 +166,10 @@ %% ignore-glob gtk_radio_button_new_* %% +register_class gtk_box_child_ce + INIT_CLASS_ENTRY(ce, "gtkboxchild", NULL); + gtk_box_child_ce = zend_register_internal_class_ex(&ce, NULL, NULL); +%% override gtk_true PHP_FUNCTION(wrap_gtk_true) { @@ -266,7 +268,9 @@ override gtk_input_add_full PHP_FUNCTION(wrap_gtk_input_add_full) { - int source; + zval *source_rsrc; + int rsrc_type; + int *source; GdkInputCondition condition; zval *callback = NULL; zval *extra, *data; @@ -279,14 +283,20 @@ return; } - if (!php_gtk_parse_args(3, "iiV", &source, &condition, &callback)) + if (!php_gtk_parse_args(3, "riV", &source_rsrc, &condition, &callback)) return; + source = zend_list_find(Z_LVAL_P(source_rsrc), &rsrc_type); + if (!source || rsrc_type != php_file_le_fopen()) { + php_error(E_WARNING, "%s() expects argument 1 to be a valid filehandle resource", get_active_function_name()); + return; + } + callback_filename = zend_get_executed_filename(ELS_C); callback_lineno = zend_get_executed_lineno(ELS_C); extra = php_gtk_func_args_as_hash(ZEND_NUM_ARGS(), 3, ZEND_NUM_ARGS()); data = php_gtk_build_value("(VNsi)", callback, extra, callback_filename, callback_lineno); - RETURN_LONG(gtk_input_add_full(source, condition, NULL, + RETURN_LONG(gtk_input_add_full(*source, condition, NULL, (GtkCallbackMarshal)php_gtk_input_marshal, data, php_gtk_destroy_notify)); } @@ -586,22 +596,6 @@ php_gtk_object_init(wrapped_obj, this_ptr); } %% -override gdk_color_parse -PHP_FUNCTION(wrap_gdk_color_parse) -{ - gchar *color_spec; - GdkColor color; - - if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "s", &color_spec)) { - return; - } - - if (gdk_color_parse(color_spec, &color)) - *return_value = *php_gdk_color_new(&color); - else - php_error(E_WARNING, "%s() could not parse color spec '%s'", get_active_function_name(), color_spec); -} -%% override gtk_list_append_items PHP_FUNCTION(wrap_gtk_list_append_items) { @@ -906,15 +900,15 @@ zval **callback_filename, **callback_lineno; zval *params; zval ***args; - gchar *callable_name; + char *callback_name; ELS_FETCH(); zend_hash_index_find(Z_ARRVAL_P(callback_data), 0, (void **)&callback); zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&callback_filename); zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&callback_lineno); - if (!php_gtk_is_callable(*callback, &callable_name)) { - php_error(E_WARNING, "unable to call item factory callback '%s' specified in %s on line %d", callable_name, Z_STRVAL_PP(callback_filename), Z_LVAL_PP(callback_lineno)); - g_free(callable_name); + if (!php_gtk_is_callable(*callback, 0, &callback_name)) { + php_error(E_WARNING, "unable to call item factory callback '%s' specified in %s on line %d", callback_name, Z_STRVAL_PP(callback_filename), Z_LVAL_PP(callback_lineno)); + efree(callback_name); return; } Index: php-gtk/generator/templates.php diff -u php-gtk/generator/templates.php:1.8 php-gtk/generator/templates.php:1.9 --- php-gtk/generator/templates.php:1.8 Thu Mar 8 20:33:35 2001 +++ php-gtk/generator/templates.php Mon Mar 12 21:48:58 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: templates.php,v 1.8 2001/03/09 04:33:35 andrei Exp $ */ +/* $Id: templates.php,v 1.9 2001/03/13 05:48:58 andrei Exp $ */ $function_tpl = " PHP_FUNCTION(wrap_%s) @@ -66,6 +66,9 @@ }\n\n"; $function_entry_tpl = "\t{\"%s\", PHP_FN(wrap_%s), %s},\n"; +$functions_decl_tpl = " +static function_entry php_%s_functions[] = { +"; $register_getter_tpl = "\tphp_gtk_register_prop_getter(%s, %s_get_property);\n"; @@ -87,7 +90,8 @@ *found = FAILURE; }\n\n"; -$init_class_tpl = "\n\tINIT_OVERLOADED_CLASS_ENTRY(ce, \"%s\", %s_functions, NULL, %s, NULL);\n"; +$init_class_tpl = " + INIT_OVERLOADED_CLASS_ENTRY(ce, \"%s\", php_%s_functions, NULL, %s, NULL);\n"; $get_type_tpl = " PHP_FUNCTION(wrap_%s_get_type) @@ -97,5 +101,17 @@ RETURN_LONG(%s_get_type()); }\n\n"; + +$register_classes_tpl = " +void php_%s_register_classes(void) +{ + zend_class_entry ce; +%s +}\n"; + + +$register_class_tpl = "\t%s = zend_register_internal_class_ex(&ce, %s, NULL);\n"; + +$class_entry_tpl = "zend_class_entry *%s;\n"; ?> Index: php-gtk/generator/Getopt.php +++ php-gtk/generator/Getopt.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 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. | // +----------------------------------------------------------------------+ // | Authors: Andrei Zmievski <andrei@ispi.net> | // +----------------------------------------------------------------------+ // // $Id: Getopt.php,v 1.1 2001/03/13 05:48:58 andrei Exp $ /** * Command-line options parsing class. * * @author Andrei Zmievski <andrei@ispi.net> * */ class Console_Getopt { /** * Parses the command-line options. * * The first parameter to this function should be the list of command-line * arguments without the leading reference to the running program. * * The second parameter is a string of allowed short options. Each of the * option letters can be followed by a colon ':' to specify that the option * requires an argument, or a double colon '::' to specify that the option * takes an optional argument. * * The third argument is an optional array of allowed long options. The * leading '--' should not be included in the option name. Options that * require an argument should be followed by '=', and options that take an * option argument should be followed by '=='. * * The return value is an array of two elements: the list of parsed * options and the list of non-option command-line arguments. Each entry in * the list of parsed options is a pair of elements - the first one * specifies the option, and the second one specifies the option argument, * if there was one. * * Long and short options can be mixed. * * Most of the semantics of this function are based on GNU getopt_long(). * * @param $args array an array of command-line arguments * @param $short_options string specifies the list of allowed short options * @param $long_options array specifies the list of allowed long options * * @return array two-element array containing the list of parsed options and * the non-option arguments * * @access public * */ function getopt($args, $short_options, $long_options = null) { $opts = array(); $non_opts = array(); settype($args, 'array'); if ($long_options) sort($long_options); reset($args); while (list(, $arg) = each($args)) { /* The special element '--' means explicit end of options. Treat the rest of the arguments as non-options and end the loop. */ if ($arg == '--') { $non_opts = array_merge($non_opts, array_slice($args, $i + 1)); break; } if ($arg{0} != '-' || ($arg{1} == '-' && !$long_options)) { $non_opts[] = $arg; } else if ($arg{1} == '-') { if (!Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args)) return false; } else { if (!Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args)) return false; } } return array($opts, $non_opts); } /** * @access private * */ function _parseShortOption($arg, $short_options, &$opts, &$args) { for ($i = 0; $i < strlen($arg); $i++) { $opt = $arg{$i}; $opt_arg = null; /* Try to find the short option in the specifier string. */ if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') { return false; } if ($spec{1} == ':') { if ($spec{2} == ':') { if ($i + 1 < strlen($arg)) { /* Option takes an optional argument. Use the remainder of the arg string if there is anything left. */ $opts[] = array($opt, substr($arg, $i + 1)); break; } } else { /* Option requires an argument. Use the remainder of the arg string if there is anything left. */ if ($i + 1 < strlen($arg)) { $opts[] = array($opt, substr($arg, $i + 1)); break; } else if (list(, $opt_arg) = each($args)) /* Else use the next argument. */; else return false; } } $opts[] = array($opt, $opt_arg); return true; } } /** * @access private * */ function _parseLongOption($arg, $long_options, &$opts, &$args) { list($opt, $opt_arg) = explode('=', $arg); $opt_len = strlen($opt); for ($i = 0; $i < count($long_options); $i++) { $long_opt = $long_options[$i]; $opt_start = substr($long_opt, 0, $opt_len); /* Option doesn't match. Go on to the next one. */ if ($opt_start != $opt) continue; $opt_rest = substr($long_opt, $opt_len); /* Check that the options uniquely matches one of the allowed options. */ if ($opt_rest != '' && $opt{0} != '=' && $i + 1 < count($long_options) && $opt == substr($long_options[$i+1], 0, $opt_len)) { return false; } if (substr($long_opt, -1) == '=') { if (substr($long_opt, -2) != '==') { /* Long option requires an argument. Take the next argument if one wasn't specified. */; if (!$opt_arg && !(list(, $opt_arg) = each($args))) { return false; } } } else if ($opt_arg) { return false; } $opts[] = array('--' . substr($long_opt, 0, strpos($long_opt, '=')), $opt_arg); return true; } return false; } } ?> Index: php-gtk/generator/gdk.overrides +++ php-gtk/generator/gdk.overrides /* vim: set ft=cpp: */ %% ignore GdkDebugFlag GdkColorInfoFlags %% override gdk_color_parse PHP_FUNCTION(wrap_gdk_color_parse) { gchar *color_spec; GdkColor color; if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "s", &color_spec)) { return; } if (gdk_color_parse(color_spec, &color)) *return_value = *php_gdk_color_new(&color); else php_error(E_WARNING, "%s() could not parse color spec '%s'", get_active_function_name(), color_spec); } Index: php-gtk/generator/make_reg_items.php +++ php-gtk/generator/make_reg_items.php <?php $fp = fopen('../src/php_gtk_gen_reg_items.h', 'w'); foreach (array_slice($argv, 1) as $module) { fwrite($fp, " php_" . $module . "_register_classes();\n"); fwrite($fp, " php_" . $module . "_register_constants(module_number ELS_CC);\n"); } fclose($fp); ?>
Index: php-gtk/generator/generator.php diff -u php-gtk/generator/generator.php:1.17 php-gtk/generator/generator.php:1.18 --- php-gtk/generator/generator.php:1.17 Thu Mar 8 22:56:31 2001 +++ php-gtk/generator/generator.php Mon Mar 12 21:48:58 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: generator.php,v 1.17 2001/03/09 06:56:31 fmk Exp $ */ +/* $Id: generator.php,v 1.18 2001/03/13 05:48:58 andrei Exp $ */ /* * Significant portions of this generator are based on the pygtk code generator @@ -29,6 +29,7 @@ set_time_limit(300); +require "Getopt.php"; require "arg_types.php"; require "override.php"; require "scheme.php"; @@ -39,14 +40,12 @@ var $overrides = null; var $prefix = null; - var $constants = "/* Generated from gtk.defs */\n\n"; + var $constants = ''; + var $register_classes = ''; + var $class_entries = array(); - var $function_entry = "\nstatic function_entry %s_functions[] = {\n"; - var $function_entry_end = "\t{NULL, NULL, NULL}\n};\n\n"; - var $register_classes = "\nvoid php_gtk_register_classes(void)\n{\n\tzend_class_entry ce;\n"; + var $functions_decl_end = "\t{NULL, NULL, NULL}\n};\n\n"; - var $byref_def = array(); - function Generator(&$parser, &$overrides, $prefix) { $this->parser = &$parser; @@ -54,14 +53,17 @@ $this->prefix = $prefix; } - function register_types() + function register_types($parser = null) { global $matcher; - foreach ($this->parser->objects as $object) + if (!$parser) + $parser = $this->parser; + + foreach ($parser->objects as $object) $matcher->register_object($object->c_name); - foreach ($this->parser->enums as $enum) { + foreach ($parser->enums as $enum) { if ($enum->def_type == 'flags') $matcher->register_flag($enum->c_name); else @@ -69,22 +71,9 @@ } } - function parse_byref($parse_type) - { - $byref_name = "NULL"; - if (trim(implode('', $parse_type))) { - $byref_name = str_replace(' ', 'A', implode('', $parse_type)); - if (!isset($this->byref_def[$byref_name])) { - $this->byref_def[$byref_name] = sprintf("unsigned char byref_" . $byref_name . "[] = {%d, %s};\n", sizeof($parse_type), str_replace(' ', 'BYREF_NONE', str_replace('F', 'BYREF_FORCE', implode(',', $parse_type)))); - } - $byref_name = "byref_$byref_name"; - } - return $byref_name; - } - function write_constants($fp) { - fwrite($fp, "\nvoid php_gtk_register_constants(int module_number ELS_DC)\n"); + fwrite($fp, "\nvoid php_". $this->prefix . "_register_constants(int module_number ELS_DC)\n"); fwrite($fp, "{\n"); foreach ($this->parser->enums as $enum) { if ($this->overrides->is_ignored($enum->c_name)) continue; @@ -149,7 +138,7 @@ $ret_handler = &$matcher->get($method->return_type); if ($ret_handler === null) { error_log("Could not write function $method->name (return type $method->return_type)"); - return; + return false; } $return_tpl = $ret_handler->write_return($method->return_type, $var_list); $return_code = sprintf($return_tpl, @@ -166,7 +155,7 @@ fwrite($fp, $method_code); - return $this->parse_byref($parse_type); + return true; } function write_constructor($fp, $obj_name, $constructor) @@ -191,7 +180,7 @@ $handler = &$matcher->get($param_type); if ($handler === null) { error_log("Could not write constructor $constructor->name (parameter type $param_type)"); - return; + return false; } $specs .= $handler->write_param($param_type, $param_name, @@ -224,8 +213,8 @@ $obj_name); fwrite($fp, $constructor_code); - - return $this->parse_byref($parse_type); + + return true; } function write_function($fp, $function) @@ -254,7 +243,7 @@ $handler = &$matcher->get($param_type); if ($handler === null) { error_log("Could not write function $function->name (parameter type $param_type)"); - return; + return false; } $specs .= $handler->write_param($param_type, $param_name, @@ -297,7 +286,7 @@ fwrite($fp, $function_code); - return $this->parse_byref($parse_type); + return true; } function write_prop_getter($fp, $object) @@ -342,17 +331,13 @@ $prop_checks)); } - function write_static_vars($fp) { - fwrite($fp, "\n/* static variables */\n"); - foreach ($this->parser->objects as $object) - fwrite($fp, "static zend_class_entry *$object->ce;\n"); - } - function write_objects($fp) { global $function_entry_tpl, + $functions_decl_tpl, $register_getter_tpl, $init_class_tpl, + $register_class_tpl, $get_type_tpl; foreach ($this->parser->objects as $object) { @@ -362,41 +347,48 @@ fwrite($fp, "\n/* object $object->c_name */\n"); $this->register_classes .= sprintf($init_class_tpl, $object_module . $object_lname, - 'php_' . $object_module . '_' . $object_lname, + $object_module . '_' . $object_lname, count($object->fields) ? 'php_gtk_get_property' : 'NULL'); - if ($object->parent == null) - $this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; + if ($object->parent === null) + $this->register_classes .= sprintf($register_class_tpl, + $object->ce, + 'NULL'); else { - $parent_obj = $this->parser->find_parent($object); - $this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, $parent_obj->ce, NULL);\n" . - "\tg_hash_table_insert(php_gtk_class_hash, g_strdup(\"Gtk$object->name\"), $object->ce);\n"; + if ($object->parent[1] === null) + $parent_ce = strtolower($object->parent[0]) . '_ce'; + else + $parent_ce = strtolower($object->parent[1] . '_' . $object->parent[0]) . '_ce'; + $this->register_classes .= sprintf($register_class_tpl, + $object->ce, + $parent_ce); + $this->register_classes .= "\tg_hash_table_insert(php_gtk_class_hash, g_strdup(\"Gtk$object->name\"), $object->ce);\n"; } if (count($object->fields)) { $this->register_classes .= sprintf($register_getter_tpl, $object->ce, $object_module . '_' . $object_lname); } - $function_entry = sprintf($this->function_entry, $this->prefix . "_" . $object_lname); + $functions_decl = sprintf($functions_decl_tpl, $object_module . '_' . $object_lname); $constructor = $this->parser->find_constructor($object); if (!$constructor || $this->overrides->is_ignored($constructor->c_name)) { - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($object->c_name), 'no_constructor', 'NULL'); } else if ($this->overrides->is_overriden($constructor->c_name)) { list(, $constructor_override) = $this->overrides->get_override($constructor->c_name); fwrite($fp, $constructor_override . "\n"); - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($constructor->is_constructor_of), strtolower($constructor->c_name), 'NULL'); } else if (!$this->overrides->is_ignored($constructor->c_name)) { - if ($byref = $this->write_constructor($fp, $object->c_name, $constructor)) { - $function_entry .= sprintf($function_entry_tpl, + if ($this->write_constructor($fp, $object->c_name, $constructor)) { + $functions_decl .= sprintf($function_entry_tpl, strtolower($constructor->is_constructor_of), strtolower($constructor->c_name), - $byref); + 'NULL'); } else { - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($constructor->is_constructor_of), 'no_constructor', 'NULL'); } @@ -404,7 +396,7 @@ /* insert get_type() as class method */ $lclass = strtolower(substr(convert_typename($object->c_name), 1)); - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, 'get_type', $lclass . '_get_type', 'NULL'); @@ -416,17 +408,17 @@ fwrite($fp, $method_override . "\n"); if (!isset($method_name)) $method_name = $method->name; - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($method->name), strtolower($method->c_name), 'NULL'); } else if (!$this->overrides->is_ignored($method->c_name)) { - if ($byref = $this->write_method($fp, $object->c_name, $method)) { - $function_entry .= sprintf($function_entry_tpl, + if ($this->write_method($fp, $object->c_name, $method)) { + $functions_decl .= sprintf($function_entry_tpl, strtolower($method->name), strtolower($method->c_name), - $byref); + 'NULL'); } } @@ -438,118 +430,124 @@ fwrite($fp, $method_override . "\n"); if (!isset($method_name)) $method_name = $method_cname; - $function_entry .= sprintf($function_entry_tpl, + $functions_decl .= sprintf($function_entry_tpl, strtolower($method_name), strtolower($method_cname), 'NULL'); } } - $function_entry .= $this->function_entry_end; - fwrite($fp, $function_entry); + $functions_decl .= $this->functions_decl_end; + fwrite($fp, $functions_decl); if (count($object->fields)) $this->write_prop_getter($fp, $object); } + + $this->register_classes .= "\n" . implode("\n", $this->overrides->get_register_classes()); } function write_functions($fp) { - global $function_entry_tpl; + global $function_entry_tpl, + $functions_decl_tpl, + $init_class_tpl, + $register_class_tpl; - fwrite($fp, "\n/* object Gtk */\n"); - fwrite($fp, "static zend_class_entry *gdk_ce;\n"); - fwrite($fp, "static zend_class_entry *gtk_ce;\n"); - fwrite($fp, "static zend_class_entry *gtk_box_child_ce;\n"); - $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gdk\", php_gdk_functions);\n" - . "\tgdk_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; - $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gtk\", php_gtk_functions);\n" - . "\tgtk_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; - $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gtkboxchild\", NULL);\n" - . "\tgtk_box_child_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; - $function_entry["gdk"] = sprintf($this->function_entry, 'php_gdk'); - $function_entry["gtk"] = sprintf($this->function_entry, $this->prefix); + $this->register_classes .= sprintf($init_class_tpl, + $this->prefix, + $this->prefix, + 'NULL'); + $this->register_classes .= sprintf($register_class_tpl, + $this->prefix . '_ce', + 'NULL'); + $functions_decl = sprintf($functions_decl_tpl, $this->prefix); foreach ($this->parser->functions as $function) { if ($this->overrides->is_overriden($function->c_name)) { list($function_name, $function_override) = $this->overrides->get_override($function->c_name); fwrite($fp, $function_override . "\n"); if ($function->name == $function->c_name) - $function_name = substr($function->name, 4); + $function_name = substr($function->name, strlen($this->prefix) + 1); else $function_name = $function->name; - $function_entry[substr($function->c_name, 0, 3)] .= sprintf($function_entry_tpl, - strtolower($function_name), - strtolower($function->c_name), - 'NULL'); + $functions_decl .= sprintf($function_entry_tpl, + strtolower($function_name), + strtolower($function->c_name), + 'NULL'); } else if (!$this->overrides->is_ignored($function->c_name)) { - if ($byref = $this->write_function($fp, $function)) { + if ($this->write_function($fp, $function)) { if ($function->name == $function->c_name) - $function_name = substr($function->name, 4); + $function_name = substr($function->name, strlen($this->prefix) + 1); else $function_name = $function->name; - $function_entry[substr($function->c_name, 0, 3)] .= sprintf($function_entry_tpl, - $function_name, - strtolower($function->c_name), - $byref); + $functions_decl .= sprintf($function_entry_tpl, + $function_name, + strtolower($function->c_name), + 'NULL'); } } } - $function_entry["gdk"] .= $this->function_entry_end; - $function_entry["gtk"] .= $this->function_entry_end; - fwrite($fp, $function_entry["gdk"]); - fwrite($fp, $function_entry["gtk"]); + $functions_decl .= $this->functions_decl_end; + fwrite($fp, $functions_decl); } + + function write_class_entries($fp) + { + global $class_entry_tpl; - function write_no_constructor($fp) - { - fwrite($fp, "PHP_FUNCTION(wrap_no_constructor)\n" . - "{\n" . - " php_error(E_WARNING, \"%s: An abstract or unimplemented class\", get_active_function_name());\n" . - " php_gtk_invalidate(this_ptr);\n" . - "}\n\n"); + fwrite($fp, sprintf($class_entry_tpl, $this->prefix . '_ce')); + foreach ($this->parser->objects as $object) + fwrite($fp, sprintf($class_entry_tpl, $object->ce)); + foreach ($this->overrides->get_register_classes() as $ce => $rest) + fwrite($fp, sprintf($class_entry_tpl, $ce)); } function create_source() { - /* Rename to php_gtk_gen.c */ - if ($fp = fopen("../src/php_gtk_gen.c", "w")) { - fwrite($fp, "\n#include \"php_gtk.h\"\n"); - fwrite($fp, "\n#if HAVE_PHP_GTK\n"); - fwrite($fp, "\n#include \"php_gtk_gen.h\"\n"); - $this->write_constants($fp); - $this->write_static_vars($fp); - $this->write_functions($fp); - $this->write_no_constructor($fp); - $this->write_objects($fp); - fwrite($fp, $this->register_classes . "}\n"); - fwrite($fp, "\n#endif HAVE_PHP_GTK\n"); - fclose($fp); - } + global $register_classes_tpl; - if ($fp = fopen("../src/php_gtk_gen.h", "w")) { - fwrite($fp, implode('', $this->byref_def)); - fclose($fp); - } + $fp = fopen('../src/php_gtk_gen_' . $this->prefix . '.c', 'w'); + fwrite($fp, "#include \"php_gtk.h\""); + fwrite($fp, "\n#if HAVE_PHP_GTK\n"); + fwrite($fp, $this->overrides->get_headers()); + $this->write_constants($fp); + $this->write_class_entries($fp); + $this->write_functions($fp); + $this->write_objects($fp); + fwrite($fp, sprintf($register_classes_tpl, + $this->prefix, + $this->register_classes)); + fwrite($fp, "\n#endif /* HAVE_PHP_GTK */\n"); + fclose($fp); } } $argc = $HTTP_SERVER_VARS['argc']; $argv = $HTTP_SERVER_VARS['argv']; -if ($argc < 2) - die("usage: php -q generator.php defsfile [overridesfile [prefix]]\n"); - -if ($argc > 2) { - $overrides = new Overrides($argv[2]); - if ($argc > 3) - $prefix = $argv[3]; - else - $prefix = 'php_gtk'; +$result = Console_Getopt::getopt($argv, 'o:p:r:'); +if (!$result || count($result[1]) < 2) + die("usage: php -q generator.php [-o overridesfile] [-p prefix] [-r typesfile] defsfile\n"); + +list($opts, $argv) = $result; + +$prefix = 'gtk'; +$overrides = new Overrides(); + +foreach ($opts as $opt) { + list($opt_spec, $opt_arg) = $opt; + if ($opt_spec == 'o') { + $overrides = new Overrides($opt_arg); + } else if ($opt_spec == 'p') { + $prefix = $opt_arg; + } else if ($opt_spec == 'r') { + $type_parser = new Defs_Parser($opt_arg); + $type_parser->start_parsing(); + Generator::register_types($type_parser); + } } -else - $overrides = new Overrides(); $parser = new Defs_Parser($argv[1]); $generator = new Generator($parser, $overrides, $prefix); Index: php-gtk/generator/gtk.defs diff -u php-gtk/generator/gtk.defs:1.6 php-gtk/generator/gtk.defs:1.7 --- php-gtk/generator/gtk.defs:1.6 Fri Mar 9 11:43:59 2001 +++ php-gtk/generator/gtk.defs Mon Mar 12 21:48:58 2001 @@ -1,7 +1,5 @@ ;; -*- scheme -*- -(include "gdk.defs") - ; object definitions ... (object Object (in-module Gtk) Index: php-gtk/generator/gtk.overrides diff -u php-gtk/generator/gtk.overrides:1.29 php-gtk/generator/gtk.overrides:1.30 --- php-gtk/generator/gtk.overrides:1.29 Thu Mar 8 20:33:35 2001 +++ php-gtk/generator/gtk.overrides Mon Mar 12 21:48:58 2001 @@ -145,8 +145,6 @@ %% ignore GtkPrivateFlags - GdkDebugFlag - GdkColorInfoFlags %% ignore gtk_container_dequeue_resize_handler @@ -168,6 +166,10 @@ %% ignore-glob gtk_radio_button_new_* %% +register_class gtk_box_child_ce + INIT_CLASS_ENTRY(ce, "gtkboxchild", NULL); + gtk_box_child_ce = zend_register_internal_class_ex(&ce, NULL, NULL); +%% override gtk_true PHP_FUNCTION(wrap_gtk_true) { @@ -266,7 +268,9 @@ override gtk_input_add_full PHP_FUNCTION(wrap_gtk_input_add_full) { - int source; + zval *source_rsrc; + int rsrc_type; + int *source; GdkInputCondition condition; zval *callback = NULL; zval *extra, *data; @@ -279,14 +283,20 @@ return; } - if (!php_gtk_parse_args(3, "iiV", &source, &condition, &callback)) + if (!php_gtk_parse_args(3, "riV", &source_rsrc, &condition, &callback)) return; + source = zend_list_find(Z_LVAL_P(source_rsrc), &rsrc_type); + if (!source || rsrc_type != php_file_le_fopen()) { + php_error(E_WARNING, "%s() expects argument 1 to be a valid filehandle resource", get_active_function_name()); + return; + } + callback_filename = zend_get_executed_filename(ELS_C); callback_lineno = zend_get_executed_lineno(ELS_C); extra = php_gtk_func_args_as_hash(ZEND_NUM_ARGS(), 3, ZEND_NUM_ARGS()); data = php_gtk_build_value("(VNsi)", callback, extra, callback_filename, callback_lineno); - RETURN_LONG(gtk_input_add_full(source, condition, NULL, + RETURN_LONG(gtk_input_add_full(*source, condition, NULL, (GtkCallbackMarshal)php_gtk_input_marshal, data, php_gtk_destroy_notify)); } @@ -586,22 +596,6 @@ php_gtk_object_init(wrapped_obj, this_ptr); } %% -override gdk_color_parse -PHP_FUNCTION(wrap_gdk_color_parse) -{ - gchar *color_spec; - GdkColor color; - - if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "s", &color_spec)) { - return; - } - - if (gdk_color_parse(color_spec, &color)) - *return_value = *php_gdk_color_new(&color); - else - php_error(E_WARNING, "%s() could not parse color spec '%s'", get_active_function_name(), color_spec); -} -%% override gtk_list_append_items PHP_FUNCTION(wrap_gtk_list_append_items) { @@ -906,15 +900,15 @@ zval **callback_filename, **callback_lineno; zval *params; zval ***args; - gchar *callable_name; + char *callback_name; ELS_FETCH(); zend_hash_index_find(Z_ARRVAL_P(callback_data), 0, (void **)&callback); zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&callback_filename); zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&callback_lineno); - if (!php_gtk_is_callable(*callback, &callable_name)) { - php_error(E_WARNING, "unable to call item factory callback '%s' specified in %s on line %d", callable_name, Z_STRVAL_PP(callback_filename), Z_LVAL_PP(callback_lineno)); - g_free(callable_name); + if (!php_gtk_is_callable(*callback, 0, &callback_name)) { + php_error(E_WARNING, "unable to call item factory callback '%s' specified in %s on line %d", callback_name, Z_STRVAL_PP(callback_filename), Z_LVAL_PP(callback_lineno)); + efree(callback_name); return; } Index: php-gtk/generator/templates.php diff -u php-gtk/generator/templates.php:1.8 php-gtk/generator/templates.php:1.9 --- php-gtk/generator/templates.php:1.8 Thu Mar 8 20:33:35 2001 +++ php-gtk/generator/templates.php Mon Mar 12 21:48:58 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: templates.php,v 1.8 2001/03/09 04:33:35 andrei Exp $ */ +/* $Id: templates.php,v 1.9 2001/03/13 05:48:58 andrei Exp $ */ $function_tpl = " PHP_FUNCTION(wrap_%s) @@ -66,6 +66,9 @@ }\n\n"; $function_entry_tpl = "\t{\"%s\", PHP_FN(wrap_%s), %s},\n"; +$functions_decl_tpl = " +static function_entry php_%s_functions[] = { +"; $register_getter_tpl = "\tphp_gtk_register_prop_getter(%s, %s_get_property);\n"; @@ -87,7 +90,8 @@ *found = FAILURE; }\n\n"; -$init_class_tpl = "\n\tINIT_OVERLOADED_CLASS_ENTRY(ce, \"%s\", %s_functions, NULL, %s, NULL);\n"; +$init_class_tpl = " + INIT_OVERLOADED_CLASS_ENTRY(ce, \"%s\", php_%s_functions, NULL, %s, NULL);\n"; $get_type_tpl = " PHP_FUNCTION(wrap_%s_get_type) @@ -97,5 +101,17 @@ RETURN_LONG(%s_get_type()); }\n\n"; + +$register_classes_tpl = " +void php_%s_register_classes(void) +{ + zend_class_entry ce; +%s +}\n"; + + +$register_class_tpl = "\t%s = zend_register_internal_class_ex(&ce, %s, NULL);\n"; + +$class_entry_tpl = "zend_class_entry *%s;\n"; ?> Index: php-gtk/generator/Getopt.php +++ php-gtk/generator/Getopt.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 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. | // +----------------------------------------------------------------------+ // | Authors: Andrei Zmievski <andrei@ispi.net> | // +----------------------------------------------------------------------+ // // $Id: Getopt.php,v 1.1 2001/03/13 05:48:58 andrei Exp $ /** * Command-line options parsing class. * * @author Andrei Zmievski <andrei@ispi.net> * */ class Console_Getopt { /** * Parses the command-line options. * * The first parameter to this function should be the list of command-line * arguments without the leading reference to the running program. * * The second parameter is a string of allowed short options. Each of the * option letters can be followed by a colon ':' to specify that the option * requires an argument, or a double colon '::' to specify that the option * takes an optional argument. * * The third argument is an optional array of allowed long options. The * leading '--' should not be included in the option name. Options that * require an argument should be followed by '=', and options that take an * option argument should be followed by '=='. * * The return value is an array of two elements: the list of parsed * options and the list of non-option command-line arguments. Each entry in * the list of parsed options is a pair of elements - the first one * specifies the option, and the second one specifies the option argument, * if there was one. * * Long and short options can be mixed. * * Most of the semantics of this function are based on GNU getopt_long(). * * @param $args array an array of command-line arguments * @param $short_options string specifies the list of allowed short options * @param $long_options array specifies the list of allowed long options * * @return array two-element array containing the list of parsed options and * the non-option arguments * * @access public * */ function getopt($args, $short_options, $long_options = null) { $opts = array(); $non_opts = array(); settype($args, 'array'); if ($long_options) sort($long_options); reset($args); while (list(, $arg) = each($args)) { /* The special element '--' means explicit end of options. Treat the rest of the arguments as non-options and end the loop. */ if ($arg == '--') { $non_opts = array_merge($non_opts, array_slice($args, $i + 1)); break; } if ($arg{0} != '-' || ($arg{1} == '-' && !$long_options)) { $non_opts[] = $arg; } else if ($arg{1} == '-') { if (!Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args)) return false; } else { if (!Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args)) return false; } } return array($opts, $non_opts); } /** * @access private * */ function _parseShortOption($arg, $short_options, &$opts, &$args) { for ($i = 0; $i < strlen($arg); $i++) { $opt = $arg{$i}; $opt_arg = null; /* Try to find the short option in the specifier string. */ if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') { return false; } if ($spec{1} == ':') { if ($spec{2} == ':') { if ($i + 1 < strlen($arg)) { /* Option takes an optional argument. Use the remainder of the arg string if there is anything left. */ $opts[] = array($opt, substr($arg, $i + 1)); break; } } else { /* Option requires an argument. Use the remainder of the arg string if there is anything left. */ if ($i + 1 < strlen($arg)) { $opts[] = array($opt, substr($arg, $i + 1)); break; } else if (list(, $opt_arg) = each($args)) /* Else use the next argument. */; else return false; } } $opts[] = array($opt, $opt_arg); return true; } } /** * @access private * */ function _parseLongOption($arg, $long_options, &$opts, &$args) { list($opt, $opt_arg) = explode('=', $arg); $opt_len = strlen($opt); for ($i = 0; $i < count($long_options); $i++) { $long_opt = $long_options[$i]; $opt_start = substr($long_opt, 0, $opt_len); /* Option doesn't match. Go on to the next one. */ if ($opt_start != $opt) continue; $opt_rest = substr($long_opt, $opt_len); /* Check that the options uniquely matches one of the allowed options. */ if ($opt_rest != '' && $opt{0} != '=' && $i + 1 < count($long_options) && $opt == substr($long_options[$i+1], 0, $opt_len)) { return false; } if (substr($long_opt, -1) == '=') { if (substr($long_opt, -2) != '==') { /* Long option requires an argument. Take the next argument if one wasn't specified. */; if (!$opt_arg && !(list(, $opt_arg) = each($args))) { return false; } } } else if ($opt_arg) { return false; } $opts[] = array('--' . substr($long_opt, 0, strpos($long_opt, '=')), $opt_arg); return true; } return false; } } ?> Index: php-gtk/generator/gdk.overrides +++ php-gtk/generator/gdk.overrides /* vim: set ft=cpp: */ %% ignore GdkDebugFlag GdkColorInfoFlags %% override gdk_color_parse PHP_FUNCTION(wrap_gdk_color_parse) { gchar *color_spec; GdkColor color; if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "s", &color_spec)) { return; } if (gdk_color_parse(color_spec, &color)) *return_value = *php_gdk_color_new(&color); else php_error(E_WARNING, "%s() could not parse color spec '%s'", get_active_function_name(), color_spec); } Index: php-gtk/generator/make_reg_items.php +++ php-gtk/generator/make_reg_items.php <?php $fp = fopen('../src/php_gtk_gen_reg_items.h', 'w'); foreach (array_slice($argv, 1) as $module) { fwrite($fp, " php_" . $module . "_register_classes();\n"); fwrite($fp, " php_" . $module . "_register_constants(module_number ELS_CC);\n"); } fclose($fp); ?>