dconschat(8): Put the fflush() under 'verbose' too.
[dragonfly.git] / sys / tools / pccarddevs2h.awk
blob659d86cfab7b4fd4ccdaefd8ca2403e0ab016241
1 #! /usr/bin/awk -f
2 # $NetBSD: devlist2h.awk,v 1.3 1998/09/05 14:42:06 christos Exp $
3 # $FreeBSD: src/sys/dev/pccard/devlist2h.awk,v 1.3 2003/03/28 06:43:50 imp Exp $
4 # $DragonFly: src/sys/bus/pccard/devlist2h.awk,v 1.1 2004/02/10 07:55:45 joerg Exp $
6 # Copyright (c) 1998 The NetBSD Foundation, Inc.
7 # All rights reserved.
9 # This code is derived from software contributed to The NetBSD Foundation
10 # by Christos Zoulas.
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
14 # are met:
15 # 1. Redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution.
20 # 3. All advertising materials mentioning features or use of this software
21 # must display the following acknowledgement:
22 # This product includes software developed by the NetBSD
23 # Foundation, Inc. and its contributors.
24 # 4. Neither the name of The NetBSD Foundation nor the names of its
25 # contributors may be used to endorse or promote products derived
26 # from this software without specific prior written permission.
28 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
40 # Copyright (c) 1995, 1996 Christopher G. Demetriou
41 # All rights reserved.
43 # Redistribution and use in source and binary forms, with or without
44 # modification, are permitted provided that the following conditions
45 # are met:
46 # 1. Redistributions of source code must retain the above copyright
47 # notice, this list of conditions and the following disclaimer.
48 # 2. Redistributions in binary form must reproduce the above copyright
49 # notice, this list of conditions and the following disclaimer in the
50 # documentation and/or other materials provided with the distribution.
51 # 3. All advertising materials mentioning features or use of this software
52 # must display the following acknowledgement:
53 # This product includes software developed by Christopher G. Demetriou.
54 # This product includes software developed by Christos Zoulas
55 # 4. The name of the author(s) may not be used to endorse or promote products
56 # derived from this software without specific prior written permission
58 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 function collectline(f, line) {
70 oparen = 0
71 line = ""
72 while (f <= NF) {
73 if ($f == "#") {
74 line = line "("
75 oparen = 1
76 f++
77 continue
79 if (oparen) {
80 line = line $f
81 if (f < NF)
82 line = line " "
83 f++
84 continue
86 line = line $f
87 if (f < NF)
88 line = line " "
89 f++
91 if (oparen)
92 line = line ")"
93 return line
95 BEGIN {
96 nproducts = nvendors = 0
97 hfile="pccarddevs.h"
99 NR == 1 {
100 printf("/*\n") > hfile
101 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
102 > hfile
103 printf(" */\n") > hfile
105 next
107 $1 == "vendor" {
108 nvendors++
110 vendorindex[$2] = nvendors; # record index for this name, for later.
111 vendors[nvendors, 1] = $2; # name
112 if ($3 == "-1")
113 $3 = "0xffffffff";
114 vendors[nvendors, 2] = $3; # id
115 printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
116 vendors[nvendors, 2]) > hfile
117 vendors[nvendors, 3] = collectline(4, line)
118 printf("/* %s */\n", vendors[nvendors, 3]) > hfile
119 next
121 $1 == "product" {
122 nproducts++
124 products[nproducts, 1] = $2; # vendor name
125 if ($3 == "-1")
126 $3 = "0xffffffff";
127 products[nproducts, 2] = $3; # product id
128 products[nproducts, 3] = $4; # id
130 f = 5;
132 if ($4 == "{") {
133 products[nproducts, 3] = "0xffffffff";
134 z = "{ "
135 for (i = 0; i < 4; i++) {
136 if (f <= NF) {
137 gsub("&sp", " ", $f)
138 gsub("&tab", "\t", $f)
139 gsub("&nl", "\n", $f)
140 z = z $f " "
143 else {
144 if (i == 3)
145 z = z "NULL "
146 else
147 z = z "NULL, "
150 products[nproducts, 4] = z $f
153 else {
154 products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
156 printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
157 products[nproducts, 1], products[nproducts, 2],
158 products[nproducts, 4]) > hfile
159 printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
160 products[nproducts, 2], products[nproducts, 3]) > hfile
162 products[nproducts, 5] = collectline(f, line)
164 printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n",
165 products[nproducts, 1], products[nproducts, 2],
166 products[nproducts, 5]) > hfile
168 next
171 print $0 > hfile