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