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