112fe8f0eSfgsch#! /usr/bin/awk -f 2*000788ebSmbalmer# $OpenBSD: devlist2h.awk,v 1.11 2007/06/04 10:34:04 mbalmer Exp $ 30897b806Snate# $NetBSD: devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $ 412fe8f0eSfgsch# 512fe8f0eSfgsch# Copyright (c) 1995, 1996 Christopher G. Demetriou 612fe8f0eSfgsch# All rights reserved. 712fe8f0eSfgsch# 812fe8f0eSfgsch# Redistribution and use in source and binary forms, with or without 912fe8f0eSfgsch# modification, are permitted provided that the following conditions 1012fe8f0eSfgsch# are met: 1112fe8f0eSfgsch# 1. Redistributions of source code must retain the above copyright 1212fe8f0eSfgsch# notice, this list of conditions and the following disclaimer. 1312fe8f0eSfgsch# 2. Redistributions in binary form must reproduce the above copyright 1412fe8f0eSfgsch# notice, this list of conditions and the following disclaimer in the 1512fe8f0eSfgsch# documentation and/or other materials provided with the distribution. 1612fe8f0eSfgsch# 3. All advertising materials mentioning features or use of this software 1712fe8f0eSfgsch# must display the following acknowledgement: 1812fe8f0eSfgsch# This product includes software developed by Christopher G. Demetriou. 1912fe8f0eSfgsch# 4. The name of the author may not be used to endorse or promote products 2012fe8f0eSfgsch# derived from this software without specific prior written permission 2112fe8f0eSfgsch# 2212fe8f0eSfgsch# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2312fe8f0eSfgsch# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2412fe8f0eSfgsch# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2512fe8f0eSfgsch# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2612fe8f0eSfgsch# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2712fe8f0eSfgsch# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2812fe8f0eSfgsch# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2912fe8f0eSfgsch# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3012fe8f0eSfgsch# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3112fe8f0eSfgsch# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3212fe8f0eSfgsch# 3312fe8f0eSfgschBEGIN { 3412fe8f0eSfgsch nproducts = nvendors = 0 3512fe8f0eSfgsch dfile="usbdevs_data.h" 3612fe8f0eSfgsch hfile="usbdevs.h" 3712fe8f0eSfgsch} 3812fe8f0eSfgschNR == 1 { 3912fe8f0eSfgsch VERSION = $0 4012fe8f0eSfgsch gsub("\\$", "", VERSION) 4112fe8f0eSfgsch 4212fe8f0eSfgsch printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile 4312fe8f0eSfgsch printf("/*\n") > dfile 4412fe8f0eSfgsch printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 4512fe8f0eSfgsch > dfile 4612fe8f0eSfgsch printf(" *\n") > dfile 4712fe8f0eSfgsch printf(" * generated from:\n") > dfile 4812fe8f0eSfgsch printf(" *\t%s\n", VERSION) > dfile 4912fe8f0eSfgsch printf(" */\n") > dfile 5012fe8f0eSfgsch 5112fe8f0eSfgsch printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile 5212fe8f0eSfgsch printf("/*\n") > hfile 5302309cbeSfgsch printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 5412fe8f0eSfgsch > hfile 5512fe8f0eSfgsch printf(" *\n") > hfile 5612fe8f0eSfgsch printf(" * generated from:\n") > hfile 5712fe8f0eSfgsch printf(" *\t%s\n", VERSION) > hfile 5812fe8f0eSfgsch printf(" */\n") > hfile 5912fe8f0eSfgsch 6012fe8f0eSfgsch next 6112fe8f0eSfgsch} 6212fe8f0eSfgsch$1 == "vendor" { 6312fe8f0eSfgsch nvendors++ 6412fe8f0eSfgsch 6512fe8f0eSfgsch vendorindex[$2] = nvendors; # record index for this name, for later. 6612fe8f0eSfgsch vendors[nvendors, 1] = $2; # name 6712fe8f0eSfgsch vendors[nvendors, 2] = $3; # id 6812fe8f0eSfgsch printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1], 6912fe8f0eSfgsch vendors[nvendors, 2]) > hfile 7012fe8f0eSfgsch 7112fe8f0eSfgsch i = 3; f = 4; 7212fe8f0eSfgsch 7312fe8f0eSfgsch # comments 7412fe8f0eSfgsch ocomment = oparen = 0 7512fe8f0eSfgsch if (f <= NF) { 7612fe8f0eSfgsch printf("\t/* ") > hfile 7712fe8f0eSfgsch ocomment = 1; 7812fe8f0eSfgsch } 7912fe8f0eSfgsch while (f <= NF) { 8012fe8f0eSfgsch if ($f == "#") { 8112fe8f0eSfgsch printf("(") > hfile 8212fe8f0eSfgsch oparen = 1 8312fe8f0eSfgsch f++ 8412fe8f0eSfgsch continue 8512fe8f0eSfgsch } 8612fe8f0eSfgsch if (oparen) { 8712fe8f0eSfgsch printf("%s", $f) > hfile 8812fe8f0eSfgsch if (f < NF) 8912fe8f0eSfgsch printf(" ") > hfile 9012fe8f0eSfgsch f++ 9112fe8f0eSfgsch continue 9212fe8f0eSfgsch } 9312fe8f0eSfgsch vendors[nvendors, i] = $f 9412fe8f0eSfgsch printf("%s", vendors[nvendors, i]) > hfile 9512fe8f0eSfgsch if (f < NF) 9612fe8f0eSfgsch printf(" ") > hfile 9712fe8f0eSfgsch i++; f++; 9812fe8f0eSfgsch } 9912fe8f0eSfgsch if (oparen) 10012fe8f0eSfgsch printf(")") > hfile 10112fe8f0eSfgsch if (ocomment) 10212fe8f0eSfgsch printf(" */") > hfile 10312fe8f0eSfgsch printf("\n") > hfile 10412fe8f0eSfgsch 10512fe8f0eSfgsch next 10612fe8f0eSfgsch} 10712fe8f0eSfgsch$1 == "product" { 10812fe8f0eSfgsch nproducts++ 10912fe8f0eSfgsch 11012fe8f0eSfgsch products[nproducts, 1] = $2; # vendor name 11112fe8f0eSfgsch products[nproducts, 2] = $3; # product id 11212fe8f0eSfgsch products[nproducts, 3] = $4; # id 11312fe8f0eSfgsch printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1], 11412fe8f0eSfgsch products[nproducts, 2], products[nproducts, 3]) > hfile 11512fe8f0eSfgsch 11612fe8f0eSfgsch i=4; f = 5; 11712fe8f0eSfgsch 11812fe8f0eSfgsch # comments 11912fe8f0eSfgsch ocomment = oparen = 0 12012fe8f0eSfgsch if (f <= NF) { 12112fe8f0eSfgsch printf("\t/* ") > hfile 12212fe8f0eSfgsch ocomment = 1; 12312fe8f0eSfgsch } 12412fe8f0eSfgsch while (f <= NF) { 12512fe8f0eSfgsch if ($f == "#") { 12612fe8f0eSfgsch printf("(") > hfile 12712fe8f0eSfgsch oparen = 1 12812fe8f0eSfgsch f++ 12912fe8f0eSfgsch continue 13012fe8f0eSfgsch } 13112fe8f0eSfgsch if (oparen) { 13212fe8f0eSfgsch printf("%s", $f) > hfile 13312fe8f0eSfgsch if (f < NF) 13412fe8f0eSfgsch printf(" ") > hfile 13512fe8f0eSfgsch f++ 13612fe8f0eSfgsch continue 13712fe8f0eSfgsch } 13812fe8f0eSfgsch products[nproducts, i] = $f 13912fe8f0eSfgsch printf("%s", products[nproducts, i]) > hfile 14012fe8f0eSfgsch if (f < NF) 14112fe8f0eSfgsch printf(" ") > hfile 14212fe8f0eSfgsch i++; f++; 14312fe8f0eSfgsch } 14412fe8f0eSfgsch if (oparen) 14512fe8f0eSfgsch printf(")") > hfile 14612fe8f0eSfgsch if (ocomment) 14712fe8f0eSfgsch printf(" */") > hfile 14812fe8f0eSfgsch printf("\n") > hfile 14912fe8f0eSfgsch 15012fe8f0eSfgsch next 15112fe8f0eSfgsch} 15212fe8f0eSfgsch{ 15312fe8f0eSfgsch if ($0 == "") 15412fe8f0eSfgsch blanklines++ 15512fe8f0eSfgsch print $0 > hfile 15612fe8f0eSfgsch if (blanklines < 2) 15712fe8f0eSfgsch print $0 > dfile 15812fe8f0eSfgsch} 15912fe8f0eSfgschEND { 16012fe8f0eSfgsch # print out the match tables 16112fe8f0eSfgsch 16212fe8f0eSfgsch printf("\n") > dfile 16312fe8f0eSfgsch 164d723a8dcSderaadt printf("/*\n") > dfile 165d723a8dcSderaadt printf(" * Descriptions of known vendors and devices (\"products\").\n") > dfile 166d723a8dcSderaadt printf(" */\n") > dfile 167d723a8dcSderaadt printf("struct usb_known_vendor {\n") > dfile 1682a2da633Sderaadt printf(" u_int16_t vendor;\n") > dfile 169d723a8dcSderaadt printf(" char *vendorname;\n") > dfile 170d723a8dcSderaadt printf("};\n\n") > dfile 171d723a8dcSderaadt 172d723a8dcSderaadt printf("struct usb_known_product {\n") > dfile 1732a2da633Sderaadt printf(" u_int16_t vendor;\n") > dfile 1742a2da633Sderaadt printf(" u_int16_t product;\n") > dfile 175d723a8dcSderaadt printf(" char *productname;\n") > dfile 176d723a8dcSderaadt printf("};\n\n") > dfile 17758629274Sdrahn printf("const struct usb_known_product usb_known_products[] = {\n") \ 17858629274Sdrahn > dfile 17912fe8f0eSfgsch for (i = 1; i <= nproducts; i++) { 18012fe8f0eSfgsch printf("\t{\n") > dfile 18112fe8f0eSfgsch printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n", 18212fe8f0eSfgsch products[i, 1], products[i, 1], products[i, 2]) \ 18312fe8f0eSfgsch > dfile 18412fe8f0eSfgsch 18512fe8f0eSfgsch printf("\t \"") > dfile 18612fe8f0eSfgsch j = 4; 18712fe8f0eSfgsch needspace = 0; 18812fe8f0eSfgsch while (products[i, j] != "") { 18912fe8f0eSfgsch if (needspace) 19012fe8f0eSfgsch printf(" ") > dfile 19112fe8f0eSfgsch printf("%s", products[i, j]) > dfile 19212fe8f0eSfgsch needspace = 1 19312fe8f0eSfgsch j++ 19412fe8f0eSfgsch } 19512fe8f0eSfgsch printf("\",\n") > dfile 19612fe8f0eSfgsch printf("\t},\n") > dfile 19712fe8f0eSfgsch } 19858629274Sdrahn printf("\t{ 0, 0, NULL }\n") > dfile 19958629274Sdrahn printf("};\n\n") > dfile 20058629274Sdrahn 20158629274Sdrahn printf("const struct usb_known_vendor usb_known_vendors[] = {\n") \ 20258629274Sdrahn > dfile 20312fe8f0eSfgsch for (i = 1; i <= nvendors; i++) { 20412fe8f0eSfgsch printf("\t{\n") > dfile 20558629274Sdrahn printf("\t USB_VENDOR_%s,\n", vendors[i, 1]) \ 20612fe8f0eSfgsch > dfile 20758629274Sdrahn 20812fe8f0eSfgsch printf("\t \"") > dfile 20912fe8f0eSfgsch j = 3; 21012fe8f0eSfgsch needspace = 0; 21112fe8f0eSfgsch while (vendors[i, j] != "") { 21212fe8f0eSfgsch if (needspace) 21312fe8f0eSfgsch printf(" ") > dfile 21412fe8f0eSfgsch printf("%s", vendors[i, j]) > dfile 21512fe8f0eSfgsch needspace = 1 21612fe8f0eSfgsch j++ 21712fe8f0eSfgsch } 21812fe8f0eSfgsch printf("\",\n") > dfile 21912fe8f0eSfgsch printf("\t},\n") > dfile 22012fe8f0eSfgsch } 22158629274Sdrahn printf("\t{ 0, NULL }\n") > dfile 22212fe8f0eSfgsch printf("};\n") > dfile 22312fe8f0eSfgsch} 224