3 # Sort the attributes in a dictionary, and put them into a canonical
4 # form. This will DESTROY any comments!
6 # Usage: cat dictionary | ./attrsort.pl > new
8 # This is a bit of a hack. The main purpose is to be able to quickly
9 # "diff" two dictionaries which have significant differences...
18 if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) {
24 $value =~ tr/[A-F]/[a-f]/; # normal form for hex
27 if ($value =~ /^0x/) {
33 $attributes{$index} = "$name $value $type$stuff";
34 $name2val{$name} = $index;
41 if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) {
47 $value =~ tr/[A-F]/[a-f]/; # normal form for hex
50 if ($value =~ /^0x/) {
56 if (!defined $name2val{$attr}) {
57 print "# FIXME: FORWARD REF?\nVALUE $attr $name $value$stuff\n";
61 $values{$name2val{$attr}}{$index} = "$attr $name $value$stuff";
67 # Print out the attributes sorted by number.
69 foreach $attr_val (sort {$a <=> $b} keys %attributes) {
70 print "ATTRIBUTE ", $attributes{$attr_val}, "\n";
73 foreach $value (sort {$a <=> $b} keys %values) {
74 print $value, "\t", $attributes{$value}, "\n";
78 # And again, this time printing out values.
80 foreach $attr_val (sort {$a <=> $b} keys %attributes) {
82 next if (!defined %{$values{$attr_val}});
84 foreach $value (sort {$a <=> $b} keys %{$values{$attr_val}}) {
85 print "VALUE ", $values{$attr_val}{$value}, "\n";