It would go into all the .c files in the current directory and in each file, it would copy the function headers for all the functions that are not static(don't begin with static) and stores them in one file with the word "extern" added at the beginning(if they are not already) and parameter names removed.
The output should look something like this:
file1 and file2 would obviously be the names of the files. And each block would contain the functions in that file.
Extra: have #include'd in each source file, and remove redundant extern declarations from them.
Last edited by James Denton; 09-24-2012 at 04:18 PM..
Well, sed and shell easily do the first bit.
Narrative: find files, for each file $f, capute in e the output of the sed script on $f. The sed first clears any leading white space, any extern with white space, and detects a name with a ( tight on the name (if you have spaces, we need to remove them just before this). For that, it loops adding lines until there is a ')', but if eof shows up, deletes everything, then normalizes all white space to a single space, ensures one space before any asterisk and none after, ensures names end in ',' or ')' tight, removes the names, adds the extern, and writes out the product.
Not sure what the second thing is. Do you want every subroutine in its own file and and extern prototype in its place? Subroutine/file names might conflict, but that is a good practice. #include'ing subroutines is a step backward; learn to make a library mystuff.a using ar or even mystuff.so (dynamic) from that using gcc. Creating a shared and static library with the gnu compiler [gcc]
Last edited by DGPickett; 09-24-2012 at 05:25 PM..
I want to find c function definition with pattern with shell script by checking condition for each line:
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... (3 Replies)
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)
I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line
if
then... (8 Replies)
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)
Hi all,
I'm trying to import some functions I have saved in a file named
functions.sh into a different script (protocol.sh). Can anybody show
me how to do this? I tried source functions.sh as I would do at the
terminal but source command cannot be found from within the script
protocol.sh.
... (2 Replies)
Let me know if there is a way to pass array to a funtion in ksh script.
function isPresent
{
typeset member
member=$1
dbList=$2
echo '$1:' $1
echo '$2' $dbList
The array will be at the second position....something like this
isPresent 12 <array>
if
then
echo... (3 Replies)
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)
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)
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)