sunifdef -h | --help
sunifdef (-s(f|a)[l] | --symbols (first | all) [,locate] ) [files...]
sunifdef [-fargfile | --file argfile] [-Dmacro[=string] | --define macro[=string]...] [-Umacro | --undef macro...] [-r | --replace] [-Bsuffix | --backup suffix] [-x(d|c|e) | --conflict ( delete | comment | error )] [-g(i|w|e|a) | --gag ( info | warning | error | abend )] [-gs | --gag summary] [-g0xXXXX | --gag 0xXXXX] [-V | --verbose] [-n(u|e[d]) | --constant ( unk | eval[,del])] [-c | --complement] [-d | --debug] [-o | --obfusc] [-k(d|b|c) | --discard ( drop | blank | comment)] [-P | --pod]
From the commandline arguments it takes a set of assumptions about the symbols to be defined, or undefined, for the CPP. From the commandline it also takes one or more source files. It parses these source files to pick out conditional preprocessor directives (#if,#ifdef,#ifndef,#else,#elif, #endif). It applies the specified assumptions to these directives in attempt to evaluate them. Directives that cannot be fully evaluated on the basis of the assumptions are simplified as much as possible. Directives that can be fully evaluated are eliminated, and the source text that they control is either retained or deleted in accordance with the evaluation, mimicking the behaviour of the CPP.
sunifdef also detects #define and #undef directives and checks them for consistency with the specified assumptions. If a #define or #undef directive repeats one of the assumptions it is deleted on output; if it conflicts with any of the assumptions then it may be deleted or replaced with a diagnostic comment or a diagnostic #error, depending on commandline options.
For each source file, an output file is generated that reflects the edits arising from the specified assumptions. The output file is a new and simpler CPP source file. The command
sunifdef -DFOO bar.c
will write on the standard output a revision of the file bar.c that has been purged as far as possible of CPP constructions controlled by the truth-value of defined(FOO). This revision is equivalent to bar.c on the assumption that FOO is defined. With appropriate options and inputs, you can use a sunifdef command to perform wholesale removal of redundant CPP complexities from a C or C++ source tree.
a | all: List all occurrences of the symbol on input.
l | locate: Report the file and line number of each listed occurrence.
The option changes the default behaviour of the command when no input files are specified. In this case, input is acquired from the standard input. If -r is not specified, then a single input file is read from the standard input. If -r is specified then the names of the input files are read from the standard input.
If the names of the input files are read from stdin, the filenames are delimited by whitespace unless enclosed in double-quotes.
c | comment: Replace the conflicting directive with a diagnostic comment (default).
e | error: Replace the conflicting directive with a diagnostic #error directive.
e[d] | eval[,del]: Evaluate constants [and optionally eliminate them].
d | drop: Drop discarded lines.
b | blank: Blank discarded lines.
c | comment: Comment out discarded lines.
warning: Indicating problematic input (0xXXXX & 0x0800 is true)
error: Indicating invalid input (0xXXXX & 0x1000 is true)
abend: Indicating a fatal environment or internal error (0xXXXX & 0x2000 is true)
info: Input lines were changed on output.
warning: Input lines were changed to #error directives.
warning: Unconditional #error directives were output.
SC & 2: Warnings diagnostics accrued.
SC & 4: Error diagnostics accrued.
SC & 8: An abend occurred.
SC & 16: Input lines were dropped on output.
SC & 32: Input lines were changed on output.
SC & 64: Input lines were changed to #error directives.
SC & 128: Unconditional #error directives were output.
Trigraphs are not parsed.
#define and #undef directives that are found to be active are not factored into the evalation of subsequent #if directives.
Please report bugs to bugs dot sunifdef at strudl dot org