How to extract a single function from a source file

Posted by Adam Matan on Stack Overflow See other posts from Stack Overflow or by Adam Matan
Published on 2009-07-17T15:37:43Z Indexed on 2010/05/21 19:30 UTC
Read the original article Hit count: 191

Filed under:
|
|
|
|

Hi,

I'm working on a small academic research about extremely long and complicated functions in the Linux kernel. I'm trying to figure out if there is a good reason to write 600 or 800 lines-long functions.

For that purpose, I would like to find a tool that can extract a function from a .c file, so I can run some automated tests on the function.

For example, If I have the function cifs_parse_mount_options() within the file connect.c, I'm seeking a solution that would roughly work like:

extract /fs/cifs/connect.c cifs_parse_mount_options

and return the 523 lines of code(!) of the function, from the opening braces to the closing braces.

Of course, any way of manipulating existing software packages like gcc to do that, would be most helpful too.

Thanks,

Udi

EDIT : The answers to Regex to pull out C function prototype declarations? convinced me that matching function declaration by regex is far from trivial.

© Stack Overflow or respective owner

Related posts about c

    Related posts about regex