Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Newbien: Extract a C function from a file

Reply
Thread Tools

Newbien: Extract a C function from a file

 
 
jose.luis.fdez.diaz@gmail.com
Guest
Posts: n/a
 
      09-29-2012
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


 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      09-29-2012
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

 
Reply With Quote
 
 
 
 
jose.luis.fdez.diaz@gmail.com
Guest
Posts: n/a
 
      09-29-2012
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
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      10-01-2012
In article <1b62de6b-931a-481d-bce1->,
<> 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
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      10-02-2012
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 )
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To extract file name only from a file Rider Perl Misc 8 07-11-2009 09:18 PM
How do i extract vidios when winrar wont extract them??? help plzzzzzzzz smuttdog@sc.rr.com Computer Support 2 12-23-2007 07:03 AM
C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX) SunRise C Programming 7 07-06-2005 08:11 AM
C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX) SunRise C Programming 2 07-02-2005 11:35 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57