C Source code pre-processing

Mark Jarnyk jarnyk at mso.anu.edu.au
Tue Mar 26 11:22:41 EST 2002

Hi Burn,

> Does anyone know of a utility which will take a C source file and strip 
>#if/#else/#endif directives, just leaving the source code dependant upon a 
> set of defines.

I have a utility written in Python called stripper which does half of what
you're asking. 

 stripper [-f] -k KEYWORD infile1 ... outpath
 -f         force clobbering of output files
 -k KEYWORD Remove the text marked by a #define KEYWORD/#endif pair
 infiles    a list of input files. The output files have the same name
            as the input files suffixed with a ".fixed".
 outpath    path to where the files should be written. If no
            directory is specified, then the current directory is

It will remove any blocks of code which are defined by a define/endif pair.
It doesn't handle elses nor elifs (because it was written to solve a particular
problem). It should be easy to change to suit your purposes (although
it is not especially well-written). If you think that you may find it useful
then I'll send it to you.



More information about the linux mailing list