mtr4cv has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a perl script which will read in Ada and C files and separate each of the functions & procedures and put them each in a separate file (these separate files don't have to be compiled, so I don't need any include or header information, just the first line of the function/procedure to the last).

Any suggestions on how best to do this? Any useful perl modules that would help? Specifically I'm looking for how to find the beginning and end of each function/procedure.
  • Comment on How to split Ada & C files by function/procedure

Replies are listed 'Best First'.
Re: How to split Ada & C files by function/procedure
by tachyon (Chancellor) on Mar 15, 2002 at 15:19 UTC

    You should find some useful code at Compressing/Obfuscating a Javascript file including a bit that splits the code into function as you desire. In essence all you need is something like:

    # do the magic and split into functions @functions = split /(?=\bfunction\s)/, $data;

    In hindsight this split regex should probably be more like:

    @functions = split /(?=\n\s*function\s)/, $data;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print