1.1.4
by Paul Hampson
Import upstream version 1.1.0 |
1 |
#!/usr/bin/env perl
|
2 |
#
|
|
3 |
# Sort the attributes in a dictionary, and put them into a canonical
|
|
4 |
# form. This will DESTROY any comments!
|
|
5 |
#
|
|
6 |
# Usage: cat dictionary | ./attrsort.pl > new
|
|
7 |
#
|
|
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...
|
|
10 |
#
|
|
1.1.12
by Chuck Short
Import upstream version 2.1.0+dfsg |
11 |
# $Id$
|
1.1.4
by Paul Hampson
Import upstream version 1.1.0 |
12 |
#
|
13 |
||
14 |
while (<>) { |
|
15 |
#
|
|
16 |
# Get attribute.
|
|
17 |
#
|
|
18 |
if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) { |
|
19 |
$name=$1; |
|
20 |
$value = $2; |
|
21 |
$type = $3; |
|
22 |
$stuff = $4; |
|
23 |
||
24 |
$value =~ tr/[A-F]/[a-f]/; # normal form for hex |
|
25 |
$value =~ tr/X/x/; |
|
26 |
||
27 |
if ($value =~ /^0x/) { |
|
28 |
$index = hex $value; |
|
29 |
} else { |
|
30 |
$index = $value; |
|
31 |
}
|
|
32 |
||
33 |
$attributes{$index} = "$name $value $type$stuff"; |
|
34 |
$name2val{$name} = $index; |
|
35 |
next; |
|
36 |
}
|
|
37 |
||
38 |
#
|
|
39 |
# Values.
|
|
40 |
#
|
|
41 |
if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) { |
|
42 |
$attr = $1; |
|
43 |
$name = $2; |
|
44 |
$value = $3; |
|
45 |
$stuff = $d; |
|
46 |
||
47 |
$value =~ tr/[A-F]/[a-f]/; # normal form for hex |
|
48 |
$value =~ tr/X/x/; |
|
49 |
||
50 |
if ($value =~ /^0x/) { |
|
51 |
$index = hex $value; |
|
52 |
} else { |
|
53 |
$index = $value; |
|
54 |
}
|
|
55 |
||
56 |
if (!defined $name2val{$attr}) { |
|
57 |
print "# FIXME: FORWARD REF?\nVALUE $attr $name $value$stuff\n"; |
|
58 |
next; |
|
59 |
}
|
|
60 |
||
61 |
$values{$name2val{$attr}}{$index} = "$attr $name $value$stuff"; |
|
62 |
next; |
|
63 |
}
|
|
64 |
}
|
|
65 |
||
66 |
#
|
|
67 |
# Print out the attributes sorted by number.
|
|
68 |
#
|
|
69 |
foreach $attr_val (sort {$a <=> $b} keys %attributes) { |
|
70 |
print "ATTRIBUTE ", $attributes{$attr_val}, "\n"; |
|
71 |
}
|
|
72 |
||
73 |
foreach $value (sort {$a <=> $b} keys %values) { |
|
74 |
print $value, "\t", $attributes{$value}, "\n"; |
|
75 |
}
|
|
76 |
||
77 |
#
|
|
78 |
# And again, this time printing out values.
|
|
79 |
#
|
|
80 |
foreach $attr_val (sort {$a <=> $b} keys %attributes) { |
|
81 |
||
82 |
next if (!defined %{$values{$attr_val}}); |
|
83 |
||
84 |
foreach $value (sort {$a <=> $b} keys %{$values{$attr_val}}) { |
|
85 |
print "VALUE ", $values{$attr_val}{$value}, "\n"; |
|
86 |
}
|
|
87 |
}
|