summaryrefslogtreecommitdiffstats
path: root/share/attrsort.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:11:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:11:00 +0000
commitaf754e596a8dbb05ed8580c342e7fe02e08b28e0 (patch)
treeb2f334c2b55ede42081aa6710a72da784547d8ea /share/attrsort.pl
parentInitial commit. (diff)
downloadfreeradius-af754e596a8dbb05ed8580c342e7fe02e08b28e0.tar.xz
freeradius-af754e596a8dbb05ed8580c342e7fe02e08b28e0.zip
Adding upstream version 3.2.3+dfsg.upstream/3.2.3+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/attrsort.pl')
-rwxr-xr-xshare/attrsort.pl87
1 files changed, 87 insertions, 0 deletions
diff --git a/share/attrsort.pl b/share/attrsort.pl
new file mode 100755
index 0000000..8967259
--- /dev/null
+++ b/share/attrsort.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+#
+# Sort the attributes in a dictionary, and put them into a canonical
+# form. This will DESTROY any comments!
+#
+# Usage: cat dictionary | ./attrsort.pl > new
+#
+# This is a bit of a hack. The main purpose is to be able to quickly
+# "diff" two dictionaries which have significant differences...
+#
+# $Id$
+#
+
+while (<>) {
+ #
+ # Get attribute.
+ #
+ if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) {
+ $name=$1;
+ $value = $2;
+ $type = $3;
+ $stuff = $4;
+
+ $value =~ tr/[A-F]/[a-f]/; # normal form for hex
+ $value =~ tr/X/x/;
+
+ if ($value =~ /^0x/) {
+ $index = hex $value;
+ } else {
+ $index = $value;
+ }
+
+ $attributes{$index} = "$name $value $type$stuff";
+ $name2val{$name} = $index;
+ next;
+ }
+
+ #
+ # Values.
+ #
+ if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) {
+ $attr = $1;
+ $name = $2;
+ $value = $3;
+ $stuff = $d;
+
+ $value =~ tr/[A-F]/[a-f]/; # normal form for hex
+ $value =~ tr/X/x/;
+
+ if ($value =~ /^0x/) {
+ $index = hex $value;
+ } else {
+ $index = $value;
+ }
+
+ if (!defined $name2val{$attr}) {
+ print "# FIXME: FORWARD REF?\nVALUE $attr $name $value$stuff\n";
+ next;
+ }
+
+ $values{$name2val{$attr}}{$index} = "$attr $name $value$stuff";
+ next;
+ }
+}
+
+#
+# Print out the attributes sorted by number.
+#
+foreach $attr_val (sort {$a <=> $b} keys %attributes) {
+ print "ATTRIBUTE ", $attributes{$attr_val}, "\n";
+}
+
+foreach $value (sort {$a <=> $b} keys %values) {
+ print $value, "\t", $attributes{$value}, "\n";
+}
+
+#
+# And again, this time printing out values.
+#
+foreach $attr_val (sort {$a <=> $b} keys %attributes) {
+
+ next if (!defined %{$values{$attr_val}});
+
+ foreach $value (sort {$a <=> $b} keys %{$values{$attr_val}}) {
+ print "VALUE ", $values{$attr_val}{$value}, "\n";
+ }
+}