Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: regex 2 find C function dependencies

by perlmonkey (Hermit)
on Sep 20, 2003 at 06:16 UTC ( #292815=note: print w/replies, xml ) Need Help??


in reply to regex 2 find C function dependencies

I just went through a similar exercise myself. I did not find C::Scan to be useful, and Parse::RecDescent can do it, but probably too much work for your needs.

You really want to use Regexp::Common here.

Something like this should get you started:
use Regexp::Common; my $func_rx = qr{ ([a-zA-Z]\w*) # match function name \s* # optional space ($RE{balanced}{-parens='()'}) # match parameter list }sx; while( $code =~ /$func_rx/g ) { print "func = $1\n"; print "param list = $2\n"; }

This will match things like if( !foo ) though, so you will probably have to explicitly skip built-in keywords like that.

Note that this is certainly not a complete solution for you, but just to point out Regexp::Common is a handy tool that should help.

Also you probably want to strip out all the comments first, so they dont throw off your matching regex. But this can also be done with Regexp::Common:
$code =~ s/$RE{comment}{'C++'}//g;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://292815]
help
Chatterbox?
[Corion]: Hmm. My overkill logging of transactions seems to bear fruit. I've built it in a way that the decision on every transaction must be logged, even if the transaction is just skipped, to prevent silent skips.
[Corion]: Now, three years in production, it found a situation (during development) where stuff was skipped without getting a log message.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2017-08-21 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (318 votes). Check out past polls.

    Notices?