Git Product home page Git Product logo

prepreprocessor's Introduction

pppc.pl

A little script that extracts two (or more) different versions of C code from the same source. This is accomplish by preprocessing preprocessor directives before the C preprocessor, extracting code from this process.

For example, this simple code, in "mycompleteproject.c":

#ifdef COMPLETE_CODE
    // each value on second argument has a special meaning.
    if (strcmp(my_array[i], "1")==0) my_var=VALUE1;
    if (strcmp(my_array[i], "2")==0) my_var=VALUE2;
#else
    //// this block reserves these values just for my complete version.
    // these values are reserved for future use.
    if (strcmp(my_array[i], "1")==0 ||
        strcmp(my_array[i], "2")==0) {
        printf ("\n'%s' value isn't valid.\n", my_array[i]);
        return 1;
    }
#endif

Would end up being just the first block after this command, in the output file "project.c":

$ perl pppc.pl mycompleteproject.c project.c COMPLETE_CODE 0

So:

    // these values are reserved for future use.
    if (strcmp(my_array[i], "1")==0 ||
    strcmp(my_array[i], "2")==0) {
        printf ("\n'%s' value isn't valid.\n", my_array[i]);
        return 1;
    }

Note that comment lines beginning with quadruple slashes are also always extracted from the final code. This allows you to make private comments to your project.

Changing the command line to "COMPLETE_CODE 1" would have written only:

    // each value on second argument has a special meaning.
    if (strcmp(my_array[i], "1")==0) my_var=VALUE1;
    if (strcmp(my_array[i], "2")==0) my_var=VALUE2;

The pre-preprocessor can be chained for multiple pre-preprocessor labels and/or multiple source files in a specially crafted shell script.sh file for the project:

perl pppc.pl mycompleteproject.c /tmp/project.c COMPLETE_CODE 0
perl pppc.pl /tmp/project.c project.c JUST_ONE_OUTPUT 1
perl pppc.pl mycompleteproject.h /tmp/project.h COMPLETE_CODE 0

note

I just made this for fun! and for little projects: in case you need more "professional" options, check unifdef, sunifdef or coan (listed in order of appearance).

prepreprocessor's People

Contributors

circulosmeos avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.