How to find C programming functions using shell script?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to find C programming functions using shell script?
# 1  
Old 03-29-2019
How to find C programming functions using shell script?

I want to find c function definition with pattern with shell script by checking condition for each line:

Code:
data_type
functionname(param_list){
  ....
}

I knew cscope or ctag is usable for this task, but if there any ways to do without using them.

I am thinking of checking line condition like this

Code:
if  [[ $line == "functionname("* ]] && [[ $line == *"){" ]]; then
    echo "found"
else
   echo "not found"
fi

I knew it is not good.
What I want in condition check is something like

Code:
if [[ $line == "functionname(.*){" ]]; then


Output should be just echo yes if found or no if not found.
# 2  
Old 03-29-2019
In general what you want to do cannot be done without actually writing a parser that understands all of the complexities of the C language. The single line that you are looking for:
Code:
functionname(param_list){

could appear anywhere within a line of C source code (not necessarily starting in position 1 nor ending at the end of a line and could include the return code type and the body of the function in addition to what you have shown, or could be spread across hundreds of lines of C source code before it gets to the body of the function definition.

Even if the group writing the kernel, utility, library, or single function you're looking for has strict function coding rules, there are occasionally exceptions that will be granted for various reasons for various functions.

Last edited by Don Cragun; 04-02-2019 at 01:34 AM.. Reason: Fix typo: s/writer/writing/
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 03-30-2019
What in your other thread could not be adapted to satisfy your current need?
# 4  
Old 03-30-2019
As a comment: many editors in development environments (IDE's) have that feature built in: list all functions,. Examples:
UltraEdit,
Linux geany editor.

So you may be trying to reinvent something you already have.
This User Gave Thanks to jim mcnamara For This Post:
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 apply functions to multiple columns dynamically

Hello, I have a requirement to apply hashing algorithm on flat file on one or more columns dynamically based on header sample input file ID|NAME|AGE|GENDER 10|ABC|30|M 20|DEF|20|F say if i want multiple columns based on the header example id,name or id,age or name,gender and hash and... (13 Replies)
Discussion started by: mkathi
13 Replies

2. Shell Programming and Scripting

Functions in a shell script

so i have a very big script that has the following format: functionA () { .... ... .... } Results=$(functionA) the code inside of functionA is very huge. so by the time the script gets to the "Results=" part, several seconds have already passed. the script is about 15MB in size.... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

Perl script to find where functions is called in c

Hello, I need to write a perl script to find where functions is called in c files.. The script should scan the file and find out the function names and then search to see where they are called... Lets for now assume all functions are internal. I don't know where to start :( ... (4 Replies)
Discussion started by: bojomojo
4 Replies

5. Shell Programming and Scripting

using library functions in shell script

hey guys, i made up a library file called common.lib so as to reuse the same code without typing it again. here is the code. its pretty basic . ## This is the second function compare() { file1 = $1 file2 = $2 cmp $file1 $file2 if then echo "comparison is possible"... (1 Reply)
Discussion started by: Irishboy24
1 Replies

6. Programming

newbie to unix programming in C, needed a few simple prgs on these functions!

Hi all, I am a newbie to unix programming using C.. So i would like to have a few simple C programs to start off with.. I wanted programs on learning , abort,kill and raise,alarm and pause,I would also like to know how to use the vfork() in a prg It would be really great if i can have... (1 Reply)
Discussion started by: wrapster
1 Replies

7. Shell Programming and Scripting

Creating functions in shell script

hi friends, I am working with shell commands and all these works properly. Then i created a small function which includes these commands. Now the problem arises. When the commands are run by calling this fuction.it shows error. Why i am not able to run the unix command inside a function.... (1 Reply)
Discussion started by: gjithin
1 Replies

8. Shell Programming and Scripting

Calling shell functions from another shell script

Hi, I have a query .. i have 2 scripts say 1.sh and 2.sh 1.sh contains many functions written using shell scripts. 2.sh is a script which needs to call the functions definded in 1.sh function calls are with arguments. Can some one tell me how to call the functions from 2.sh? Thanks in... (6 Replies)
Discussion started by: jisha
6 Replies

9. Shell Programming and Scripting

Shell Script Programming

The problem is to : develop a shell script which allow patty and mick( two login names) to execute a program (3 Replies)
Discussion started by: abhishek0216
3 Replies

10. Shell Programming and Scripting

Shell script functions

Simple shell script : date test_fn() { echo "function within test shell script " } on the shell prompt I run > . test Then I invoke the function on the command line as below : test_fn() It echos the line function within test shell script and works as expected. ... (5 Replies)
Discussion started by: r_subrahmanian
5 Replies
Login or Register to Ask a Question