pccarddevs2h.awk revision 86271
152506Simp#! /usr/bin/awk -f 252506Simp# $NetBSD: devlist2h.awk,v 1.3 1998/09/05 14:42:06 christos Exp $ 352506Simp# $FreeBSD: head/sys/tools/pccarddevs2h.awk 86271 2001-11-11 20:15:06Z imp $ 452506Simp# 552506Simp# Copyright (c) 1998 The NetBSD Foundation, Inc. 652506Simp# All rights reserved. 752506Simp# 852506Simp# This code is derived from software contributed to The NetBSD Foundation 952506Simp# by Christos Zoulas. 1052506Simp# 1152506Simp# Redistribution and use in source and binary forms, with or without 1252506Simp# modification, are permitted provided that the following conditions 1352506Simp# are met: 1452506Simp# 1. Redistributions of source code must retain the above copyright 1552506Simp# notice, this list of conditions and the following disclaimer. 1652506Simp# 2. Redistributions in binary form must reproduce the above copyright 1752506Simp# notice, this list of conditions and the following disclaimer in the 1852506Simp# documentation and/or other materials provided with the distribution. 1952506Simp# 3. All advertising materials mentioning features or use of this software 2052506Simp# must display the following acknowledgement: 2152506Simp# This product includes software developed by the NetBSD 2252506Simp# Foundation, Inc. and its contributors. 2352506Simp# 4. Neither the name of The NetBSD Foundation nor the names of its 2452506Simp# contributors may be used to endorse or promote products derived 2552506Simp# from this software without specific prior written permission. 2652506Simp# 2752506Simp# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2852506Simp# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2952506Simp# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3052506Simp# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3152506Simp# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3252506Simp# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3352506Simp# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3452506Simp# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3552506Simp# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3652506Simp# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3752506Simp# POSSIBILITY OF SUCH DAMAGE. 3852506Simp# 3952506Simp# Copyright (c) 1995, 1996 Christopher G. Demetriou 4052506Simp# All rights reserved. 4152506Simp# 4252506Simp# Redistribution and use in source and binary forms, with or without 4352506Simp# modification, are permitted provided that the following conditions 4452506Simp# are met: 4552506Simp# 1. Redistributions of source code must retain the above copyright 4652506Simp# notice, this list of conditions and the following disclaimer. 4752506Simp# 2. Redistributions in binary form must reproduce the above copyright 4852506Simp# notice, this list of conditions and the following disclaimer in the 4952506Simp# documentation and/or other materials provided with the distribution. 5052506Simp# 3. All advertising materials mentioning features or use of this software 5152506Simp# must display the following acknowledgement: 5252506Simp# This product includes software developed by Christopher G. Demetriou. 5352506Simp# This product includes software developed by Christos Zoulas 5452506Simp# 4. The name of the author(s) may not be used to endorse or promote products 5552506Simp# derived from this software without specific prior written permission 5652506Simp# 5752506Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 5852506Simp# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 5952506Simp# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 6052506Simp# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 6152506Simp# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 6252506Simp# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 6352506Simp# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 6452506Simp# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 6552506Simp# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 6652506Simp# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6752506Simp# 6852506Simpfunction collectline(f, line) { 6952506Simp oparen = 0 7052506Simp line = "" 7152506Simp while (f <= NF) { 7252506Simp if ($f == "#") { 7352506Simp line = line "(" 7452506Simp oparen = 1 7552506Simp f++ 7652506Simp continue 7752506Simp } 7852506Simp if (oparen) { 7952506Simp line = line $f 8052506Simp if (f < NF) 8152506Simp line = line " " 8252506Simp f++ 8352506Simp continue 8452506Simp } 8552506Simp line = line $f 8652506Simp if (f < NF) 8752506Simp line = line " " 8852506Simp f++ 8952506Simp } 9052506Simp if (oparen) 9152506Simp line = line ")" 9252506Simp return line 9352506Simp} 9452506SimpBEGIN { 9552506Simp nproducts = nvendors = 0 9652506Simp dfile="pccarddevs_data.h" 9752506Simp hfile="pccarddevs.h" 9852506Simp} 9952506SimpNR == 1 { 10052506Simp VERSION = $0 10152506Simp gsub("\\$", "", VERSION) 10252506Simp 10352506Simp printf("/*\t\$FreeBSD\$\t*/\n\n") > dfile 10452506Simp printf("/*\n") > dfile 10552506Simp printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 10652506Simp > dfile 10752506Simp printf(" *\n") > dfile 10852506Simp printf(" * generated from:\n") > dfile 10952506Simp printf(" *\t%s\n", VERSION) > dfile 11052506Simp printf(" */\n") > dfile 11152506Simp 11252506Simp printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile 11352506Simp printf("/*\n") > hfile 11452506Simp printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 11552506Simp > hfile 11652506Simp printf(" *\n") > hfile 11752506Simp printf(" * generated from:\n") > hfile 11852506Simp printf(" *\t%s\n", VERSION) > hfile 11952506Simp printf(" */\n") > hfile 12052506Simp 12152506Simp next 12252506Simp} 12352506Simp$1 == "vendor" { 12452506Simp nvendors++ 12552506Simp 12652506Simp vendorindex[$2] = nvendors; # record index for this name, for later. 12752506Simp vendors[nvendors, 1] = $2; # name 12852506Simp vendors[nvendors, 2] = $3; # id 12986271Simp printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1], 13052506Simp vendors[nvendors, 2]) > hfile 13152506Simp vendors[nvendors, 3] = collectline(4, line) 13252506Simp printf("/* %s */\n", vendors[nvendors, 3]) > hfile 13352506Simp next 13452506Simp} 13552506Simp$1 == "product" { 13652506Simp nproducts++ 13752506Simp 13852506Simp products[nproducts, 1] = $2; # vendor name 13952506Simp products[nproducts, 2] = $3; # product id 14052506Simp products[nproducts, 3] = $4; # id 14152506Simp 14252506Simp f = 5; 14352506Simp 14452506Simp if ($4 == "{") { 14552506Simp products[nproducts, 3] = -1 14652506Simp z = "{ " 14752506Simp for (i = 0; i < 4; i++) { 14852506Simp if (f <= NF) { 14952506Simp gsub("&sp", " ", $f) 15052506Simp gsub("&tab", "\t", $f) 15152506Simp gsub("&nl", "\n", $f) 15252506Simp z = z $f " " 15352506Simp f++ 15452506Simp } 15552506Simp else { 15652506Simp if (i == 3) 15752506Simp z = z "NULL " 15852506Simp else 15952506Simp z = z "NULL, " 16052506Simp } 16152506Simp } 16252506Simp products[nproducts, 4] = z $f 16352506Simp f++ 16452506Simp } 16552506Simp else { 16652506Simp products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }" 16752506Simp } 16886271Simp printf("#define\tPCMCIA_CIS_%s_%s\t%s\n", 16952506Simp products[nproducts, 1], products[nproducts, 2], 17052506Simp products[nproducts, 4]) > hfile 17186271Simp printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1], 17252506Simp products[nproducts, 2], products[nproducts, 3]) > hfile 17352506Simp 17452506Simp products[nproducts, 5] = collectline(f, line) 17552506Simp 17686271Simp printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n", 17752506Simp products[nproducts, 1], products[nproducts, 2], 17852506Simp products[nproducts, 5]) > hfile 17952506Simp 18052506Simp next 18152506Simp} 18252506Simp{ 18352506Simp if ($0 == "") 18452506Simp blanklines++ 18552506Simp print $0 > hfile 18652506Simp if (blanklines < 2) 18752506Simp print $0 > dfile 18852506Simp} 18952506SimpEND { 19052506Simp # print out the match tables 19152506Simp 19252506Simp printf("\n") > dfile 19352506Simp 19452506Simp printf("struct pccard_knowndev pccard_knowndevs[] = {\n") > dfile 19552506Simp for (i = 1; i <= nproducts; i++) { 19652506Simp printf("\t{\n") > dfile 19752506Simp if (products[i, 3] == -1) { 19886271Simp printf("\t PCMCIA_VENDOR_UNKNOWN, PCMCIA_PRODUCT_%s_%s,\n", 19952506Simp products[i, 1], products[i, 2]) > dfile 20052506Simp } else { 20186271Simp printf("\t PCMCIA_VENDOR_%s, PCMCIA_PRODUCT_%s_%s,\n", 20252506Simp products[i, 1], products[i, 1], products[i, 2]) > dfile 20352506Simp } 20486271Simp printf("\t PCMCIA_CIS_%s_%s,\n", 20552506Simp products[i, 1], products[i, 2]) > dfile 20652506Simp printf("\t ") > dfile 20752506Simp printf("0") > dfile 20852506Simp printf(",\n") > dfile 20952506Simp 21052506Simp vendi = vendorindex[products[i, 1]]; 21152506Simp printf("\t \"%s\",\n", vendors[vendi, 3]) > dfile 21252506Simp printf("\t \"%s\"\t},\n", products[i, 5]) > dfile 21352506Simp printf("\t},\n") > dfile 21452506Simp } 21552506Simp for (i = 1; i <= nvendors; i++) { 21652506Simp printf("\t{\n") > dfile 21786271Simp printf("\t PCMCIA_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile 21886271Simp printf("\t PCMCIA_KNOWNDEV_NOPROD,\n") > dfile 21986271Simp printf("\t PCMCIA_CIS_INVALID,\n") > dfile 22052506Simp printf("\t \"%s\",\n", vendors[i, 3]) > dfile 22152506Simp printf("\t NULL,\n") > dfile 22252506Simp printf("\t},\n") > dfile 22352506Simp } 22452506Simp printf("\t{ 0, 0, { NULL, NULL, NULL, NULL }, 0, NULL, NULL, }\n") > dfile 22552506Simp printf("};\n") > dfile 22652506Simp} 227