Quiet compiler warnings
[freeradius.git] / share / header.pl
1 #!/usr/bin/perl
2
3 $begin_vendor = 0;
4 $blank = 0;
5
6 while (@ARGV) {
7     $filename = shift;
8
9     open FILE, "<$filename" or die "Failed to open $filename: $!\n";
10
11     @output = ();
12
13     while (<FILE>) {
14         #
15         #  Clear out trailing whitespace
16         #
17         s/[ \t]+$//;
18
19         #
20         #  And CR's
21         #
22         s/\r//g;
23
24         #
25         #  Suppress multiple blank lines
26         #
27         if (/^\s+$/) {
28             next if ($blank == 1);
29             $blank = 1;
30             next;
31         }
32         $blank = 0;
33
34         #
35         #  Remember the vendor
36         #
37         if (/^VENDOR\s+([\w-]+)\s+(\w+)(.*)/) {
38             $name=$1;
39
40             $pname = $name;
41             $pname =~ tr/[a-z].-/[A-Z]__/;
42
43             $vvalue = "FR_VENDOR_$pname";
44             push @output, "#define $vvalue $2\n";
45             push @output, "#define ${vvalue}_H ($2 << 16)\n";
46             $vendor = $pname;
47             next;
48         }
49
50         #
51         #  Remember if we did begin-vendor.
52         #
53         if (/^BEGIN-VENDOR\s+([\w-]+)/) {
54             $begin_vendor = 1;
55             if (!defined $vendor) {
56                 $vendor = $1;
57             } elsif ($vendor ne $1) {
58                 # do something smart
59             }
60
61             next;
62         }
63
64         #
65         #  Get attribute.
66         #
67         if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) {
68             $name=$1;
69
70
71             $value = $2;
72             $type = $3;
73             $stuff = $4;
74
75             #
76             #  See if it's old format, with the vendor at the end of
77             #  the line.  If so, make it the new format.
78             #
79             if ($stuff =~ /$vendor/) {
80                 if ($begin_vendor == 0) {
81                     $begin_vendor = 1;
82                 }
83                 $stuff =~ s/$vendor//;
84                 $stuff =~ s/\s+$//;
85             }
86
87
88             $pname = $name;
89             $pname =~ tr/[a-z].-/[A-Z]__/;
90
91             next if (defined $attr{$pname});
92
93             if ($vvalue) {
94                 push @output, "#define FR_ATTR_$pname (${vvalue}_H | $value)\n";
95             } else {
96                 push @output, "#define FR_ATTR_$pname ($value)\n";
97             }
98
99             $attr{$pname}++;
100
101             next;
102         }
103
104         #
105         #  Values.
106         #
107         if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) {
108             $attr=$1;
109             $name = $2;
110
111             $pattr = $attr;
112             $pattr =~ tr/[a-z].\/-/[A-Z]___/;
113
114             # FIXME: check if vendor name is in attribute name.
115             #        if not, add it in.
116
117             $pname = $name;
118             $pname =~ tr/[a-z].\/,-/[A-Z]____/;
119
120             push @output, "#define FR_VALUE_${pattr}_${pname} ($3)\n";
121             next;
122         }
123
124         #
125         #  Remember if we did this.
126         #
127         if (/^END-VENDOR/) {
128             $begin_vendor = 0;
129             next;
130         }
131
132         if (/^\$INCLUDE ([a-z0-9.A-Z_]+)/) {
133             push @output, "#include <freeradius-devel/dict/${1}.h>\n";
134             next;
135         }
136     }
137
138     close FILE;
139
140     print "/* AUTO-GENERATED HEADER - DO NOT EDIT */\n";
141     print @output;
142 }