shell program- how many times a function is called

Thread Tools Search this Thread
# 1  
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:

for i in $*;do
    if ! [ $i.c ]
    echo $i is not a C file.
    else echo $i is a C file.
    echo "enter the string to search:"
    read string
    u=`grep -c $string $i`;
    v=`grep -n $string $i`;
        if [ $u -gt 0 ] 
            { echo $i contains the searched function, $u times.
            echo $v
        else    echo ERROR- the file does not contain that function.


but for eg. if I give a file that isn't C source it doesn't show the right message.
also I'm not very sure that this is the right way to solve this problem, because it only works for the functions that you read from the keyboard , not for each function that you have in your program.
so if you have other ideas please help.
thank you. and sorry for my bad exprimation.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Easy
Microphones can be used not only to pick up sound, but also to project sound similar to a speaker.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Problem while Invoke Shell Script function from Java Program

Hi, I have create a Shell Script, with one function. I want to call the script file in Java Program. It working fine. but the problem is the function in the Shell Script is not executed. Please suggest me, Regards, Nanthagopal A (2 Replies)
Discussion started by: nanthagopal
2 Replies

3. UNIX for Advanced & Expert Users

System call failed with 127 .. after 500 times when called in loop

Hi Experts, I have a code like this. ===== #include.... int main() { int count = 0; while(1){ printf("\n Interation number is: %d \n ",count); rv = system(" > log.txt " ); if (-1 == rv) { printf("Could not generate static log: error... (12 Replies)
Discussion started by: binnyjeshan
12 Replies

4. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

5. Shell Programming and Scripting

Can a shell variable be called in a cobol program

Hi All, I have a file which sets all the variables on unix , based on the hostname. Currently these variables are hardcoded in the cobol programs.I was wondering if unix variables can be used in Cobol programs ? Example : I have a variable $SHTEMP which is set based on the following : Prod... (2 Replies)
Discussion started by: nua7
2 Replies

6. Programming

parent called more times - fork - C language

Hi gurus can you explain following lines of code ? #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(void) { pid_t pid; int rv; switch(pid = fork()) { case -1: ... (7 Replies)
Discussion started by: wakatana
7 Replies

7. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- #!/bin/bash sh //simply calling ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

8. Shell Programming and Scripting

Shell Script to display function names (called & defined) in a C++ Source Code

Hello to all, I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

10. Shell Programming and Scripting

Can I use $1 several times in shell program?

Hi, I am new to Unix and shell programming. I am trying to write a shell program to read 4 variables from command line. For example, Please enter your name: somebody Please enter your address: address plase enter your phone: phone I'd like to save all threee variables in my program for... (3 Replies)
Discussion started by: whatisthis
3 Replies
times(1)							   User Commands							  times(1)

times - shell built-in function to report time usages of the current shell SYNOPSIS
sh times ksh times DESCRIPTION
sh Print the accumulated user and system times for processes run from the shell. ksh Print the accumulated user and system times for the shell and for processes run from the shell. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), sh(1), time(1), attributes(5) SunOS 5.10 15 Apr 1994 times(1)

Featured Tech Videos