?
Solved

analysing the header files in a project

Posted on 2003-03-20
11
Medium Priority
?
247 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:sureshkm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 6

Accepted Solution

by:
gj62 earned 192 total points
ID: 8175371
#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
 
LVL 5

Expert Comment

by:ecw
ID: 8175543
On most *nix, run it through cc -E or cpp.
0
 

Author Comment

by:sureshkm
ID: 8175574
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:gj62
ID: 8175614
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
 
LVL 6

Expert Comment

by:gj62
ID: 8175678
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
 
LVL 6

Expert Comment

by:gj62
ID: 8175684
-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
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 186 total points
ID: 8177629
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
 
LVL 11

Assisted Solution

by:cup
cup earned 186 total points
ID: 8182528
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
 
LVL 2

Assisted Solution

by:ewest
ewest earned 186 total points
ID: 8188840
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
 
LVL 20

Expert Comment

by:jmcg
ID: 10187082
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question