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.1 2006/06/15 13:37:35 swildner Exp $
29 # usage: mk_pci_vendors [-lq] [-p pcidevs.txt] [-v vendors.txt]
31 # Generate src/share/misc/pci_vendors from the Hart and Boemler 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
37 # -l Where an entry is found in both input lists, use the entry with
38 # the longest description. The default is for the Boemler file to
39 # override the Hart file.
40 # -q Do not print diagnostics.
41 # -p Specify the pathname of the Hart file. (Default ./pcidevs.txt)
42 # -v Specify the pathname of the Boemler file. (Default ./vendors.txt)
47 my $PROGNAME = 'mk_pci_vendors';
48 my $VENDORS_FILE = 'vendors.txt';
49 my $PCIDEVS_FILE = 'pcidevs.txt';
54 my ($descr, $existing, $id, $line, $rv, $winner, $optlused);
65 sub vendors_parse($\$\$);
66 sub pcidevs_parse($\$\$);
68 if (not getopts('lp:qv:', \%opts) or @ARGV > 0) {
69 print STDERR "usage: $PROGNAME [-lq] [-p pcidevs.txt] [-v vendors.txt]\n";
73 if (not defined($opts{p})) {
74 $opts{p} = $PCIDEVS_FILE;
76 if (not defined($opts{v})) {
77 $opts{v} = $VENDORS_FILE;
79 foreach (('l', 'q')) {
80 if (not exists($opts{$_})) {
87 open(VENDORS, "< $opts{v}") or
88 die "$PROGNAME: $opts{v}: $!\n";
89 while ($line = <VENDORS>) {
91 $rv = vendors_parse($line, $id, $descr);
92 if ($rv == $IS_VENDOR) {
93 if (exists($vendors{$id})) {
94 die "$PROGNAME: $id: duplicate vendor ID\n";
96 $vendors{$id} = [$descr, {}];
98 } elsif ($rv == $IS_DEVICE) {
99 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
104 open(PCIDEVS, "< $opts{p}") or
105 die "$PROGNAME: $opts{p}: $!\n";
106 while ($line = <PCIDEVS>) {
108 $rv = pcidevs_parse($line, $id, $descr);
109 if ($rv == $IS_VENDOR) {
110 if (not exists($vendors{$id})) {
111 $vendors{$id} = [$descr, {}];
112 $winner = $W_NOCONTEST;
114 $existing = $vendors{$id}->[$V_DESCR];
115 if (length($existing) < length($descr)) {
116 $vendors{$id}->[$V_DESCR] = $descr;
117 $winner = $W_PCIDEVS;
119 $winner = $W_VENDORS;
122 $winner = $W_VENDORS;
125 if (not $opts{q} and $winner != $W_NOCONTEST) {
126 $existing = $vendors{$id}->[$V_DESCR];
127 print STDERR "$PROGNAME: ",
128 $winner == $W_VENDORS ? "Boemler" : "Hart",
129 " vendor wins: $id\t$existing\n";
131 } elsif ($rv == $IS_DEVICE) {
132 if (not exists(${$vendors{$cur_vendor}->[$V_DEVSL]}{$id})) {
133 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
134 $winner = $W_NOCONTEST;
136 $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
137 if (length($existing) < length($descr)) {
138 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} =
140 $winner = $W_PCIDEVS;
142 $winner = $W_VENDORS;
145 $winner = $W_VENDORS;
147 if (not $opts{q} and $winner != $W_NOCONTEST) {
148 $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
149 print STDERR "$PROGNAME: ",
150 $winner == $W_VENDORS ? "Boemler" : "Hart",
151 " device wins: $id\t$existing\n";
157 $optlused = $opts{l} ? "with" : "without";
161 ; Automatically generated by src/tools/tools/pciid/mk_pci_vendors.pl
162 ; ($optlused the -l option), using the following source lists:
164 ; http://www.pcidatabase.com/reports.php?type=tab-delimeted
165 ; http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
167 ; Manual edits on this file will be lost!
171 foreach $cur_vendor (sort keys %vendors) {
173 $descr = $vendors{$id}->[$V_DESCR];
174 print "$id\t$descr\n";
175 foreach $id (sort keys %{$vendors{$cur_vendor}->[$V_DEVSL]}) {
176 $descr = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
177 print "\t$id\t$descr\n";
183 # Parse a line from the Boemler file and place the ID and description
184 # in the scalars referenced by $id_ref and $descr_ref.
186 # On success, returns $IS_VENDOR if the line represents a vendor entity
187 # or $IS_DEVICE if the line represents a device entity.
189 # Returns 0 on failure.
191 sub vendors_parse($\$\$)
193 my ($line, $id_ref, $descr_ref) = @_;
195 if ($line =~ /^([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
196 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
198 } elsif ($line =~ /^\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
199 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
201 } elsif (not $opts{q} and
202 $line !~ /^\s*$/ and $line !~ /^;/) {
204 print STDERR "$PROGNAME: ignored Boemler: $line\n";
210 # Parse a line from the Hart 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 pcidevs_parse($\$\$)
220 my ($line, $id_ref, $descr_ref) = @_;
223 if ($line =~ /^V\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
224 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
226 } elsif ($line =~ /^D\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
227 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
229 } elsif (not $opts{q} and
230 $line !~ /^\s*$/ and $line !~ /^[;ORSX]/) {
231 print STDERR "$PROGNAME: ignored Hart: $line\n";