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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#!/usr/bin/awk -f
function gobble(s, x)
{
sub(/^ /, "", line)
match(line, "^" "(" s ")")
x = substr(line, 1, RLENGTH)
line = substr(line, RLENGTH+1)
return x
}
function convert(i, j)
{
type = argtypes[i,j]
name = argnames[i,j]
opt = optionals[i,j]
x = ""
if (type == "int") {
x = "convert_to_long_ex(" name ");\n"
} else if (type == "double") {
x = "convert_to_double_ex(" name ");\n"
} else if (type == "string") {
x = "convert_to_string_ex(" name ");\n"
} else if (type == "array") {
x = "convert_to_array_ex(" name ");\n"
} else if (type == "resource") {
if (opt && i) {
resources = resources "\tif (argc < " j+1 ") {\n\t\t/* Argument not given, do something before\n\t\t trying to fetch resource " name ". */\n\t}\n\tZEND_FETCH_RESOURCE(???, ???, " name ", " name "_id, \"???\", ???G());\n"
} else {
resources = resources "\tZEND_FETCH_RESOURCE(???, ???, " name ", " name "_id, \"???\", ???G());\n"
}
funcvals = funcvals "\tint " name "_id = -1;\n"
} else {
x = "/* Write your own code here to handle argument " name ". */\n"
}
if (x) return x
}
BEGIN {
name = "[_A-Za-z][_A-Za-z0-9]*"
type = "int|double|string|bool|array|object|resource|mixed|void"
num_funcs = 0
}
{
args_max = args_min = optional = i = 0
line = $0
func_type = gobble(type);
func_name = gobble(name);
if (gobble("\\(")) {
if (gobble("\\[")) optional = 1
while (arg_type = gobble(type)) {
arg_name = gobble(name)
argtypes[num_funcs,args_max] = arg_type
argnames[num_funcs,args_max] = arg_name
args_max++
if (optional) {
optionals[num_funcs,i] = optional
if (arg_type != "resource") {
useswitch[num_funcs] = 1
}
} else {
args_min++
}
if (x = gobble("\\[")) {
optional++
}
gobble(",")
i++
}
}
funcs[num_funcs] = func_name
types[num_funcs] = func_type
maxargs[num_funcs] = args_max
minargs[num_funcs] = args_min
num_funcs++
}
END {
for (i = 0; i < num_funcs; i++) {
compareargc = maxargs[i] - minargs[i]
funcvals = resources = handleargs = closeopts = ""
proto = "/* {{{ proto " types[i] " " funcs[i] "("
if (maxargs[i]) {
zvals = "\tzval "
if (compareargc) {
funcvals = "\tint argc;\n"
if (minargs[i]) {
fetchargs = "\targc = ZEND_NUM_ARGS();\n\tif (argc < " minargs[i] " || argc > " maxargs[i] " || zend_get_parameters_ex(argc, "
} else {
fetchargs = "\targc = ZEND_NUM_ARGS();\n\tif ((argc && argc < " maxargs[i]+1 " || zend_get_parameters_ex(argc, "
}
} else {
fetchargs = "\tif (ZEND_NUM_ARGS() != " maxargs[i] " || zend_get_parameters_ex(" maxargs[i] ", "
}
}
for (j = 0; j < maxargs[i]; j++) {
if (j) {
zvals = zvals ", "
fetchargs = fetchargs ", "
}
zvals = zvals "**" argnames[i,j]
fetchargs = fetchargs "&" argnames[i,j]
if (j > minargs[i]-1) {
if (j) proto = proto " "
proto = proto "["
closeopts = closeopts "]"
}
if (j > 0) proto = proto ", "
proto = proto argtypes[i,j] " " argnames[i,j]
code = convert(i, j)
if (useswitch[i]) {
if (j > minargs[i]-1) {
if (code) {
handleargs = "\t\tcase " j+1 ":\n\t\t\t" code "\t\t\t/* Fall-through. */\n" handleargs
} else {
handleargs = "\t\tcase " j+1 ":\t/* Fall-through. */\n" handleargs
}
} else if (j >= minargs[i]-1) {
if (code) {
handleargs = "\t\tcase " j+1 ":\n\t\t\t" code handleargs
} else {
handleargs = "\t\tcase " j+1 ":\n" handleargs
}
} else {
handleargs = "\t\t\t" code handleargs
}
} else {
if (code) handleargs = handleargs "\t" code
}
}
proto = proto closeopts ")\n */\nPHP_FUNCTION(" funcs[i] ")\n{"
if (maxargs[i]) {
zvals = zvals ";"
fetchargs = fetchargs ") == FAILURE) {\n\t\tWRONG_PARAM_COUNT;\n\t}\n"
}
if (resources ) funcvals = funcvals "\t???LS_FETCH();\n"
if (useswitch[i]) handleargs = "\tswitch (argc) {\n" handleargs "\t\t\tbreak;\n\t\tdefault:\n\t\t\tWRONG_PARAM_COUNT;\n\t}"
print proto > extname "/function_stubs"
if (zvals) print zvals > extname "/function_stubs"
if (funcvals) print funcvals > extname "/function_stubs"
if (fetchargs) print fetchargs > extname "/function_stubs"
if (resources) {
print resources > extname "/function_stubs"
print "" > extname "/function_warning"
}
if (handleargs) print handleargs > extname "/function_stubs"
print "\n\tphp_error(E_WARNING, \"" funcs[i] ": not yet implemented\");" > extname "/function_stubs"
print "}\n/* }}} */\n" > extname "/function_stubs"
print "PHP_FUNCTION(" funcs[i] ");" > extname "/function_declarations"
print "\tPHP_FE(" funcs[i] ",\tNULL)" > extname "/function_entries"
}
}
#
# Local variables:
# tab-width: 2
# c-basic-offset: 2
# End:
#
|