1#!/usr/bin/perl -w 2# Create a DNS zone with PCI ID records 3 4use strict; 5 6my %ids = (); 7my %comments = (); 8foreach our $file (@ARGV) { 9 my $fn = ($file =~ /\.gz$/) ? "zcat $file |" : ($file =~ /\.bz2$/) ? "bzcat $file |" : $file; 10 open F, $fn or die "Unable to open $file: $!"; 11 my @id = (); 12 my $comm = ""; 13 sub err($) { 14 print STDERR "Error in $file, line $.: @_\n"; 15 exit 1; 16 } 17 while (<F>) { 18 if (/^(#.*)/) { 19 $comm .= $_; 20 next; 21 } 22 chomp; 23 if (my ($indent, $id, $ignored, $name) = /^(\t*)(([0-9a-fA-Z]+ ?)*)(( |\t|$)\s*(.*))$/) { 24 my $depth = length $indent; 25 $depth <= @id or err "Mismatched indentation"; 26 @id = (@id[0..$depth-1], $id); 27 my $i = join(":", @id); 28 if ($i ne "") { 29 !exists $ids{$i} or die "ID $i defined twice"; 30 $ids{$i} = $name; 31 $comments{$i} = $comm if $comm; 32 } 33 } elsif (!/^$/) { 34 err "Parse error"; 35 } 36 $comm = ""; 37 } 38 close F; 39} 40 41sub esc($) { 42 my ($x) = @_; 43 $x =~ s/^\s+//; 44 $x =~ s/"/\\"/g; 45 return $x; 46} 47 48foreach my $i (keys %ids) { 49 my $j = join(".", reverse split(/[: ]/, $i)); 50 print "$j.pci\tTXT \"i=", esc($ids{$i}), "\"\n"; 51 # print "$j.pci\tTXT \"c=", esc($comments{$i}), "\"\n" 52} 53