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

« back to all changes in this revision

Viewing changes to share/attrnew.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
#  Print out the ATTRIBUTE's which are defined only once on input,
 
4
#  and any VALUE's which are defined for those attributes.  It does NOT
 
5
#  print out unique VALUEs for multiple-defined attributes, though.
 
6
#
 
7
#  Usage: cat dictionary1 dictionary2 | ./attrnew.pl > unique
 
8
#
 
9
#  This is a bit of a hack.  In order to make it work, you've got to
 
10
#  add a "fake" attribute to the end of dictionary1, so that you know
 
11
#  which attributes belong to which dictionary...
 
12
#
 
13
#  $Id: attrnew.pl,v 1.1.2.1 2005/11/30 22:17:18 aland Exp $
 
14
#
 
15
 
 
16
$line = 0;
 
17
while (<>) {
 
18
    $line++;
 
19
 
 
20
    #
 
21
    #  Get attribute.
 
22
    #
 
23
    if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) {
 
24
        $name=$1;
 
25
        $value = $2;
 
26
        $type = $3;
 
27
        $stuff = $4;
 
28
 
 
29
        $value =~ tr/[A-F]/[a-f]/; # normal form for hex
 
30
        $value =~ tr/X/x/;
 
31
 
 
32
        if ($value =~ /^0x/) {
 
33
            $index = hex $value;
 
34
        } else {
 
35
            $index = $value;
 
36
        }
 
37
 
 
38
        if (defined $attributes{$index}) {
 
39
            $dup{$index}++;
 
40
        } else {
 
41
            $first_ref{$line} = $index;
 
42
        }
 
43
 
 
44
        $attributes{$index} = "$name $value $type$stuff";
 
45
        $name2val{$name} = $index;
 
46
        next;
 
47
    }
 
48
 
 
49
    #
 
50
    #  Values.
 
51
    #
 
52
    if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) {
 
53
        $attr = $1;
 
54
        $name = $2;
 
55
        $value = $3;
 
56
        $stuff = $d;
 
57
 
 
58
        $value =~ tr/[A-F]/[a-f]/; # normal form for hex
 
59
        $value =~ tr/X/x/;
 
60
 
 
61
        if ($value =~ /^0x/) {
 
62
            $index = hex $value;
 
63
        } else {
 
64
            $index = $value;
 
65
        }
 
66
 
 
67
        if (!defined $name2val{$attr}) {
 
68
            print "# FIXME: FORWARD REF?\nVALUE $attr $name $value$stuff\n";
 
69
            next;
 
70
        }
 
71
 
 
72
        $values{$name2val{$attr}}{$index} = "$attr $name $value$stuff";
 
73
        next;
 
74
    }
 
75
}
 
76
 
 
77
#
 
78
#  Print out the attributes sorted by number.
 
79
#
 
80
foreach $line (sort {$a <=> $b} keys %first_ref) {
 
81
    $attr_val = $first_ref{$line};
 
82
 
 
83
    next if (defined $dup{$attr_val});
 
84
 
 
85
    print "ATTRIBUTE ", $attributes{$attr_val}, "\n";
 
86
 
 
87
    next if (!defined %{$values{$attr_val}});
 
88
 
 
89
    foreach $value (sort {$a <=> $b} keys %{$values{$attr_val}}) {
 
90
        print "VALUE ", $values{$attr_val}{$value}, "\n";
 
91
    }
 
92
 
 
93
}