$begin_vendor = 0;
$blank = 0;
while (<>) {
s/[ \t]+$//;
s/\r//g;
if (/^\s+$/) {
next if ($blank == 1);
$blank = 1;
print "\n";
next;
}
$blank = 0;
if (/^VENDOR\s+([\w-]+)\s+(\w+)(.*)/) {
$name=$1;
$len = length $name;
if ($len < 32) {
$lenx = 32 - $len;
$lenx += 7; $lenx /= 8;
$lenx = int $lenx;
$tabs = "\t" x $lenx;
} else {
$tabs = " ";
}
print "VENDOR\t\t$name$tabs$2$3\n";
$vendor = $name;
next;
}
if (/^BEGIN-VENDOR\s+([\w-]+)/) {
$begin_vendor = 1;
print "BEGIN-VENDOR\t$vendor\n";
next;
}
if (/^ATTRIBUTE\s+([\w-]+)\s+(\w+)\s+(\w+)(.*)/) {
$name=$1;
$len = length $name;
if ($len < 40) {
$lenx = 40 - $len;
$lenx += 7; $lenx /= 8;
$lenx = int $lenx;
$tabs = "\t" x $lenx;
if ($tabs eq "") {
$tabs = " ";
}
} else {
$tabs = " ";
}
$value = $2;
$type = $3;
$stuff = $4;
if ($stuff =~ /$vendor/) {
if ($begin_vendor == 0) {
print "BEGIN-VENDOR\t$vendor\n\n";
$begin_vendor = 1;
}
$stuff =~ s/$vendor//;
$stuff =~ s/\s+$//;
}
print "ATTRIBUTE\t$name$tabs$value\t$type$stuff\n";
next;
}
if (/^VALUE\s+([\w-]+)\s+([\w-\/,.]+)\s+(\w+)(.*)/) {
$attr=$1;
$len = length $attr;
if ($len < 32) {
$lenx = 32 - $len;
$lenx += 7; $lenx /= 8;
$lenx = int $lenx;
$tabsa = "\t" x $lenx;
if ($tabsa eq "") {
$tabsa = " ";
$len += 1;
} else {
$len -= $len % 8;
$len += 8 * length $tabsa;
}
} else {
$tabsa = " ";
$len += 1;
}
if ($len < 32) {
$lena = 0;
} else {
$lena = $len - 32;
}
$name = $2;
$len = length $name;
if ($len < 24) {
$lenx = 24 - $lena - $len;
$lenx += 7; $lenx /= 8;
$lenx = int $lenx;
$tabsn = "\t" x $lenx;
if ($tabsn eq "") {
$tabsn = " ";
}
} else {
$tabsn = " ";
}
print "VALUE\t$attr$tabsa$name$tabsn$3$4\n";
next;
}
if (/^END-VENDOR/) {
$begin_vendor = 0;
}
print;
}
if ($begin_vendor) {
print "\nEND-VENDOR\t$vendor\n";
}