pccarddevs2h.awk revision 139825
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 139825 2005-01-07 02:29:27Z imp $ 4139825Simp 5139825Simp#- 652506Simp# Copyright (c) 1998 The NetBSD Foundation, Inc. 752506Simp# All rights reserved. 852506Simp# 952506Simp# This code is derived from software contributed to The NetBSD Foundation 1052506Simp# by Christos Zoulas. 1152506Simp# 1252506Simp# Redistribution and use in source and binary forms, with or without 1352506Simp# modification, are permitted provided that the following conditions 1452506Simp# are met: 1552506Simp# 1. Redistributions of source code must retain the above copyright 1652506Simp# notice, this list of conditions and the following disclaimer. 1752506Simp# 2. Redistributions in binary form must reproduce the above copyright 1852506Simp# notice, this list of conditions and the following disclaimer in the 1952506Simp# documentation and/or other materials provided with the distribution. 2052506Simp# 3. All advertising materials mentioning features or use of this software 2152506Simp# must display the following acknowledgement: 2252506Simp# This product includes software developed by the NetBSD 2352506Simp# Foundation, Inc. and its contributors. 2452506Simp# 4. Neither the name of The NetBSD Foundation nor the names of its 2552506Simp# contributors may be used to endorse or promote products derived 2652506Simp# from this software without specific prior written permission. 2752506Simp# 2852506Simp# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2952506Simp# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 3052506Simp# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3152506Simp# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3252506Simp# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3352506Simp# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3452506Simp# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3552506Simp# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3652506Simp# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3752506Simp# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3852506Simp# POSSIBILITY OF SUCH DAMAGE. 3952506Simp# 4052506Simp# Copyright (c) 1995, 1996 Christopher G. Demetriou 4152506Simp# All rights reserved. 4252506Simp# 4352506Simp# Redistribution and use in source and binary forms, with or without 4452506Simp# modification, are permitted provided that the following conditions 4552506Simp# are met: 4652506Simp# 1. Redistributions of source code must retain the above copyright 4752506Simp# notice, this list of conditions and the following disclaimer. 4852506Simp# 2. Redistributions in binary form must reproduce the above copyright 4952506Simp# notice, this list of conditions and the following disclaimer in the 5052506Simp# documentation and/or other materials provided with the distribution. 5152506Simp# 3. All advertising materials mentioning features or use of this software 5252506Simp# must display the following acknowledgement: 5352506Simp# This product includes software developed by Christopher G. Demetriou. 5452506Simp# This product includes software developed by Christos Zoulas 5552506Simp# 4. The name of the author(s) may not be used to endorse or promote products 5652506Simp# derived from this software without specific prior written permission 5752506Simp# 5852506Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 5952506Simp# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 6052506Simp# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 6152506Simp# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 6252506Simp# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 6352506Simp# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 6452506Simp# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 6552506Simp# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 6652506Simp# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 6752506Simp# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6852506Simp# 6952506Simpfunction collectline(f, line) { 7052506Simp oparen = 0 7152506Simp line = "" 7252506Simp while (f <= NF) { 7352506Simp if ($f == "#") { 7452506Simp line = line "(" 7552506Simp oparen = 1 7652506Simp f++ 7752506Simp continue 7852506Simp } 7952506Simp if (oparen) { 8052506Simp line = line $f 8152506Simp if (f < NF) 8252506Simp line = line " " 8352506Simp f++ 8452506Simp continue 8552506Simp } 8652506Simp line = line $f 8752506Simp if (f < NF) 8852506Simp line = line " " 8952506Simp f++ 9052506Simp } 9152506Simp if (oparen) 9252506Simp line = line ")" 9352506Simp return line 9452506Simp} 9552506SimpBEGIN { 9652506Simp nproducts = nvendors = 0 9752506Simp hfile="pccarddevs.h" 9852506Simp} 9952506SimpNR == 1 { 10052506Simp VERSION = $0 10152506Simp gsub("\\$", "", VERSION) 10252506Simp 10352506Simp printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile 10452506Simp printf("/*\n") > hfile 10552506Simp printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 10652506Simp > hfile 10752506Simp printf(" *\n") > hfile 10852506Simp printf(" * generated from:\n") > hfile 10952506Simp printf(" *\t%s\n", VERSION) > hfile 11052506Simp printf(" */\n") > hfile 11152506Simp 11252506Simp next 11352506Simp} 11452506Simp$1 == "vendor" { 11552506Simp nvendors++ 11652506Simp 11752506Simp vendorindex[$2] = nvendors; # record index for this name, for later. 11852506Simp vendors[nvendors, 1] = $2; # name 119112735Simp if ($3 == "-1") 120112735Simp $3 = "0xffffffff"; 12152506Simp vendors[nvendors, 2] = $3; # id 12286271Simp printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1], 12352506Simp vendors[nvendors, 2]) > hfile 12452506Simp vendors[nvendors, 3] = collectline(4, line) 12552506Simp printf("/* %s */\n", vendors[nvendors, 3]) > hfile 12652506Simp next 12752506Simp} 12852506Simp$1 == "product" { 12952506Simp nproducts++ 13052506Simp 13152506Simp products[nproducts, 1] = $2; # vendor name 132112735Simp if ($3 == "-1") 133112735Simp $3 = "0xffffffff"; 13452506Simp products[nproducts, 2] = $3; # product id 13552506Simp products[nproducts, 3] = $4; # id 13652506Simp 13752506Simp f = 5; 13852506Simp 13952506Simp if ($4 == "{") { 140112735Simp products[nproducts, 3] = "0xffffffff"; 14152506Simp z = "{ " 14252506Simp for (i = 0; i < 4; i++) { 14352506Simp if (f <= NF) { 14452506Simp gsub("&sp", " ", $f) 14552506Simp gsub("&tab", "\t", $f) 14652506Simp gsub("&nl", "\n", $f) 14752506Simp z = z $f " " 14852506Simp f++ 14952506Simp } 15052506Simp else { 15152506Simp if (i == 3) 15252506Simp z = z "NULL " 15352506Simp else 15452506Simp z = z "NULL, " 15552506Simp } 15652506Simp } 15752506Simp products[nproducts, 4] = z $f 15852506Simp f++ 15952506Simp } 16052506Simp else { 16152506Simp products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }" 16252506Simp } 16386271Simp printf("#define\tPCMCIA_CIS_%s_%s\t%s\n", 16452506Simp products[nproducts, 1], products[nproducts, 2], 16552506Simp products[nproducts, 4]) > hfile 16686271Simp printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1], 16752506Simp products[nproducts, 2], products[nproducts, 3]) > hfile 16852506Simp 16952506Simp products[nproducts, 5] = collectline(f, line) 17052506Simp 17186271Simp printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n", 17252506Simp products[nproducts, 1], products[nproducts, 2], 17352506Simp products[nproducts, 5]) > hfile 17452506Simp 17552506Simp next 17652506Simp} 17752506Simp{ 17852506Simp print $0 > hfile 17952506Simp} 180