We inherited a very minimized project (500kloc) with the conditional logic of the lot of conditional logic of the preprocessor, most of which is no longer relevant, and I want to clear it.
Can I use the preprocessor¹ to extend only some conditional logic and leave all other macros of the preprocessor, define and enable only at the output?
¹ Here, by "preprocessor", I really mean "any tool", or the standard C preprocessor, then I can install it, or even a hacked Perl or Python script.
For example, suppose we have this code set:
#include <foo>
#define baz
#define bar(a) do{(a)+1} \
while(0)
#ifdef X
#if Y > 20
#if Z > 5
so_far_so_good = true;
#endif
#ifdef baz
something();
#endif
#else
otherthing();
#endif
#else
#if Z > 10
wow().this.is.bad;
#endif
#endif
, (, , , ), CPP, , , . . :
cpptreadlight -DY=22 --only=Y
:
#include <foo>
#define baz
#define bar(a) do{(a)+1} \
while(0)
#ifdef X
#if Z > 5
so_far_so_good = true;
#endif
#ifdef baz
something();
#endif
#else
#if Z > 10
wow().this.is.bad;
#endif
#endif
cpptreadlight -DY=22 -DZ=8 -DX --only=Y,baz,Z
:
#include <foo>
#define bar(a) do{(a)+1} \
while(0)
#ifdef X
so_far_so_good = true;
something();
#else
#endif
, X , , --only. , baz --only , .
: , ( gsub , , ):
function escape_tr() {
gsub "#(define|include)" '@@@\1' < $1 |
(echo '#include "simple.h"' && gsub '\\$' "%%%") |
cpp -C -P -DY=301 -DZ > $1.new
}
, , , simple.h. , #line .
, , #define . , , , . . .
#if, #else #endif , regex. , cpp, .
, , , , - . , , .