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