summaryrefslogtreecommitdiffstats
path: root/sortrefl
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2021-06-16 10:06:17 +0200
committerRemi Collet <remi@remirepo.net>2021-06-16 10:06:17 +0200
commitd18cf8bc918d26cdad25d1311a7effe4bd308f48 (patch)
tree7edbee7a806f8339213cad22879a16eff9e6bdcc /sortrefl
parent7e6f833ca3f4421f410322aa1f1b398173befe00 (diff)
add small script to sort reflection of an PHP extension (only methods)
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);
+?>