Ace128 has asked for the wisdom of the Perl Monks concerning the following question:
I wanna do so this becomes:static struct super_block* sfs_get_super(struct file_system_type *fst, + int flags, const char *devname, void *data) { struct super_block *sb = 0; struct mounter_data_t *mount_data = sfs_get_mounter_data(dat +a); HIGHPRINT("Calling get_sb_single\n"); sb = get_sb_single(fst, flags, mount_data, sfs_fill_super); HIGHPRINT("Returned from get_sb_single\n"); dealloc_mounter_data(mount_data); return sb; }
That is, takes out the function and its arguments, and creates that skeleton documentation. I'm using Tie::File to read the file, and am currently halted on parsing the code. So far I've done this:/* Function: sfs_get_super(struct file_system_type *fst, int flags, co +nst char *devname, void *data) * * Parameters: * fst - * flags - * devname - * data - * * Returns: * struct super_block* */ static struct super_block* sfs_get_super(struct file_system_type *fst, + int flags, const char *devname, void *data) { struct super_block *sb = 0; struct mounter_data_t *mount_data = sfs_get_mounter_data(dat +a); HIGHPRINT("Calling get_sb_single\n"); sb = get_sb_single(fst, flags, mount_data, sfs_fill_super); HIGHPRINT("Returned from get_sb_single\n"); dealloc_mounter_data(mount_data); return sb; }
This only works with parsing one row (aka static int sfs_fill_super(struct super_block *sb, void *data, int silent) ), but its a start. { is always on a new line after the function (good old C coding style apparently :) ). I got tips to use C::Scan, but that that lacks documentation, and it seem to need some external application named "cppstdin". (Im using Windows here). So, I was wondering if anyone here had some smart way to solve this problem. I know there are some bright people here! ;)#!/usr/bin/perl # Script to add comments for Natural Doc. http://www.naturaldoc.org use Tie::File; use strict; use warnings; use Data::Dumper; my @FILE_ARRAY; tie @FILE_ARRAY, 'Tie::File', "searchfs.c", recsep => "\n" or die $!; my $found = 0; foreach (@FILE_ARRAY) { #if (/^(sub .+)/) { # Match .c function if (/^(?:([0-9_a-zA-Z*]+) +)?(?:([0-9_a-zA-Z*]+) +)?(?:([0-9_a-zA- +Z*]+) +)?([0-9_a-zA-Z*]+)\((.+?)\)/) { my ($a, $b, $c, $d, $e) = ("") x 5; if (defined($1)) { $a = $1; } if (defined($2)) { $b = $2; } if (defined($3)) { $c = $3; } if (defined($4)) { $d = $4; } if (defined($5)) { $e = $5; } print $a . " " . $b . " " . $c . " " . $d . " ARGS: " . $e . +"\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing C Source File Functions.
by Khen1950fx (Canon) on Oct 21, 2006 at 14:57 UTC | |
Re: Parsing C Source File Functions.
by davidrw (Prior) on Oct 21, 2006 at 16:07 UTC | |
by Ace128 (Hermit) on Oct 21, 2006 at 16:20 UTC | |
Re: Parsing C Source File Functions.
by graff (Chancellor) on Oct 21, 2006 at 16:33 UTC | |
by Ace128 (Hermit) on Oct 21, 2006 at 17:24 UTC | |
Re: Parsing C Source File Functions.
by Ace128 (Hermit) on Oct 22, 2006 at 23:52 UTC | |
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 | |
Re: Parsing C Source File Functions.
by Ace128 (Hermit) on Oct 22, 2006 at 21:14 UTC |