1 #! /usr/bin/awk -f 2 # $NetBSD: devlist2h.awk,v 1.10 2007/04/12 21:35:08 matt 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 = ndevices = blanklines = 0 34 dfile="tcdevs_data.h" 35 hfile="tcdevs.h" 36 } 37 NR == 1 { 38 VERSION = $0 39 gsub("\\$", "", VERSION) 40 gsub(/ $/, "", VERSION) 41 42 printf("/*\t$NetBSD" "$\t*/\n\n") > dfile 43 printf("/*\n") > dfile 44 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 45 > dfile 46 printf(" *\n") > dfile 47 printf(" * generated from:\n") > dfile 48 printf(" *\t%s\n", VERSION) > dfile 49 printf(" */\n") > dfile 50 51 printf("/*\t$NetBSD" "$\t*/\n\n") > hfile 52 printf("/*\n") > hfile 53 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 54 > hfile 55 printf(" *\n") > hfile 56 printf(" * generated from:\n") > hfile 57 printf(" *\t%s\n", VERSION) > hfile 58 printf(" */\n") > hfile 59 60 next 61 } 62 NF > 0 && $1 == "device" { 63 ndevices++ 64 65 devices[ndevices, 0] = $2; # devices id 66 devices[ndevices, 1] = $2; # C identifier for device 67 gsub("-", "_", devices[ndevices, 1]); 68 69 devices[ndevices, 2] = $3; # driver name 70 71 printf("\n") > hfile 72 printf("#define\tTC_DEVICE_%s\t\"%s\"\n", devices[ndevices, 1], 73 devices[ndevices, 2]) > hfile 74 75 printf("#define\tTC_DESCRIPTION_%s\t\"", devices[ndevices, 1]) > hfile 76 77 f = 4; 78 i = 3; 79 80 # comments 81 ocomment = oparen = 0 82 if (f <= NF) { 83 ocomment = 1; 84 } 85 while (f <= NF) { 86 if ($f == "#") { 87 printf("(") > hfile 88 oparen = 1 89 f++ 90 continue 91 } 92 if (oparen) { 93 printf("%s", $f) > hfile 94 if (f < NF) 95 printf(" ") > hfile 96 f++ 97 continue 98 } 99 devices[ndevices, i] = $f 100 printf("%s", devices[ndevices, i]) > hfile 101 if (f < NF) 102 printf(" ") > hfile 103 i++; f++; 104 } 105 if (oparen) 106 printf(")") > hfile 107 if (ocomment) 108 printf("\"") > hfile 109 printf("\n") > hfile 110 111 next 112 } 113 { 114 if ($0 == "") 115 blanklines++ 116 if (blanklines < 2) 117 print $0 > hfile 118 if (blanklines < 2) 119 print $0 > dfile 120 } 121 END { 122 # print out the match tables 123 124 printf("\n") > dfile 125 126 printf("const struct tc_knowndev tc_knowndevs[] = {\n") > dfile 127 for (i = 1; i <= ndevices; i++) { 128 printf("\t{\n") > dfile 129 printf("\t \"%-8s\",\n", devices[i, 0]) \ 130 > dfile 131 printf("\t TC_DEVICE_%s,\n", devices[i, 1]) \ 132 > dfile 133 printf("\t TC_DESCRIPTION_%s,\n", devices[i, 1]) \ 134 > dfile 135 136 printf("\t},\n") > dfile 137 } 138 printf("\t{ NULL, NULL, NULL, }\n") > dfile 139 printf("};\n") > dfile 140 close(dfile) 141 close(hfile) 142 } 143