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