Let’s suppose I have a bunch of source code files (C or Delphi, i.e., *.c or *.pas). I want to purge them of blocks of text which are not used in the compilation. Those blocks are:
- Comments. They can be removed with regexp. (But, for example, Delphi uses the preprocessor directives which look like comments (“{ is it a comment or a directive? }”), so the regexp would not be trivial.)
- But the most tricking part is the blocks of code which are excluded from the compilation with #ifdef. These blocks have to be removed too.
So, the question is: “Is there a way to do it with some program or script?” Let’s suppose there is a program that can be given a source code file and a list of defined symbols to distinguish unused blocks of code, and it would spit out the cleansed file I want to get.