#!/usr/bin/perl

die unless open(K,"<".(shift)); @kfile=<K>; close(K);
die unless open(D,"<".(shift)); @dfile=<D>; close(D);

my @extra;

#        0e113033        video   Server:XF86_SVGA        QVision 1280/p
# 0x0e11  0xb060  "cciss" "Compaq|Smart Array 5300 Controller"
foreach $d (@dfile)
 {
  if($d =~ /0x([0-9a-f]{4})[ \t]+0x([0-9a-f]{4})[ \t]+"([^ \t]+)"[ \t]+"(.*)"$/i)
   {
    $new=sprintf("0x%04x\t0x%04x\t\"%s\"\t\"%s\"\n",hex($1),hex($2),"$3","$4");
    $found=0;
    for ($i=0;$i<=$#kfile;$i++)
     {
      $cmp=sprintf('(0x%x|0x%0.4x)\s(0x%x|0x%0.4x)',hex($1),hex($1),hex($2),hex($2));
      if($kfile[$i] =~ /$cmp/i ) # Found a matching line in pcitable
       {
        $kfile[$i]=$new; $found=1;
       }
     }
    if(!$found) { push @extra,$new; }
   }
 }

 print join("",@kfile);
 print "# Extra\n";
 print join("",@extra);
