Giving up isn't my deal :)
#!/usr/bin/perl
# Script to add comments for Natural Doc. http://www.naturaldoc.org
use strict;
use warnings;
use Tie::File;
use Data::Dumper;
if (@ARGV < 1) {
print "Usage: app file";
exit(0);
}
my $file;
open $file, $ARGV[0] or die $!;
my $data = join("", <$file>);
close $file;
my $data_with_comment = "";
my @matches;
while ( $data =~ /\n((?:\w+\*?\*?\s+)+) (\*?\w+\s*) \s* \((.*?) \) (\s
+*\{)/gsx ) {
push(@matches, { 'fullmatch' => $&, 'functype' => $1, 'funcname' =
+> $2, 'funcargs' => $3 });
}
foreach (@matches) {
my $fullmatch = $_->{'fullmatch'};
my $functype = $_->{'functype'};
my $funcname = $_->{'funcname'};
my $funcargs = $_->{'funcargs'};
my $comment = "";
my @funcargs = split /,\s*/, $funcargs;
my $args = join( ", ", @funcargs );
my $args2 = join( "\n * ", @funcargs );
$comment .= qq {
/* Function: $funcname($args)
*
*
*
* Arguments:
* $args2
*
* Returns:
* $functype
*
*/ };
$data =~ s/\Q$fullmatch\E/$comment$fullmatch/;
}
print $data;
This works for me atleast.