-
Notifications
You must be signed in to change notification settings - Fork 86
/
reascript_vararg.php
executable file
·127 lines (106 loc) · 2.82 KB
/
reascript_vararg.php
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
<?php
$fp= fopen("./ReaScript.cpp","r");
if (!$fp) die("error opening ReaScript.cpp");
echo "#ifndef _REASCRIPT_VARARG_H_\n";
echo "#define _REASCRIPT_VARARG_H_\n\n";
$funcs = array();
while (($x=fgets($fp,4096)))
{
$aroffs=-1;
if (preg_match('/\\s*{\\s*APIFUNC_NAMED\\(\\s*(.+?)\\s*,\\s*(.+?)\\s*\\)\\s*,\\s*"(.*?)"\\s*,\\s*"(.*?)"\\s*,\\s*"(.*?)".*$/',$x,$matches))
{
$aroffs=1;
}
else if (preg_match('/\\s*{\\s*APIFUNC\\(\\s*(.+?)\\s*\\)\\s*,\\s*"(.*?)"\\s*,\\s*"(.*?)"\\s*,\\s*"(.*?)".*$/',$x,$matches))
{
$aroffs=0;
}
if ($aroffs >= 0)
{
if (isset($funcs[$matches[1]]))
{
die("#error APIFUNC $matches[1] has duplicate entries\n");
}
if ($matches[1] == "time_precise")
{
continue;
}
$funcs[$matches[1]] = array("func" => $matches[1+$aroffs],
"ret" => $matches[2+$aroffs],
"types" => $matches[3+$aroffs],
"names" => $matches[4+$aroffs]);
}
}
fclose($fp);
//ksort($funcs);
foreach ($funcs as $name => &$rec)
{
$cfunc = "__vararg_$name";
$names = explode(",",$rec["names"]);
$types = explode(",",$rec["types"]);
if (count($names) != count($types))
{
die("#error $name has mismatched parmname/types\n");
}
$ret_type = $rec["ret"];
$code = "";
$code .= "static void* " . $cfunc . "(void** arglist, int numparms)\n{\n ";
if ($ret_type != "void")
{
if ($ret_type == "double")
{
$code .= "double* p =(double*)arglist[numparms-1];\n";
$code .= " double d = ";
}
else
{
$code .= "return (void*)(INT_PTR)";
}
}
$code .= $name . "(";
$parm_offs = 0;
$next_sz = 0;
$lastreq = 0;
for ($x=0; $x < count($names); $x++)
{
$nm = trim($names[$x]);
$type = trim($types[$x]);
if ($type == "") continue;
if ($type == "int")
{
$code .= "(" . $type . ")(INT_PTR)arglist[" . $x . "]";
}
else if ($type == "double")
{
$code .= "arglist[" . $x . "] ? *(double*)arglist[" . $x . "] : 0.0";
}
else
{
$code .= "(" . $type . ")arglist[" . $x . "]";
}
if ($x < count($names)-1)
{
$code .= ", ";
}
$parm_offs++;
if ($next_sz) $x++;
}
$code .= ");\n";
if ($ret_type == "void")
{
$code .= " return NULL;\n";
}
else if ($ret_type == "double")
{
$code .= " if (p) *p=d;\n";
$code .= " return p;\n";
}
$code .= "}\n\n";
$rec["ret_type"] = $ret_type;
$rec["cfunc"] = $cfunc;
$rec["np"] = max($lastreq+1,1);
$rec["npf"] = $parm_offs;
echo $code;
}
echo "\n#endif\n";
?>