http://www.perlmonks.org?node_id=951682

dgsmith_50 has asked for the wisdom of the Perl Monks concerning the following question:

I work on a large codebase of code written in C for embedded processors. There are many conditionally compiled statements in the code that makes it difficult to read. I would like to know if there exists a perl script that will execute like a C pre-processor to strip away code which is not relavant based on a set of macros. The output from the script would then be used just for reading the code. I want to use PERL because I want to be able to easily modify the script. For example, in the code snippet below, I would want to include the code unmodified if the macro BCS_GFSK_TRACKING_HW_FIX if defined. I would not want to replace BCS_LINKTYPE_ACL_MDR with an actual number because I want to maintain the readability of the code.
#ifdef BCS_GFSK_TRACKING_HW_FIX // The following is HWWA for BR freq tracking switch ( logicalConnInfo ) { case BCS_LINKTYPE_ACL_MDR: case BCS_LINKTYPE_ESCO_MDR: { REG32(dcOffEstCtrl5_adr) &= ~(((UINT32)1) << TRACK_GFSK_FR +EQ_MASK_OFFSET); break; } default: { REG32(dcOffEstCtrl5_adr) |= (((UINT32)1) << TRACK_GFSK_FRE +Q_MASK_OFFSET); break; } } #endif
I found a script at the location below, but it does not appear to handle complex statements such as:
#if (defined(BCM20702) || defined(BCM20733)) && !defined(FPGA_BD_2 +045)
http://software.hixie.ch/utilities/unix/preprocessor/