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