xref: /openbsd-src/sys/dev/eisa/devlist2h.awk (revision 1bc412e4ce7cb03798ee22e72994691c7c713ae6)
1#! /usr/bin/awk -f
2#	$OpenBSD: devlist2h.awk,v 1.4 2003/03/29 00:17:44 mickey Exp $
3#	$NetBSD: devlist2h.awk,v 1.2 1996/04/09 20:07:16 cgd Exp $
4#
5# Copyright (c) 1995, 1996 Christopher G. Demetriou
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. All advertising materials mentioning features or use of this software
17#    must display the following acknowledgement:
18#      This product includes software developed by Christopher G. Demetriou.
19# 4. The name of the author may not be used to endorse or promote products
20#    derived from this software without specific prior written permission
21#
22# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32#
33BEGIN {
34	nproducts = nvendors = 0
35	dfile="eisadevs_data.h"
36	hfile="eisadevs.h"
37}
38NR == 1 {
39	VERSION = $0
40	gsub("\\$", "", VERSION)
41
42	printf("/*\n") > dfile
43	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
44	    > dfile
45	printf(" *\n") > dfile
46	printf(" * generated from:\n") > dfile
47	printf(" *\t%s\n", VERSION) > dfile
48	printf(" */\n") > dfile
49
50	printf("/*\n") > hfile
51	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
52	    > hfile
53	printf(" *\n") > hfile
54	printf(" * generated from:\n") > hfile
55	printf(" *\t%s\n", VERSION) > hfile
56	printf(" */\n") > hfile
57
58	next
59}
60$1 == "vendor" {
61	nvendors++
62
63	vendorindex[$2] = nvendors;	# record index for this name, for later.
64	vendors[nvendors, 1] = $2;	# name/ID
65	i = 2; f = 3;
66
67	# comments
68	ocomment = oparen = 0
69	if (f <= NF) {
70		ocomment = 1;
71	}
72	while (f <= NF) {
73		if ($f == "#") {
74			oparen = 1
75			f++
76			continue
77		}
78		if (oparen) {
79			f++
80			continue
81		}
82		vendors[nvendors, i] = $f
83		i++; f++;
84	}
85
86	next
87}
88$1 == "product" {
89	nproducts++
90
91	products[nproducts, 1] = $2;		# vendor name
92	products[nproducts, 2] = $3;		# product id
93	printf("#define\tEISA_PRODUCT_%s%s\t\"", products[nproducts, 1],
94	    products[nproducts, 2]) > hfile
95
96	i = vendorindex[products[nproducts, 1]]; j = 2;
97	needspace = 0;
98	while (vendors[i, j] != "") {
99		if (needspace)
100			printf(" ") > hfile
101		printf("%s", vendors[i, j]) > hfile
102		needspace = 1
103		j++
104	}
105
106	if (needspace)
107		printf(" ") > hfile
108
109	i=3; f = 4;
110
111	# comments
112	ocomment = oparen = 0
113	if (f <= NF) {
114		ocomment = 1;
115	}
116	while (f <= NF) {
117		if ($f == "#") {
118			printf("(") > hfile
119			oparen = 1
120			f++
121			continue
122		}
123		if (oparen) {
124			printf("%s", $f) > hfile
125			if (f < NF)
126				printf(" ") > hfile
127			f++
128			continue
129		}
130		products[nproducts, i] = $f
131		printf("%s", products[nproducts, i]) > hfile
132		if (f < NF)
133			printf(" ") > hfile
134		i++; f++;
135	}
136	if (oparen)
137		printf(")") > hfile
138	if (ocomment)
139		printf("\"") > hfile
140	printf("\n") > hfile
141
142	next
143}
144{
145	if ($0 == "")
146		blanklines++
147	if (blanklines != 2 && blanklines != 3)
148		print $0 > hfile
149	if (blanklines < 2)
150		print $0 > dfile
151}
152END {
153	# print out the match tables
154
155	printf("\n") > dfile
156
157	printf("static const struct eisa_knowndev eisa_knowndevs[] = {\n") > dfile
158	for (i = 1; i <= nproducts; i++) {
159		printf("\t{\n") > dfile
160		printf("\t    0,\n") > dfile
161		printf("\t    \"%s%s\",\n", products[i, 1], products[i, 2]) \
162		    > dfile
163		printf("\t    EISA_PRODUCT_%s%s,\n", \
164		    products[i, 1], products[i, 2]) \
165		    > dfile
166
167		printf("\t},\n") > dfile
168	}
169	for (i = 1; i <= nvendors; i++) {
170		printf("\t{\n") > dfile
171		printf("\t    EISA_KNOWNDEV_NOPROD,\n") \
172		    > dfile
173		printf("\t    \"%s\",\n", vendors[i, 1]) \
174		    > dfile
175		printf("\t    \"") > dfile
176		j = 2;
177		needspace = 0;
178		while (vendors[i, j] != "") {
179			if (needspace)
180				printf(" ") > dfile
181			printf("%s", vendors[i, j]) > dfile
182			needspace = 1
183			j++
184		}
185		printf("\",\n") > dfile
186		printf("\t},\n") > dfile
187	}
188	printf("\t{ 0, \"\", NULL, }\n") > dfile
189	printf("};\n") > dfile
190}
191