forked from i-RIC/iriclib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_iriclib_singlefuncs.php
82 lines (76 loc) · 2.05 KB
/
make_iriclib_singlefuncs.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
<?php
print <<< END
#include "iriclib.h"
extern int lastfileid;
/*********************************************************/
/* The following function implementations are generated */
/* using make_iriclib_singlefuncs.php */
/*********************************************************/
END;
$fp = fopen("iriclib.h", "r");
while (! feof($fp)){
$line = fgets($fp);
if (preg_match("/^ *(.+) +(.+)_Mul\\((.*)\\)/", $line, $matches)){
// echo $line;
// print_r($matches);
$rettype = str_replace(" IRICLIBDLL", "", $matches[1]);
$funcname = $matches[2];
$argstr = $matches[3];
$argstrs = explode(",", $argstr);
$args = array();
foreach ($argstrs as $tmparg){
$tmparg = trim($tmparg);
$arg = array();
if (strpos($tmparg, "*") === FALSE){
$words = explode(" ", $tmparg);
$tmpwords = array();
foreach ($words as $w){
if ($w){
$tmpwords[] = $w;
}
}
$arg['type'] = $tmpwords[0];
$arg['name'] = $tmpwords[1];
} else {
if (preg_match("/^(.+) *\\* *([a-zA-Z_]+)/", $tmparg, $matches)){
// print_r($matches);
$arg['type'] = str_replace(" ", "", $matches[1]) . "*";
$arg['type'] = str_replace("constchar", "const char", $arg['type']);
$arg['name'] = $matches[2];
} else {
echo "HANDLE Error: ", $tmparg, "\n";
}
}
// print_r($arg);
$args[] = $arg;
}
echo $rettype . " " . $funcname . "(";
$argfrags = array();
for ($i = 0; $i < count($args); ++$i){
if ($i == 0){continue;}
$arg = $args[$i];
$argfrags[] = $arg['type'] . " " . $arg['name'];
}
echo implode(", ", $argfrags);
echo ")\n";
echo "{\n";
echo "\t";
if ($rettype != "void"){
echo "return ";
}
echo $funcname . "_Mul(";
$argfrags = array();
$argfrags[] = "lastfileid";
for ($i = 0; $i < count($args); ++$i){
if ($i == 0){continue;}
$arg = $args[$i];
$argfrags[] = $arg['name'];
}
echo implode(", ", $argfrags);
echo ");\n";
echo "}\n";
echo "\n";
}
}
fclose($fp);
?>