3 # Format the dictionaries according to a standard scheme.
5 # Usage: ./format.pl dictionary.foo
7 # We don't over-write the dictionaries in place, so that the process
8 # can be double-checked by hand.
10 # This is a bit of a hack.
12 # FIXME: get lengths from variables, rather than hard-coding.
14 ######################################################################
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 # Copyright (C) 2010 Alan DeKok <aland@freeradius.org>
32 ######################################################################
43 open FILE, "<$filename" or die "Failed to open $filename: $!\n";
49 # Clear out trailing whitespace
59 # Suppress multiple blank lines
62 next if ($blank == 1);
74 if (/^VENDOR\s+([-\w]+)\s+(\w+)(.*)/) {
79 $lenx += 7; # round up
86 push @output, "VENDOR\t\t$name$tabs$2$3\n";
92 # Remember if we did begin-vendor.
94 if (/^BEGIN-VENDOR\s+([-\w]+)/) {
96 if (!defined $vendor) {
98 } elsif ($vendor ne $1) {
102 push @output, "BEGIN-VENDOR\t$vendor\n";
109 if (/^ATTRIBUTE\s+([-\w]+)\s+([\w.]+)\s+(\w+)(.*)/) {
114 $lenx += 7; # round up
117 $tabs = "\t" x $lenx;
130 # See if it's old format, with the vendor at the end of
131 # the line. If so, make it the new format.
133 if ($stuff =~ /$vendor/) {
134 if ($begin_vendor == 0) {
135 push @output, "BEGIN-VENDOR\t$vendor\n\n";
138 $stuff =~ s/$vendor//;
142 push @output, "ATTRIBUTE\t$name$tabs$value\t$type$stuff\n";
149 if (/^VALUE\s+([-\w]+)\s+([-\w\/,.]+)\s+(\w+)(.*)/) {
154 $lenx += 7; # round up
157 $tabsa = "\t" x $lenx;
163 $len += 8 * length $tabsa;
171 # For the code below, we assume that the attribute lengths
182 $lenx = 24 - $lena - $len;
183 $lenx += 7; # round up
186 $tabsn = "\t" x $lenx;
194 push @output, "VALUE\t$attr$tabsa$name$tabsn$3$4\n";
199 # Remember if we did this.
206 # Everything else gets dumped out as-is.
212 # If we changed the format, print the end vendor, too.
215 push @output, "\nEND-VENDOR\t$vendor\n";
220 open FILE, ">$filename" or die "Failed to open $filename: $!\n";