Sponsored Content
Full Discussion: shell problem
Top Forums Shell Programming and Scripting shell problem Post 302627937 by agama on Sunday 22nd of April 2012 12:50:30 PM
Old 04-22-2012
Seems more efficient to let awk do the work rather than invoking two extra processes for each function encountered:

Code:
BEGIN { level=0; }
{
if (index($0,"{")<1) {
   if ((level==0) && (index($0,"(")>0) && (index($0,")")>0))
   {
       split( $0, a, "(" );
       n = split( a[1], b, " " );
       print b[n];
   }
   if (index($0,"{")>0) level++;
   if (index($0,"}")>0) level--;
   }
}



This also handles the case where the programmer used the more traditional style that places the function type on the previous line:

Code:
float
dist(int *a,int *b,int n){



---------- Post updated at 12:50 ---------- Previous update was at 11:58 ----------

Looking at your code a bit more closely, I'm not sure that it's going to do what you expected. In particular, this seems wrong:

Code:
if (index($0,"{")<1) {


This will execute the contents of the block only if the record does not have an opening (left) curly brace, but from the code it seems that you want the block to execute when there is an opening curly brace. The code also assumes that the programmer hasn't dropped the opening brace to the next line.


You could extend the awk a bit, and do everything in one pass across your C source with one awk programme. Something like this:

Code:
awk '
    /\(.*\)/ && level == 0 {        # capture each function name
        split( $0, a, "(" );
        n = split( a[1], b, " " );
        list[b[n]] = 1;
    }

    /{/ {
        if( ++level == 1 )          # don't need to process further if level 0
            next;
     }

    /}/ { level--; }

    level > 0 {                     # search for function use only if not a 0th level
        for( f in list )
            if( match( $0, f"[(]" ) )
            {
                loc[f] = loc[f] NR " ";
                num[f]++;
            }
    }

    END {                           # print each function, lines where its called and number of uses
        for( f in list )
            if( length( loc[f] ) )
                printf( "%s\n%s\n%d\n\n", f, loc[f], num[f] );
    }
'



This also handles the case where the opening curly brace is dropped to the next line, the type is on the preceding line, and allows for prototype statements.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shell problem

&& set -x && echo "enter tablespace_end_backup" >&2 Can you tell me what's mean above? thanx (1 Reply)
Discussion started by: Lee
1 Replies

2. UNIX for Dummies Questions & Answers

Shell Problem.

Hello and Good day to all. Im having a problem here and would like to know if there is any solution that could overcome my problem. I have changed from bash to csh (c-shell) yesterday on my Linux 7.2. When i do $echo $SHELL i can see the output /bin/csh which means ihave succesfully landed on... (4 Replies)
Discussion started by: ###1tomato
4 Replies

3. UNIX for Advanced & Expert Users

Shell Problem

Dear Members; I changed ,by mistake ,the root shell in /etc/passwd and logged out. Thereafter, I can no more have a prompt when trynig to log in as root. How to solve this pb ? Regards :confused: (8 Replies)
Discussion started by: oss
8 Replies

4. UNIX for Dummies Questions & Answers

shell problem

What are the different type of shell available in UNIX and how to change the shell? just this 2 question pls help mi (4 Replies)
Discussion started by: yeah016
4 Replies

5. Shell Programming and Scripting

Problem in shell

hi, can any one tell a solution for the following : I want to append 10 spaces and a string say "ok" to 12 digit number which is stored in a varialbe & display using shell script. (1 Reply)
Discussion started by: Sandeep Kale
1 Replies

6. Shell Programming and Scripting

Shell Problem

Hi all, until yesturday grep command was running in KSH .... I was executing this command ls -l | grep *.sh But today its not working at all ... Should I check any of the setting ... I am not getting whats the problem ... I have relogged to unix box but it didn't... (14 Replies)
Discussion started by: dhananjayk
14 Replies

7. Shell Programming and Scripting

problem with if in shell

Hi, My sheel script has below statement: if; then When I run iam getting the below error: -bash: syntax error near unexpected token `then' What is wrong with that statement: Plz help me. (2 Replies)
Discussion started by: pradeep_script
2 Replies

8. Shell Programming and Scripting

shell problem

Hello! Can you please help me on a lab at school: I have to to write a shell program which reads all .C files from the current directory and prints for each file how many '#define' directives it has and for each macro defined how many times is it used in that file. Can you suggest how can i... (1 Reply)
Discussion started by: dark_knight
1 Replies

9. Shell Programming and Scripting

Problem in shell script

hi...i create a script which reads data from file and compare that the data which is entered by me through keyboard...i can easily read first two contents of file..i am facing the problem to read other contents.. structure of my file is username:password:username1:password1.......and so on ... (1 Reply)
Discussion started by: shubhig15
1 Replies

10. UNIX for Dummies Questions & Answers

shell problem

this picture for print You didn't do the question. Go back. if $1 = 0 but until now it give me this message what i should be do ? http://img717.imageshack.us/img717/6137/eeevb.jpg (2 Replies)
Discussion started by: NeeZaaR
2 Replies
Traffic control index filter(8) 				       Linux					   Traffic control index filter(8)

NAME
tcindex - traffic control index filter SYNOPSIS
tc filter ... tcindex [ hash SIZE ] [ mask MASK ] [ shift SHIFT ] [ pass_on | fall_through ] [ classid CLASSID ] [ action ACTION_SPEC ] DESCRIPTION
This filter allows to match packets based on their tcindex field value, i.e. the combination of the DSCP and ECN fields as present in IPv4 and IPv6 headers. OPTIONS
action ACTION_SPEC Apply an action from the generic actions framework on matching packets. classid CLASSID Push matching packets into the class identified by CLASSID. hash SIZE Hash table size in entries to use. Defaults to 64. mask MASK An optional bitmask to binary AND to the packet's tcindex field before use. shift SHIFT The number of bits to right-shift a packet's tcindex value before use. If a mask has been set, masking is done before shifting. pass_on If this flag is set, failure to find a class for the resulting ID will make the filter fail and lead to the next filter being con- sulted. fall_through This is the opposite of pass_on and the default. The filter will classify the packet even if there is no class present for the resulting class ID. SEE ALSO
tc(8) iproute2 21 Oct 2015 Traffic control index filter(8)
All times are GMT -4. The time now is 05:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy