pccarddevs2h.awk revision 112735
1278798Shselasky#! /usr/bin/awk -f
2278798Shselasky#	$NetBSD: devlist2h.awk,v 1.3 1998/09/05 14:42:06 christos Exp $
3278798Shselasky# $FreeBSD: head/sys/tools/pccarddevs2h.awk 112735 2003-03-28 06:43:50Z imp $
4278798Shselasky#
5278798Shselasky# Copyright (c) 1998 The NetBSD Foundation, Inc.
6278798Shselasky# All rights reserved.
7278798Shselasky#
8278798Shselasky# This code is derived from software contributed to The NetBSD Foundation
9278798Shselasky# by Christos Zoulas.
10278798Shselasky#
11278798Shselasky# Redistribution and use in source and binary forms, with or without
12278798Shselasky# modification, are permitted provided that the following conditions
13278798Shselasky# are met:
14278798Shselasky# 1. Redistributions of source code must retain the above copyright
15278798Shselasky#    notice, this list of conditions and the following disclaimer.
16278798Shselasky# 2. Redistributions in binary form must reproduce the above copyright
17278798Shselasky#    notice, this list of conditions and the following disclaimer in the
18278798Shselasky#    documentation and/or other materials provided with the distribution.
19278798Shselasky# 3. All advertising materials mentioning features or use of this software
20278798Shselasky#    must display the following acknowledgement:
21278798Shselasky#        This product includes software developed by the NetBSD
22278798Shselasky#        Foundation, Inc. and its contributors.
23278798Shselasky# 4. Neither the name of The NetBSD Foundation nor the names of its
24278798Shselasky#    contributors may be used to endorse or promote products derived
25278798Shselasky#    from this software without specific prior written permission.
26278798Shselasky#
27278798Shselasky# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28278798Shselasky# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29278798Shselasky# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30278798Shselasky# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31278798Shselasky# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32278798Shselasky# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33278798Shselasky# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34278798Shselasky# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35278798Shselasky# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36278798Shselasky# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37278798Shselasky# POSSIBILITY OF SUCH DAMAGE.
38278798Shselasky#
39278798Shselasky# Copyright (c) 1995, 1996 Christopher G. Demetriou
40278798Shselasky# All rights reserved.
41278798Shselasky#
42278798Shselasky# Redistribution and use in source and binary forms, with or without
43278798Shselasky# modification, are permitted provided that the following conditions
44278798Shselasky# are met:
45278798Shselasky# 1. Redistributions of source code must retain the above copyright
46278798Shselasky#    notice, this list of conditions and the following disclaimer.
47278798Shselasky# 2. Redistributions in binary form must reproduce the above copyright
48278798Shselasky#    notice, this list of conditions and the following disclaimer in the
49278798Shselasky#    documentation and/or other materials provided with the distribution.
50278798Shselasky# 3. All advertising materials mentioning features or use of this software
51278798Shselasky#    must display the following acknowledgement:
52278798Shselasky#      This product includes software developed by Christopher G. Demetriou.
53278798Shselasky#      This product includes software developed by Christos Zoulas
54278798Shselasky# 4. The name of the author(s) may not be used to endorse or promote products
55278798Shselasky#    derived from this software without specific prior written permission
56278798Shselasky#
57278798Shselasky# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58278798Shselasky# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59278798Shselasky# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60278798Shselasky# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61278798Shselasky# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62278798Shselasky# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63278798Shselasky# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64278798Shselasky# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65278798Shselasky# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66278798Shselasky# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67278798Shselasky#
68278798Shselaskyfunction collectline(f, line) {
69278798Shselasky	oparen = 0
70278798Shselasky	line = ""
71278798Shselasky	while (f <= NF) {
72278798Shselasky		if ($f == "#") {
73278798Shselasky			line = line "("
74278798Shselasky			oparen = 1
75278798Shselasky			f++
76278798Shselasky			continue
77278798Shselasky		}
78278798Shselasky		if (oparen) {
79278798Shselasky			line = line $f
80278798Shselasky			if (f < NF)
81278798Shselasky				line = line " "
82278798Shselasky			f++
83278798Shselasky			continue
84278798Shselasky		}
85278798Shselasky		line = line $f
86278798Shselasky		if (f < NF)
87278798Shselasky			line = line " "
88278798Shselasky		f++
89278798Shselasky	}
90278798Shselasky	if (oparen)
91278798Shselasky		line = line ")"
92278798Shselasky	return line
93278798Shselasky}
94278798ShselaskyBEGIN {
95278798Shselasky	nproducts = nvendors = 0
96278798Shselasky	hfile="pccarddevs.h"
97278798Shselasky}
98278798ShselaskyNR == 1 {
99278798Shselasky	VERSION = $0
100278798Shselasky	gsub("\\$", "", VERSION)
101278798Shselasky
102278798Shselasky	printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile
103278798Shselasky	printf("/*\n") > hfile
104278798Shselasky	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
105278798Shselasky	    > hfile
106278798Shselasky	printf(" *\n") > hfile
107278798Shselasky	printf(" * generated from:\n") > hfile
108	printf(" *\t%s\n", VERSION) > hfile
109	printf(" */\n") > hfile
110
111	next
112}
113$1 == "vendor" {
114	nvendors++
115
116	vendorindex[$2] = nvendors;		# record index for this name, for later.
117	vendors[nvendors, 1] = $2;		# name
118	if ($3 == "-1")
119		$3 = "0xffffffff";
120	vendors[nvendors, 2] = $3;		# id
121	printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
122	    vendors[nvendors, 2]) > hfile
123	vendors[nvendors, 3] = collectline(4, line)
124	printf("/* %s */\n", vendors[nvendors, 3]) > hfile
125	next
126}
127$1 == "product" {
128	nproducts++
129
130	products[nproducts, 1] = $2;		# vendor name
131	if ($3 == "-1")
132		$3 = "0xffffffff";
133	products[nproducts, 2] = $3;		# product id
134	products[nproducts, 3] = $4;		# id
135
136	f = 5;
137
138	if ($4 == "{") {
139		products[nproducts, 3] = "0xffffffff";
140		z = "{ "
141		for (i = 0; i < 4; i++) {
142			if (f <= NF) {
143				gsub("&sp", " ", $f)
144				gsub("&tab", "\t", $f)
145				gsub("&nl", "\n", $f)
146				z = z $f " "
147				f++
148			}
149			else {
150				if (i == 3)
151					z = z "NULL "
152				else
153					z = z "NULL, "
154			}
155		}
156		products[nproducts, 4] = z $f
157		f++
158	}
159	else {
160		products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
161	}
162	printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
163	    products[nproducts, 1], products[nproducts, 2],
164	    products[nproducts, 4]) > hfile
165	printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
166	    products[nproducts, 2], products[nproducts, 3]) > hfile
167
168	products[nproducts, 5] = collectline(f, line)
169
170	printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n",
171	    products[nproducts, 1], products[nproducts, 2],
172	    products[nproducts, 5]) > hfile
173
174	next
175}
176{
177	print $0 > hfile
178}
179