Perl Search Help

M

mihirtr

Hi,
I am trying to do following with Perl. Can someone check and help me
out if it is possible.

I am have multiple .c files, I need to find out second parameter in
function call My_Function_Test from these files and output to a file.

For example:

Example .c file

Sample_Func1()
{
MY_STRUCT_1 abc;
My_Function_Test (MY_1ST_PARAMETER,
sizeof(MY_STRUCT_1),
MY_3RD_PARAMETER);

}

Sample_Func1()
{
MY_STRUCT_2 abc;
My_Function_Test (MY_1ST_PARAMETER,
sizeof(MY_STRUCT_2),
MY_3RD_PARAMETER);

}


After running perl script, the output should be following
sizeof(MY_STRUCT_1)
sizeof(MY_STRUCT_2)
 
J

J. Gleixner

Hi,
I am trying to do following with Perl. Can someone check and help me
out if it is possible.

I am have multiple .c files, I need to find out second parameter in
function call My_Function_Test from these files and output to a file.

Post what you have tried so far.
 
J

Jens Thoms Toerring

I am trying to do following with Perl. Can someone check and help me
out if it is possible.
I am have multiple .c files, I need to find out second parameter in
function call My_Function_Test from these files and output to a file.
For example:
Example .c file
Sample_Func1()
{
MY_STRUCT_1 abc;
My_Function_Test (MY_1ST_PARAMETER,
sizeof(MY_STRUCT_1),
MY_3RD_PARAMETER);

Sample_Func1()
{
MY_STRUCT_2 abc;
My_Function_Test (MY_1ST_PARAMETER,
sizeof(MY_STRUCT_2),
MY_3RD_PARAMETER);

After running perl script, the output should be following
sizeof(MY_STRUCT_1)
sizeof(MY_STRUCT_2)

If you don't mind a few false positives (from the functions
definition and possible prototype declarations or places where
calls of the function are commented out) and and the way you
call the function isn't too complicated (e.g. with arguments
that are enclosed in parenthesis and then contain commas or
the functions, the function call isn't part of a macro etc.)
it can be rather simple: Read in the whole file into a single
string and do repeated regexp searches for

\WMy_Function_Test\s*\([^,]*,\s*([^,]*)

The second argument should then be in $1. Print it out after
removing trailing white space. But for a 100% reliable solu-
tion I guess you probably will need a full-blown preprocessor
and parser for C.
Regards, Jens
 
M

mihirtr

I am trying to do following with Perl. Can someone check and help me
out if it is possible.
I am have multiple .c files, I need to find out second parameter in
function call My_Function_Test from these files and output to a file.
For example:
Example .c file
Sample_Func1()
{
MY_STRUCT_1 abc;
My_Function_Test (MY_1ST_PARAMETER,
sizeof(MY_STRUCT_1),
MY_3RD_PARAMETER);
}
Sample_Func1()
{
MY_STRUCT_2 abc;
My_Function_Test (MY_1ST_PARAMETER,
sizeof(MY_STRUCT_2),
MY_3RD_PARAMETER);
}
After running perl script, the output should be following
sizeof(MY_STRUCT_1)
sizeof(MY_STRUCT_2)

If you don't mind a few false positives (from the functions
definition and possible prototype declarations or places where
calls of the function are commented out) and and the way you
call the function isn't too complicated (e.g. with arguments
that are enclosed in parenthesis and then contain commas or
the functions, the function call isn't part of a macro etc.)
it can be rather simple: Read in the whole file into a single
string and do repeated regexp searches for

\WMy_Function_Test\s*\([^,]*,\s*([^,]*)

The second argument should then be in $1. Print it out after
removing trailing white space. But for a 100% reliable solu-
tion I guess you probably will need a full-blown preprocessor
and parser for C.
Regards, Jens
--
\ Jens Thoms Toerring ___ (e-mail address removed)
\__________________________ http://toerring.de- Hide quoted text -

- Show quoted text -

Thanks, I will try it out.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top