2

Is there a utility that can strip out say #ifdef PRO_VERSION ... #endif code?

Please don't tell me about the Visual Studio compiler flag or XCode's view post-processed source. I can't automate it conveniently like, say, a console application.

What I am looking to do here is find an existing utility if it exists. If not ... I guess I'll have to reinvent the wheel.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
B. Nadolson
  • 2,988
  • 2
  • 20
  • 27
  • Why won't looking at preprocessed source work? You could do that from the command line, right? – Carl Norum Apr 09 '13 at 05:10
  • A preprocessed source has all the .h header stuff in it! Like 100,000 lines of code from or equivalent and and yada yada yada. – B. Nadolson Apr 09 '13 at 05:19
  • @ hyde ... it may be dup. I'm playing with sunifdef right now, my initial search attempts here didn't yield anything. Go figure ... – B. Nadolson Apr 09 '13 at 05:21

1 Answers1

6

unifdef might be what you're looking for.

From its manual:

The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines. A directive is only processed if the symbols specified on the command line are sufficient to allow unifdef to get a definite value for its control expression. If the result is false, the directive and the following lines under its control are removed. If the result is true, only the directive is removed. An #ifdef or #ifndef directive is passed through unchanged if its controlling symbol is not specified on the command line. Any #if or #elif control expression that has an unknown value or that unifdef cannot parse is passed through unchanged.

Mark Rushakoff
  • 249,864
  • 45
  • 407
  • 398