miidevs2h.awk revision 139825
11573Srgrimes#! /usr/bin/awk -f
21573Srgrimes#	$NetBSD: devlist2h.awk,v 1.2 1998/09/05 14:42:06 christos Exp $
31573Srgrimes
41573Srgrimes#-
51573Srgrimes# Copyright (c) 1998 The NetBSD Foundation, Inc.
61573Srgrimes# All rights reserved.
71573Srgrimes#
81573Srgrimes# This code is derived from software contributed to The NetBSD Foundation
91573Srgrimes# by Christos Zoulas.
101573Srgrimes#
111573Srgrimes# Redistribution and use in source and binary forms, with or without
121573Srgrimes# modification, are permitted provided that the following conditions
131573Srgrimes# are met:
141573Srgrimes# 1. Redistributions of source code must retain the above copyright
151573Srgrimes#    notice, this list of conditions and the following disclaimer.
161573Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
171573Srgrimes#    notice, this list of conditions and the following disclaimer in the
181573Srgrimes#    documentation and/or other materials provided with the distribution.
191573Srgrimes# 3. All advertising materials mentioning features or use of this software
201573Srgrimes#    must display the following acknowledgement:
211573Srgrimes#        This product includes software developed by the NetBSD
221573Srgrimes#        Foundation, Inc. and its contributors.
231573Srgrimes# 4. Neither the name of The NetBSD Foundation nor the names of its
241573Srgrimes#    contributors may be used to endorse or promote products derived
251573Srgrimes#    from this software without specific prior written permission.
261573Srgrimes#
271573Srgrimes# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
281573Srgrimes# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2950476Speter# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
301573Srgrimes# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31282417Sjhb# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
321573Srgrimes# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3379531Sru# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
341573Srgrimes# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
351573Srgrimes# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
361573Srgrimes# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3716165Salex# POSSIBILITY OF SUCH DAMAGE.
3859460Sphantom#
3959460Sphantom# Copyright (c) 1995, 1996 Christopher G. Demetriou
401573Srgrimes# All rights reserved.
4184306Sru#
421573Srgrimes# Redistribution and use in source and binary forms, with or without
431573Srgrimes# modification, are permitted provided that the following conditions
441573Srgrimes# are met:
451573Srgrimes# 1. Redistributions of source code must retain the above copyright
461573Srgrimes#    notice, this list of conditions and the following disclaimer.
47108028Sru# 2. Redistributions in binary form must reproduce the above copyright
48108028Sru#    notice, this list of conditions and the following disclaimer in the
49108028Sru#    documentation and/or other materials provided with the distribution.
501573Srgrimes# 3. All advertising materials mentioning features or use of this software
511573Srgrimes#    must display the following acknowledgement:
521573Srgrimes#      This model includes software developed by Christopher G. Demetriou.
531573Srgrimes#      This model includes software developed by Christos Zoulas
5416165Salex# 4. The name of the author(s) may not be used to endorse or promote models
551573Srgrimes#    derived from this software without specific prior written permission
56131504Sru#
57131504Sru# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
581573Srgrimes# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
591573Srgrimes# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6016165Salex# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6116229Salex# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6216229Salex# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63282417Sjhb# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64282417Sjhb# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65282417Sjhb# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66282417Sjhb# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67282417Sjhb#
68282417Sjhb# $FreeBSD: head/sys/tools/miidevs2h.awk 139825 2005-01-07 02:29:27Z imp $
69282417Sjhb#
70282417Sjhbfunction collectline(f, line) {
71282417Sjhb	oparen = 0
72282417Sjhb	line = ""
73282417Sjhb	while (f <= NF) {
74282417Sjhb		if ($f == "#") {
751573Srgrimes			line = line "("
7682642Sru			oparen = 1
77159141Smaxim			f++
78159141Smaxim			continue
79159141Smaxim		}
80159141Smaxim		if (oparen) {
811573Srgrimes			line = line $f
82108028Sru			if (f < NF)
83108028Sru				line = line " "
84108028Sru			f++
851573Srgrimes			continue
8659954Sphantom		}
871573Srgrimes		line = line $f
881573Srgrimes		if (f < NF)
891573Srgrimes			line = line " "
901573Srgrimes		f++
911573Srgrimes	}
921573Srgrimes	if (oparen)
931573Srgrimes		line = line ")"
941573Srgrimes	return line
951573Srgrimes}
961573SrgrimesBEGIN {
971573Srgrimes	nmodels = nouis = 0
981573Srgrimes	hfile="miidevs.h"
991573Srgrimes}
100165051SpjdNR == 1 {
101165051Spjd	VERSION = $0
102165051Spjd	gsub("\\$", "", VERSION)
103165051Spjd
1041573Srgrimes	printf("/* \$FreeBSD\$ */\n\n") > hfile
1051573Srgrimes	printf("/*\n") > hfile
1061573Srgrimes	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
1071573Srgrimes	    > hfile
1081573Srgrimes	printf(" *\n") > hfile
1091573Srgrimes	printf(" * generated from:\n") > hfile
110165192Spjd	printf(" *\t%s\n", VERSION) > hfile
111165192Spjd	printf(" */\n") > hfile
112165192Spjd
113165192Spjd	next
114165192Spjd}
115165192Spjd$1 == "oui" {
116165192Spjd	nuios++
117165192Spjd
1181573Srgrimes	ouiindex[$2] = nouis;		# record index for this name, for later.
1191573Srgrimes
1201573Srgrimes	ouis[nouis, 1] = $2;		# name
121108087Sru	ouis[nouis, 2] = $3;		# id
122108087Sru	printf("#define\tMII_OUI_%s\t%s\t", ouis[nouis, 1],
123108087Sru	    ouis[nouis, 2]) > hfile
1241573Srgrimes	ouis[nouis, 3] = collectline(4, line)
1251573Srgrimes	printf("/* %s */\n", ouis[nouis, 3]) > hfile
1261573Srgrimes	next
127108028Sru}
128108028Sru$1 == "model" {
129108028Sru	nmodels++
1301573Srgrimes
13169051Sru	models[nmodels, 1] = $2;		# oui name
1321573Srgrimes	models[nmodels, 2] = $3;		# model id
1331573Srgrimes	models[nmodels, 3] = $4;		# id
1341573Srgrimes
135108087Sru	printf("#define\tMII_MODEL_%s_%s\t%s\n", models[nmodels, 1],
1361573Srgrimes	    models[nmodels, 2], models[nmodels, 3]) > hfile
1371573Srgrimes
1381573Srgrimes	models[nmodels, 4] = collectline(5, line)
1391573Srgrimes
140108087Sru	printf("#define\tMII_STR_%s_%s\t\"%s\"\n",
141282417Sjhb	    models[nmodels, 1], models[nmodels, 2],
1421573Srgrimes	    models[nmodels, 4]) > hfile
1431573Srgrimes
1441573Srgrimes	next
145108087Sru}
1461573Srgrimes{
1471573Srgrimes	print $0 > hfile
1481573Srgrimes}
149165051Spjd