summaryrefslogtreecommitdiffstats
path: root/sortrefl
diff options
context:
space:
mode:
Diffstat (limited to 'sortrefl')
-rwxr-xr-xsortrefl51
1 files changed, 51 insertions, 0 deletions
diff --git a/sortrefl b/sortrefl
new file mode 100755
index 0000000..f38efb5
--- /dev/null
+++ b/sortrefl
@@ -0,0 +1,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);
+?>