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