1#! /usr/bin/awk -f 2# $OpenBSD: devlist2h.awk,v 1.4 2023/01/04 14:42:46 jsg Exp $ 3# $NetBSD: devlist2h.awk,v 1.2 1998/07/22 11:47:13 christos 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(s) 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# 33function collectline(f, line) { 34 oparen = 0 35 line = "" 36 while (f <= NF) { 37 if ($f == "#") { 38 line = line "(" 39 oparen = 1 40 f++ 41 continue 42 } 43 if (oparen) { 44 line = line $f 45 if (f < NF) 46 line = line " " 47 f++ 48 continue 49 } 50 line = line $f 51 if (f < NF) 52 line = line " " 53 f++ 54 } 55 if (oparen) 56 line = line ")" 57 return line 58} 59BEGIN { 60 nproducts = nvendors = 0 61 hfile="sdmmcdevs.h" 62} 63NR == 1 { 64 VERSION = $0 65 gsub("\\$", "", VERSION) 66 67 printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile 68 printf("/*\n") > hfile 69 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 70 > hfile 71 printf(" *\n") > hfile 72 printf(" * generated from:\n") > hfile 73 printf(" *\t%s\n", VERSION) > hfile 74 printf(" */\n") > hfile 75 76 next 77} 78$1 == "vendor" { 79 nvendors++ 80 81 vendors[nvendors, 1] = $2; # name 82 vendors[nvendors, 2] = $3; # id 83 printf("#define\tSDMMC_VENDOR_%s\t%s\t", vendors[nvendors, 1], 84 vendors[nvendors, 2]) > hfile 85 vendors[nvendors, 3] = collectline(4, line) 86 printf("/* %s */\n", vendors[nvendors, 3]) > hfile 87 next 88} 89$1 == "product" { 90 nproducts++ 91 92 products[nproducts, 1] = $2; # vendor name 93 products[nproducts, 2] = $3; # product id 94 products[nproducts, 3] = $4; # id 95 printf("#define\tSDMMC_PRODUCT_%s_%s\t%s\n", products[nproducts, 1], 96 products[nproducts, 2], products[nproducts, 3]) > hfile 97 next 98} 99{ 100 if ($0 == "") 101 blanklines++ 102 print $0 > hfile 103} 104