3 # Format the dictionaries according to a standard scheme.
5 # Usage: cat dictionary | ./format.pl > new
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.
23 open FILE, "<$filename" or die "Failed to open $filename: $!\n";
29 # Clear out trailing whitespace
39 # Suppress multiple blank lines
42 next if ($blank == 1);
52 if (/^VENDOR\s+([\w-]+)\s+(\w+)(.*)/) {
57 $lenx += 7; # round up
64 push @output, "VENDOR\t\t$name$tabs$2$3\n";
70 # Remember if we did begin-vendor.
72 if (/^BEGIN-VENDOR\s+([\w-]+)/) {
74 if (!defined $vendor) {
76 } elsif ($vendor ne $1) {
80 push @output, "BEGIN-VENDOR\t$vendor\n";
87 if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) {
92 $lenx += 7; # round up
108 # See if it's old format, with the vendor at the end of
109 # the line. If so, make it the new format.
111 if ($stuff =~ /$vendor/) {
112 if ($begin_vendor == 0) {
113 push @output, "BEGIN-VENDOR\t$vendor\n\n";
116 $stuff =~ s/$vendor//;
120 push @output, "ATTRIBUTE\t$name$tabs$value\t$type$stuff\n";
127 if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) {
132 $lenx += 7; # round up
135 $tabsa = "\t" x $lenx;
141 $len += 8 * length $tabsa;
149 # For the code below, we assume that the attribute lengths
160 $lenx = 24 - $lena - $len;
161 $lenx += 7; # round up
164 $tabsn = "\t" x $lenx;
172 push @output, "VALUE\t$attr$tabsa$name$tabsn$3$4\n";
177 # Remember if we did this.
184 # Everything else gets dumped out as-is.
190 # If we changed the format, print the end vendor, too.
193 push @output, "\nEND-VENDOR\t$vendor\n";
198 open FILE, ">$filename" or die "Failed to open $filename: $!\n";