-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaspis_prototypes.php
More file actions
executable file
·121 lines (115 loc) · 3.45 KB
/
aspis_prototypes.php
File metadata and controls
executable file
·121 lines (115 loc) · 3.45 KB
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
#!/usr/bin/php
<?php
if (!isset($argv[1]) || !file_exists($argv[1])) die("Please supply an IN file\n");
if (!isset($argv[2])) die("Please supply an OUT file\n");
$file=file($argv[1]);
$couples=array();
$couples_methods=array();
$i=0;
$header="";
foreach ($file as $line) {
if ($i++%2==1) {
if (strpos($header,"method ")!==0) $couples[$header]=trim($line);
else $couples_methods[$header]=trim($line);
}
else {
$header=trim($line);
}
}
//sorted output
ksort($couples);
ksort($couples_methods);
//$out = fopen('current_sorted.prototypes', 'w');
//foreach ($couples as $key=>$value) {
//// echo $key."\n";
// fwrite($out,$key);
// fwrite($out,$value."\n");
//}
//fclose($out);
function print_array($header,$out,$couples) {
fwrite($out,$header);
foreach ($couples as $key=>$value) {
// echo $key;
$i=strpos($key,' ');
if (substr($key,0,$i)=="method") { //ingore any "method" prefix
$key=substr($key,$i+1);
$i=strpos($key,' ');
}
$name=substr($key,0,$i);
$key=substr($key,$i+1);
$params=array();
$param="";
$ignore=false;
$i=strpos($key,' ');
$key=substr($key,$i+1);
$try=0;
$mod=2;
$kind="";
$pcount=0;
while (strlen($key)>0) {
$i=strpos($key,' ');
if ($i>0) {
if (strpos(substr($key,0,$i),"[")>-1) {
$try=0;
$kind="p";
$pcount++;
$key=substr($key,$i+1);
continue;
}
if ($try%$mod==0) {
$s=substr($key,0,$i);
if (strpos($s,"...")>-1) {
$kind="r".$kind;
$s=substr($s,strpos($s,"..."));
}
if ($s!=")" && $s!="]") {
if ($kind=="") $params[]=$s;
else {
$params[]="$kind $s";
}
}
else if ($s=="]") {
if (--$pcount==0) $kind="";
}
}
else if ($try%$mod==1) {
if ($key[0]=='&') {
$params[count($params)-1]=$params[count($params)-1]." &";
}
$s=substr($key,0,$i);
if (strpos($s,"...")>-1) {
$params[count($params)-1]="r".$params[count($params)-1];
} else if ($s=="]") {
if (--$pcount==0) $kind="";
}
}
$try++;
$key=substr($key,$i+1);
}
else break;
}
$returns="";
$reversed=trim(strrev($value));
$reversed = preg_split('//', $reversed, -1, PREG_SPLIT_NO_EMPTY);
foreach($reversed as $c) {
if ($c==')') continue;
else if ($c=='(') break;
else $returns=$c.$returns;
}
// echo $returns."\n";
//write to file
fwrite($out,$name."\n");
// echo "$name\n";
foreach ($params as $p) {
fwrite($out,"\t".$p."\n");
}
// echo "\n";
fwrite($out,"\t\t".$returns."\n");
}
}
//processed output
$out = fopen($argv[2], 'w');
print_array(">functions\n",$out,$couples);
print_array(">methods\n",$out,$couples_methods);
fclose($out);
?>