Debian Codegraph @

debian/tests/test-db-format

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my ($SELF) = $0 =~ m{(?:.*/)?([^/]*)};
7 my $DEBUG = defined $ENV{PCI_IDS_DEBUG};
8 my $PCIIDS = $ARGV[0] // '/usr/share/misc/pci.ids';
9
10 sub error
11 {
12 my (@args) = @_;
13
14 die "$SELF: @args: FAIL\n";
15 }
16
17 sub debug
18 {
19 my (@args) = @_;
20
21 print "@args\n" if $DEBUG;
22 }
23
24 sub check
25 {
26 my $fh = shift;
27
28 my ($vendor, $device);
29 my ($class, $subclass);
30
31 while (<$fh>) {
32 next if m/^#/;
33 next if m/^\s*$/;
34
35 s/#.*$//;
36
37 if (m/^([0-9a-fA-F]{4}) (.*)$/) {
38 debug("Vendor ($1) ($2)");
39 $vendor = $1;
40 $device = undef;
41 $class = undef;
42 $subclass = undef;
43 } elsif (m/^\t([0-9a-fA-F]{4}) (.*)$/) {
44 if (not defined $vendor) {
45 error("Device defined not within a Vendor at line $.");
46 }
47 debug("Device ($1) ($2)");
48 $device = $1;
49 } elsif (m/^\t\t([0-9a-fA-F]{4}) ([0-9a-fA-F]{4}) (.*)$/) {
50 if (not defined $device) {
51 error("SubDevice defined not within a Device at line $.");
52 }
53 debug("SubVendor SubDevice ($1 $2) ($2)");
54 } elsif (m/^C ([0-9a-fA-F]{2}) (.*)$/) {
55 debug("Class ($1) ($2)");
56 $vendor = undef;
57 $device = undef;
58 $class = $1;
59 $subclass = undef;
60 } elsif (m/^\t([0-9a-fA-F]{2}) (.*)$/) {
61 if (not defined $class) {
62 error("SubClass defined not within a Class at line $.");
63 }
64 debug("SubClass ($1) ($2)");
65 $subclass = $1;
66 } elsif (m/^\t\t([0-9a-fA-F]{2}) (.*)$/) {
67 if (not defined $subclass) {
68 error("Programming Interface defined not within a SubClass at line $.");
69 }
70 debug("ProgIface ($1) ($2)");
71 } else {
72 error("Unknown entry in file at line $.");
73 }
74 }
75 }
76
77 open my $fh, '<', $PCIIDS or error("cannot open $PCIIDS database: $!");
78 check($fh);
79 close $fh;
80
81 print "$SELF: format of $PCIIDS is ok: PASS\n";
82
83 exit 0;