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