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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to display function names (called & defined) in a C++ Source Code
# 1  
Old 07-16-2009
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 all combinations of function calls/definitions. Kindly help me.

Is there any command in linux that can print the function calls/definitions, variables etc used in a C++ source code ?

Input
-----
File:Sample.cpp

Content:
void display_here() {
cdef
}

int sample() {
abcd
process_somewhere(nowhere(abc),
abc)
display_here()
rstuv
}

Output
-------
void display_here()
int sample()
process_somewhere(nowhere(abc),
abc)
display_here()


Thanks.
SmilieSmilie
# 2  
Old 07-16-2009
You need to use a debugger to look at the code to see all function calls/definitions, variables, etc. You can use strace to look at the system calls to help debug some things the programs are doing. But a debugger like gdb would be the only thing that will give you indepth analysis of a c++.
# 3  
Old 07-16-2009
I'm really annoyed at myself, because this should be a pure awk solution, but I have only a passing understanding of awk... so we're stuck with this abomination:

Code:
(03:59:46+deco@DeCoBuntu)
[~]:cat sample 
File:Sample.cpp

Content:
void display_here() {
cdef
}

int sample() {
abcd
process_somewhere(nowhere(abc),
abc

(04:00:40+deco@DeCoBuntu)
[~]:grep "(*)" sample |awk -F\{ '{print $1}'
void display_here() 
int sample() 
process_somewhere(nowhere(abc),
abc)
display_here()

I know that it should be something more along the lines of:

Code:
(04:04:52+deco@DeCoBuntu)
[~]:awk -F\{ /"\(*\)"/ '{print $1}' sample 
awk: cannot open {print $1} (No such file or directory)

But obviously I've done something wrong, and I'm too tired to figure it out. (Note, I know nothing about C++ so this may have nothing to do with the type of solution you're looking for...I just treated it like a flat file)
Login or Register to Ask a Question

Previous Thread | Next Thread

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

Mkdir fails when defined and called with functions.

In the below script i found that the alias mkdir_s is getting invoked from function configure() i.e the alias is kicking in. #!/bin/bash -e shopt -s expand_aliases alias mkdir=mkdir_s mkdir_s(){ if ]; then return else /usr/bin/mkdir "$1" return fi } configure() { mkdir -p... (9 Replies)
Discussion started by: mohtashims
9 Replies

3. Shell Programming and Scripting

Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you. I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I... (1 Reply)
Discussion started by: HiFuture0801
1 Replies

4. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

5. UNIX for Dummies Questions & Answers

Implement the '&&' function in a shell

Hello, I'm currently implementing the && function in a shell using C. For example, if we input cmd1 && cmd2, then cmd2 executes only when cmd1 exits successfully. I'm thinking about: int main() { int i; char **args; while(1) { printf("yongfeng's shell:~$ "); args =... (5 Replies)
Discussion started by: Yongfeng
5 Replies

6. 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

7. Shell Programming and Scripting

How to pass parameter to User defined function in shell script?

Hello, Can anyone guide me tin passing parameters into user defined function of shell script (KSH). Here is my code, InsertRecord() { DB_TBL=$(sqlplus $USERID/$PASSWORD@$DATABASE << EOF set head off set feed off set serveroutput on INSERT INTO TBL1 ( OLD_VAL, NEW_VAL, ... (7 Replies)
Discussion started by: Poonamol
7 Replies

8. Shell Programming and Scripting

Return a value from called function to the calling function

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

9. Shell Programming and Scripting

Protect shell script source code

Hello, Is there any way where a shell scripts source code can be protected? Basically, I'm after to convert shell scripts into to some form of binaries so that my shell script source code can be protected. Forgot to mention, this is on solaris. Many thx, kam (6 Replies)
Discussion started by: jkkstar
6 Replies

10. 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
Login or Register to Ask a Question