summaryrefslogtreecommitdiffstats
path: root/sortrefl
blob: f38efb5f546f1c87daa096c69ec8a2d9d7f964b2 (plain)
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
#!/usr/bin/php
<?php
if ($_SERVER['argc'] < 2) {
	die("usage %s filename\n");
}
$in = fopen($name = $_SERVER['argv'][1], "r");
if (!$in) {
	die("Can't read input file $name\n");
}

$res = [];
$tab = [];
$class = $method = false;
fprintf(STDERR, "Reading $name:\n");
while ($buf = fgets($in)) {
	if (preg_match("/Class .* class ([^ ]*) /", $buf, $m)) {
		$class = strtolower($m[1]);
		$res[$class] = [];
		$tab[$class] = $buf;
		fprintf(STDERR, "+ $class\n");
	} else if (preg_match("/Method .* method ([^ ]*) /", $buf, $m)) {
		$method = strtolower($m[1]);
		$res[$class][$method] = '';
		fprintf(STDERR, "+     $method\n");
	} 

	if ($class) {
		if ($method) {
			$res[$class][$method] .= $buf;
		}
	}

	if (strpos($buf, "}") == 8) {
		$method = false;
	} else if (strpos($buf, "}") == 4) {
		$class = false;
	}
}

ksort($res);
foreach ($res as $class => $methods) {
	echo $tab[$class];
	
	ksort($methods);
	foreach ($methods as $method => $def) {
		echo $def;
	}
}
fprintf(STDERR, "\nDone\n");
fclose($in);
?>