#!/bin/sh
#
#	DISTRIBUTION: HNMS v2.0
#	FILE: asn1/makeoids
#
#	Create oids.c and oids.h for fast access to predefined OIDs.
#	The input file is the table-format MIB file generated by
#	SMIC (the free Synoptics MIB compiler) with the -N flag.
#
#	Jude George
#	NAS Facility, NASA Ames Research Center
#
#	Copyright (c) 1994 Jude George
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 1, or (at your option)
#	any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

AWK=/usr/bin/awk

MIB=gen/mibtable
TARG_C=gen/oids.c
TARG_H=gen/oids.h
OID_SIZE=80

echo "creating $TARG_H from $MIB"
if test -f $TARG_H
then
	rm -f $TARG_H
fi
echo "/*\\" >> $TARG_H
echo " *\tDISTRIBUTION: HNMS v2.0" >> $TARG_H
echo " *\tFILE: $TARG_H" >> $TARG_H
echo " *" >> $TARG_H
echo " *\tEdit not!  This file is automatically generated." >> $TARG_H
echo " *" >> $TARG_H
echo " *\tJude George" >> $TARG_H
echo " *\tNAS Facility, NASA Ames Research Center" >> $TARG_H
echo "\\*/" >> $TARG_H
echo "" >> $TARG_H
echo "int OID_init();" >> $TARG_H
echo "" >> $TARG_H
tr -d ":-" < $MIB | $AWK 'substr($1, 1, 1) == "1" { \
	printf "extern OID oid_"; \
	printf $2; \
	printf ";\n" \
      }' >> $TARG_H
echo "creating $TARG_C from $MIB"
rm -f $TARG_C
echo "/*\\" >> $TARG_C
echo " *\tDISTRIBUTION: HNMS v2.0" >> $TARG_C
echo " *\tFILE: $TARG_C" >> $TARG_C
echo " *" >> $TARG_C
echo " *\tEdit not!  This file is automatically generated." >> $TARG_C
echo " *" >> $TARG_C
echo " *\tJude George" >> $TARG_C
echo " *\tNAS Facility, NASA Ames Research Center" >> $TARG_C
echo "\\*/" >> $TARG_C
echo "" >> $TARG_C
echo "#include \"stdhnms.h\"" >> $TARG_C
echo "" >> $TARG_C
echo "#define OID_SIZE\t$OID_SIZE" >> $TARG_C
echo "" >> $TARG_C
tr -d ":-" < $MIB | $AWK 'substr($1, 1, 1) == "1" { \
	printf "OID oid_"; \
	printf $2; \
	printf ";\n" \
      }' >> $TARG_C
echo "" >> $TARG_C
echo "int OID_init()" >> $TARG_C
echo "{" >> $TARG_C
echo "    OID\toid;" >> $TARG_C
echo "" >>  $TARG_C
echo "    /*" >> $TARG_C
echo "     * We use an oid with an instance identifier of .0 for" >> $TARG_C
echo "     * the global constants.  We use an oid without the" >> $TARG_C
echo "     * instance identifier for the entry in the MIB struct." >> $TARG_C
echo "     */" >> $TARG_C
tr -d ":-" < $MIB | $AWK 'substr($1, 1, 1) == "1" { \
	printf "    oid_"; \
	printf $2; \
	printf " = oid_cpy(str2oid(\""; \
	printf $1; \
	printf ".0\", NULL));\n"; \
	printf "    MIB_add(str2oid(\""; \
	printf $1; \
	printf "\", NULL), \""; \
	printf $2; \
	printf "\", \""; \
	printf $3; \
	printf "\");\n" \
      }' >> $TARG_C
echo "    return 0;" >> $TARG_C
echo "}" >> $TARG_C
exit 0
