This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
/
parse.pl
92 lines (86 loc) · 3.1 KB
/
parse.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
open my $fh, '<', 'download/pci.ids';
my @vendors = ();
my %queries = ();
my %key = (
0 => sub {
s/^(....)\s+//; chomp;
push @vendors, {
"id" => $1,
"name" => $_,
"devices" => [] }
},
1 => sub {
s/^(....)\s+//; chomp;
push $vendors[-1]{devices}, {
"id" => $1,
"name" => $_,
"subdevices" => [] }
},
2 => sub {
s/^(....)\ (....)\s+//; chomp;
return if not $2;
push $vendors[-1]{devices}[-1]{subdevices}, {
"subvendor" => $1,
"subdevice" => $2,
"subsystem_name" => $_ };
},
);
while (<$fh>) {
next if m/^#|^\s+$/;
$key{length $1}->(s/^(\t{0,2})//);
}
foreach my $vendor (@vendors) {
my $category = scalar @{$vendor->{devices}} > 10 ? 1 : 0;
$queries{$vendor->{id}} = {
"abstract" =>"<i>Vendor</i>: $vendor->{name}",
};
if (scalar @{$vendor->{devices}} > 0) {
foreach my $device (@{$vendor->{devices}}) {
$queries{"$vendor->{id} $device->{id}"} = {
"abstract" => "<i>Device</i>: $device->{name}<br>"
. "<i>Vendor</i>: $vendor->{name}",
"category" => $category ? "PCI vendor ID $vendor->{id}"
: ""
};
if (scalar @{$device->{subdevices}} > 0) {
foreach my $subdevice (@{$device->{subdevices}}) {
$queries{"$vendor->{id} $device->{id} "
. "$subdevice->{subvendor} "
. "$subdevice->{subdevice}"} = {
"abstract" => "<i>Subdevice/subvendor</i>: "
. "$subdevice->{subsystem_name}<br>"
. "<i>Device</i>: "
. "$device->{name}<br>"
. "<i>Vendor</i>: $vendor->{name}<br>",
"category" => $category ? "PCI vendor ID "
. "$vendor->{id}" : ""
};
}
}
}
}
}
open my $output, '>', 'output.txt';
map {
print $output join "\t", (
$_, # title
"A", # type
"", # redirect
"", # otheruses
"PCI IDs\\n"
. (exists $queries{$_}->{category} ?
$queries{$_}->{category} : ""), # categories
"", # references
"", # see_also
"", # further_reading
"", # external_links
"", # disambiguation
"", # images
$queries{$_}->{abstract}, # abstract
"http://pciids.sourceforge.net/\n" # source_url
);
} keys %queries;