~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to share/attrsort.pl

  • Committer: Bazaar Package Importer
  • Author(s): Paul Hampson
  • Date: 2006-01-15 13:34:13 UTC
  • mto: (3.1.3 dapper) (4.1.3 sid) (1.1.14 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060115133413-zo1dslttvdoalqym
Tags: upstream-1.1.0
ImportĀ upstreamĀ versionĀ 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#
 
11
#  $Id: attrsort.pl,v 1.1.2.1 2005/11/30 22:17:18 aland Exp $
 
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
}