GPP
General Porpuse Pre-processor
Use C like Pre-Processor directives with any language(Python, Javascript, Shell, even text documents). A project to bring Pre-processor directives to everywhere
Getting Started
Installing
Install the gpp with the folloning script
Using curl
curl https://raw.githubusercontent.com/yigitgunduc/gpp/master/scripts/install.sh > install.sh && bash install.sh
Using wget
wget https://raw.githubusercontent.com/yigitgunduc/gpp/master/scripts/install.sh && bash install.sh
- tools for building the project and installing it will be present in the
script/
CLI Interface
flag | description |
---|---|
-o |
name of the output file |
-E |
outputs the result of the preprocessor to the terminal |
file |
name of the input file |
--run |
command to execute after done processing the file |
running the pre-processor and generating an output file
gpp filename -o output
running the pre-processor and printing the results to the terminal
gpp filename -E
running the pre-processor and executing a command
gpp filename -o myproject.sh --run "bash myproject.sh"
Syntax Basics
Keyword | description | example |
---|---|---|
#include |
include contents of other files to the current one | #include "hey.sh" |
#define |
Define pre-processor directives that will be replaced before runtime | #define MY_DEF 10 |
#undef |
Undefine defined pre-processor directives | #undef MY_DEF |
#if |
Compare number, defines, string | #define MY_DEF 10 |
#else |
Else branch for if statments | #define MY_DEF 10 |
#ifdef |
check if a macro have been defined | #define DEF |
#ifndef |
check if a macro have not been defined | #define DEF |
- various example with different programming languages can be found in the
example/
dir
Syntax Guidlines
- There shoul not be any space between
#
and the keyword(define, if, ifdef, include, ...) - All if expression must be trailed with end
#endif
Examples
- including contents of a file to an other one
#include "hey.sh"
- define a macro
#define MY_MACRO 5
- FILE macro
echo __FILE__
will be replaced the cwd
- TIME macro
echo __TIME__
will be replaced the time in the HH:MM:SS format
- DATE macro
echo __DATE__
will be replaced the date in the YYYY-MM-DD format
- undefine a macro
#define MY_MACRO 5
#undef MY_MARCO
- comparint two number with an if statement
#if 4 == 4
echo "equal"
#endif
- comparint macros with an if statement
#define MY_MACRO 5
#if MY_MACRO == 5
echo "equal"
#endif
- else branch for if statements
#define MY_MACRO 5
#if MY_MACRO == 3
echo "equal to 3"
#else
echo "equal to something else"
#endif
- check if a macro is defined
#define MY_MACRO
#ifdef MY_MACRO
echo "it's defined"
#else
echo "not defined"
#endif
- check if a macro is not defined
#define MY_MACRO
#ifndef MY_MACRO
echo "not defined"
#else
echo "it's defined"
#endif
- all the keywords together
#include "hey.sh"
#define AREA 43
#define W 43
#if W == AREA
echo "equal"
#else
echo "not equal"
#endif
#ifdef MACRO
echo "not defined"
#else
echo "it's defined"
#endif
echo "you are working in the __FILE__ dir"
echo "time is __TIME__"
echo "todays date is __DATE__"
echo "it's done"
- various example with different programming languages can be found in the
example/
dir
Roadmap
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.