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
28 # usage: mk_pci_vendors [-lq] [-p pcidevs.txt] [-v vendors.txt]
30 # Generate src/share/misc/pci_vendors from the Hart and Boemler lists,
31 # currently available at:
33 # Boemler: http://www.pcidatabase.com/reports.php?type=tab-delimeted
34 # Hart: http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
36 # -l Where an entry is found in both input lists, use the entry with
37 # the longest description. The default is for the Boemler file to
38 # override the Hart file.
39 # -q Do not print diagnostics.
40 # -p Specify the pathname of the Hart file. (Default ./pcidevs.txt)
41 # -v Specify the pathname of the Boemler file. (Default ./vendors.txt)
46 my $PROGNAME = 'mk_pci_vendors';
47 my $VENDORS_FILE = 'vendors.txt';
48 my $PCIDEVS_FILE = 'pcidevs.txt';
53 my ($descr, $existing, $id, $line, $rv, $winner, $optlused);
64 sub vendors_parse($\$\$);
65 sub pcidevs_parse($\$\$);
67 if (not getopts('lp:qv:', \%opts) or @ARGV > 0) {
68 print STDERR "usage: $PROGNAME [-lq] [-p pcidevs.txt] [-v vendors.txt]\n";
72 if (not defined($opts{p})) {
73 $opts{p} = $PCIDEVS_FILE;
75 if (not defined($opts{v})) {
76 $opts{v} = $VENDORS_FILE;
78 foreach (('l', 'q')) {
79 if (not exists($opts{$_})) {
86 open(VENDORS, "< $opts{v}") or
87 die "$PROGNAME: $opts{v}: $!\n";
88 while ($line = <VENDORS>) {
90 $rv = vendors_parse($line, $id, $descr);
91 if ($rv == $IS_VENDOR) {
92 if (exists($vendors{$id})) {
93 die "$PROGNAME: $id: duplicate vendor ID\n";
95 $vendors{$id} = [$descr, {}];
97 } elsif ($rv == $IS_DEVICE) {
98 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
103 open(PCIDEVS, "< $opts{p}") or
104 die "$PROGNAME: $opts{p}: $!\n";
105 while ($line = <PCIDEVS>) {
107 $rv = pcidevs_parse($line, $id, $descr);
108 if ($rv == $IS_VENDOR) {
109 if (not exists($vendors{$id})) {
110 $vendors{$id} = [$descr, {}];
111 $winner = $W_NOCONTEST;
113 $existing = $vendors{$id}->[$V_DESCR];
114 if (length($existing) < length($descr)) {
115 $vendors{$id}->[$V_DESCR] = $descr;
116 $winner = $W_PCIDEVS;
118 $winner = $W_VENDORS;
121 $winner = $W_VENDORS;
124 if (not $opts{q} and $winner != $W_NOCONTEST) {
125 $existing = $vendors{$id}->[$V_DESCR];
126 print STDERR "$PROGNAME: ",
127 $winner == $W_VENDORS ? "Boemler" : "Hart",
128 " vendor wins: $id\t$existing\n";
130 } elsif ($rv == $IS_DEVICE) {
131 if (not exists(${$vendors{$cur_vendor}->[$V_DEVSL]}{$id})) {
132 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
133 $winner = $W_NOCONTEST;
135 $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
136 if (length($existing) < length($descr)) {
137 ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} =
139 $winner = $W_PCIDEVS;
141 $winner = $W_VENDORS;
144 $winner = $W_VENDORS;
146 if (not $opts{q} and $winner != $W_NOCONTEST) {
147 $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
148 print STDERR "$PROGNAME: ",
149 $winner == $W_VENDORS ? "Boemler" : "Hart",
150 " device wins: $id\t$existing\n";
156 $optlused = $opts{l} ? "with" : "without";
160 ; Automatically generated by src/tools/tools/pciid/mk_pci_vendors.pl
161 ; ($optlused the -l option), using the following source lists:
163 ; http://www.pcidatabase.com/reports.php?type=tab-delimeted
164 ; http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
166 ; Manual edits on this file will be lost!
170 foreach $cur_vendor (sort keys %vendors) {
172 $descr = $vendors{$id}->[$V_DESCR];
173 print "$id\t$descr\n";
174 foreach $id (sort keys %{$vendors{$cur_vendor}->[$V_DEVSL]}) {
175 $descr = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
176 print "\t$id\t$descr\n";
182 # Parse a line from the Boemler file and place the ID and description
183 # in the scalars referenced by $id_ref and $descr_ref.
185 # On success, returns $IS_VENDOR if the line represents a vendor entity
186 # or $IS_DEVICE if the line represents a device entity.
188 # Returns 0 on failure.
190 sub vendors_parse($\$\$)
192 my ($line, $id_ref, $descr_ref) = @_;
194 if ($line =~ /^([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
195 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
197 } elsif ($line =~ /^\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
198 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
200 } elsif (not $opts{q} and
201 $line !~ /^\s*$/ and $line !~ /^;/) {
203 print STDERR "$PROGNAME: ignored Boemler: $line\n";
209 # Parse a line from the Hart file and place the ID and description
210 # in the scalars referenced by $id_ref and $descr_ref.
212 # On success, returns $IS_VENDOR if the line represents a vendor entity
213 # or $IS_DEVICE if the line represents a device entity.
215 # Returns 0 on failure.
217 sub pcidevs_parse($\$\$)
219 my ($line, $id_ref, $descr_ref) = @_;
222 if ($line =~ /^V\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
223 ($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
225 } elsif ($line =~ /^D\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 !~ /^[;ORSX]/) {
230 print STDERR "$PROGNAME: ignored Hart: $line\n";