Newbien: Extract a C function from a file

Discussion in 'Perl Misc' started by jose.luis.fdez.diaz@gmail.com, Sep 29, 2012.

  1. Guest

    Hi,

    This is the pattern from a C function:

    <<snip>>
    void foo(....)
    {
    .....
    }
    <<snip>>

    Given the function name, is there an easy way to extract the function text from a C file in Perl?

    Thanks in advance,
    Jose Luis
     
    , Sep 29, 2012
    #1
    1. Advertisements

  2. On 09/29/2012 11:56 AM, wrote:
    > Hi,
    >
    > This is the pattern from a C function:
    >
    > <<snip>>
    > void foo(....)
    > {
    > ....
    > }
    > <<snip>>
    >
    > Given the function name, is there an easy way to extract the function text from a C file in Perl?


    In general: No.
    You need a /scanner/parser for C for that.

    Josef
     
    Josef Moellers, Sep 29, 2012
    #2
    1. Advertisements

  3. Guest

    El sábado, 29 de septiembre de 2012 16:30:24 UTC+2, Josef Moellers escribió:
    > On 09/29/2012 11:56 AM, jose.luis.fdez.diaz at ..... gmail.com wrote:
    >
    > > Hi,

    >
    > >

    >
    > > This is the pattern from a C function:

    >
    > >

    >
    > > <<snip>>

    >
    > > void foo(....)

    >
    > > {

    >
    > > ....

    >
    > > }

    >
    > > <<snip>>

    >
    > >

    >
    > > Given the function name, is there an easy way to extract the function text from a C file in Perl?

    >
    >
    >
    > In general: No.
    >
    > You need a /scanner/parser for C for that.
    >
    >
    >
    > Josef


    Thanks for your answer Josef.

    Perhaps this is possible. Given this pattern:

    <<snip>>
    {
    {
    ....
    }

    {
    ....

    {
    ...
    }

    ....

    }
    }
    <<snip>>

    Is there and easy way to get the text between the external braces?


    Regards,
    Jose Luis
     
    , Sep 29, 2012
    #3
  4. Jim Gibson Guest

    In article <>,
    <> wrote:

    > Hi,
    >
    > This is the pattern from a C function:
    >
    > <<snip>>
    > void foo(....)
    > {
    > ....
    > }
    > <<snip>>
    >
    > Given the function name, is there an easy way to extract the function text
    > from a C file in Perl?


    I have used the Text::Balanced module for this kind of thing in the
    past.

    --
    Jim Gibson
     
    Jim Gibson, Oct 1, 2012
    #4
  5. Kaz Kylheku Guest

    On 2012-10-01, Eli the Bearded <*@eli.users.panix.com> wrote:
    > In comp.lang.perl.misc, <> wrote:
    >> Given the function name, is there an easy way to extract the function
    >> text from a C file in Perl?

    >
    > You are in a world of hurt if the programmer hates you.
    >
    >:r macro.c
    > #include <stdio.h>
    >
    > #define PROGRAMMER_HATES_YOU }


    Note that such buffoonery in the source will also likely defeat numerous
    popular programming tools like cscope, mkid and ctags. Oh, not to mention
    syntax highlighting and automatic code indentation in your text editor, and the
    reporting of function names in context diff hunks.

    So that should really be:

    #define PROGRAMMER_HATED_BY_TEAM_CUSTOMERS_WIFE_KIDS_DOG )
     
    Kaz Kylheku, Oct 2, 2012
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Duke of Hazard
    Replies:
    0
    Views:
    872
    Duke of Hazard
    Jan 23, 2004
  2. Robert Schultz

    Extract a function from C code?

    Robert Schultz, Oct 28, 2004, in forum: C Programming
    Replies:
    13
    Views:
    1,440
    Cedric LEMAIRE
    Nov 4, 2004
  3. SunRise
    Replies:
    2
    Views:
    827
    SunRise
    Jul 3, 2005
  4. SunRise
    Replies:
    7
    Views:
    951
    S.Tobias
    Jul 6, 2005
  5. moerchendiser2k3
    Replies:
    2
    Views:
    324
    Stefan Behnel
    Mar 25, 2010
  6. kittywindz2

    Extract a specific function in C source code

    kittywindz2, Dec 4, 2010, in forum: C Programming
    Replies:
    0
    Views:
    462
    kittywindz2
    Dec 4, 2010
  7. gnobal
    Replies:
    5
    Views:
    863
    gnobal
    Jul 4, 2011
  8. Rider
    Replies:
    8
    Views:
    216
Loading...