djoslin@bbn.com (David Joslin) (08/18/88)
I would like something similar to cpp that only handles selected #ifdef's and #if's, leaving all other #ifdef's, #if's, #define's and comments intact. I have some code that has grotesquely layered #ifdefs, about half of which are around archaic code. The code is roughly the size of a Unix kernel, so I don't want to strip out the extraneous #ifdef's by hand. Somebody must have had this problem before...
mlandau@bbn.com (Matt Landau) (08/18/88)
In comp.sources.wanted (<28595@bbn.COM>), djoslin@BBN.COM (David Joslin) writes: >I would like something similar to cpp that only handles >selected #ifdef's and #if's, leaving all other #ifdef's, >#if's, #define's and comments intact. There is actually a *standard* BSD Unix tool to do this. Check out the manual page for unifdef, which (at least under SunOS) begins as shown below. BSD 4.3 has the same program, with a slightly different manual page. (Sun reformatted the descriptions of the options, and stripped out the "AUTHOR" section that gives credit for unifdef to the Reverend Himself, Dave Yost -- thanks Dave!) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - UNIFDEF(1) UNIX Programmer's Manual UNIFDEF(1) NAME unifdef - resolve and remove ifdef'ed lines SYNOPSIS unifdef [ -t ] [ -l ] [ -c ] [ -Dname ] [ -Uname ] [ -idname ] [ -iuname ] ... [ filename ] DESCRIPTION unifdef removes ifdef'ed lines from a file while otherwise leaving the file alone. It is smart enough to deal with the nested ifdefs, comments, single and double quotes of C syn- tax, but it doesn't do any including or interpretation of macros. Neither does it strip out comments, though it recognizes and ignores them. You specify which symbols you want defined with -D options, and which you want undefined with -U options. Lines within those ifdefs will be copied to the output, or removed, as appropriate. Any ifdef, ifndef, else, and endif lines associated with name will also be removed. Ifdefs involving symbols you don't specify are untouched and copied out along with their associated ifdef, else, and endif lines.