head	1.2;
access;
symbols
	RELENG_8_4:1.2.0.18
	RELENG_9_1_0_RELEASE:1.2
	RELENG_9_1:1.2.0.16
	RELENG_9_1_BP:1.2
	RELENG_8_3_0_RELEASE:1.2
	RELENG_8_3:1.2.0.14
	RELENG_8_3_BP:1.2
	RELENG_9_0_0_RELEASE:1.2
	RELENG_9_0:1.2.0.12
	RELENG_9_0_BP:1.2
	RELENG_9:1.2.0.10
	RELENG_9_BP:1.2
	RELENG_7_4_0_RELEASE:1.1.1.3
	RELENG_8_2_0_RELEASE:1.2
	RELENG_7_4:1.1.1.3.0.38
	RELENG_7_4_BP:1.1.1.3
	RELENG_8_2:1.2.0.8
	RELENG_8_2_BP:1.2
	RELENG_8_1_0_RELEASE:1.2
	RELENG_8_1:1.2.0.6
	RELENG_8_1_BP:1.2
	RELENG_7_3_0_RELEASE:1.1.1.3
	RELENG_7_3:1.1.1.3.0.36
	RELENG_7_3_BP:1.1.1.3
	RELENG_8_0_0_RELEASE:1.2
	RELENG_8_0:1.2.0.4
	RELENG_8_0_BP:1.2
	RELENG_8:1.2.0.2
	RELENG_8_BP:1.2
	RELENG_7_2_0_RELEASE:1.1.1.3
	RELENG_7_2:1.1.1.3.0.34
	RELENG_7_2_BP:1.1.1.3
	RELENG_7_1_0_RELEASE:1.1.1.3
	RELENG_6_4_0_RELEASE:1.1.1.3
	RELENG_7_1:1.1.1.3.0.32
	RELENG_7_1_BP:1.1.1.3
	RELENG_6_4:1.1.1.3.0.30
	RELENG_6_4_BP:1.1.1.3
	RELENG_7_0_0_RELEASE:1.1.1.3
	RELENG_6_3_0_RELEASE:1.1.1.3
	RELENG_7_0:1.1.1.3.0.28
	RELENG_7_0_BP:1.1.1.3
	RELENG_6_3:1.1.1.3.0.26
	RELENG_6_3_BP:1.1.1.3
	v3_9_8:1.1.1.3
	RELENG_7:1.1.1.3.0.24
	RELENG_7_BP:1.1.1.3
	RELENG_6_2_0_RELEASE:1.1.1.3
	RELENG_6_2:1.1.1.3.0.22
	RELENG_6_2_BP:1.1.1.3
	v3_9_4:1.1.1.3
	RELENG_5_5_0_RELEASE:1.1.1.3
	RELENG_5_5:1.1.1.3.0.20
	RELENG_5_5_BP:1.1.1.3
	RELENG_6_1_0_RELEASE:1.1.1.3
	RELENG_6_1:1.1.1.3.0.18
	RELENG_6_1_BP:1.1.1.3
	RELENG_6_0_0_RELEASE:1.1.1.3
	RELENG_6_0:1.1.1.3.0.16
	RELENG_6_0_BP:1.1.1.3
	RELENG_6:1.1.1.3.0.14
	RELENG_6_BP:1.1.1.3
	v3_9_1:1.1.1.3
	v3_9_1-096:1.1.1.3
	RELENG_5_4_0_RELEASE:1.1.1.3
	RELENG_5_4:1.1.1.3.0.12
	RELENG_5_4_BP:1.1.1.3
	RELENG_4_11_0_RELEASE:1.1.1.2.2.1
	RELENG_4_11:1.1.1.2.2.1.0.10
	RELENG_4_11_BP:1.1.1.2.2.1
	RELENG_5_3_0_RELEASE:1.1.1.3
	RELENG_5_3:1.1.1.3.0.10
	RELENG_5_3_BP:1.1.1.3
	RELENG_5:1.1.1.3.0.8
	RELENG_5_BP:1.1.1.3
	RELENG_4_10_0_RELEASE:1.1.1.2.2.1
	RELENG_4_10:1.1.1.2.2.1.0.8
	RELENG_4_10_BP:1.1.1.2.2.1
	v3_8_3:1.1.1.3
	RELENG_5_2_1_RELEASE:1.1.1.3
	RELENG_5_2_0_RELEASE:1.1.1.3
	RELENG_5_2:1.1.1.3.0.6
	RELENG_5_2_BP:1.1.1.3
	RELENG_4_9_0_RELEASE:1.1.1.2.2.1
	RELENG_4_9:1.1.1.2.2.1.0.6
	RELENG_4_9_BP:1.1.1.2.2.1
	RELENG_5_1_0_RELEASE:1.1.1.3
	RELENG_5_1:1.1.1.3.0.4
	RELENG_5_1_BP:1.1.1.3
	RELENG_4_8_0_RELEASE:1.1.1.2.2.1
	RELENG_4_8:1.1.1.2.2.1.0.4
	RELENG_4_8_BP:1.1.1.2.2.1
	v3_7_2:1.1.1.3
	RELENG_5_0_0_RELEASE:1.1.1.3
	RELENG_5_0:1.1.1.3.0.2
	RELENG_5_0_BP:1.1.1.3
	RELENG_4_7_0_RELEASE:1.1.1.2.2.1
	RELENG_4_7:1.1.1.2.2.1.0.2
	RELENG_4_7_BP:1.1.1.2.2.1
	RELENG_4_6_2_RELEASE:1.1.1.2
	RELENG_4_6_1_RELEASE:1.1.1.2
	v3_7_1:1.1.1.3
	RELENG_4_6_0_RELEASE:1.1.1.2
	RELENG_4_6:1.1.1.2.0.10
	RELENG_4_6_BP:1.1.1.2
	RELENG_4_5_0_RELEASE:1.1.1.2
	RELENG_4_5:1.1.1.2.0.8
	RELENG_4_5_BP:1.1.1.2
	RELENG_4_4_0_RELEASE:1.1.1.2
	RELENG_4_4:1.1.1.2.0.6
	RELENG_4_4_BP:1.1.1.2
	v3_6_3:1.1.1.2
	RELENG_4_3_0_RELEASE:1.1.1.2
	RELENG_4_3:1.1.1.2.0.4
	RELENG_4_3_BP:1.1.1.2
	v3_6_2:1.1.1.2
	RELENG_4_2_0_RELEASE:1.1.1.2
	RELENG_4_1_1_RELEASE:1.1.1.2
	PRE_SMPNG:1.1.1.2
	RELENG_4_1_0_RELEASE:1.1.1.2
	RELENG_3_5_0_RELEASE:1.1.1.1
	RELENG_4_0_0_RELEASE:1.1.1.2
	RELENG_4:1.1.1.2.0.2
	RELENG_4_BP:1.1.1.2
	v3_5:1.1.1.2
	TCPDUMP_ORG:1.1.1
	RELENG_3_4_0_RELEASE:1.1.1.1
	RELENG_3_3_0_RELEASE:1.1.1.1
	RELENG_3_2_PAO:1.1.1.1.0.6
	RELENG_3_2_PAO_BP:1.1.1.1
	RELENG_3_2_0_RELEASE:1.1.1.1
	RELENG_3_1_0_RELEASE:1.1.1.1
	RELENG_3:1.1.1.1.0.4
	RELENG_3_BP:1.1.1.1
	RELENG_2_2_8_RELEASE:1.1.1.1
	RELENG_3_0_0_RELEASE:1.1.1.1
	v3_4:1.1.1.1
	RELENG_2_2_7_RELEASE:1.1.1.1
	RELENG_2_2_6_RELEASE:1.1.1.1
	RELENG_2_2_5_RELEASE:1.1.1.1
	v3_3:1.1.1.1
	RELENG_2_2_2_RELEASE:1.1.1.1
	RELENG_2_2_1_RELEASE:1.1.1.1
	RELENG_2_2_0_RELEASE:1.1.1.1
	RELENG_2_2:1.1.1.1.0.2
	RELENG_2_2_BP:1.1.1.1
	v3_2_1:1.1.1.1
	LBL:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2009.03.21.18.30.25;	author rpaulo;	state Exp;
branches
	1.2.18.1;
next	1.1;

1.1
date	96.08.19.20.34.06;	author pst;	state Exp;
branches
	1.1.1.1;
next	;

1.2.18.1
date	2009.03.21.18.30.25;	author svnexp;	state dead;
branches;
next	1.2.18.2;

1.2.18.2
date	2013.03.28.13.02.03;	author svnexp;	state Exp;
branches;
next	;

1.1.1.1
date	96.08.19.20.34.06;	author pst;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2000.01.30.00.45.27;	author fenner;	state Exp;
branches
	1.1.1.2.2.1;
next	1.1.1.3;

1.1.1.3
date	2002.06.21.00.43.22;	author fenner;	state Exp;
branches;
next	;

1.1.1.2.2.1
date	2002.07.05.11.04.49;	author fenner;	state Exp;
branches;
next	;


desc
@@


1.2
log
@SVN rev 190207 on 2009-03-21 18:30:25Z by rpaulo

Merge tcpdump 4.0.0 from the vendor branch.
@
text
@#!/bin/sh
#
# Copyright (c) 1990, 1996
#	John Robert LoVerso. All rights reserved.
# SMIv2 parsing copyright (c) 1999
#	William C. Fenner.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notices, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notices, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# @@(#) $Id: makemib,v 1.3 2001-09-17 22:16:52 fenner Exp $ (jlv)

#
# This script will read either ASN.1-style MIB files or the ".defs" files
# created by the ISODE "mosy" program on such files.
#
# The output of this script is the "mib.h" file used by tcpdumps' ASN.1/SNMP
# decoding code.
#
# This script needs to be run by "gawk" (GNU awk).  "nawk" will work, but
# dump will get a recursion error if you process LARGE mibs.  While it would
# by farily easy to rewrite this not to use recursion (and also easy to
# eliminate use of gsub and functions to use classic "awk"), you have to 
# order the structure declarations in defined-first order for the compiler
# not to barf; too bad tsort doesn't take arguments.
#

cat << EOF
/*
 * This file was generated by tcpdump/makemib on `date`
 * You probably don't want to edit this by hand!
 *
 * struct mib somename = { desc, oid-octet, type, child-pointer, next-pointer 
};
 */

EOF

awk '
BEGIN {
	debug=0;
	# for sanity, we prep the namespace with objects from RFC-1155
	# (we manually establish the root)
	oid["iso"]=1
	oidadd("org", "iso", 3)
	oidadd("dod", "org", 6)
	oidadd("internet", "dod", 1)
	oidadd("directory", "internet", 1)
	oidadd("mgmt", "internet", 2)
#XXX	oidadd("mib", "mgmt", 1)
	oidadd("mib-2", "mgmt", 1)
	oidadd("experimental", "internet", 3)
	oidadd("private", "internet", 4)
	oidadd("enterprises", "private", 1)
	oidadd("ip", "mib-2", 4)
	oidadd("transmission", "mib-2", 10)

	holddesc="none"
}

#
# Read mosy "*.defs" file.  mosy does all the parsing work; we just read
# its simple and straightforward output.  It would not be too hard to make
# tcpdump directly read mosy output, but...
#
# Ignore these unless the current file is called something.defs; false
# positives are too common in DESCRIPTIONs.

NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ {
	# currently ignore items of the form "{ iso.3.6.1 }"
	if (split($2, p, ".") == 2) {
		oidadd($1, p[1], p[2])
	}
	next
}

#
# Must be a MIB file
# Make it easier to parse - used to be done by sed
{ sub(/--\*.*\*--/, ""); sub(/--.*/, ""); gsub(/[{}]/, " & "); }

#
# this next section is simple and naive, but does the job ok
#

# foo OBJECT IDENTIFIER ::= { baz 17 }
# or
# foo OBJECT IDENTIFIER ::=
# { baz 17 }
$2$3$4 == "OBJECTIDENTIFIER::=" {
	holddesc="none"
	if (NF == 8)
		oidadd($1, $6, $7)
	if (NF == 4)
		holddesc=$1
	next
}
$1 == "{" && holddesc != "none" && NF == 4 {
	oidadd(holddesc, $2, $3)
	holddesc="none"
}
#
# foo OBJECT IDENTIFIER
#  ::= { bar 1 }
$2$3 == "OBJECTIDENTIFIER" && $1 != "SYNTAX" && NF == 3 {
	holddesc=$1
}
#
# foo
# OBJECT IDENTIFIER ::= { bar 1 }
# a couple of heuristics to exclude single words in e.g. long
#  DESCRIPTION clauses
NF == 1 && $1 ~ "[a-z][a-z]*[A-Z]" && $1 !~ /[(){}.,]/ && holddesc == "none" {
	holddesc=$1
}
$1$2$3 == "OBJECTIDENTIFIER::=" && holddesc != "none" {
	oidadd(holddesc, $5, $6)
	holddesc="none"
}
#
# "normal" style
# foo OBJECT-TYPE ...
# ...
#   ::= { baz 5 }
$2 == "MODULE-IDENTITY" || $2 == "MODULE-COMPLIANCE" ||
	$2 == "OBJECT-IDENTITY" || $2 == "OBJECT-TYPE" ||
	$2 == "OBJECT-GROUP" ||
	$2 == "NOTIFICATION-TYPE" || $2 == "NOTIFICATION-GROUP" {
	holddesc=$1
}
$1 == "::=" && holddesc != "none" && NF == 5 {
	oidadd(holddesc, $3, $4)
	holddesc="none"
}
#
# foo ::= { baz 17 }
$2$3 == "::={" {
	oidadd($1,$4,$5)
	holddesc="none"
}


# 
# End of the road - output the data.
#

END {
	print "struct obj"
	dump("iso")
	print "*mibroot = &_iso_obj;"
}

function inn(file) {
	if (file == "" || file == "-")
		return ""
	return " in " file
}

#
# add a new object to the tree
#
#		new OBJECT IDENTIFIER ::= { parent value }
#

function oidadd(new, parent, value) {
	# Ignore 0.0
	if (parent == "0" && value == 0)
		return
	if (debug)
		print "/* oidadd" inn(FILENAME) ":", new, "in", parent, "as", value, "line", $0, "*/"
	# use safe C identifiers
	gsub(/[-&\/]/,"",new)
	gsub(/[-&\/]/,"",parent)
	# check if parent missing
	if (oid[parent] == "") {
		printf "/* parse problem%s: no parent for %s.%s(%d) */\n", \
			inn(FILENAME), parent, new, value
		return
	}
	# check if parent.value already exists
	if (oid[new] > 0 && oid[new] != value) {
		printf "/* parse problem%s: dup %s.%s(%d) != old (%d) */\n", \
			inn(FILENAME), parent, new, value, oid[new]
		return
	}
	# check for new name for parent.value
	if (child[parent] != "") {
		for (sib = child[parent]; sib != ""; sib = sibling[sib])
			if (oid[sib] == value) {
				if (new != sib)
					printf "/* parse problem%s: new name" \
						" \"%s\"" \
						" for %s.%s(%d) ignored */\n", \
						inn(FILENAME), new, parent, \
						sib, value
				return
			}
	}

	oid[new]=value
	if (child[parent] == "") {
		child[parent] = new
	} else {
		sibling[new] = child[parent]
		child[parent] = new
	}
}

#
# old(?) routine to recurse down the tree (in postfix order for convenience)
#

function dump(item, c, s) {
#	newitem=sofar"."item"("oid[item]")"
#	printf "/* %s c=%s s=%s */\n", newitem, child[item], sibling[item]
	c="NULL"
	if (child[item] != "") {
		dump(child[item])
		c = "&_"child[item]"_obj"
	}
	s="NULL"
	if (sibling[item] != "") {
		dump(sibling[item])
		s = "&_"sibling[item]"_obj"
	}
	printf "_%s_obj = {\n\t\"%s\", %d, 0,\n\t%s, %s\n},\n", \
		item, item, oid[item], c, s
}
' $@@
exit 0
@


1.2.18.1
log
@file makemib was added on branch RELENG_8_4 on 2013-03-28 13:02:03 +0000
@
text
@d1 249
@


1.2.18.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248810
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 249
#!/bin/sh
#
# Copyright (c) 1990, 1996
#	John Robert LoVerso. All rights reserved.
# SMIv2 parsing copyright (c) 1999
#	William C. Fenner.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notices, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notices, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# @@(#) $Id: makemib,v 1.3 2001-09-17 22:16:52 fenner Exp $ (jlv)

#
# This script will read either ASN.1-style MIB files or the ".defs" files
# created by the ISODE "mosy" program on such files.
#
# The output of this script is the "mib.h" file used by tcpdumps' ASN.1/SNMP
# decoding code.
#
# This script needs to be run by "gawk" (GNU awk).  "nawk" will work, but
# dump will get a recursion error if you process LARGE mibs.  While it would
# by farily easy to rewrite this not to use recursion (and also easy to
# eliminate use of gsub and functions to use classic "awk"), you have to 
# order the structure declarations in defined-first order for the compiler
# not to barf; too bad tsort doesn't take arguments.
#

cat << EOF
/*
 * This file was generated by tcpdump/makemib on `date`
 * You probably don't want to edit this by hand!
 *
 * struct mib somename = { desc, oid-octet, type, child-pointer, next-pointer 
};
 */

EOF

awk '
BEGIN {
	debug=0;
	# for sanity, we prep the namespace with objects from RFC-1155
	# (we manually establish the root)
	oid["iso"]=1
	oidadd("org", "iso", 3)
	oidadd("dod", "org", 6)
	oidadd("internet", "dod", 1)
	oidadd("directory", "internet", 1)
	oidadd("mgmt", "internet", 2)
#XXX	oidadd("mib", "mgmt", 1)
	oidadd("mib-2", "mgmt", 1)
	oidadd("experimental", "internet", 3)
	oidadd("private", "internet", 4)
	oidadd("enterprises", "private", 1)
	oidadd("ip", "mib-2", 4)
	oidadd("transmission", "mib-2", 10)

	holddesc="none"
}

#
# Read mosy "*.defs" file.  mosy does all the parsing work; we just read
# its simple and straightforward output.  It would not be too hard to make
# tcpdump directly read mosy output, but...
#
# Ignore these unless the current file is called something.defs; false
# positives are too common in DESCRIPTIONs.

NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ {
	# currently ignore items of the form "{ iso.3.6.1 }"
	if (split($2, p, ".") == 2) {
		oidadd($1, p[1], p[2])
	}
	next
}

#
# Must be a MIB file
# Make it easier to parse - used to be done by sed
{ sub(/--\*.*\*--/, ""); sub(/--.*/, ""); gsub(/[{}]/, " & "); }

#
# this next section is simple and naive, but does the job ok
#

# foo OBJECT IDENTIFIER ::= { baz 17 }
# or
# foo OBJECT IDENTIFIER ::=
# { baz 17 }
$2$3$4 == "OBJECTIDENTIFIER::=" {
	holddesc="none"
	if (NF == 8)
		oidadd($1, $6, $7)
	if (NF == 4)
		holddesc=$1
	next
}
$1 == "{" && holddesc != "none" && NF == 4 {
	oidadd(holddesc, $2, $3)
	holddesc="none"
}
#
# foo OBJECT IDENTIFIER
#  ::= { bar 1 }
$2$3 == "OBJECTIDENTIFIER" && $1 != "SYNTAX" && NF == 3 {
	holddesc=$1
}
#
# foo
# OBJECT IDENTIFIER ::= { bar 1 }
# a couple of heuristics to exclude single words in e.g. long
#  DESCRIPTION clauses
NF == 1 && $1 ~ "[a-z][a-z]*[A-Z]" && $1 !~ /[(){}.,]/ && holddesc == "none" {
	holddesc=$1
}
$1$2$3 == "OBJECTIDENTIFIER::=" && holddesc != "none" {
	oidadd(holddesc, $5, $6)
	holddesc="none"
}
#
# "normal" style
# foo OBJECT-TYPE ...
# ...
#   ::= { baz 5 }
$2 == "MODULE-IDENTITY" || $2 == "MODULE-COMPLIANCE" ||
	$2 == "OBJECT-IDENTITY" || $2 == "OBJECT-TYPE" ||
	$2 == "OBJECT-GROUP" ||
	$2 == "NOTIFICATION-TYPE" || $2 == "NOTIFICATION-GROUP" {
	holddesc=$1
}
$1 == "::=" && holddesc != "none" && NF == 5 {
	oidadd(holddesc, $3, $4)
	holddesc="none"
}
#
# foo ::= { baz 17 }
$2$3 == "::={" {
	oidadd($1,$4,$5)
	holddesc="none"
}


# 
# End of the road - output the data.
#

END {
	print "struct obj"
	dump("iso")
	print "*mibroot = &_iso_obj;"
}

function inn(file) {
	if (file == "" || file == "-")
		return ""
	return " in " file
}

#
# add a new object to the tree
#
#		new OBJECT IDENTIFIER ::= { parent value }
#

function oidadd(new, parent, value) {
	# Ignore 0.0
	if (parent == "0" && value == 0)
		return
	if (debug)
		print "/* oidadd" inn(FILENAME) ":", new, "in", parent, "as", value, "line", $0, "*/"
	# use safe C identifiers
	gsub(/[-&\/]/,"",new)
	gsub(/[-&\/]/,"",parent)
	# check if parent missing
	if (oid[parent] == "") {
		printf "/* parse problem%s: no parent for %s.%s(%d) */\n", \
			inn(FILENAME), parent, new, value
		return
	}
	# check if parent.value already exists
	if (oid[new] > 0 && oid[new] != value) {
		printf "/* parse problem%s: dup %s.%s(%d) != old (%d) */\n", \
			inn(FILENAME), parent, new, value, oid[new]
		return
	}
	# check for new name for parent.value
	if (child[parent] != "") {
		for (sib = child[parent]; sib != ""; sib = sibling[sib])
			if (oid[sib] == value) {
				if (new != sib)
					printf "/* parse problem%s: new name" \
						" \"%s\"" \
						" for %s.%s(%d) ignored */\n", \
						inn(FILENAME), new, parent, \
						sib, value
				return
			}
	}

	oid[new]=value
	if (child[parent] == "") {
		child[parent] = new
	} else {
		sibling[new] = child[parent]
		child[parent] = new
	}
}

#
# old(?) routine to recurse down the tree (in postfix order for convenience)
#

function dump(item, c, s) {
#	newitem=sofar"."item"("oid[item]")"
#	printf "/* %s c=%s s=%s */\n", newitem, child[item], sibling[item]
	c="NULL"
	if (child[item] != "") {
		dump(child[item])
		c = "&_"child[item]"_obj"
	}
	s="NULL"
	if (sibling[item] != "") {
		dump(sibling[item])
		s = "&_"sibling[item]"_obj"
	}
	printf "_%s_obj = {\n\t\"%s\", %d, 0,\n\t%s, %s\n},\n", \
		item, item, oid[item], c, s
}
' $@@
exit 0
@


1.1
log
@Initial revision
@
text
@d3 26
a28 2
# Copyright (c) 1990, 1996, by John Robert LoVerso.
# All rights reserved.
d30 1
a30 12
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by John Robert LoVerso.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# @@(#) $Id: makemib,v 2.1 90/07/10 23:51:54 loverso Exp Locker: loverso $ (jlv
)
d58 1
a58 8
# use sed to make the ASN.1 easier to parse
# I should really just use a recursive descent parser in awk, but...
sed \
	-e 's/--\*.*\*--//' \
	-e 's/--.*//' \
	-e 's/\([{}]\)/ \1 /g' \
	$@@ \
| gawk '
d60 1
d69 2
a70 1
	oidadd("mib", "mgmt", 1)
d74 2
d85 2
d88 1
a88 1
NF > 1 && index($2,".")>0 {
d90 1
a90 1
	if (split($2, p, ".") == 2)
d92 1
d97 6
a102 1
# this next section is simple and naive, but does the job 100%
d105 4
d113 13
d127 21
a147 1
$2 == "OBJECT-TYPE" {
d154 7
d172 6
d185 5
d194 3
a196 3
	if (oid[parent] == 0) {
		printf "/* parse problem: no parent for %s.%s(%d) */\n", \
			parent, new, value
d201 2
a202 2
		printf "/* parse problem: dup %s.%s(%d) != old (%d) */\n", \
			parent, new, value, oid[new]
d209 6
a214 3
				printf "/* parse problem: new name \"%s\"" \
					" for %s.%s(%d) ignored */\n", \
						new, parent, sib, value
d248 1
a248 1
'
@


1.1.1.1
log
@Virgin import of unmodified tcpdump v3.2.1 distribution from LBL.
Obtained from: ftp://ftp.ee.lbl.gov/tcpdump.tar.Z on 19-Aug-1996.
@
text
@@


1.1.1.2
log
@Virgin import of tcpdump.org tcpdump v3.5
@
text
@a4 1
# SMIv2 parsing copyright (c) 1999 by William C. Fenner.
d16 2
a17 1
# @@(#) $Id: makemib,v 1.2 1999/11/21 17:24:15 fenner Exp $ (jlv)
d45 8
a52 1
awk '
a53 1
	debug=0;
d62 1
a62 2
#XXX	oidadd("mib", "mgmt", 1)
	oidadd("mib-2", "mgmt", 1)
a65 2
	oidadd("ip", "mib-2", 4)
	oidadd("transmission", "mib-2", 10)
a74 2
# Ignore these unless the current file is called something.defs; false
# positives are too common in DESCRIPTIONs.
d76 1
a76 1
NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ {
d78 1
a78 1
	if (split($2, p, ".") == 2) {
a79 1
	}
d84 1
a84 6
# Must be a MIB file
# Make it easier to parse - used to be done by sed
{ sub(/--\*.*\*--/, ""); sub(/--.*/, ""); gsub(/[{}]/, " & "); }

#
# this next section is simple and naive, but does the job ok
a86 4
# foo OBJECT IDENTIFIER ::= { baz 17 }
# or
# foo OBJECT IDENTIFIER ::=
# { baz 17 }
a90 25
	if (NF == 4)
		holddesc=$1
	next
}
$1 == "{" && holddesc != "none" && NF == 4 {
	oidadd(holddesc, $2, $3)
	holddesc="none"
}
#
# foo OBJECT IDENTIFIER
#  ::= { bar 1 }
$2$3 == "OBJECTIDENTIFIER" && $1 != "SYNTAX" && NF == 3 {
	holddesc=$1
}
#
# foo
# OBJECT IDENTIFIER ::= { bar 1 }
# a couple of heuristics to exclude single words in e.g. long
#  DESCRIPTION clauses
NF == 1 && $1 ~ "[a-z][a-z]*[A-Z]" && $1 !~ /[(){}.,]/ && holddesc == "none" {
	holddesc=$1
}
$1$2$3 == "OBJECTIDENTIFIER::=" && holddesc != "none" {
	oidadd(holddesc, $5, $6)
	holddesc="none"
d92 1
a92 9
#
# "normal" style
# foo OBJECT-TYPE ...
# ...
#   ::= { baz 5 }
$2 == "MODULE-IDENTITY" || $2 == "MODULE-COMPLIANCE" ||
	$2 == "OBJECT-IDENTITY" || $2 == "OBJECT-TYPE" ||
	$2 == "OBJECT-GROUP" ||
	$2 == "NOTIFICATION-TYPE" || $2 == "NOTIFICATION-GROUP" {
a98 7
#
# foo ::= { baz 17 }
$2$3 == "::={" {
	oidadd($1,$4,$5)
	holddesc="none"
}

a109 6
function inn(file) {
	if (file == "" || file == "-")
		return ""
	return " in " file
}

a116 5
	# Ignore 0.0
	if (parent == "0" && value == 0)
		return
	if (debug)
		print "/* oidadd" inn(FILENAME) ":", new, "in", parent, "as", value, "line", $0, "*/"
d121 3
a123 3
	if (oid[parent] == "") {
		printf "/* parse problem%s: no parent for %s.%s(%d) */\n", \
			inn(FILENAME), parent, new, value
d128 2
a129 2
		printf "/* parse problem%s: dup %s.%s(%d) != old (%d) */\n", \
			inn(FILENAME), parent, new, value, oid[new]
d136 3
a138 6
				if (new != sib)
					printf "/* parse problem%s: new name" \
						" \"%s\"" \
						" for %s.%s(%d) ignored */\n", \
						inn(FILENAME), new, parent, \
						sib, value
d172 1
a172 1
' $@@
@


1.1.1.2.2.1
log
@MFC: tcpdump 3.7.1
@
text
@d3 3
a5 4
# Copyright (c) 1990, 1996
#	John Robert LoVerso. All rights reserved.
# SMIv2 parsing copyright (c) 1999
#	William C. Fenner.
d7 9
a15 3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
d17 1
a17 19
# 1. Redistributions of source code must retain the above copyright
#    notices, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notices, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# @@(#) $Id: makemib,v 1.3 2001/09/17 22:16:52 fenner Exp $ (jlv)
@


1.1.1.3
log
@Import tcpdump 3.7.1, from
 http://www.tcpdump.org/release/tcpdump-3.7.1.tar.gz
@
text
@d3 3
a5 4
# Copyright (c) 1990, 1996
#	John Robert LoVerso. All rights reserved.
# SMIv2 parsing copyright (c) 1999
#	William C. Fenner.
d7 9
a15 3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
d17 1
a17 19
# 1. Redistributions of source code must retain the above copyright
#    notices, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notices, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# @@(#) $Id: makemib,v 1.3 2001/09/17 22:16:52 fenner Exp $ (jlv)
@


