#!/usr/bin/perl -w

use strict;

my $class;

print "/* Do not edit - generated from pci.ids by make_pci_class_lookup */\n\n";print "#include <stdio.h>\n#include <stdbool.h>\n#include \"proc_pci.h\"\n\n";
print "bool\nproc_pci_class(const char * this_line, proc_pci_list_t * l)\n{\n";
print "\tchar c;\n\n";
print "\tif (false) {\n\t\treturn false;\n";

while (<>) {
    chomp;
    if ($_ =~ "^\t\t") {
	next;
    } elsif ($class && ($_ =~ '^\t([[:xdigit:]]+)\s+(.+)$')) {
	print "\t} else if (1 == sscanf(this_line, \" $2: \%c\", \&c)) {\n";
	print "\t\tl->class = (uint16_t) 0x${class}$1;\n";
	print "\t\treturn true;\n";
    } elsif ($_ =~ '^C\s+([[:xdigit:]]+)\s+.+$') {
	$class = $1;
    }
}

print "\t} else\n\t\treturn false;\n}\n";
