#!/usr/local/bin/perl
# mkproto: Munge the FUNCTION macro into prototypes.
#
# This software is Copyright 1996 by Craig Metz, All Rights Reserved. The
# Inner Net Copyright Notice and License Agreement applies to these portions
# of the software.
#
#	History:
#
#	Created by cmetz for OPIE 2.2.
#
while(<>) {
	/^static/ && next;
	/FUNCTION/ || next;
	/^((struct[ \t]+)?[a-zA-Z0-9\_]+[ \t]*\*?)([A-Z0-9a-z_]+)[ \t]+FUNCTION\(\(.+\),[ \t]*([A-Za-z0-9\_\t \*]+)\)/ && do {
		print "$1 $3 __P((";
		@arglist = ();
		for $_ (split(/AND/, $4)) {
			s/^[ \t]+//;
			s/[ \t]+$//;
			/^(.+[ \t*])[a-zA-Z0-9\_]+?$/ || do {
				print "mkproto: error parsing +$_+\n";
				next;
			};
			$_ = $1;
			s/[ \t]+$//;
			@arglist = (@arglist, $_);
		};
		print join(',', @arglist);
		print "));\n";
		next;
	};
	/^((struct[ \t]+)?[a-zA-Z0-9\_]+[ \t]*\*?)([A-Z0-9a-z_]+)[ \t]+FUNCTION_NOARGS[ \t]/ && do {
		print "$1 $3 __P((void))\n";
		next;
	};
};
