3 # Copyright (C) 2001 Sheldon Hearn. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # $FreeBSD: src/tools/tools/pciid/mk_pci_vendors.pl,v 1.5 2004/06/28 11:46:48 mux Exp $
27 # $DragonFly: src/tools/tools/pciid/mk_pci_vendors.pl,v 1.2 2008/03/08 20:17:38 swildner Exp $
29 # usage: mk_pci_vendors [-lq] [-p pcidevs.txt] [-v vendors.txt] [-x pci.ids]
31 # Generate src/share/misc/pci_vendors from the Hart, Boemler and Mares lists,
32 # currently available at:
34 # Boemler: http://www.pcidatabase.com/reports.php?type=tab-delimeted
35 # Hart: http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
36 # Mares: http://pciids.sourceforge.net/pci.ids
38 # -l Where an entry is found in the Boemler and the Hart lists, use the
39 # entry with the longest description. The -l option doesn't affect
40 # the Mares list whose entries are only used if they are new. The
41 # default is for the Boemler file to override the Hart file to
42 # override the Mares file.
43 # -q Do not print diagnostics.
44 # -p Specify the pathname of the Hart file. (Default ./pcidevs.txt)
45 # -v Specify the pathname of the Boemler file. (Default ./vendors.txt)
46 # -x Specify the pathname of the Mares file. (Default ./pci.ids)
51 my $PROGNAME = 'mk_pci_vendors';
52 my $VENDORS_FILE = 'vendors.txt';
53 my $PCIDEVS_FILE = 'pcidevs.txt';
54 my $PCIIDS_FILE = 'pci.ids';
59 my ($descr, $existing, $id, $line, $rv, $winner, $optlused);
70 sub vendors_parse
($\
$\
$);
71 sub pcidevs_parse
($\
$\
$);
72 sub pciids_parse
($\
$\
$);
74 if (not getopts
('lp:qv:x:', \
%opts) or @ARGV > 0) {
75 print STDERR
"usage: $PROGNAME [-lq] [-p pcidevs.txt] [-v vendors.txt] [-x pci.ids]\n";
79 if (not defined($opts{p
})) {
80 $opts{p
} = $PCIDEVS_FILE;
82 if (not defined($opts{v
})) {
83 $opts{v
} = $VENDORS_FILE;
85 if (not defined($opts{x
})) {
86 $opts{x
} = $PCIIDS_FILE;
88 foreach (('l', 'q')) {
89 if (not exists($opts{$_})) {
96 open(VENDORS
, "< $opts{v}") or
97 die "$PROGNAME: $opts{v}: $!\n";
98 while ($line = <VENDORS
>) {
100 $rv = vendors_parse
($line, $id, $descr);
101 if ($rv == $IS_VENDOR) {
102 if (exists($vendors{$id})) {
103 die "$PROGNAME: $id: duplicate vendor ID\n";
105 $vendors{$id} = [$descr, {}];
107 } elsif ($rv == $IS_DEVICE) {
108 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
113 open(PCIDEVS
, "< $opts{p}") or
114 die "$PROGNAME: $opts{p}: $!\n";
115 while ($line = <PCIDEVS
>) {
117 $rv = pcidevs_parse
($line, $id, $descr);
118 if ($rv == $IS_VENDOR) {
119 if (not exists($vendors{$id})) {
120 $vendors{$id} = [$descr, {}];
121 $winner = $W_NOCONTEST;
123 $existing = $vendors{$id}->[$V_DESCR];
124 if (length($existing) < length($descr)) {
125 $vendors{$id}->[$V_DESCR] = $descr;
126 $winner = $W_PCIDEVS;
128 $winner = $W_VENDORS;
131 $winner = $W_VENDORS;
134 if (not $opts{q
} and $winner != $W_NOCONTEST) {
135 $existing = $vendors{$id}->[$V_DESCR];
136 print STDERR
"$PROGNAME: ",
137 $winner == $W_VENDORS ?
"Boemler" : "Hart",
138 " vendor wins: $id\t$existing\n";
140 } elsif ($rv == $IS_DEVICE) {
141 if (not exists(${$vendors{$cur_vendor}->[$V_DEVSL]}{$id})) {
142 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
143 $winner = $W_NOCONTEST;
145 $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
146 if (length($existing) < length($descr)) {
147 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} =
149 $winner = $W_PCIDEVS;
151 $winner = $W_VENDORS;
154 $winner = $W_VENDORS;
156 if (not $opts{q
} and $winner != $W_NOCONTEST) {
157 $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
158 print STDERR
"$PROGNAME: ",
159 $winner == $W_VENDORS ?
"Boemler" : "Hart",
160 " device wins: $id\t$existing\n";
166 open(PCIIDS
, "< $opts{x}") or
167 die "$PROGNAME: $opts{x}: $!\n";
168 while ($line = <PCIIDS
>) {
170 $rv = pciids_parse
($line, $id, $descr);
171 if ($rv == $IS_VENDOR) {
172 if (not exists($vendors{$id})) {
173 $vendors{$id} = [$descr, {}];
176 } elsif ($rv == $IS_DEVICE) {
177 if (not exists(${$vendors{$cur_vendor}->[$V_DEVSL]}{$id})) {
178 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
184 $optlused = $opts{l
} ?
"with" : "without";
187 ; Automatically generated by src/tools/tools/pciid/mk_pci_vendors.pl
188 ; ($optlused the -l option), using the following source lists:
190 ; http://www.pcidatabase.com/reports.php?type=tab-delimeted
191 ; http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
192 ; http://pciids.sourceforge.net/pci.ids
194 ; Manual edits on this file will be lost!
198 foreach $cur_vendor (sort keys %vendors) {
200 $descr = $vendors{$id}->[$V_DESCR];
201 print "$id\t$descr\n";
202 foreach $id (sort keys %{$vendors{$cur_vendor}->[$V_DEVSL]}) {
203 $descr = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
204 print "\t$id\t$descr\n";
210 # Parse a line from the Boemler file and place the ID and description
211 # in the scalars referenced by $id_ref and $descr_ref.
213 # On success, returns $IS_VENDOR if the line represents a vendor entity
214 # or $IS_DEVICE if the line represents a device entity.
216 # Returns 0 on failure.
218 sub vendors_parse($\$\$)
220 my ($line, $id_ref, $descr_ref) = @_;
222 if ($line =~ /^([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
223 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
225 } elsif ($line =~ /^\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
226 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
228 } elsif (not $opts{q} and
229 $line !~ /^\s*$/ and $line !~ /^;/) {
231 print STDERR "$PROGNAME: ignored Boemler: $line\n";
237 # Parse a line from the Hart file and place the ID and description
238 # in the scalars referenced by $id_ref and $descr_ref.
240 # On success, returns $IS_VENDOR if the line represents a vendor entity
241 # or $IS_DEVICE if the line represents a device entity.
243 # Returns 0 on failure.
245 sub pcidevs_parse($\$\$)
247 my ($line, $id_ref, $descr_ref) = @_;
250 if ($line =~ /^V\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
251 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
253 } elsif ($line =~ /^D\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
254 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
256 } elsif (not $opts{q} and
257 $line !~ /^\s*$/ and $line !~ /^[;ORSX]/) {
258 print STDERR "$PROGNAME: ignored Hart: $line\n";
264 # Parse a line from the Mares file and place the ID and description
265 # in the scalars referenced by $id_ref and $descr_ref.
267 # On success, returns $IS_VENDOR if the line represents a vendor entity
268 # or $IS_DEVICE if the line represents a device entity.
270 # Returns 0 on failure.
272 sub pciids_parse($\$\$)
274 my ($line, $id_ref, $descr_ref) = @_;
277 if ($line =~ /^([A-Fa-f0-9]{4}) (.+?)$/) {
278 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
280 } elsif ($line =~ /^\t([A-Fa-f0-9]{4}) (.+?)$/) {
281 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
283 } elsif (not $opts{q} and
284 $line !~ /^\s*$/ and $line !~ /^#/) {
286 print STDERR "$PROGNAME: ignored Mares: $line\n";