Removes ifdef lines from a file.
unifdef [ -t ] [ -l ] [ -c ] [ -DSymbol ] [ -USymbol ] [ -idSymbol ] [ -iuSymbol ] [ File ]
The unifdef command is useful for removing ifdef lines from a file while otherwise leaving the file alone. The unifdef command recognizes nested ifdefs, comments, and single and double quotes of C syntax in order to function correctly, but does not include files or interpret macros. The unifdef command recognizes but does not remove comments.
The unifdef command takes its input from standard input if no File is specified and copies its output to standard output.
Once a Symbol is specified, the lines inside those ifdefs are copied to the output or removed, as appropriate. The ifdef, ifndef, else, elif, and endif lines associated with the symbol are also removed. Ifdefs that involve unspecified symbols are untouched and copied out along with their associated ifdef, else, elif, and endif lines. If the same symbol appears in more than one argument, only the first occurrence is significant. For instance, if an ifdef X occurs nested inside another ifdef X, the inside ifdef is considered an unrecognized symbol.
When using ifdefs to delimit non-C lines such as comments or unfinished code, it is necessary to specify which symbols are to be used for that purpose. Otherwise, the unifdef command will try to parse for quotes and comments in those ifdef lines.
The unifdef command cannot process cpp constructs such as:
#if defined(X) || defined(Y)
OR
#elif X
OR
#elif defined(X) || defined(Y)
The following keywords are recognized by the unifdef command:
This command returns the following exit values:
0 | The output is an exact copy of the input. |
1 | The output is not an exact copy of the input. |
2 | The command failed due to a premature EOF, or to an inappropriate else, elif, or endif. |
unifdef -DA original.c > modified.c
causes the unifdef command to read the file original.c, and remove the #ifdef A lines. It then removes everything following an #elif/#else associated with the #ifdef A, down to the #endif. The output is placed in the modified.c file.
unifdef -UA original.c > modified.c
causes the unifdef command to read the file original.c, and remove the #ifdef A down to either its associated #elif//#else, or its associated #endif. In the case of the #elif, the #elif is replaced with #if. In the case of #else, the #else is deleted along with its associated #endif. The output is placed in the modified.c file.
/usr/bin/unifdef | Contains the unifdef command. |
The cpp command.
The Commands Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.