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