hi,
i am a newbie and have to write a rather complicated script. Assume that i have a variable called x and a C source code file say file1.c (this are the inputs of the script) and i need to find the names of all the functions in the C file containing x.Take the following code as an example:
1.int main(void);
2.void foo(void);
3.void bar(void);
4.
5.int main(void)
6.{
7.int x;
8.return 0;
9.}
10.
11.void foo(void)
12.{
13.int x;
14.}
15.
16.void bar(void)
17.{
18.int x;
19.}
so i guess the output should be:
in 5. main(void) x occurs in line 7 as int x;
in 11.foo(void) x occurs in line 13 as int x
and in 16.bar(void) x occurs in line 18 as int x
Something similar to but not exactly as above. To print the name of the functions containing x is crucial.
i can find line number using grep -n and probably use sed -n '/{/,/}/p' file1.c to select blocks of code delimited by { and } but I'm not sure how to refine this further.
any help would be welcome.
thanks,
Sam