Filtering endless #defines

B

BldrCowboy

I've just been put on a project in which I have to use and modify an
existing code base. To be frank, this code is virtually unreadable
because of the rampant use of #define's. It is so bad that in many
places I can hardly tell what code is compiled and what is not.

Before I can even start working I have to figure out what the code does
(or is suppose to do). I need something that will simply help read it.
Is there anything out there that will help?? I've looked at a couple of
code formatters. They don't seem to do anything but fix up braces and
indents. If that was my only issue, I'd be home free. What I really
want is something like a pre-processor which will pull out the active
code and throw the rest of it away.

It doesn't need to be free. I'm more than willing to pay for a tool
that will actually help.

Thanks for any advice.

Fred
 
S

santosh

BldrCowboy said:
I've just been put on a project in which I have to use and modify an
existing code base. To be frank, this code is virtually unreadable
because of the rampant use of #define's. It is so bad that in many
places I can hardly tell what code is compiled and what is not.

Before I can even start working I have to figure out what the code does
(or is suppose to do). I need something that will simply help read it.
Is there anything out there that will help?? I've looked at a couple of
code formatters. They don't seem to do anything but fix up braces and
indents. If that was my only issue, I'd be home free. What I really
want is something like a pre-processor which will pull out the active
code and throw the rest of it away.

It doesn't need to be free. I'm more than willing to pay for a tool
that will actually help.

What's wrong with simply redirecting the preprocessed output to a file?

If you want to filter out the unused code but retain the active code in
the original form, then I think you'll have to look for some
specialised tools to do this.
 
B

Barry Schwarz

I've just been put on a project in which I have to use and modify an
existing code base. To be frank, this code is virtually unreadable
because of the rampant use of #define's. It is so bad that in many
places I can hardly tell what code is compiled and what is not.

Before I can even start working I have to figure out what the code does
(or is suppose to do). I need something that will simply help read it.
Is there anything out there that will help?? I've looked at a couple of
code formatters. They don't seem to do anything but fix up braces and
indents. If that was my only issue, I'd be home free. What I really
want is something like a pre-processor which will pull out the active
code and throw the rest of it away.

It doesn't need to be free. I'm more than willing to pay for a tool
that will actually help.

Does your compiler have an option to store the output from the
preprocessor in a file you can view. You would have to clean out the
#include data but the non-compiled code would not be there.


Remove del for email
 
K

Keith Thompson

Barry Schwarz said:
Does your compiler have an option to store the output from the
preprocessor in a file you can view. You would have to clean out the
#include data but the non-compiled code would not be there.

You can always temporarily comment out any #includes and macro
definitions that you want to keep, and let the preprocessor expand
just the ones you want to get rid of.

This still isn't a complete solution. For one thing, the preprocessor
can delete comments. But it could at least give you some good
information to help you modify the code manually.
 
E

Eric Sosman

Question 10.18 in the comp.lang.c Frequently Asked Questions
(FAQ) list offers some suggestions. See http://c-faq.com/ .
What's wrong with simply redirecting the preprocessed output to a file?

Nothing "wrong," really, if you're fond of code like

while ((__dj_ctype_flags[(int)((unsigned char)*cur)+1] & 0x0100))
++cur;
 
J

jacob navia

BldrCowboy a écrit :
I've just been put on a project in which I have to use and modify an
existing code base. To be frank, this code is virtually unreadable
because of the rampant use of #define's. It is so bad that in many
places I can hardly tell what code is compiled and what is not.

Before I can even start working I have to figure out what the code does
(or is suppose to do). I need something that will simply help read it.
Is there anything out there that will help?? I've looked at a couple of
code formatters. They don't seem to do anything but fix up braces and
indents. If that was my only issue, I'd be home free. What I really
want is something like a pre-processor which will pull out the active
code and throw the rest of it away.

It doesn't need to be free. I'm more than willing to pay for a tool
that will actually help.

Thanks for any advice.

Fred

Use the lcc-win32 IDE and ask it to "show #ifdefs" in the menu
"Utils". The command line utility (included in the lcc-win32
compiler distribution) is

browsegen.exe -showifdeflines file.c

You should add the defines that are active, for instance

browsegen.exe -DWINDOWS -DNOFPU file.c

The output consists of a list of line numbers that are NOT active
in the given source file.

You can download lcc-win32 at no cost from
http://www.cs.virginia.edu/~lcc-win32

Please email me if you have any problems with it.
 
M

mohammad.nabil.h

BldrCowboy said:
I've just been put on a project in which I have to use and modify an
existing code base. To be frank, this code is virtually unreadable
because of the rampant use of #define's. It is so bad that in many
places I can hardly tell what code is compiled and what is not.

Before I can even start working I have to figure out what the code does
(or is suppose to do). I need something that will simply help read it.
Is there anything out there that will help?? I've looked at a couple of
code formatters. They don't seem to do anything but fix up braces and
indents. If that was my only issue, I'd be home free. What I really
want is something like a pre-processor which will pull out the active
code and throw the rest of it away.

It doesn't need to be free. I'm more than willing to pay for a tool
that will actually help.

Thanks for any advice.

Fred

Microsoft Visual C++ 2005 IDE ( you can try the free Express version ),
puts the inactive code in all gray color, while other active code are
in black and colorized. But you'd have to create a Visual C++ project
and add the files to it, and be sure the code can be compiled by that
compiler ( long long isn't valid, it's __int64 fro example).
 
N

Nick Keighley

BldrCowboy wrote:

Microsoft Visual C++ 2005 IDE ( you can try the free Express version ),
puts the inactive code in all gray color, while other active code are
in black and colorized. But you'd have to create a Visual C++ project
and add the files to it, and be sure the code can be compiled by that
compiler ( long long isn't valid, it's __int64 fro example).

STI's Understand for C++ does similar tricks and it's generally a
useful tool.
It is expensive. I don't know if there is a C version.
 
S

santosh

BldrCowboy said:
I've just been put on a project in which I have to use and modify an
existing code base. To be frank, this code is virtually unreadable
because of the rampant use of #define's.
I need something that will simply help read it.
Is there anything out there that will help??
What I really
want is something like a pre-processor which will pull out the active
code and throw the rest of it away.

It doesn't need to be free. I'm more than willing to pay for a tool
that will actually help.

May be the following page may give you a start...
<http://www.spinroot.com/static/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top