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