Perl Search Help
am 17.08.2007 18:32:24 von 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)
Re: Perl Search Help
am 17.08.2007 18:36:59 von glex_no-spam
mihirtr@gmail.com wrote:
> 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.
Re: Perl Search Help
am 17.08.2007 19:09:41 von JT
mihirtr@gmail.com wrote:
> 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 ___ jt@toerring.de
\__________________________ http://toerring.de
Re: Perl Search Help
am 17.08.2007 22:38:34 von mihirtr
On Aug 17, 12:09 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> mihi...@gmail.com wrote:
> > 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 ___ j...@toerring.de
> \__________________________ http://toerring.de- Hide quoted text -
>
> - Show quoted text -
Thanks, I will try it out.