in reply to Parsing C Source File Functions.
This works for me atleast.#!/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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parsing C Source File Functions.
by Anonymous Monk on Jan 10, 2014 at 10:49 UTC | |
by roboticus (Chancellor) on Jan 10, 2014 at 12:39 UTC | |
by Anonymous Monk on Jan 10, 2014 at 13:35 UTC | |
by roboticus (Chancellor) on Jan 11, 2014 at 01:01 UTC |