167ca7330SBjoern A. Zeeb#! /usr/bin/awk -f 267ca7330SBjoern A. Zeeb#- 367ca7330SBjoern A. Zeeb# $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $ 467ca7330SBjoern A. Zeeb# 567ca7330SBjoern A. Zeeb# SPDX-License-Identifier: BSD-4-Clause 667ca7330SBjoern A. Zeeb# 767ca7330SBjoern A. Zeeb# Copyright (c) 1995, 1996 Christopher G. Demetriou 867ca7330SBjoern A. Zeeb# All rights reserved. 967ca7330SBjoern A. Zeeb# 1067ca7330SBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 1167ca7330SBjoern A. Zeeb# modification, are permitted provided that the following conditions 1267ca7330SBjoern A. Zeeb# are met: 1367ca7330SBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 1467ca7330SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 1567ca7330SBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 1667ca7330SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 1767ca7330SBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 1867ca7330SBjoern A. Zeeb# 3. All advertising materials mentioning features or use of this software 1967ca7330SBjoern A. Zeeb# must display the following acknowledgement: 2067ca7330SBjoern A. Zeeb# This product includes software developed by Christopher G. Demetriou. 2167ca7330SBjoern A. Zeeb# 4. The name of the author may not be used to endorse or promote products 2267ca7330SBjoern A. Zeeb# derived from this software without specific prior written permission 2367ca7330SBjoern A. Zeeb# 2467ca7330SBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2567ca7330SBjoern A. Zeeb# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2667ca7330SBjoern A. Zeeb# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2767ca7330SBjoern A. Zeeb# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2867ca7330SBjoern A. Zeeb# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2967ca7330SBjoern A. Zeeb# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3067ca7330SBjoern A. Zeeb# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3167ca7330SBjoern A. Zeeb# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3267ca7330SBjoern A. Zeeb# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3367ca7330SBjoern A. Zeeb# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3467ca7330SBjoern A. Zeeb# 3567ca7330SBjoern A. Zeeb 3667ca7330SBjoern A. Zeebfunction usage() 3767ca7330SBjoern A. Zeeb{ 3867ca7330SBjoern A. Zeeb print "usage: sdiodevs2h.awk <srcfile> [-d|-h]"; 3967ca7330SBjoern A. Zeeb exit 1; 4067ca7330SBjoern A. Zeeb} 4167ca7330SBjoern A. Zeeb 4267ca7330SBjoern A. Zeebfunction header(file) 4367ca7330SBjoern A. Zeeb{ 4467ca7330SBjoern A. Zeeb printf("/*\n") > file 4567ca7330SBjoern A. Zeeb printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 4667ca7330SBjoern A. Zeeb > file 4767ca7330SBjoern A. Zeeb printf(" */\n") > file 4867ca7330SBjoern A. Zeeb} 4967ca7330SBjoern A. Zeeb 5067ca7330SBjoern A. Zeebfunction vendor(hfile) 5167ca7330SBjoern A. Zeeb{ 5267ca7330SBjoern A. Zeeb nvendors++ 5367ca7330SBjoern A. Zeeb 5467ca7330SBjoern A. Zeeb vendorindex[$2] = nvendors; # record index for this name, for later. 5567ca7330SBjoern A. Zeeb vendors[nvendors, 1] = $2; # name 5667ca7330SBjoern A. Zeeb vendors[nvendors, 2] = $3; # id 5767ca7330SBjoern A. Zeeb if (hfile) 5851cb6f52SBjoern A. Zeeb printf("#define\tSDIO_VENDOR_ID_%s\t%s\t", vendors[nvendors, 1], 5967ca7330SBjoern A. Zeeb vendors[nvendors, 2]) > hfile 6067ca7330SBjoern A. Zeeb i = 3; f = 4; 6167ca7330SBjoern A. Zeeb 6267ca7330SBjoern A. Zeeb # comments 6367ca7330SBjoern A. Zeeb ocomment = oparen = 0 6467ca7330SBjoern A. Zeeb if (f <= NF) { 6567ca7330SBjoern A. Zeeb if (hfile) 6667ca7330SBjoern A. Zeeb printf("\t/* ") > hfile 6767ca7330SBjoern A. Zeeb ocomment = 1; 6867ca7330SBjoern A. Zeeb } 6967ca7330SBjoern A. Zeeb while (f <= NF) { 7067ca7330SBjoern A. Zeeb if ($f == "#") { 7167ca7330SBjoern A. Zeeb if (hfile) 7267ca7330SBjoern A. Zeeb printf("(") > hfile 7367ca7330SBjoern A. Zeeb oparen = 1 7467ca7330SBjoern A. Zeeb f++ 7567ca7330SBjoern A. Zeeb continue 7667ca7330SBjoern A. Zeeb } 7767ca7330SBjoern A. Zeeb if (oparen) { 7867ca7330SBjoern A. Zeeb if (hfile) 7967ca7330SBjoern A. Zeeb printf("%s", $f) > hfile 8067ca7330SBjoern A. Zeeb if (f < NF && hfile) 8167ca7330SBjoern A. Zeeb printf(" ") > hfile 8267ca7330SBjoern A. Zeeb f++ 8367ca7330SBjoern A. Zeeb continue 8467ca7330SBjoern A. Zeeb } 8567ca7330SBjoern A. Zeeb vendors[nvendors, i] = $f 8667ca7330SBjoern A. Zeeb if (hfile) 8767ca7330SBjoern A. Zeeb printf("%s", vendors[nvendors, i]) > hfile 8867ca7330SBjoern A. Zeeb if (f < NF && hfile) 8967ca7330SBjoern A. Zeeb printf(" ") > hfile 9067ca7330SBjoern A. Zeeb i++; f++; 9167ca7330SBjoern A. Zeeb } 9267ca7330SBjoern A. Zeeb if (oparen && hfile) 9367ca7330SBjoern A. Zeeb printf(")") > hfile 9467ca7330SBjoern A. Zeeb if (ocomment && hfile) 9567ca7330SBjoern A. Zeeb printf(" */") > hfile 9667ca7330SBjoern A. Zeeb if (hfile) 9767ca7330SBjoern A. Zeeb printf("\n") > hfile 9867ca7330SBjoern A. Zeeb} 9967ca7330SBjoern A. Zeeb 10067ca7330SBjoern A. Zeebfunction product(hfile) 10167ca7330SBjoern A. Zeeb{ 10267ca7330SBjoern A. Zeeb nproducts++ 10367ca7330SBjoern A. Zeeb 10467ca7330SBjoern A. Zeeb products[nproducts, 1] = $2; # vendor name 10567ca7330SBjoern A. Zeeb products[nproducts, 2] = $3; # product id 10667ca7330SBjoern A. Zeeb products[nproducts, 3] = $4; # id 10767ca7330SBjoern A. Zeeb if (hfile) 10851cb6f52SBjoern A. Zeeb printf("#define\tSDIO_DEVICE_ID_%s_%s\t%s\t", \ 10967ca7330SBjoern A. Zeeb products[nproducts, 1], products[nproducts, 2], \ 11067ca7330SBjoern A. Zeeb products[nproducts, 3]) > hfile 11167ca7330SBjoern A. Zeeb 11267ca7330SBjoern A. Zeeb i=4; f = 5; 11367ca7330SBjoern A. Zeeb 11467ca7330SBjoern A. Zeeb # comments 11567ca7330SBjoern A. Zeeb ocomment = oparen = 0 11667ca7330SBjoern A. Zeeb if (f <= NF) { 11767ca7330SBjoern A. Zeeb if (hfile) 11867ca7330SBjoern A. Zeeb printf("\t/* ") > hfile 11967ca7330SBjoern A. Zeeb ocomment = 1; 12067ca7330SBjoern A. Zeeb } 12167ca7330SBjoern A. Zeeb while (f <= NF) { 12267ca7330SBjoern A. Zeeb if ($f == "#") { 12367ca7330SBjoern A. Zeeb if (hfile) 12467ca7330SBjoern A. Zeeb printf("(") > hfile 12567ca7330SBjoern A. Zeeb oparen = 1 12667ca7330SBjoern A. Zeeb f++ 12767ca7330SBjoern A. Zeeb continue 12867ca7330SBjoern A. Zeeb } 12967ca7330SBjoern A. Zeeb if (oparen) { 13067ca7330SBjoern A. Zeeb if (hfile) 13167ca7330SBjoern A. Zeeb printf("%s", $f) > hfile 13267ca7330SBjoern A. Zeeb if (f < NF && hfile) 13367ca7330SBjoern A. Zeeb printf(" ") > hfile 13467ca7330SBjoern A. Zeeb f++ 13567ca7330SBjoern A. Zeeb continue 13667ca7330SBjoern A. Zeeb } 13767ca7330SBjoern A. Zeeb products[nproducts, i] = $f 13867ca7330SBjoern A. Zeeb if (hfile) 13967ca7330SBjoern A. Zeeb printf("%s", products[nproducts, i]) > hfile 14067ca7330SBjoern A. Zeeb if (f < NF && hfile) 14167ca7330SBjoern A. Zeeb printf(" ") > hfile 14267ca7330SBjoern A. Zeeb i++; f++; 14367ca7330SBjoern A. Zeeb } 14467ca7330SBjoern A. Zeeb if (oparen && hfile) 14567ca7330SBjoern A. Zeeb printf(")") > hfile 14667ca7330SBjoern A. Zeeb if (ocomment && hfile) 14767ca7330SBjoern A. Zeeb printf(" */") > hfile 14867ca7330SBjoern A. Zeeb if (hfile) 14967ca7330SBjoern A. Zeeb printf("\n") > hfile 15067ca7330SBjoern A. Zeeb} 15167ca7330SBjoern A. Zeeb 152*b4ef1b1bSBjoern A. Zeebfunction palias(hfile) 153*b4ef1b1bSBjoern A. Zeeb{ 154*b4ef1b1bSBjoern A. Zeeb nproducts++ 155*b4ef1b1bSBjoern A. Zeeb 156*b4ef1b1bSBjoern A. Zeeb products[nproducts, 1] = $2; # vendor name 157*b4ef1b1bSBjoern A. Zeeb products[nproducts, 2] = $3; # product id 158*b4ef1b1bSBjoern A. Zeeb products[nproducts, 3] = $4; # id 159*b4ef1b1bSBjoern A. Zeeb if (hfile) 160*b4ef1b1bSBjoern A. Zeeb printf("#define\tSDIO_DEVICE_ID_%s\tSDIO_DEVICE_ID_%s\n", \ 161*b4ef1b1bSBjoern A. Zeeb $2, $3) > hfile 162*b4ef1b1bSBjoern A. Zeeb} 163*b4ef1b1bSBjoern A. Zeeb 16467ca7330SBjoern A. Zeebfunction dump_dfile(dfile) 16567ca7330SBjoern A. Zeeb{ 16667ca7330SBjoern A. Zeeb printf("\n") > dfile 16767ca7330SBjoern A. Zeeb printf("const struct sdio_knowndev sdio_knowndevs[] = {\n") > dfile 16867ca7330SBjoern A. Zeeb for (i = 1; i <= nproducts; i++) { 16967ca7330SBjoern A. Zeeb printf("\t{\n") > dfile 17051cb6f52SBjoern A. Zeeb printf("\t SDIO_VENDOR_ID_%s, SDIO_DEVICE_ID_%s_%s,\n", 17167ca7330SBjoern A. Zeeb products[i, 1], products[i, 1], products[i, 2]) > dfile 17267ca7330SBjoern A. Zeeb printf("\t ") > dfile 17367ca7330SBjoern A. Zeeb printf("0") > dfile 17467ca7330SBjoern A. Zeeb printf(",\n") > dfile 17567ca7330SBjoern A. Zeeb 17667ca7330SBjoern A. Zeeb vendi = vendorindex[products[i, 1]]; 17767ca7330SBjoern A. Zeeb printf("\t \"") > dfile 17867ca7330SBjoern A. Zeeb j = 3; 17967ca7330SBjoern A. Zeeb needspace = 0; 18067ca7330SBjoern A. Zeeb while (vendors[vendi, j] != "") { 18167ca7330SBjoern A. Zeeb if (needspace) 18267ca7330SBjoern A. Zeeb printf(" ") > dfile 18367ca7330SBjoern A. Zeeb printf("%s", vendors[vendi, j]) > dfile 18467ca7330SBjoern A. Zeeb needspace = 1 18567ca7330SBjoern A. Zeeb j++ 18667ca7330SBjoern A. Zeeb } 18767ca7330SBjoern A. Zeeb printf("\",\n") > dfile 18867ca7330SBjoern A. Zeeb 18967ca7330SBjoern A. Zeeb printf("\t \"") > dfile 19067ca7330SBjoern A. Zeeb j = 4; 19167ca7330SBjoern A. Zeeb needspace = 0; 19267ca7330SBjoern A. Zeeb while (products[i, j] != "") { 19367ca7330SBjoern A. Zeeb if (needspace) 19467ca7330SBjoern A. Zeeb printf(" ") > dfile 19567ca7330SBjoern A. Zeeb printf("%s", products[i, j]) > dfile 19667ca7330SBjoern A. Zeeb needspace = 1 19767ca7330SBjoern A. Zeeb j++ 19867ca7330SBjoern A. Zeeb } 19967ca7330SBjoern A. Zeeb printf("\",\n") > dfile 20067ca7330SBjoern A. Zeeb printf("\t},\n") > dfile 20167ca7330SBjoern A. Zeeb } 20267ca7330SBjoern A. Zeeb for (i = 1; i <= nvendors; i++) { 20367ca7330SBjoern A. Zeeb printf("\t{\n") > dfile 20451cb6f52SBjoern A. Zeeb printf("\t SDIO_VENDOR_ID_%s, 0,\n", vendors[i, 1]) > dfile 20567ca7330SBjoern A. Zeeb printf("\t SDIO_KNOWNDEV_NOPROD,\n") > dfile 20667ca7330SBjoern A. Zeeb printf("\t \"") > dfile 20767ca7330SBjoern A. Zeeb j = 3; 20867ca7330SBjoern A. Zeeb needspace = 0; 20967ca7330SBjoern A. Zeeb while (vendors[i, j] != "") { 21067ca7330SBjoern A. Zeeb if (needspace) 21167ca7330SBjoern A. Zeeb printf(" ") > dfile 21267ca7330SBjoern A. Zeeb printf("%s", vendors[i, j]) > dfile 21367ca7330SBjoern A. Zeeb needspace = 1 21467ca7330SBjoern A. Zeeb j++ 21567ca7330SBjoern A. Zeeb } 21667ca7330SBjoern A. Zeeb printf("\",\n") > dfile 21767ca7330SBjoern A. Zeeb printf("\t NULL,\n") > dfile 21867ca7330SBjoern A. Zeeb printf("\t},\n") > dfile 21967ca7330SBjoern A. Zeeb } 22067ca7330SBjoern A. Zeeb printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile 22167ca7330SBjoern A. Zeeb printf("};\n") > dfile 22267ca7330SBjoern A. Zeeb} 22367ca7330SBjoern A. Zeeb 22467ca7330SBjoern A. ZeebBEGIN { 22567ca7330SBjoern A. Zeeb 22667ca7330SBjoern A. Zeebnproducts = nvendors = 0 22767ca7330SBjoern A. Zeeb# Process the command line 22867ca7330SBjoern A. Zeebfor (i = 1; i < ARGC; i++) { 22967ca7330SBjoern A. Zeeb arg = ARGV[i]; 23067ca7330SBjoern A. Zeeb if (arg !~ /^-[dh]+$/ && arg !~ /devs$/) 23167ca7330SBjoern A. Zeeb usage(); 23267ca7330SBjoern A. Zeeb if (arg ~ /^-.*d/) 23367ca7330SBjoern A. Zeeb dfile="sdiodevs_data.h" 23467ca7330SBjoern A. Zeeb if (arg ~ /^-.*h/) 23567ca7330SBjoern A. Zeeb hfile="sdiodevs.h" 23667ca7330SBjoern A. Zeeb if (arg ~ /devs$/) 23767ca7330SBjoern A. Zeeb srcfile = arg; 23867ca7330SBjoern A. Zeeb} 23967ca7330SBjoern A. ZeebARGC = 1; 24067ca7330SBjoern A. Zeebline=0; 24167ca7330SBjoern A. Zeeb 24267ca7330SBjoern A. Zeebwhile ((getline < srcfile) > 0) { 24367ca7330SBjoern A. Zeeb line++; 24467ca7330SBjoern A. Zeeb if (line == 1) { 24567ca7330SBjoern A. Zeeb if (dfile) 24667ca7330SBjoern A. Zeeb header(dfile) 24767ca7330SBjoern A. Zeeb if (hfile) 24867ca7330SBjoern A. Zeeb header(hfile) 24967ca7330SBjoern A. Zeeb } 25067ca7330SBjoern A. Zeeb if ($1 == "vendor") { 25167ca7330SBjoern A. Zeeb vendor(hfile) 25267ca7330SBjoern A. Zeeb continue 25367ca7330SBjoern A. Zeeb } 25467ca7330SBjoern A. Zeeb if ($1 == "product") { 25567ca7330SBjoern A. Zeeb product(hfile) 25667ca7330SBjoern A. Zeeb continue 25767ca7330SBjoern A. Zeeb } 258*b4ef1b1bSBjoern A. Zeeb if ($1 == "palias") { 259*b4ef1b1bSBjoern A. Zeeb palias(hfile) 260*b4ef1b1bSBjoern A. Zeeb continue 261*b4ef1b1bSBjoern A. Zeeb } 26267ca7330SBjoern A. Zeeb if ($0 == "") 26367ca7330SBjoern A. Zeeb blanklines++ 26467ca7330SBjoern A. Zeeb if (hfile) 26567ca7330SBjoern A. Zeeb print $0 > hfile 26667ca7330SBjoern A. Zeeb if (blanklines < 2 && dfile) 26767ca7330SBjoern A. Zeeb print $0 > dfile 26867ca7330SBjoern A. Zeeb} 26967ca7330SBjoern A. Zeeb 27067ca7330SBjoern A. Zeeb# print out the match tables 27167ca7330SBjoern A. Zeeb 27267ca7330SBjoern A. Zeebif (dfile) 27367ca7330SBjoern A. Zeeb dump_dfile(dfile) 27467ca7330SBjoern A. Zeeb} 275