1#! /usr/bin/awk -f 2# $NetBSD: devlist2h.awk,v 1.5 2008/05/02 18:11:05 martin Exp $ 3# 4# Copyright (c) 1998 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Christos Zoulas. 9# 10# Redistribution and use in source and binary forms, with or without 11# modification, are permitted provided that the following conditions 12# are met: 13# 1. Redistributions of source code must retain the above copyright 14# notice, this list of conditions and the following disclaimer. 15# 2. Redistributions in binary form must reproduce the above copyright 16# notice, this list of conditions and the following disclaimer in the 17# documentation and/or other materials provided with the distribution. 18# 19# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29# POSSIBILITY OF SUCH DAMAGE. 30# 31# Copyright (c) 1995, 1996 Christopher G. Demetriou 32# All rights reserved. 33# 34# Redistribution and use in source and binary forms, with or without 35# modification, are permitted provided that the following conditions 36# are met: 37# 1. Redistributions of source code must retain the above copyright 38# notice, this list of conditions and the following disclaimer. 39# 2. Redistributions in binary form must reproduce the above copyright 40# notice, this list of conditions and the following disclaimer in the 41# documentation and/or other materials provided with the distribution. 42# 3. All advertising materials mentioning features or use of this software 43# must display the following acknowledgement: 44# This product includes software developed by Christopher G. Demetriou. 45# This product includes software developed by Christos Zoulas 46# 4. The name of the author(s) may not be used to endorse or promote products 47# derived from this software without specific prior written permission 48# 49# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 50# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 51# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 52# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 53# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 54# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 55# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 56# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 57# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 58# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59# 60function collectline(_f, _line) { 61 _oparen = 0 62 _line = "" 63 while (_f <= NF) { 64 if ($_f == "#") { 65 _line = _line "(" 66 _oparen = 1 67 _f++ 68 continue 69 } 70 if (_oparen) { 71 _line = _line $_f 72 if (_f < NF) 73 _line = _line " " 74 _f++ 75 continue 76 } 77 _line = _line $_f 78 if (_f < NF) 79 _line = _line " " 80 _f++ 81 } 82 if (_oparen) 83 _line = _line ")" 84 return _line 85} 86BEGIN { 87 nproducts = nvendors = blanklines = 0 88 dfile="giodevs_data.h" 89 hfile="giodevs.h" 90 line="" 91} 92NR == 1 { 93 VERSION = $0 94 gsub("\\$", "", VERSION) 95 96 printf("/*\t$NetBSD" "$\t*/\n\n") > hfile 97 printf("/*\n") > hfile 98 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 99 > hfile 100 printf(" */\n") > hfile 101 102 printf("/*\t$NetBSD" "$\t*/\n\n") > dfile 103 printf("/*\n") > dfile 104 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 105 > dfile 106 printf(" */\n") > dfile 107 108 next 109} 110NF > 0 && $1 == "product" { 111 nproducts++ 112 113 products[nproducts, 1] = $2; 114 products[nproducts, 2] = $3 115 products[nproducts, 3] = collectline(4, line) 116 117 next 118} 119{ 120 if ($0 == "") 121 blanklines++ 122 if (blanklines < 2) 123 print $0 > dfile 124} 125END { 126 # print out the match tables 127 128 printf("\n") > dfile 129 130 printf("struct gio_knowndev {\n") > dfile 131 printf("\tint productid;\n") > dfile 132 printf("\tconst char *product;\n") > dfile 133 printf("};\n") > dfile 134 printf("\nstruct gio_knowndev gio_knowndevs[] = {\n") > dfile 135 136 printf("\n") > hfile 137 for (i = 1; i <= nproducts; i++) { 138 printf("#define %s\t%s\t/* %s */\n", products[i, 1], products[i,2], products[i, 3]) > hfile 139 140 printf("\t{ %s, \"%s\" },\n", 141 products[i, 2], products[i, 3]) > dfile 142 } 143 printf("\t{ 0, NULL }\n") > dfile 144 printf("};\n") > dfile 145 close(dfile) 146 close(hfile) 147} 148