1#! /usr/bin/awk -f 2# $MirOS: src/sys/dev/usb/devlist2h.awk,v 1.3 2005/03/14 21:10:38 tg Exp $ 3# $OpenBSD: devlist2h.awk,v 1.7 2001/10/31 04:24:44 nate Exp $ 4# $NetBSD: devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek 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 = nvendors = 0 36 dfile="usbdevs_data.h" 37 hfile="usbdevs.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 IS 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 IS 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 vendorindex[$2] = nvendors; # record index for this name, for later. 67 vendors[nvendors, 1] = $2; # name 68 vendors[nvendors, 2] = $3; # id 69 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1], 70 vendors[nvendors, 2]) > hfile 71 72 i = 3; f = 4; 73 74 # comments 75 ocomment = oparen = 0 76 if (f <= NF) { 77 printf("\t/* ") > hfile 78 ocomment = 1; 79 } 80 while (f <= NF) { 81 if ($f == "#") { 82 printf("(") > hfile 83 oparen = 1 84 f++ 85 continue 86 } 87 if (oparen) { 88 printf("%s", $f) > hfile 89 if (f < NF) 90 printf(" ") > hfile 91 f++ 92 continue 93 } 94 vendors[nvendors, i] = $f 95 printf("%s", vendors[nvendors, i]) > hfile 96 if (f < NF) 97 printf(" ") > hfile 98 i++; f++; 99 } 100 if (oparen) 101 printf(")") > hfile 102 if (ocomment) 103 printf(" */") > hfile 104 printf("\n") > hfile 105 106 next 107} 108$1 == "product" { 109 nproducts++ 110 111 products[nproducts, 1] = $2; # vendor name 112 products[nproducts, 2] = $3; # product id 113 products[nproducts, 3] = $4; # id 114 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1], 115 products[nproducts, 2], products[nproducts, 3]) > hfile 116 117 i=4; f = 5; 118 119 # comments 120 ocomment = oparen = 0 121 if (f <= NF) { 122 printf("\t/* ") > hfile 123 ocomment = 1; 124 } 125 while (f <= NF) { 126 if ($f == "#") { 127 printf("(") > hfile 128 oparen = 1 129 f++ 130 continue 131 } 132 if (oparen) { 133 printf("%s", $f) > hfile 134 if (f < NF) 135 printf(" ") > hfile 136 f++ 137 continue 138 } 139 products[nproducts, i] = $f 140 printf("%s", products[nproducts, i]) > hfile 141 if (f < NF) 142 printf(" ") > hfile 143 i++; f++; 144 } 145 if (oparen) 146 printf(")") > hfile 147 if (ocomment) 148 printf(" */") > hfile 149 printf("\n") > hfile 150 151 next 152} 153{ 154 if ($0 == "") 155 blanklines++ 156 print $0 > hfile 157 if (blanklines < 2) 158 print $0 > dfile 159} 160END { 161 # print out the match tables 162 163 printf("\n") > dfile 164 165 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile 166 for (i = 1; i <= nproducts; i++) { 167 printf("\t{\n") > dfile 168 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n", 169 products[i, 1], products[i, 1], products[i, 2]) \ 170 > dfile 171 printf("\t ") > dfile 172 printf("0") > dfile 173 printf(",\n") > dfile 174 175 vendi = vendorindex[products[i, 1]]; 176 printf("\t \"") > dfile 177 j = 3; 178 needspace = 0; 179 while (vendors[vendi, j] != "") { 180 if (needspace) 181 printf(" ") > dfile 182 printf("%s", vendors[vendi, j]) > dfile 183 needspace = 1 184 j++ 185 } 186 printf("\",\n") > dfile 187 188 printf("\t \"") > dfile 189 j = 4; 190 needspace = 0; 191 while (products[i, j] != "") { 192 if (needspace) 193 printf(" ") > dfile 194 printf("%s", products[i, j]) > dfile 195 needspace = 1 196 j++ 197 } 198 printf("\",\n") > dfile 199 printf("\t},\n") > dfile 200 } 201 for (i = 1; i <= nvendors; i++) { 202 printf("\t{\n") > dfile 203 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) \ 204 > dfile 205 printf("\t USB_KNOWNDEV_NOPROD,\n") \ 206 > dfile 207 printf("\t \"") > dfile 208 j = 3; 209 needspace = 0; 210 while (vendors[i, j] != "") { 211 if (needspace) 212 printf(" ") > dfile 213 printf("%s", vendors[i, j]) > dfile 214 needspace = 1 215 j++ 216 } 217 printf("\",\n") > dfile 218 printf("\t NULL,\n") > dfile 219 printf("\t},\n") > dfile 220 } 221 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile 222 printf("};\n") > dfile 223} 224