grep matter between braces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep matter between braces
# 1  
Old 03-14-2009
Bug grep matter between braces

Code:
#include<header.h>
void classname :: pvvd_init        
                   ( abcd
                    ,efgh
                    ,ijkl
                    ,mnop )
{                       
  rvcl_tabl_name_tabl.pvvd_init
                   ( xxxx
                    ,"tabl_mame" ) ;
  rvvd_call_tabl ()
}
 
void classname :: rvvd_call_tabl       <<<<  ----  2nd function 
                   ( abcd
                    ,efgh
                    ,ijkl
                    ,mnop )
{
  rvcl_tabl_name_tabl.pvvd_init
                   ( xxxx
                    ,"tabl_mame" ) ;
rvvd_inst_for_tabl ()
}
void classname :: rvvd_inst_for_tabl    <<<<---- 3rd function
                   ( abcd
                    ,efgh
                    ,ijkl
                    ,mnop )
{
  rvcl_tabl_name_tabl.pvvd_init
                   ( xxxx
                    ,"tabl_mame" ) ;
 rvcl_tabl_name_tabl.pvvd_inst
}

In the above cpp class
pvvd_inst is called by function rvvd_inst_for_tabl which is in turn called by function
rvvd_call_tabl..
I am developing a script which reads a cpp class .. Finds the pvvd_inst function
and backtraces it ...
eg : pvvd_inst <<<<<------ rvvd_inst_for_tab <<<<<------rvvd_call_tabl ..
I have tried it in following way :

I am reading cpp files from a file and grepping for a paatern
Code:
grep -w 'pvvd_inst' $rvst_clas_name >> tempfile1
        
    if  [ `ll inst_fncn.tmp | awk {'print$5'}` -eq 0 ] ;
        then
  Now I am checking the filesize , If its equal to zero thn i am concluding 
  inst fncn not callled in this class
  echo ""
  echo "pvvd_inst not called in this class "$rvst_clas_name""

   The problem starts with else part .... How do i proceedc  
        
 else
 In the else part , The logic that i developed is to  read the file line by line
 Capture text between opening and closing braces of each function .. and then grep 
 but I am running short of how to implement these ideas ...
   fi

Please Help .....
thanks and Regards
--- Ultimatix

Last edited by Franklin52; 03-14-2009 at 04:06 PM.. Reason: adding code tags
# 2  
Old 03-14-2009
Code tags for code, please, otherwise the forum will strip all the spacing from it and make it unreadable. [ code ] stuff [ /code ] without the extra spaces in the tags.

Since nearly all whitespace in C is interchangable, I might try rearranging it to remake the lines more to my pleasing:
  • Rip out all preprocessor lines: egrep -v '^#|\\$' This does not do a perfect job, involving the C++ preprocessor would do better but would be more complex.
  • Replace all linefeeds with spaces: tr '\n' ' '
  • Replace "}" with "}\n" and "{" with "\n{": sed 's/}/}\n/g;s/{/\n{/g'

So:
Code:
$ echo "#include <stdio.h>

int main(void)
{
        int i=3;
        if(i==2)
        {
                something();
        }
        else
        {
                something_else();
        }

        return(0);
}" > omg.c

$ grep -v '^#' < omg.c | tr '\n' ' ' | sed 's/{/\n{/g;s/}/}\n/g'
 int main(void) 
{         int i=3;         if(i==2)         
{                 something();         }
         else         
{                 something_else();         }
          return(0); }
$

Perhaps you'd find that output easier to find what you wanted in.
# 3  
Old 03-15-2009
Bug

Thanks Franklin..

Some Body Please Help m out with this issue. I am stuck up
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Code that has to end no matter what

Since this is maxxing out my CPU, is there anything I can add that will make sure stress always ends? echo "CPU Stress Test" >> CPU_Stress_Test.txt echo "stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 1m" >> CPU_Stress_Test.txt echo >> CPU_Stress_Test.txt date +"%Y-%m-%d-%H-%M" >>... (9 Replies)
Discussion started by: drew77
9 Replies

2. Shell Programming and Scripting

For getting value between the braces

Hi I have a file called tmp with the content as belowmore tmp NAMELIST(Hari) NAMELIST(Raju) I want to get the values between the brackets. When I executed the below command on zlinux I get the output which I wantedmore tmp |awk -F'' '{print $2}' But when I execute the same in... (3 Replies)
Discussion started by: harimhkr
3 Replies

3. Solaris

Does file extension matter in UNIX?

Hi friends, I was wondering if UNIX programs really care about file extensions like Microsoft Windows applications do. Because I think an extension doesn't really change the nature of a file, or does it? But when I try to compile the c source code file named "hello", gcc gives me error, saying... (1 Reply)
Discussion started by: gabam
1 Replies

4. Shell Programming and Scripting

Terminal to the front no matter what

Is there a way to bring the terminal script to the front? I am running this script through OMCEdit which is then running it through Terminal. I have some dialog boxes (using osascript) and the dialog boxes are not coming to the front...Terminal bounces and I have to click on Terminal to see the... (1 Reply)
Discussion started by: mainegate
1 Replies

5. Shell Programming and Scripting

How to delete matter in between two lines

help I am having text file like this... ------------------------END OF UPDATION ------------------ xxxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyyyyyyyy 1 row updated ------------------------END OF UPDATION ------------------ TTTTTTTTTTTTTTTT FFFFFFFFFFFFFFFFF ... (3 Replies)
Discussion started by: suryanarayana
3 Replies

6. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies

7. Linux

Need help with this matter

I have a PC that was built in Europe pre-installed with Windows 2000. The HDD is 40GB, but, its split up as two 20GB (Taken up by Windows). I want to take over my Mandrake 9.1 CDs and install Linux on that machine. My question is, how would I proceed to install Linux this way??? Now, If... (1 Reply)
Discussion started by: wardialer
1 Replies
Login or Register to Ask a Question