1 1.1 gdamore #! /usr/bin/awk -f 2 1.1 gdamore # $NetBSD: devlist2h.awk,v 1.1 2006/05/11 01:49:53 gdamore Exp $ 3 1.1 gdamore # 4 1.1 gdamore # Copyright (c) 1995, 1996 Christopher G. Demetriou 5 1.1 gdamore # All rights reserved. 6 1.1 gdamore # 7 1.1 gdamore # Redistribution and use in source and binary forms, with or without 8 1.1 gdamore # modification, are permitted provided that the following conditions 9 1.1 gdamore # are met: 10 1.1 gdamore # 1. Redistributions of source code must retain the above copyright 11 1.1 gdamore # notice, this list of conditions and the following disclaimer. 12 1.1 gdamore # 2. Redistributions in binary form must reproduce the above copyright 13 1.1 gdamore # notice, this list of conditions and the following disclaimer in the 14 1.1 gdamore # documentation and/or other materials provided with the distribution. 15 1.1 gdamore # 3. All advertising materials mentioning features or use of this software 16 1.1 gdamore # must display the following acknowledgement: 17 1.1 gdamore # This product includes software developed by Christopher G. Demetriou. 18 1.1 gdamore # 4. The name of the author may not be used to endorse or promote products 19 1.1 gdamore # derived from this software without specific prior written permission 20 1.1 gdamore # 21 1.1 gdamore # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 1.1 gdamore # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 1.1 gdamore # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 1.1 gdamore # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 1.1 gdamore # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 1.1 gdamore # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 1.1 gdamore # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 1.1 gdamore # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 1.1 gdamore # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 1.1 gdamore # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 1.1 gdamore # 32 1.1 gdamore BEGIN { 33 1.1 gdamore nproducts = nvendors = blanklines = 0 34 1.1 gdamore dfile="ediddevs_data.h" 35 1.1 gdamore hfile="ediddevs.h" 36 1.1 gdamore } 37 1.1 gdamore NR == 1 { 38 1.1 gdamore VERSION = $0 39 1.1 gdamore gsub("\\$", "", VERSION) 40 1.1 gdamore gsub(/ $/, "", VERSION) 41 1.1 gdamore 42 1.1 gdamore printf("/*\t$NetBSD" "$\t*/\n\n") > dfile 43 1.1 gdamore printf("/*\n") > dfile 44 1.1 gdamore printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 45 1.1 gdamore > dfile 46 1.1 gdamore printf(" *\n") > dfile 47 1.1 gdamore printf(" * generated from:\n") > dfile 48 1.1 gdamore printf(" *\t%s\n", VERSION) > dfile 49 1.1 gdamore printf(" */\n") > dfile 50 1.1 gdamore 51 1.1 gdamore printf("/*\t$NetBSD" "$\t*/\n\n") > hfile 52 1.1 gdamore printf("/*\n") > hfile 53 1.1 gdamore printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 54 1.1 gdamore > hfile 55 1.1 gdamore printf(" *\n") > hfile 56 1.1 gdamore printf(" * generated from:\n") > hfile 57 1.1 gdamore printf(" *\t%s\n", VERSION) > hfile 58 1.1 gdamore printf(" */\n") > hfile 59 1.1 gdamore 60 1.1 gdamore next 61 1.1 gdamore } 62 1.1 gdamore 63 1.1 gdamore NF > 0 && $1 == "vendor" { 64 1.1 gdamore nvendors++ 65 1.1 gdamore 66 1.1 gdamore vendorindex[$2] = nvendors; # record index for this name, for later. 67 1.1 gdamore vendors[nvendors, 1] = $2; # name/ID 68 1.1 gdamore i = 2; f = 3; 69 1.1 gdamore 70 1.1 gdamore printf("#define\tEDID_VENDOR_%s\t\"", vendors[nvendors, 1]) > hfile 71 1.1 gdamore 72 1.1 gdamore # comments 73 1.1 gdamore oparen = 0 74 1.1 gdamore while (f <= NF) { 75 1.1 gdamore if ($f == "#") { 76 1.1 gdamore printf("(") > hfile 77 1.1 gdamore oparen = 1 78 1.1 gdamore f++ 79 1.1 gdamore continue 80 1.1 gdamore } 81 1.1 gdamore if (oparen) { 82 1.1 gdamore printf("%s", $f) > hfile 83 1.1 gdamore f++ 84 1.1 gdamore continue 85 1.1 gdamore } 86 1.1 gdamore vendors[nvendors, i] = $f 87 1.1 gdamore printf("%s", vendors[nvendors, i]) > hfile 88 1.1 gdamore if (f < NF) 89 1.1 gdamore printf(" ") > hfile 90 1.1 gdamore i++; f++; 91 1.1 gdamore } 92 1.1 gdamore if (oparen) 93 1.1 gdamore printf(")") > hfile 94 1.1 gdamore printf("\"") > hfile 95 1.1 gdamore printf("\n") > hfile 96 1.1 gdamore 97 1.1 gdamore next 98 1.1 gdamore } 99 1.1 gdamore 100 1.1 gdamore NF > 0 && $1 == "product" { 101 1.1 gdamore nproducts++ 102 1.1 gdamore 103 1.1 gdamore products[nproducts, 1] = $2; # vendor name 104 1.1 gdamore products[nproducts, 2] = $3; # product id 105 1.1 gdamore products[nproducts, 3] = $4; # id 106 1.1 gdamore printf("#define\tEDID_PRODUCT_%s_%s\t%s", products[nproducts, 1], 107 1.1 gdamore products[nproducts, 2], products[nproducts, 3]) > hfile 108 1.1 gdamore 109 1.1 gdamore i = 4; f = 5; 110 1.1 gdamore 111 1.1 gdamore ocomment = oparen = 0 112 1.1 gdamore if (f <= NF) { 113 1.1 gdamore printf("\t\t/* ") > hfile 114 1.1 gdamore ocomment = 1; 115 1.1 gdamore } 116 1.1 gdamore while (f <= NF) { 117 1.1 gdamore if ($f == "#") { 118 1.1 gdamore printf("(") > hfile 119 1.1 gdamore oparen = 1 120 1.1 gdamore f++ 121 1.1 gdamore continue 122 1.1 gdamore } 123 1.1 gdamore if (oparen) { 124 1.1 gdamore printf("%s", $f) > hfile 125 1.1 gdamore if (f < NF) 126 1.1 gdamore printf(" ") > hfile 127 1.1 gdamore f++ 128 1.1 gdamore continue 129 1.1 gdamore } 130 1.1 gdamore products[nproducts, i] = $f 131 1.1 gdamore printf("%s", products[nproducts, i]) > hfile 132 1.1 gdamore if (f < NF) 133 1.1 gdamore printf(" ") > hfile 134 1.1 gdamore i++; f++; 135 1.1 gdamore } 136 1.1 gdamore if (oparen) 137 1.1 gdamore printf(")") > hfile 138 1.1 gdamore if (ocomment) 139 1.1 gdamore printf(" */") > hfile 140 1.1 gdamore printf("\n") > hfile 141 1.1 gdamore 142 1.1 gdamore next 143 1.1 gdamore } 144 1.1 gdamore { 145 1.1 gdamore if ($0 == "") 146 1.1 gdamore blanklines++ 147 1.1 gdamore if (blanklines != 2 && blanklines != 3) 148 1.1 gdamore print $0 > hfile 149 1.1 gdamore if (blanklines < 2) 150 1.1 gdamore print $0 > dfile 151 1.1 gdamore } 152 1.1 gdamore END { 153 1.1 gdamore # print out the match tables 154 1.1 gdamore 155 1.1 gdamore printf("\n") > dfile 156 1.1 gdamore printf("const struct edid_vendor edid_vendors[] = {\n") > dfile 157 1.1 gdamore 158 1.1 gdamore for (i = 1; i <= nvendors; i++) { 159 1.1 gdamore printf("\t{") > dfile 160 1.1 gdamore printf(" \"%s\", EDID_VENDOR_%s", vendors[i, 1], \ 161 1.1 gdamore vendors[i, 1]) > dfile 162 1.1 gdamore printf(" },\n") > dfile 163 1.1 gdamore } 164 1.1 gdamore printf("};\n") > dfile 165 1.1 gdamore printf("const int edid_nvendors = %d;\n", nvendors) > dfile 166 1.1 gdamore 167 1.1 gdamore printf("\n") > dfile 168 1.1 gdamore 169 1.1 gdamore printf("const struct edid_product edid_products[] = {\n") > dfile 170 1.1 gdamore for (i = 1; i <= nproducts; i++) { 171 1.1 gdamore printf("\t{\n") > dfile 172 1.1 gdamore printf("\t \"%s\", EDID_PRODUCT_%s_%s,\n", \ 173 1.1 gdamore products[i, 1], products[i, 1], products[i, 2]) > dfile 174 1.1 gdamore printf("\t \"") > dfile 175 1.1 gdamore j = 4 176 1.1 gdamore needspace = 0 177 1.1 gdamore while ((i, j) in products) { 178 1.1 gdamore if (needspace) 179 1.1 gdamore printf(" ") > dfile 180 1.1 gdamore printf("%s", products[i, j]) > dfile 181 1.1 gdamore needspace = 1 182 1.1 gdamore j++ 183 1.1 gdamore } 184 1.1 gdamore printf("\",\n") > dfile 185 1.1 gdamore printf("\t},\n") > dfile 186 1.1 gdamore } 187 1.1 gdamore printf("};\n") > dfile 188 1.1 gdamore printf("const int edid_nproducts = %d;\n", nproducts) >dfile 189 1.1 gdamore 190 1.1 gdamore close(dfile) 191 1.1 gdamore close(hfile) 192 1.1 gdamore } 193