summaryrefslogtreecommitdiff
path: root/scripts/ext_skel_ng/php_constant.php
blob: 4f377a963da7b3c7bf1d3b15c1ed18a27f1237d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

	class php_constant extends php_element {

		function __construct($attr, $desc) {

			$this->name = $attr["name"];
			if (!$this->is_name($this->name)) {
				$this->error[] = "'$attr[name]'is not a valid constant name";
			}

			$this->type = isset($attr["type"]) ? $this->is_type($attr["type"]) : "string";
			if (!in_array($this->type, array('int', 'float', 'string'))) {
				$this->error[] = "'$attr[type]' is not a valid constant type, only int, float and string";
			} 

			$this->value= $attr["value"];
			$this->desc = $desc;
		} 


		static function c_code_header($name) {
			return "";
		}
		
		function c_code() {
			switch ($this->type) {
			case "int":
				return "REGISTER_LONG_CONSTANT(\"{$this->name}\", {$this->value}, 0);\n";
			
			case "float":
				return "REGISTER_DOUBLE_CONSTANT(\"{$this->name}\", {$this->value}, 0);\n";

			case "string":
				return "REGISTER_STRING_CONSTANT(\"{$this->name}\", \"$value\", ".strlen($this->value).", 0);\n";
			}
		}

		static function c_code_footer() {
			return "";
		}

		
		
		static function docbook_xml_header($name) {
			return
"    <table>
     <title>$name constants</title>
      <tgroup cols='3'>
       <thead>
        <row>
         <entry>name</entry>
         <entry>value</entry>
         <entry>descrpition</entry>
        </row>
       </thead>
      <tbody>
";
		}
			
		function docbook_xml() {
			return trim("
<row>
 <entry>
  <constant id='constant".strtolower(str_replace("_","-",$this->name))."'>{$this->name}</constant>
  (<link linkend='language.types.integer'>integer</link>)
 </entry>
 <entry>{$this->value}</entry>
 <entry>{$this->desc}</entry>
</row>
")."\n";
		}

		static function docbook_xml_footer() {
			return
"     </tbody>
    </tgroup>
   </table>
";
		}
	}

?>