# # rmsif - an ifdef cleaner (ReMove Selected IF) # # Another Aromatic Productions # http://www.aromatic.com/ # # Copyright (C) 1997-1998 Raffaele Sena (raff@aromatic.com) # All rights reserved # # $Revision: 1.3 $ # $Author: raff $ # $Date: 1998/05/25 03:08:14 $ NAME rmsif - ReMove Selected IF : an ifdef cleaner SYNOPSYS rmsif [-i] [-v] [-#] [-k] [-Dsym[=val]] [-Usym] file DESCRIPTION rmsif selectively removes if-then-else cpp directives from a file, according to symbols you define or undefine on the command line. There are a few other packages around (unifdef, rmifdef, scpp, etc.) but either they don't support #if statements and expression or they have trouble with it. So, I decided to write another one. rmsif supports all the #if-related cpp directives (#ifdef, #ifndef, #if, #elif, #else, #endif) and, according to the command line parameters, simplifies #if expressions or removes them (and the source code they cover, if that's the case). OPTIONS -i: ignore errors on a file and proceed with the other files If not defined, the process will stop at the first error. Note: the program accepts and processes multiple files, but the current version sends the output of the processed file on standard output. So, it's not very useful to process more than one file at a time. -v: dump symbols definitions at the beginning of the file Symbol are printed according to cpp grammar (#define and #undef). If a symbol is multiple-defined, the generated code will not compile. -#: print all the # directives By default fully simplified expression make the directives disappear. This version has a limitation that simplified expression will come up as #if 0 or #if 1, because the original expression get lost. But still the option can be useful to debug the process. -d: -D: create a symbol and mark it DEFINED The symbol can be simply defined (-DSYM) or defined with a value (-DSYM=value) If the symbol has already been created undefined, its state will change into defined. A symbol can have multiple definitions (with different values) to allow the inclusion/exclusion of code marked by a subset of the full set of values (for example for a source file with code for three different processors - CPU=R3000, CPU=R4000, CPU=R4400, you can specify '-DCPU=R3000 -DCPU=R4000' and remove the code for CPU=R4400) -u: -U: create a symbol and mark it UNDEFINED you cannot undefine a symbol already defined. -k: remove constants Remove code under #if 0 and remove the #if 1 directives. Can be useful to clean-up the sources and remove debugging or temporary code. KNOWN BUGS Allocated memory is not correctly released. This is not really a problem on U*ix-like machines, where the system provides to release all the memory associated to a terminating proces, but it's not nice programming technique. Fixed a problem of lines starting with '#' but inside a comment. But the current code for checking for comments does not check yet if the open comment ( '/*' ) is inside a quoted string.