find function name in a program file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find function name in a program file
# 8  
Old 06-25-2010
here's the code with some comments to try to explain...i hope it helps..


Code:
$str=shift @ARGV;
while(<>){
        # match function name and save name and line to display later in
        # case the RA is found
        if(!$sw && /(.+\(.*\))/){
                $func_name=$1;
                $func_start=$.;
                $sw=1;  
                @ra=();
                next;
        }       
        # those counters basically server to know if we are ($c>0) or not ($c==0) 
        # inside a function body i.e. between { and } 
        $c++ if $sw && /\{/;
        $c-- if $sw && /\}/; 

        # match RA string and save it in a list
        if(/\/\*RA (.+)\*\//){
                push(@ra,$1);
        }       
                
        # flag to know if the RA in questions was found, so we'll preint everything
       # we've saved   
        if(/\/\*RA $str/){ 
                $print=1;
        }       
                
        # if we are at the end of a function $sw==1 and $c==0 then 
        if($sw && $c==0){ 
            # we test if any of the RAs in the function was the one we were 
            # looking for, if so print all the elements
                if($print){
                        print "function $func_name\n";
                        print "start line $func_start\n";
                        print "end line $.\n";
                        print "ra's:\n  ".join("\n  ",@ra)."\n";
                        $print=0;
                }
                $sw=0;
        }       
}

This User Gave Thanks to rugdog For This Post:
# 9  
Old 06-26-2010
Lightbulb

what is
if(!$sw && /(.+\(.*\))/) looking for. and we didn't declare $sw previously, how it works and what is the use for it.?

Thanks & Regards,
Parthiban.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

how to find which program that update a specific file

Hello Would you tell me how to find which program that update a specific file? I am implementing migration project. My machines OS are AIX. It is because lack of documentation, some program cannot working properly on new machine. We found the root cause of this problem is that some data... (4 Replies)
Discussion started by: cstsang
4 Replies

2. Shell Programming and Scripting

Perl program for find one entry and put in different file

Hi I have a file name1 xxxxx name1 xxxxx name1 yyyyy name 1 zzzzz name1 Uniprot Id 1234 name2 sssss name2 eeeee name2 bengamine name2 Uniprot Id 3456 ......................and so on I have to capture Uniprot IDs only in a separate file so that output contain only ... (20 Replies)
Discussion started by: manigrover
20 Replies

3. UNIX for Dummies Questions & Answers

shell program- how many times a function is called

We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call. I've tried something like this: #!/bin/sh for i in $*;do if ! then echo $i is not a C file. else echo $i... (0 Replies)
Discussion started by: oana06
0 Replies

4. Shell Programming and Scripting

How to find the matched numbers between 2 text file using perl program??

hi dudes, I nee you kind assistance, I have to find the matched numbers from 2 text files and output of matched numbers should be in another text file.. I do have text files like this , for example File 1 787 665*5-p 5454 545-p 445-p 5454*-p File 2 5455 787 445-p 4356 2445 144 ... (3 Replies)
Discussion started by: sureshraj
3 Replies

5. Shell Programming and Scripting

use File::Find function

Hello, I'm learning the perl's Find function using unix but I keep getting this error when running the script: "Not a CODE reference at /usr/lib.perl5/5.8.8/File/Find.pm line 822" - what does this mean? Does anyone know??? Here's my script: use File::Find; find (\$dir,$ENV{HOME}); ... (4 Replies)
Discussion started by: new bie
4 Replies

6. Shell Programming and Scripting

program name and function name builtins

Hi Is there a way to get the program/script name or function name usng built ins. Like in many languages arg holds the program name regards (2 Replies)
Discussion started by: xiamin
2 Replies

7. Shell Programming and Scripting

want to find out a function name in a cpp file

I have an error in my logs as it shows some function name . 1. I dnt know where is the file.cpp located only i know the machine . 2. How to find out that the function name is loacated in which path and which file into that machine. Thanks . (1 Reply)
Discussion started by: madfox
1 Replies

8. UNIX for Dummies Questions & Answers

Program to find palindrome from a file

hello i came up with this ..The problematic part that i am facing is in underline and bold format. exec<file while read line do set $line i=1 while do str=$i #problematic i want the positional parameter but here it takes integer value. p=1 q=`expr length $str` flag=1... (6 Replies)
Discussion started by: salman4u
6 Replies

9. Programming

Tracing Function Calls in a program

Apart from writing debug and statements in constructors is there any way by which we can trace the function call stack at any depth? The issue that we always face is that when program crashes (Web Server running on Linux) we have no idea where it crashes and we have to do the hard way of... (1 Reply)
Discussion started by: uunniixx
1 Replies

10. UNIX for Dummies Questions & Answers

EXIT from a Program not from the function..

Hi, I want a command in unix shell script which will exit my whole program, not only from the function it's using. For e.g: $1 == "m_who" && $4 == "Extrnl Vendor" { print "You don have access" exit (0); } If this error is showing on the screen, then nothing should not... (9 Replies)
Discussion started by: ronix007
9 Replies
Login or Register to Ask a Question