pccarddevs2h.awk revision 112735
133965Sjdp#! /usr/bin/awk -f 238891Sjdp# $NetBSD: devlist2h.awk,v 1.3 1998/09/05 14:42:06 christos Exp $ 333965Sjdp# $FreeBSD: head/sys/tools/pccarddevs2h.awk 112735 2003-03-28 06:43:50Z imp $ 433965Sjdp# 533965Sjdp# Copyright (c) 1998 The NetBSD Foundation, Inc. 633965Sjdp# All rights reserved. 733965Sjdp# 833965Sjdp# This code is derived from software contributed to The NetBSD Foundation 933965Sjdp# by Christos Zoulas. 1033965Sjdp# 1133965Sjdp# Redistribution and use in source and binary forms, with or without 1233965Sjdp# modification, are permitted provided that the following conditions 1333965Sjdp# are met: 1433965Sjdp# 1. Redistributions of source code must retain the above copyright 1533965Sjdp# notice, this list of conditions and the following disclaimer. 1633965Sjdp# 2. Redistributions in binary form must reproduce the above copyright 1733965Sjdp# notice, this list of conditions and the following disclaimer in the 1833965Sjdp# documentation and/or other materials provided with the distribution. 1933965Sjdp# 3. All advertising materials mentioning features or use of this software 2033965Sjdp# must display the following acknowledgement: 2133965Sjdp# This product includes software developed by the NetBSD 2233965Sjdp# Foundation, Inc. and its contributors. 2333965Sjdp# 4. Neither the name of The NetBSD Foundation nor the names of its 2433965Sjdp# contributors may be used to endorse or promote products derived 2533965Sjdp# from this software without specific prior written permission. 2633965Sjdp# 2733965Sjdp# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2833965Sjdp# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2933965Sjdp# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3033965Sjdp# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3133965Sjdp# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3233965Sjdp# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3333965Sjdp# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3433965Sjdp# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3533965Sjdp# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3633965Sjdp# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3733965Sjdp# POSSIBILITY OF SUCH DAMAGE. 3833965Sjdp# 3933965Sjdp# Copyright (c) 1995, 1996 Christopher G. Demetriou 4033965Sjdp# All rights reserved. 4133965Sjdp# 4233965Sjdp# Redistribution and use in source and binary forms, with or without 4333965Sjdp# modification, are permitted provided that the following conditions 4433965Sjdp# are met: 4533965Sjdp# 1. Redistributions of source code must retain the above copyright 4633965Sjdp# notice, this list of conditions and the following disclaimer. 4733965Sjdp# 2. Redistributions in binary form must reproduce the above copyright 4833965Sjdp# notice, this list of conditions and the following disclaimer in the 4933965Sjdp# documentation and/or other materials provided with the distribution. 5033965Sjdp# 3. All advertising materials mentioning features or use of this software 5133965Sjdp# must display the following acknowledgement: 5233965Sjdp# This product includes software developed by Christopher G. Demetriou. 5333965Sjdp# This product includes software developed by Christos Zoulas 5433965Sjdp# 4. The name of the author(s) may not be used to endorse or promote products 5533965Sjdp# derived from this software without specific prior written permission 5633965Sjdp# 5733965Sjdp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 5833965Sjdp# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 5933965Sjdp# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 6033965Sjdp# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 6133965Sjdp# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 6233965Sjdp# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 6333965Sjdp# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 6433965Sjdp# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 6533965Sjdp# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 6633965Sjdp# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6733965Sjdp# 6833965Sjdpfunction collectline(f, line) { 6933965Sjdp oparen = 0 7033965Sjdp line = "" 7133965Sjdp while (f <= NF) { 7233965Sjdp if ($f == "#") { 7333965Sjdp line = line "(" 7433965Sjdp oparen = 1 7533965Sjdp f++ 7633965Sjdp continue 7733965Sjdp } 7833965Sjdp if (oparen) { 7933965Sjdp line = line $f 8033965Sjdp if (f < NF) 8133965Sjdp line = line " " 8233965Sjdp f++ 8333965Sjdp continue 8433965Sjdp } 8533965Sjdp line = line $f 8633965Sjdp if (f < NF) 8733965Sjdp line = line " " 8833965Sjdp f++ 8933965Sjdp } 9033965Sjdp if (oparen) 9133965Sjdp line = line ")" 9233965Sjdp return line 9333965Sjdp} 9433965SjdpBEGIN { 9533965Sjdp nproducts = nvendors = 0 9633965Sjdp hfile="pccarddevs.h" 9733965Sjdp} 9833965SjdpNR == 1 { 9933965Sjdp VERSION = $0 10033965Sjdp gsub("\\$", "", VERSION) 10133965Sjdp 10233965Sjdp printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile 10333965Sjdp printf("/*\n") > hfile 10433965Sjdp printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 10533965Sjdp > hfile 10633965Sjdp printf(" *\n") > hfile 10733965Sjdp printf(" * generated from:\n") > hfile 10833965Sjdp printf(" *\t%s\n", VERSION) > hfile 10933965Sjdp printf(" */\n") > hfile 11033965Sjdp 11133965Sjdp next 11233965Sjdp} 11333965Sjdp$1 == "vendor" { 11433965Sjdp nvendors++ 11533965Sjdp 11633965Sjdp vendorindex[$2] = nvendors; # record index for this name, for later. 11733965Sjdp vendors[nvendors, 1] = $2; # name 11833965Sjdp if ($3 == "-1") 11933965Sjdp $3 = "0xffffffff"; 12033965Sjdp vendors[nvendors, 2] = $3; # id 12133965Sjdp printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1], 12233965Sjdp vendors[nvendors, 2]) > hfile 12333965Sjdp vendors[nvendors, 3] = collectline(4, line) 12433965Sjdp printf("/* %s */\n", vendors[nvendors, 3]) > hfile 12533965Sjdp next 12633965Sjdp} 12733965Sjdp$1 == "product" { 12833965Sjdp nproducts++ 12933965Sjdp 13033965Sjdp products[nproducts, 1] = $2; # vendor name 13133965Sjdp if ($3 == "-1") 13233965Sjdp $3 = "0xffffffff"; 13333965Sjdp products[nproducts, 2] = $3; # product id 13433965Sjdp products[nproducts, 3] = $4; # id 13533965Sjdp 13633965Sjdp f = 5; 13733965Sjdp 13833965Sjdp if ($4 == "{") { 13933965Sjdp products[nproducts, 3] = "0xffffffff"; 14033965Sjdp z = "{ " 14133965Sjdp for (i = 0; i < 4; i++) { 14233965Sjdp if (f <= NF) { 14333965Sjdp gsub("&sp", " ", $f) 14433965Sjdp gsub("&tab", "\t", $f) 14533965Sjdp gsub("&nl", "\n", $f) 14633965Sjdp z = z $f " " 14733965Sjdp f++ 14833965Sjdp } 14933965Sjdp else { 15033965Sjdp if (i == 3) 15133965Sjdp z = z "NULL " 15233965Sjdp else 15333965Sjdp z = z "NULL, " 15433965Sjdp } 15533965Sjdp } 15633965Sjdp products[nproducts, 4] = z $f 15733965Sjdp f++ 15833965Sjdp } 15933965Sjdp else { 16033965Sjdp products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }" 16133965Sjdp } 16233965Sjdp printf("#define\tPCMCIA_CIS_%s_%s\t%s\n", 16333965Sjdp products[nproducts, 1], products[nproducts, 2], 16433965Sjdp products[nproducts, 4]) > hfile 16533965Sjdp printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1], 16633965Sjdp products[nproducts, 2], products[nproducts, 3]) > hfile 16733965Sjdp 16833965Sjdp products[nproducts, 5] = collectline(f, line) 16933965Sjdp 17033965Sjdp printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n", 17133965Sjdp products[nproducts, 1], products[nproducts, 2], 17233965Sjdp products[nproducts, 5]) > hfile 17333965Sjdp 17433965Sjdp next 17533965Sjdp} 17633965Sjdp{ 17733965Sjdp print $0 > hfile 17833965Sjdp} 17933965Sjdp