[32523] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3787 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 30 09:09:18 2012

Date: Sun, 30 Sep 2012 06: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           Sun, 30 Sep 2012     Volume: 11 Number: 3787

Today's topics:
        Newbien: Extract a C function from a file jose.luis.fdez.diaz@gmail.com
    Re: Newbien: Extract a C function from a file <josef.moellers@invalid.invalid>
    Re: Newbien: Extract a C function from a file jose.luis.fdez.diaz@gmail.com
    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: Sat, 29 Sep 2012 02:56:34 -0700 (PDT)
From: jose.luis.fdez.diaz@gmail.com
Subject: Newbien: Extract a C function from a file
Message-Id: <1b62de6b-931a-481d-bce1-2acbd1cf16f5@googlegroups.com>

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




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

Date: Sat, 29 Sep 2012 16:30:23 +0200
From: Josef Moellers <josef.moellers@invalid.invalid>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <acoevvFf0lpU1@mid.individual.net>

On 09/29/2012 11:56 AM, 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?

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

Josef



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

Date: Sat, 29 Sep 2012 12:27:15 -0700 (PDT)
From: jose.luis.fdez.diaz@gmail.com
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <b31f477a-e726-4295-9e64-c9db99049a89@googlegroups.com>

El s=E1bado, 29 de septiembre de 2012 16:30:24 UTC+2, Josef Moellers  escri=
bi=F3:
> On 09/29/2012 11:56 AM, jose.luis.fdez.diaz at ..... gmail.com wrote:
>=20
> > Hi,
>=20
> >=20
>=20
> > This is the pattern from a C function:
>=20
> >=20
>=20
> > <<snip>>
>=20
> > void foo(....)
>=20
> > {
>=20
> > ....
>=20
> > }
>=20
> > <<snip>>
>=20
> >=20
>=20
> > Given the function name, is there an easy way to extract the function t=
ext from a C file in Perl?
>=20
>=20
>=20
> In general: No.
>=20
> You need a /scanner/parser for C for that.
>=20
>=20
>=20
> Josef

Thanks for your answer Josef.

Perhaps this is possible. Given this pattern:

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

   {
     ....

     {
     ...
     }

     ....
 =20
   }
}
<<snip>>

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


Regards,
Jose Luis


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

Date: Sat, 29 Sep 2012 23:00:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Newbien: Extract a C function from a file
Message-Id: <tk7kj9-5k41.ln1@anubis.morrow.me.uk>


Quoth jose.luis.fdez.diaz@gmail.com:
> 
> Perhaps this is possible. Given this pattern:
> 
> <<snip>>
> {
>    {
>     ....
>    }
> 
>    {
>      ....
> 
>      {
>      ...
>      }
> 
>      ....
>   
>    }
> }
> <<snip>>
> 
> Is there and easy way to get the text between the external braces?

You can match matched braces with the (?R) construct introduced in perl
5.10, but you have to be careful about braces inside quotes and
comments. (You can probably ignore the possibility of unmatched braces
inside macro definitions and expansions.)

If you can assume the C is 'properly' formatted, of course, it becomes
much easier: the only time you get an open brace in the first column is
when it is starting a function, and the end of the function is the next
close brace which is also in the first column. Depending on what you're
trying to do you could consider running the C through indent(1) with
some appropriate set of options, since that has something approximating
a C parser.

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 3787
***************************************


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