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