#!/usr/bin/perl -w
#
# perlstub: ok, I've got bored typing all those perl function stubs
#	    this is a code generator (see The Pragmatic Programmer)
#	    that reads a function stub file of the form
#		typical call example
#		{
#		comment lines
#		}
#	    for instance:
#		( a, b ) = wibble( x, y, @z )
#		{
#		do some wibbling with $x, $y and @z
#		}
#	    and then writes the perl subroutine stub, complete with
#	    standard comment format, the prototype line and the
#	    breaking of the param array into variables named precisely
#	    like the example, with '$' prefixes added if they're missing..
#	    
#	(C) Duncan C. White, May 2007
#

use strict;

my $func = <>;
chomp $func;

# lose any trailing stuff after the close bracket
$func =~ s/\)[^\)]*$/)/;

print "#\n";
print "# $func:\n";

# consume all the rest of the comments.
while( <> )
{
	print "#\t$_" unless /^[{}]$/;
}
print "#\n";

# lose all whitespace
$func =~ s/\s+//g;

# lose any crap = prefix..
$func =~ s/^.*=//;

# what's left should look like: wibble(x,y,@z)

$func =~ /^(\w+)\(([^)]*)\)$/;

my $funcname = $1;
my $params = $2;

#print "debug: func $func, name $funcname, params $params\n";

my @params;
my $protostr = "";
foreach (split( /,/, $params ))
{
	/^[\$@%]/ || s/^/\$/;
	push @params, $_;
	/^(.)/;
	$protostr .= $1;
}

my $paramstr = join( ", ", @params );

print "sub $funcname ($protostr)\n";
print "{\n";
print "\tmy( $paramstr ) = \@_;\n";
print "\n\t# DCW: write me...\n";
print "}\n\n\n";
