Newbien: Extract a C function from a file

  • Thread starter jose.luis.fdez.diaz
  • Start date
J

jose.luis.fdez.diaz

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
 
J

Josef Moellers

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
 
J

jose.luis.fdez.diaz

El sábado, 29 de septiembre de 2012 16:30:24 UTC+2, Josef Moellers escribió:
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
 
J

Jim Gibson

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.
 
K

Kaz Kylheku

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 )
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top