From 76d82c53bb6d3aa3f7d32fc3c8c4aa964bfb9c4e Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Sat, 26 Apr 2003 15:05:01 +0000 Subject: [PATCH] module global variables and ini parameters now have their own generator classes --- scripts/ext_skel_ng/php_global.php | 80 ++++++++++++++++++++ scripts/ext_skel_ng/php_ini.php | 117 +++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 scripts/ext_skel_ng/php_global.php create mode 100644 scripts/ext_skel_ng/php_ini.php diff --git a/scripts/ext_skel_ng/php_global.php b/scripts/ext_skel_ng/php_global.php new file mode 100644 index 0000000000..bec2082e09 --- /dev/null +++ b/scripts/ext_skel_ng/php_global.php @@ -0,0 +1,80 @@ +name = $attr["name"]; + + if (!$this->is_name($this->name)) { + $this->error[] = "'$attr[name]' is not a valid C variable name"; + } + + $this->type = $attr['type']; + if (!$this->is_type($this->type)) { + $this->error[] = "'$attr[type]' is not a valid C data type"; + } + } + + /* overriding type check as we deal with C types here + check is rather naive as it doesn't know about context + so we check for a sequence of valid names for now + TODO: check for either simple type, struct/class or single word (typedef) + */ + function is_type($type) { + $array = explode(" ", str_replace('*',' ',$type)); + foreach ($array as $name) { + if (empty($name)) continue; + if (!$this->is_name($name)) return false; + } + return true; + } + + + + static function c_code_header($name) { + return "static void php_{name}_init_globals(zend_{name}_globals *{name}_globals)\n{\n"; + } + + function c_code($name) { + $code = " {$name}_globals->{$this->name} = "; + if (strstr($this->type, "*")) { + $code .= "NULL;\n"; + } else { + $code .= "0;\n"; + } + return $code; + } + + static function c_code_footer() { + return "}\n\n"; + } + + static function h_code_header($name) { + return "ZEND_BEGIN_MODULE_GLOBALS({$name})\n"; + } + + function h_code($name) { + return " {$this->type} {$this->name};\n"; + } + + static function h_code_footer($name) { + $upname = strtoupper($name); + + return " +ZEND_END_MODULE_GLOBALS({$name}) + +#ifdef ZTS +#define {$upname}_G(v) TSRMG({$name}_globals_id, zend_{$name}_globals *, v) +#else +#define {$upname}_G(v) ({$name}_globals.v) +#endif + +"; + + } + + + } + +?> diff --git a/scripts/ext_skel_ng/php_ini.php b/scripts/ext_skel_ng/php_ini.php new file mode 100644 index 0000000000..88da50ae28 --- /dev/null +++ b/scripts/ext_skel_ng/php_ini.php @@ -0,0 +1,117 @@ +name = $attr["name"]; + + if (!$this->is_name($this->name)) { + $this->error[] = "'$attr[name]' is not a valid php.ini directive name"; + } + + $this->type = $this->is_type($attr['type']); + if (!$this->type) { + $this->error[] = "'$attr[type]' is not a valid PHP data type"; + } + + $this->value = $attr["value"]; + $this->desc = $attr["desc"]; + + switch ($attr["access"]) { + case "system": + $this->access = "PHP_INI_SYSTEM"; + break; + case "perdir": + $this->access = "PHP_INI_PERDIR"; + break; + case "user": + $this->access = "PHP_INI_USER"; + break; + case "all": + case "": + $this->access = "PHP_INI_ALL"; + break; + default: + $this->error[] = "'$attr[access]' is not a valid access mode (system|perdir|user|all)"; + } + + switch ($this->type) { + case "bool": + $this->onupdate = "OnUpdateBool"; + $this->c_type = "zend_bool"; + break; + case "int": + $this->onupdate = "OnUpdateLong"; + $this->c_type = "long"; + break; + case "float": + $this->onupdate = "OnUpdateReal"; + $this->c_type = "double"; + break; + case "string": + $this->onupdate = "OnUpdateString"; + $this->c_type = "char *"; + break; + default: + $this->error[] = "'$this->type' not supported, only bool, int, float and string"; + break; + } + + if (isset($attr["onupdate"])) { + $this->onupdate = $attr["onupdate"]; + } + } + + + + static function c_code_header($name) { + return "PHP_INI_BEGIN()\n"; + } + + function c_code($name) { + return " STD_PHP_INI_ENTRY(\"{$name}.$name\", \"{$this->value}\", {$this->access}, {$this->onupdate}, $name, zend_{$name}_globals, {$name}_globals)\n"; + } + + static function c_code_footer() { + return "PHP_INI_END()\n\n"; + } + + + + static function docbook_xml_header($name) { + return +" + $name runtime configuration + + + + directive + default value + descrpition + + + +"; + } + + function docbook_xml() { + return +" + $this->name + $this->value + $this->desc + +"; + } + + static function docbook_xml_footer() { + return +" + +
+"; + } + } + +?> -- 2.40.0