devlist2h.awk revision 1.5.44.1 1 #! /usr/bin/awk -f
2 # $NetBSD: devlist2h.awk,v 1.5.44.1 2017/12/03 11:36:41 jdolecek 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 # 4. The name of the author(s) may not be used to endorse or promote products
46 # derived from this software without specific prior written permission
47 #
48 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
49 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
52 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
57 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 #
59 function collectline(_f, _line) {
60 _oparen = 0
61 _line = ""
62 while (_f <= NF) {
63 if ($_f == "#") {
64 _line = _line "("
65 _oparen = 1
66 _f++
67 continue
68 }
69 if (_oparen) {
70 _line = _line $_f
71 if (_f < NF)
72 _line = _line " "
73 _f++
74 continue
75 }
76 _line = _line $_f
77 if (_f < NF)
78 _line = _line " "
79 _f++
80 }
81 if (_oparen)
82 _line = _line ")"
83 return _line
84 }
85 BEGIN {
86 nproducts = nvendors = blanklines = 0
87 dfile="giodevs_data.h"
88 hfile="giodevs.h"
89 line=""
90 }
91 NR == 1 {
92 VERSION = $0
93 gsub("\\$", "", VERSION)
94
95 printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
96 printf("/*\n") > hfile
97 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
98 > hfile
99 printf(" */\n") > hfile
100
101 printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
102 printf("/*\n") > dfile
103 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
104 > dfile
105 printf(" */\n") > dfile
106
107 next
108 }
109 NF > 0 && $1 == "product" {
110 nproducts++
111
112 products[nproducts, 1] = $2;
113 products[nproducts, 2] = $3
114 products[nproducts, 3] = collectline(4, line)
115
116 next
117 }
118 {
119 if ($0 == "")
120 blanklines++
121 if (blanklines < 2)
122 print $0 > dfile
123 }
124 END {
125 # print out the match tables
126
127 printf("\n") > dfile
128
129 printf("struct gio_knowndev {\n") > dfile
130 printf("\tint productid;\n") > dfile
131 printf("\tconst char *product;\n") > dfile
132 printf("};\n") > dfile
133 printf("\nstruct gio_knowndev gio_knowndevs[] = {\n") > dfile
134
135 printf("\n") > hfile
136 for (i = 1; i <= nproducts; i++) {
137 printf("#define %s\t%s\t/* %s */\n", products[i, 1], products[i,2], products[i, 3]) > hfile
138
139 printf("\t{ %s, \"%s\" },\n",
140 products[i, 2], products[i, 3]) > dfile
141 }
142 printf("\t{ 0, NULL }\n") > dfile
143 printf("};\n") > dfile
144 close(dfile)
145 close(hfile)
146 }
147