#!/usr/bin/perl
#
#   mkvarmodule name...
#
# This takes a list of names, which should be names of the group-level
# data  routines  within  the  SNMP  agent,  and  builds "stub" source
# modules for each of them.  This is done by copying  the  "v_proto.b"
# source  file,  and  changing  the  word  "proto" to the desired name
# throughout.  The resulting module should compile and return  a  null
# value  for  all calls.  This is a kludge to get the calling sequence
# right, and to make sure that we can link snmpd successfully.
#
# The name "foo" may be given in various forms:
#     foo
#     foo.o
#     v_foo
#     var_foo
#     _v_foo
# so you can feed it the list from the linker, for example.  The extra
# stuff  will be stripped off, and 'v_' prepended and '.b" appended to
# form the module's real name.
#
# Take care not to stomp on existing modules.

$proto = 'v_proto.b';

for $m (@ARGV) {
	print "Name: $m\n";
	open(P, "<$proto") ||
		die "### Can't read \"$proto\" [$!]\n";
	$m =~ s/^_*//;
	$m =~ s/^v_//;
	$m =~ s/^var_//;
	$m =~ s/\.o$//;
	if (open(M, ">v_$m.b")) {
		print "File: v_$m.b\n";
	} else {
		print STDERR "### Can't write \"v_$m.b\" [$!]\n";
		next;
	}
	for $l (<P>) {
		$l =~ s/proto/$m/g;
		print M $l;
	}
}
