xref: /netbsd/sys/dev/sdmmc/devlist2h.awk (revision 6550d01e)
1#! /usr/bin/awk -f
2#	$NetBSD: devlist2h.awk,v 1.1 2009/04/21 03:00:30 nonaka Exp $
3#	$OpenBSD: devlist2h.awk,v 1.2 2006/06/02 21:16:44 uwe Exp $
4#	NetBSD: devlist2h.awk,v 1.2 1998/07/22 11:47:13 christos Exp
5#
6# Copyright (c) 1998, Christos Zoulas
7# Copyright (c) 1995, 1996 Christopher G. Demetriou
8# All rights reserved.
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# 3. All advertising materials mentioning features or use of this software
19#    must display the following acknowledgement:
20#      This product includes software developed by Christopher G. Demetriou.
21#      This product includes software developed by Christos Zoulas
22# 4. The name of the author(s) may not be used to endorse or promote products
23#    derived from this software without specific prior written permission
24#
25# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#
36function collectline(f, line) {
37	oparen = 0
38	line = ""
39	while (f <= NF) {
40		if ($f == "#") {
41			line = line "("
42			oparen = 1
43			f++
44			continue
45		}
46		if (oparen) {
47			line = line $f
48			if (f < NF)
49				line = line " "
50			f++
51			continue
52		}
53		line = line $f
54		if (f < NF)
55			line = line " "
56		f++
57	}
58	if (oparen)
59		line = line ")"
60	return line
61}
62BEGIN {
63	nproducts = nvendors = 0
64	hfile="sdmmcdevs.h"
65}
66NR == 1 {
67	VERSION = $0
68	gsub("\\$", "", VERSION)
69
70	printf("/*\t$NetBSD: devlist2h.awk,v 1.1 2009/04/21 03:00:30 nonaka Exp $\t*/\n\n") > hfile
71	printf("/*\n") > hfile
72	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
73	    > hfile
74	printf(" *\n") > hfile
75	printf(" * generated from:\n") > hfile
76	printf(" *\t%s\n", VERSION) > hfile
77	printf(" */\n") > hfile
78
79	next
80}
81$1 == "vendor" {
82	nvendors++
83
84	vendorindex[$2] = nvendors;		# record index for this name, for later.
85	vendors[nvendors, 1] = $2;		# name
86	vendors[nvendors, 2] = $3;		# id
87	printf("#define\tSDMMC_VENDOR_%s\t%s\t", vendors[nvendors, 1],
88	    vendors[nvendors, 2]) > hfile
89	vendors[nvendors, 3] = collectline(4, line)
90	printf("/* %s */\n", vendors[nvendors, 3]) > hfile
91	next
92}
93$1 == "product" {
94	nproducts++
95
96	products[nproducts, 1] = $2;		# vendor name
97	products[nproducts, 2] = $3;		# product id
98	products[nproducts, 3] = $4;		# id
99
100	f = 5;
101
102	if ($4 == "{") {
103		products[nproducts, 3] = "SDMMC_PRODUCT_INVALID"
104		z = "{ "
105		for (i = 0; i < 4; i++) {
106			if (f <= NF) {
107				gsub("&sp", " ", $f)
108				gsub("&tab", "\t", $f)
109				gsub("&nl", "\n", $f)
110				z = z $f " "
111				f++
112			}
113			else {
114				if (i == 3)
115					z = z "NULL "
116				else
117					z = z "NULL, "
118			}
119		}
120		products[nproducts, 4] = z $f
121		f++
122	}
123	else {
124		products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
125	}
126	printf("#define\tSDMMC_CIS_%s_%s\t%s\n",
127	    products[nproducts, 1], products[nproducts, 2],
128	    products[nproducts, 4]) > hfile
129	printf("#define\tSDMMC_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
130	    products[nproducts, 2], products[nproducts, 3]) > hfile
131
132#	products[nproducts, 5] = collectline(f, line)
133#
134#	printf("#define\tSDMMC_STR_%s_%s\t\"%s\"\n",
135#	    products[nproducts, 1], products[nproducts, 2],
136#	    products[nproducts, 5]) > hfile
137
138	next
139}
140{
141	if ($0 == "")
142		blanklines++
143	print $0 > hfile
144}
145