Search code examples
cpreprocessorfiltering

Pre-preprocessor


I want to have a C pre-preprocessor which is filtering some #define statements from the sourcecode without changing anything else.

Why? This should be used to remove some client specific code from the sources if the source is handed out to another client.

Does anyone know of an existing solution?

Thanks! Simon


Solution

  • You can use something like awk instead of CPP ? Add some flags in your code surrounding the piece of code to be removed. For example:

    (...)
    //BEGIN_REMOVE_THIS_CODE
    
    printf("secret code");
    
    //END_REMOVE_THIS_CODE
    (...)
    

    then write a awk script to remove this code, something like...

    BEGIN { write=1;}
    /^\/\/BEGIN_REMOVE_THIS_CODE/ { write=0; next;}
    /^\/\/END_REMOVE_THIS_CODE/ { write=1; next;}
        {
        if(write==1) print $0;
        }