#!/usr/bin/perl
#
# Read in the C MIB tree generated by parse and produce a bunch of
# C #define commands for the symbols in field four.
#
$I = 100;

while (<>) {
	chop;
	if (/\{\{(.*)\},\s*(\d+),\s*(\w+),\s*(\w+),\s*(\w+),\s*(\w+),\s*"(\w+)"\},\s*$/) {
		$oid = $1;
		$sym = $4;
		$fct = $6;
		$nam = $7;
		$fct =~ s/Entry$//;
		if (++$S{$sym} == 1) {	# Count the symbol references.
			++$I;		# Only #define the first time we see a symbol.
#			print "#define $sym $I /* $nam */\n";
		}
		if ($oid =~ /G$/) {
			$Fct{$fct} = -1		# Note the group function references.
				if (!defined($Fct{$fct}));
		} else {
			$Fct{$fct} ++;	# Count the real function references.
		}
	} else {
		print "### no match: \"$_\"\n";
	}
}
#
# Now produce extern declarations for all the functions:
for $f (sort keys(%Fct)) {
	if ($Fct{$f} > 0) {
		print"extern byte* $f();\n";
	} else {
		print"#define $f 0\n";
	}
}
