473,657 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting list of functions in a header file

Hi,
I am wondering if anyone has some insight into a way to get the names of
the functions that are defined in a C header file.

What I am trying to do is develop tests for a large amount of C files.

i have written a Perl script to traverse the directory tree looking for
..h files. i find them and then comes the hard part.
I have found that searching for ";" and then going backwards looking for
close and then open parens gets me to the name, then backing over
whitespace until I find text then getting to the beginning of the text
can give me the name (does this sound like it might net me most of the
functions names ?).

but it can get hairy, since the signatures might not be all on the
same line. I am a newbie to Perl, so that is also a hinderance.

this is what I am trying to accomplish:
I want to open those .h, find the names of the functions, and write a
new .c file that contains test routines for the functions.
For example, if a header file unita.h has 3 functions A, B, C I want to
generate a file called test_unita.c that contains 3 functions,
test_a, test_b, test_c, and a main that calls the 3 functions.
The function bodies for test_a, test_b, test_c will be filled in by
hand, so all I need is the names of the functions.

thanks for reading !
Joe Simon
Newark Valley, NY
Mar 4 '07 #1
4 5286
none <""root\"@(none )"writes:
I am wondering if anyone has some insight into a way to get the names
of the functions that are defined in a C header file.
I'd use an existing program that can already do that, such as
ctags or cscope.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Mar 4 '07 #2
>I am wondering if anyone has some insight into a way to get the names of
>the functions that are defined in a C header file.
Header files rarely *define* functions; they often declare them, though.
>What I am trying to do is develop tests for a large amount of C files.

i have written a Perl script to traverse the directory tree looking for
.h files. i find them and then comes the hard part.
Look at the program "cproto", which generates declarations
for functions in C programs, and obviously knows how to parse
C files.
>I have found that searching for ";" and then going backwards looking for
close and then open parens gets me to the name, then backing over
whitespace until I find text then getting to the beginning of the text
can give me the name (does this sound like it might net me most of the
functions names ?).

but it can get hairy, since the signatures might not be all on the
same line. I am a newbie to Perl, so that is also a hinderance.

this is what I am trying to accomplish:
I want to open those .h, find the names of the functions, and write a
new .c file that contains test routines for the functions.
For example, if a header file unita.h has 3 functions A, B, C I want to
generate a file called test_unita.c that contains 3 functions,
test_a, test_b, test_c, and a main that calls the 3 functions.
The function bodies for test_a, test_b, test_c will be filled in by
hand, so all I need is the names of the functions.
Mar 4 '07 #3
none wrote:
Hi,
I am wondering if anyone has some insight into a way to get the names of
the functions that are defined in a C header file.
I've used the ctags utility for this purpose before.

Mar 5 '07 #4
santosh wrote:
none wrote:
>Hi,
I am wondering if anyone has some insight into a way to get the names of
the functions that are defined in a C header file.

I've used the ctags utility for this purpose before.
OK thanks for all the replies, everyone... I'll give check these out !

Joe
Mar 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5486
by: Fabio | last post by:
Hi everyone, Is there anybody who can suggest me a link where I can find information about 'Persistent linked list' ? I need to implement a linked list where every node is a structure like the following: struct Node { int integer_value;
7
2855
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must be defined either within the class or within the same header file. But its generally a good programming practice to have the declarations and definitions in seperate files. This would make the future maintenance of the code easier.
19
4245
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
3
3319
by: Little | last post by:
Could someone help me get started on this program or where to look to get information, I am not sure how to put things together. 1. Create 4 double linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier will be represented by a triple (I, length, string) where I is used to identify the type of
1
4153
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier
2
6987
by: Susan.Adkins | last post by:
Alright, I must say that the problem my teacher has given us to do has royally annoyed me. We are to take a letter *txt file* and then read in the words. Make 2 seperate lists *even and odd* for the number of occurances... so the first time a word is entered its going to have an occurance of one and be in the odd list then it is going to go to the next word see if its in the odd list. If its not its going to check the even list. if...
6
1973
by: citlaly | last post by:
Hi!! I'm a beginner in python and I'm trying to use the files from a "folder" as a list. What I want to do is read each one as a list, but just the name of the file, the data inside doesn't matter. How can I do it? I was trying using a list, but I don't know how "convert" the elements (files) to a list that I can read and manipulate... Thanks in advance for your help!! Citlaly....
10
10975
by: Kristan | last post by:
Hi there, quick question, how would I retrieve a list of files in ANSI C in a purely platform independent way? Any pointers would be great! thanks Kristan
3
1630
by: keclipse2525 | last post by:
I have a program that is set up like a bank database and I need to use linked list to write all the transactions into a file. Where would you implement the code to write the transactions to a file? It is set up with two .cpp files and a header file. The header contains a structure with the declaration of functions and the one .cpp is the main while the other .cpp contains all the functions operations. Would the code to write the file go in the...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.