in reply to pattern matching c-style function definitions :o(

What about a line processing approach? If function declarations always begin with a left brace at column 0 and end with a right brace at column 0, the following should work:
my ($prev, $type, $func, $args, $body); while (<>) { if (/^\{/) { # maybe check for structs/classes here if necessary ($type, $func, $args) = split(' ', $prev, 3); $body = ''; } elsif (/^\}/) { # ... process the function here ... $func = undef; } else { if (defined($func)) { $body .= $_; } else { $prev = $_; } } }
As noted in the code, you might have to check for structs and/or classes.

Replies are listed 'Best First'.
Re^2: pattern matching c-style function definitions :o(
by barryscott (Acolyte) on Jan 07, 2008 at 20:39 UTC
    Thanks for the help everyone. What I basically need is to collect a list of all arguments and local variables in each function, which I'm then matching against known sizes from the map file to automatically calculate the worst case stack depth, after extract the call charts with cflow. Fairly ambitious for my limited perl knowhow, but the above will get me a step closer.