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