php-src/ext/skeleton/create_stubs

283 lines
7.1 KiB
Plaintext
Raw Normal View History

#!/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, t)
{
type = argtypes[i,j]
name = argnames[i,j]
opt = optionals[i,j]
tabs = x = ""
for (i = 0; i < t; i++) { tabs = tabs "\t" }
if (type == "int" || type == "long") {
longs = longs "\tlong " name ";\n"
2001-12-18 11:16:53 +00:00
} else if (type == "bool" || type == "boolean") {
bools = bools "\tzend_bool " name ";\n"
} else if (type == "double" || type == "float") {
doubles = doubles "\tdouble " name ";\n"
} else if (type == "string") {
strings = strings "\tchar *" name " = NULL;\n"
ints = ints "\tint " name "_len;\n"
} else if (type == "array" || type == "object" || type == "mixed") {
zvals = zvals "\tzval *" name " = NULL;\n"
} else if (type == "resource" || type == "handle") {
zvals = zvals "\tzval *" name " = NULL;\n"
resources = resources "\tif (" name ") {\n" \
"\t\tZEND_FETCH_RESOURCE(???, ???, " name ", " name "_id, \"???\", ???_rsrc_id);\n\t}\n"
2001-08-08 00:20:19 +00:00
ints = ints "\tint " name "_id = -1;\n"
}
}
function comment(s)
{
if (i_know_what_to_do_shut_up_i_dont_need_your_help_mode) {
return
} else {
return s
}
}
BEGIN {
name = "[_A-Za-z][_A-Za-z0-9]*"
type = "int|long|double|float|string|bool|boolean|array|object|resource|handle|mixed|void"
spec = "l|l|d|d|s|b|b|a|o|r|r|z|"
num_funcs = 0
# create a map from type name to the spec
split(type, type_array, "\|")
split(spec, spec_array, "\|")
for (i in type_array) {
spec_map[type_array[i]] = spec_array[i]
}
if (xml && xml != "yes") {
xmldoc = xml
} else {
xmldoc = extname "/" extname ".xml"
}
xmlhead = "<?xml version='1.0' encoding='iso-8859-1'?>\n" \
"<!-- $Revision$ -->\n" \
" <reference id=\"ref." extname "\">\n" \
" <title> functions</title>\n" \
" <titleabbrev></titleabbrev>\n\n" \
2001-04-25 21:26:05 +00:00
" <partintro>\n" \
" &warn.experimental;\n" \
" <para>\n" \
" </para>\n" \
" </partintro>\n\n";
xmlfoot = " </reference>\n\n" \
"<!-- Keep this comment at the end of the file\n" \
"Local variables:\n" \
"mode: sgml\n" \
"sgml-omittag:t\n" \
"sgml-shorttag:t\n" \
"sgml-minimize-attributes:nil\n" \
"sgml-always-quote-attributes:t\n" \
"sgml-indent-step:1\n" \
"sgml-indent-data:t\n" \
"indent-tabs-mode:nil\n" \
"sgml-parent-document:nil\n" \
"sgml-default-dtd-file:\"../../manual.ced\"\n" \
"sgml-exposed-tags:nil\n" \
"sgml-local-catalogs:nil\n" \
"sgml-local-ecat-files:nil\n" \
"End:\n" \
"vim600: syn=xml fen fdm=syntax fdl=2 si\n" \
"vim: et tw=78 syn=sgml\n" \
"vi: ts=1 sw=1\n" \
"-->\n"
}
{
args_max = args_min = optional = i = spec_opt = 0
line = $0
spec_str = "\""
func_type = gobble(type);
func_name = gobble(name);
if (gobble("\\(")) {
if (gobble("\\[")) optional = 1
while (arg_type = gobble(type)) {
arg_name = gobble(name)
2001-08-08 00:20:19 +00:00
if(arg_type == "void") {
args_max = 0;
args_min = 0;
break;
} else {
2001-08-08 00:20:19 +00:00
argtypes[num_funcs,args_max] = arg_type
argnames[num_funcs,args_max] = arg_name
args_max++
if (optional) {
2001-08-12 02:45:41 +00:00
if (!spec_opt) {
spec_str = spec_str "|"
spec_opt = 1
2001-08-08 00:20:19 +00:00
}
2001-08-12 02:45:41 +00:00
optionals[num_funcs,i] = optional
2001-08-08 00:20:19 +00:00
} else {
2001-08-12 02:45:41 +00:00
args_min++
2001-08-08 00:20:19 +00:00
}
2001-08-12 02:45:41 +00:00
spec_str = spec_str spec_map[arg_type]
2001-08-08 00:20:19 +00:00
if (x = gobble("\\[")) {
optional++
}
2001-08-08 00:20:19 +00:00
y = gobble(",")
if (!x && y && optional) {
grouped_optional_param[num_funcs,i] = 1
}
i++
}
}
}
2001-08-08 00:20:19 +00:00
# if (x = gobble("\\)")) {
gobble("\\]* *)")
sub(/^[ \t]+/, "", line)
fcomments[num_funcs] = line
2001-08-08 00:20:19 +00:00
# }
spec_str = spec_str "\""
funcs[num_funcs] = func_name
types[num_funcs] = func_type
maxargs[num_funcs] = args_max
minargs[num_funcs] = args_min
specs[num_funcs] = spec_str
2001-08-12 03:46:25 +00:00
spec_opts[num_funcs] = spec_opt
num_funcs++
}
END {
if (xml) print xmlhead > xmldoc
for (i = 0; i < num_funcs; i++) {
compareargc = maxargs[i] - minargs[i]
2001-08-08 00:20:19 +00:00
closefetch = fetchargs = zvals = xmlparams = funcvals = resources = handleargs = closeopts = ""
ints = longs = doubles = strings = bools = zvals = ""
proto = "/* {{{ proto " types[i] " " funcs[i] "("
2001-08-08 00:20:19 +00:00
refid = funcs[i]
gsub(/_/, "-", refid)
xmlstr = " <refentry id=\"function." refid "\">\n" \
" <refnamediv>\n" \
" <refname>" funcs[i] "</refname>\n" \
" <refpurpose>" fcomments[i] "</refpurpose>\n" \
" </refnamediv>\n" \
" <refsect1>\n" \
" <title>Description</title>\n" \
" <funcsynopsis>\n" \
" <funcprototype>\n" \
" <funcdef>" types[i] " <function>" funcs[i] "</function></funcdef>\n"
if (maxargs[i]>0) {
fetchargs = "\tif (zend_parse_parameters("
2001-08-12 02:45:41 +00:00
ints = ints "\tint argc = ZEND_NUM_ARGS();\n"
2001-08-13 19:36:43 +00:00
fetchargs = fetchargs "argc TSRMLS_CC, " specs[i]
} else {
fetchargs = fetchargs "\tif (ZEND_NUM_ARGS() != 0) {\n\t\tWRONG_PARAM_COUNT;\n\t}"
xmlparams = xmlparams " <void/>\n"
}
for (j = 0; j < maxargs[i]; j++) {
2001-08-12 02:45:41 +00:00
fetchargs = fetchargs ", "
fetchargs = fetchargs "&" argnames[i,j]
if (argtypes[i,j] == "string") {
fetchargs = fetchargs ", &" argnames[i,j] "_len"
}
xmlparams = xmlparams " <paramdef>" argtypes[i,j]
if (j > minargs[i]-1) {
if (!grouped_optional_param[i,j-1]) {
if (j > 0) proto = proto " "
proto = proto "["
closeopts = closeopts "]"
}
xmlparams = xmlparams "\n <parameter><optional>" \
argnames[i,j] \
"</optional></parameter>\n </paramdef>\n"
} else {
xmlparams = xmlparams \
" <parameter>" \
argnames[i,j] \
"</parameter></paramdef>\n"
}
if (j > 0) proto = proto ", "
proto = proto argtypes[i,j] " " argnames[i,j]
convert(i, j, 1)
}
proto = proto closeopts ")\n " fcomments[i] " */\nPHP_FUNCTION(" funcs[i] ")\n{"
if (maxargs[i]>0) {
fetchargs = fetchargs ") == FAILURE)" closefetch " \n\t\treturn;\n"
}
funcvals = strings ints longs doubles bools zvals
xmlstr = xmlstr xmlparams \
" </funcprototype>\n" \
" </funcsynopsis>\n" \
" &warn.experimental.func;\n" \
" <para>\n" \
" &warn.undocumented.func;\n" \
" </para>\n" \
" </refsect1>\n" \
" </refentry>\n"
print proto > stubfile
if (funcvals) print funcvals > stubfile
if (fetchargs) print fetchargs > stubfile
if (resources) {
print resources > stubfile
if (!stubs) print "" > extname "/function_warning"
}
if (!i_know_what_to_do_shut_up_i_dont_need_your_help_mode) {
print "\tphp_error(E_WARNING, \"" funcs[i] ": not yet implemented\");" > stubfile
}
print "}\n/* }}} */\n" > stubfile
if (stubs) {
h_stubs = h_stubs "PHP_FUNCTION(" funcs[i] ");\n"
c_stubs = c_stubs "\tPHP_FE(" funcs[i] ",\tNULL)\n"
} else {
print "PHP_FUNCTION(" funcs[i] ");" > extname "/function_declarations"
print "\tPHP_FE(" funcs[i] ",\tNULL)" > extname "/function_entries"
}
if (xml) print xmlstr > xmldoc
}
if (stubs) {
print "\n/* ----------------------------------------------------------- */\n" > stubfile
print c_stubs > stubfile
print "\n/* ----------------------------------------------------------- */\n" > stubfile
print h_stubs > stubfile
}
if (xml) print xmlfoot > xmldoc
}
#
# Local variables:
# tab-width: 2
# c-basic-offset: 2
# End: