[32525] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3789 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 2 16:09:18 2012

Date: Tue, 2 Oct 2012 13:09:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 2 Oct 2012     Volume: 11 Number: 3789

Today's topics:
    Re: Newbien: Extract a C function from a file <jimsgibson@gmail.com>
    Re: Newbien: Extract a C function from a file <*@eli.users.panix.com>
    Re: Newbien: Extract a C function from a file <kaz@kylheku.com>
    Re: Newbien: Extract a C function from a file <ben@morrow.me.uk>
    Re: Newbien: Extract a C function from a file <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 01 Oct 2012 10:00:37 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <011020121000378595%jimsgibson@gmail.com>

In article <1b62de6b-931a-481d-bce1-2acbd1cf16f5@googlegroups.com>,
<jose.luis.fdez.diaz@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?

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

-- 
Jim Gibson


------------------------------

Date: Mon, 1 Oct 2012 22:13:08 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <eli$1210011808@qz.little-neck.ny.us>

In comp.lang.perl.misc,  <jose.luis.fdez.diaz@gmail.com> 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 }

void
function_name
( int param )
        {
                char *haha = " } ";
                if (param) {
     puts(haha);
}
	puts("Feel the love.\n");
        PROGRAMMER_HATES_YOU

        int main ( int a, char**v) {
        function_name( a%2 ); return /* } done { */ (0); }

:r! gcc -Wall -o macro macro.c && ./macro
 } 
Feel the love.


Elijah
------
preprocessor makes everything much nastier



------------------------------

Date: Tue, 2 Oct 2012 00:02:35 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <20121001165758.638@kylheku.com>

On 2012-10-01, Eli the Bearded <*@eli.users.panix.com> wrote:
> In comp.lang.perl.misc,  <jose.luis.fdez.diaz@gmail.com> 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 )


------------------------------

Date: Tue, 2 Oct 2012 00:52:33 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <1vmpj9-ldv2.ln1@anubis.morrow.me.uk>


Quoth Eli the Bearded <*@eli.users.panix.com>:
> In comp.lang.perl.misc,  <jose.luis.fdez.diaz@gmail.com> 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 }

So run it through cpp before trying to parse it... Whether that's useful
or not depends on what exactly the OP is trying to do with these
function bodies, which he hasn't said.

Ben



------------------------------

Date: Tue, 2 Oct 2012 03:56:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <ho1qj9-0e2.ln1@anubis.morrow.me.uk>


Quoth Kaz Kylheku <kaz@kylheku.com>:
> On 2012-10-01, Eli the Bearded <*@eli.users.panix.com> wrote:
> > In comp.lang.perl.misc,  <jose.luis.fdez.diaz@gmail.com> 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 )

The perl source contains (in some configurations) all of

    #define END_EXTERN_C }
    #define STMT_END )
    #define PERL_FPU_PRE_EXEC {

though in all cases when these macros are used correctly the visible
braces and brackets end up balancing. (The STMT_END definition is
particularly evil...)

Ben



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3789
***************************************


home help back first fref pref prev next nref lref last post