]> mj.ucw.cz Git - pciids.git/blob - scripts/ids_to_dbdump
ids_to_dbdump is still needed by the mailbot
[pciids.git] / scripts / ids_to_dbdump
1 #!/usr/bin/perl
2 # Convert pci.ids to format used by the database.
3
4 sub id {
5         $_ = shift @_;
6         tr/A-F/a-f/;
7         return $_;
8 }
9
10 $last = "????"; $lastd = "????????"; $cmt = "";
11 while (<>) {
12         chomp;
13         s/ +$//;
14         s/([^\t])\t+/$1 /g;
15         if (/^$/) { $cmt=""; next; }
16         if (/^#/) { s/^#//; $cmt="$cmt $_"; next; }
17         /^C/ && last;
18         $cmt =~ s/  +/ /g;
19         $cmt =~ s/^ +//;
20         if (/^\t\t([0-9a-fA-F]{4}) ([0-9a-fA-F]{4})\s+([^\t]*)$/) {
21                 print "s\t",id("$lastd$1$2"),"\t$3\t0\t$cmt\n";
22         } elsif (/^\t([0-9a-fA-F]{4})\s+([^\t]*)$/) {
23                 $lastd="$last$1";
24                 print "d\t",id($lastd),"\t$2\t0\t$cmt\n";
25         } elsif (/^([0-9a-fA-F]{4})\s+([^\t]*)$/) {
26                 $last=$1; $lastd="$1????";
27                 print "v\t",id($1),"\t$2\t0\t$cmt\n";
28         } else {
29                 die "Syntax error: $_";
30         }
31         $cmt="";
32 }