Home > Archive > AWK > September 2006 > Name of C function containing a pattern
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Name of C function containing a pattern
|
|
| Karthick S. 2006-09-24, 6:56 pm |
| Hi,
I am writing a shell script that will print the name of the C function
that contains a specified pattern. I found that grep prints the
"context" of a pattern, but could not find any method to exactly print
the name of the C function which contains the specified pattern.
For example:
#include <stdio.h>
int fun1()
{
// Some lines here
printf("Hello World")
// Some lines here
}
How do I print "fun1" using awk/sed/bash/perl?
Please help me.
Thanks and regards,
Karthick S.
| |
| Ed Morton 2006-09-25, 3:56 am |
| Karthick S. wrote:
> Hi,
>
> I am writing a shell script that will print the name of the C function
> that contains a specified pattern. I found that grep prints the
> "context" of a pattern, but could not find any method to exactly print
> the name of the C function which contains the specified pattern.
>
> For example:
> #include <stdio.h>
>
> int fun1()
> {
> // Some lines here
> printf("Hello World")
> // Some lines here
> }
>
> How do I print "fun1" using awk/sed/bash/perl?
>
> Please help me.
>
> Thanks and regards,
> Karthick S.
>
Use cscope (http://cscope.sourceforge.net/) to find the definition, then
pass it's output to awk/sed/bash/perl. Rather than the raw C code, show
us the output you get from cscope as that'd be the input for the awk script.
Ed.
|
|
|
|
|