1#! /usr/bin/awk -f 2# $MirOS: src/sys/dev/pci/devlist2h.awk,v 1.3 2005/03/14 21:10:37 tg Exp $ 3# $OpenBSD: devlist2h.awk,v 1.6 2001/01/27 01:19:11 deraadt Exp $ 4# $NetBSD: devlist2h.awk,v 1.2 1996/01/22 21:08:09 cgd Exp $ 5# 6# Copyright (c) 1995, 1996 Christopher G. Demetriou 7# All rights reserved. 8# 9# Redistribution and use in source and binary forms, with or without 10# modification, are permitted provided that the following conditions 11# are met: 12# 1. Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# 2. Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 3. All advertising materials mentioning features or use of this software 18# must display the following acknowledgement: 19# This product includes software developed by Christopher G. Demetriou. 20# 4. The name of the author may not be used to endorse or promote products 21# derived from this software without specific prior written permission 22# 23# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33# 34BEGIN { 35 nproducts = nvendor_dup = nvendors = 0 36 dfile="pcidevs_data.h" 37 hfile="pcidevs.h" 38} 39NR == 1 { 40 VERSION = $0 41 gsub("\\$", "", VERSION) 42 43 printf("/* \$MirOS\$ */\n\n") > dfile 44 printf("/*-\n") > dfile 45 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 46 > dfile 47 printf(" *\n") > dfile 48 printf(" * generated from:\n") > dfile 49 printf(" *\t%s\n", VERSION) > dfile 50 printf(" */\n") > dfile 51 52 printf("/* \$MirOS\$ */\n\n") > hfile 53 printf("/*-\n") > hfile 54 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 55 > hfile 56 printf(" *\n") > hfile 57 printf(" * generated from:\n") > hfile 58 printf(" *\t%s\n", VERSION) > hfile 59 printf(" */\n") > hfile 60 61 next 62} 63$1 == "vendor" { 64 nvendors++ 65 66 if ($2 in vendorindex) { 67 printf("duplicate vendor name %s\n", $2); 68 nvendor_dup++; 69 } 70 71 vendorindex[$2] = nvendors; # record index for this name, for later. 72 vendors[nvendors, 1] = $2; # name 73 vendors[nvendors, 2] = $3; # id 74 printf("#define\tPCI_VENDOR_%s\t%s\t", vendors[nvendors, 1], 75 vendors[nvendors, 2]) > hfile 76 77 i = 3; f = 4; 78 79 # comments 80 ocomment = oparen = 0 81 if (f <= NF) { 82 printf("\t/* ") > hfile 83 ocomment = 1; 84 } 85 while (f <= NF) { 86 if ($f == "#") { 87 printf("(") > hfile 88 oparen = 1 89 f++ 90 continue 91 } 92 if (oparen) { 93 printf("%s", $f) > hfile 94 if (f < NF) 95 printf(" ") > hfile 96 f++ 97 continue 98 } 99 vendors[nvendors, i] = $f 100 printf("%s", vendors[nvendors, i]) > hfile 101 if (f < NF) 102 printf(" ") > hfile 103 i++; f++; 104 } 105 if (oparen) 106 printf(")") > hfile 107 if (ocomment) 108 printf(" */") > hfile 109 printf("\n") > hfile 110 111 next 112} 113$1 == "product" { 114 nproducts++ 115 116 products[nproducts, 1] = $2; # vendor name 117 products[nproducts, 2] = $3; # product id 118 products[nproducts, 3] = $4; # id 119 printf("#define\tPCI_PRODUCT_%s_%s\t%s\t", products[nproducts, 1], 120 products[nproducts, 2], products[nproducts, 3]) > hfile 121 122 i=4; f = 5; 123 124 # comments 125 ocomment = oparen = 0 126 if (f <= NF) { 127 printf("\t/* ") > hfile 128 ocomment = 1; 129 } 130 while (f <= NF) { 131 if ($f == "#") { 132 printf("(") > hfile 133 oparen = 1 134 f++ 135 continue 136 } 137 if (oparen) { 138 printf("%s", $f) > hfile 139 if (f < NF) 140 printf(" ") > hfile 141 f++ 142 continue 143 } 144 products[nproducts, i] = $f 145 printf("%s", products[nproducts, i]) > hfile 146 if (f < NF) 147 printf(" ") > hfile 148 i++; f++; 149 } 150 if (oparen) 151 printf(")") > hfile 152 if (ocomment) 153 printf(" */") > hfile 154 printf("\n") > hfile 155 156 next 157} 158{ 159 if ($0 == "") 160 blanklines++ 161 print $0 > hfile 162 if (blanklines < 2) 163 print $0 > dfile 164} 165END { 166 # print out the match tables 167 168 printf("\n") > dfile 169 170 if (nvendor_dup > 0) 171 exit(1); 172 173 printf("static const struct pci_known_product pci_known_products[] = {\n") \ 174 > dfile 175 for (i = 1; i <= nproducts; i++) { 176 printf("\t{\n") > dfile 177 printf("\t PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\n", 178 products[i, 1], products[i, 1], products[i, 2]) \ 179 > dfile 180 181 printf("\t \"") > dfile 182 j = 4; 183 needspace = 0; 184 while (products[i, j] != "") { 185 if (needspace) 186 printf(" ") > dfile 187 printf("%s", products[i, j]) > dfile 188 needspace = 1 189 j++ 190 } 191 printf("\",\n") > dfile 192 printf("\t},\n") > dfile 193 } 194 printf("\t{ 0, 0, NULL, }\n") > dfile 195 printf("};\n\n") > dfile 196 197 printf("static const struct pci_known_vendor pci_known_vendors[] = {\n") \ 198 > dfile 199 for (i = 1; i <= nvendors; i++) { 200 printf("\t{\n") > dfile 201 printf("\t PCI_VENDOR_%s,\n", vendors[i, 1]) \ 202 > dfile 203 printf("\t \"") > dfile 204 j = 3; 205 needspace = 0; 206 while (vendors[i, j] != "") { 207 if (needspace) 208 printf(" ") > dfile 209 printf("%s", vendors[i, j]) > dfile 210 needspace = 1 211 j++ 212 } 213 printf("\",\n") > dfile 214 printf("\t},\n") > dfile 215 } 216 printf("\t{ 0, NULL, }\n") > dfile 217 printf("};\n") > dfile 218} 219