miidevs2h.awk revision 263687
1117395Skan#! /usr/bin/awk -f 2117395Skan# $NetBSD: devlist2h.awk,v 1.2 1998/09/05 14:42:06 christos Exp $ 3117395Skan 4117395Skan#- 5132718Skan# Copyright (c) 1998 The NetBSD Foundation, Inc. 6117395Skan# All rights reserved. 7132718Skan# 8132718Skan# This code is derived from software contributed to The NetBSD Foundation 9132718Skan# by Christos Zoulas. 10132718Skan# 11117395Skan# Redistribution and use in source and binary forms, with or without 12132718Skan# modification, are permitted provided that the following conditions 13132718Skan# are met: 14132718Skan# 1. Redistributions of source code must retain the above copyright 15132718Skan# notice, this list of conditions and the following disclaimer. 16117395Skan# 2. Redistributions in binary form must reproduce the above copyright 17132718Skan# notice, this list of conditions and the following disclaimer in the 18132718Skan# documentation and/or other materials provided with the distribution. 19132718Skan# 20132718Skan# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21117395Skan# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22117395Skan# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23117395Skan# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24117395Skan# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25117395Skan# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26117395Skan# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27117395Skan# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28117395Skan# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29117395Skan# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30117395Skan# POSSIBILITY OF SUCH DAMAGE. 31117395Skan# 32117395Skan# Copyright (c) 1995, 1996 Christopher G. Demetriou 33117395Skan# All rights reserved. 34117395Skan# 35117395Skan# Redistribution and use in source and binary forms, with or without 36117395Skan# modification, are permitted provided that the following conditions 37117395Skan# are met: 38117395Skan# 1. Redistributions of source code must retain the above copyright 39117395Skan# notice, this list of conditions and the following disclaimer. 40117395Skan# 2. Redistributions in binary form must reproduce the above copyright 41117395Skan# notice, this list of conditions and the following disclaimer in the 42117395Skan# documentation and/or other materials provided with the distribution. 43117395Skan# 3. All advertising materials mentioning features or use of this software 44117395Skan# must display the following acknowledgement: 45117395Skan# This model includes software developed by Christopher G. Demetriou. 46117395Skan# This model includes software developed by Christos Zoulas 47117395Skan# 4. The name of the author(s) may not be used to endorse or promote models 48117395Skan# derived from this software without specific prior written permission 49117395Skan# 50117395Skan# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 51117395Skan# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 52132718Skan# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 53132718Skan# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 54132718Skan# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 55132718Skan# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56132718Skan# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57132718Skan# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58132718Skan# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 59132718Skan# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60132718Skan# 61132718Skan# $FreeBSD: stable/10/sys/tools/miidevs2h.awk 263687 2014-03-24 13:48:04Z emaste $ 62132718Skan# 63132718Skanfunction collectline(f, line) { 64132718Skan oparen = 0 65132718Skan line = "" 66132718Skan while (f <= NF) { 67132718Skan if ($f == "#") { 68132718Skan line = line "(" 69132718Skan oparen = 1 70132718Skan f++ 71132718Skan continue 72132718Skan } 73132718Skan if (oparen) { 74132718Skan line = line $f 75132718Skan if (f < NF) 76132718Skan line = line " " 77132718Skan f++ 78132718Skan continue 79132718Skan } 80132718Skan line = line $f 81132718Skan if (f < NF) 82132718Skan line = line " " 83132718Skan f++ 84132718Skan } 85132718Skan if (oparen) 86132718Skan line = line ")" 87132718Skan return line 88132718Skan} 89132718SkanBEGIN { 90117395Skan nmodels = nouis = 0 91117395Skan hfile="miidevs.h" 92117395Skan} 93117395SkanNR == 1 { 94117395Skan VERSION = $0 95132718Skan gsub("\\$", "", VERSION) 96132718Skan 97132718Skan printf("/* \$FreeBSD\$ */\n\n") > hfile 98132718Skan printf("/*\n") > hfile 99132718Skan printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ 100132718Skan > hfile 101132718Skan printf(" *\n") > hfile 102132718Skan printf(" * generated from:\n") > hfile 103132718Skan printf(" *\t%s\n", VERSION) > hfile 104132718Skan printf(" */\n") > hfile 105132718Skan 106132718Skan next 107132718Skan} 108132718Skan$1 == "oui" { 109132718Skan nuios++ 110132718Skan 111132718Skan ouiindex[$2] = nouis; # record index for this name, for later. 112132718Skan 113132718Skan ouis[nouis, 1] = $2; # name 114132718Skan ouis[nouis, 2] = $3; # id 115132718Skan printf("#define\tMII_OUI_%s\t%s\t", ouis[nouis, 1], 116132718Skan ouis[nouis, 2]) > hfile 117117395Skan ouis[nouis, 3] = collectline(4, line) 118117395Skan printf("/* %s */\n", ouis[nouis, 3]) > hfile 119117395Skan next 120132718Skan} 121132718Skan$1 == "model" { 122132718Skan nmodels++ 123132718Skan 124132718Skan models[nmodels, 1] = $2; # oui name 125132718Skan models[nmodels, 2] = $3; # model id 126132718Skan models[nmodels, 3] = $4; # id 127132718Skan 128132718Skan printf("#define\tMII_MODEL_%s_%s\t%s\n", models[nmodels, 1], 129132718Skan models[nmodels, 2], models[nmodels, 3]) > hfile 130132718Skan 131132718Skan models[nmodels, 4] = collectline(5, line) 132132718Skan 133132718Skan printf("#define\tMII_STR_%s_%s\t\"%s\"\n", 134117395Skan models[nmodels, 1], models[nmodels, 2], 135117395Skan models[nmodels, 4]) > hfile 136117395Skan 137132718Skan next 138132718Skan} 139132718Skan{ 140132718Skan print $0 > hfile 141132718Skan} 142132718Skan