analysing the header files in a project

Hello All,
   
     I would like to know if there are any parsers that would help us in parsing through the header files and gives us the analysed out put. I would like to analyse the #defines and typedefs. In short i would like to get all the #defines and typedefs in a project.
     Any kind of help would be appreciated.

thanx in advance,
krishna
sureshkmAsked:
Who is Participating?
 
gj62Connect With a Mentor Commented:
#defines should be pretty easy to do.  typedefs for structs are a bit more interesting - are you looking for a premade utility, or help with source code?
0
 
ecwCommented:
On most *nix, run it through cc -E or cpp.
0
 
sureshkmAuthor Commented:
Hello gj62,
     
     It would be great if it is a Premade utility and if it is possible to customise it. Even the sourcecode help is also appreciable. The problem with the #defines is that, depending on the programmer the structure varies :(
0
The eGuide to Automating Firewall Change Control

Today‚Äôs IT environment is constantly changing, which affects security policies and firewall rules. Discover tips to help you embrace this change through process improvement & identify areas where automation & actionable intelligence can enhance both security and business agility.

 
gj62Commented:
ecw -

Unless I'm mistaken, that gives the preprocessed source code - somewhat different (and much more verbose) from what they are asking for, no?
0
 
gj62Commented:
My apologies, ecw has a point...

The -E option WOULD have the advantage of putting everything you need into one file, but it will also indiscriminantly contain not only for your include files, but any system includes as well (source would also be included).  

You will still have some processing to do, but the format of the -E output will probably be easier (since it would get around some programming style differences) in this output than scanning the source files themselves.
0
 
gj62Commented:
-E would also ignore anything that is commented out - which could be problematic with C-style comments, without building a much smarter parser than you'd actually need.
0
 
grg99Connect With a Mentor Commented:
It's a tad tricky-- you could run things thru the cpp preprocessor, but that filters out any #ifdef'ed out stuff, and the macros and defines are expended, so you lose all the original information.

A little Perl progrram, about 25 lines max, would do the trick.

Something not far from:

sub Process{ my( $fn ) = @_;
f = open( F, "<$fn" );
if( f == 0 ) { f = open( F, "$ENV{ 'INC' }\$fn" );
if( f == 0 ) { die "Cant find $fn!!\n"; }

while( <F> ) {  
     if( /#include\s+[\"\<](.+)[\"\>] ) { Process( $1 ); }
     else {
    if( /#define/ || /typedef/ ) { print $_; }
}
close F
}

Process( $ARGV[1] );
0
 
cupConnect With a Mentor Commented:
What kind of analysis are you expecting or do you just want a list of #defines?  If you are on Solaris, you could try cscope.
0
 
ewestConnect With a Mentor Commented:
You might try something like doxygen. This is a tool to create documentation from source code in a manner similar to javadoc. Among other things it will produce a listing of typedefs and #defines.

You can find doxygen at http://sourceforge.net/projects/doxygen/
0
 
jmcgOwnerCommented:
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points [grade B] between gj62, grg99, cup, and ewest (some good progress on what the asker wanted, but not a complete solution).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.