A general purpose single-header preprocessor library.
The following directives are currently supported:
#define <word>
#undef <word>
#if <condition>
#elif <condition>
#else
#endif
#include
(viaset_include_callback
)- Other arbitrary directives (via
set_command_callback
)
static char* read_file(const char* path, size_t* out_size) { /* ... */ }
int main()
{
// Read contents of file "SomeFile.txt" into "buffer"
size_t size;
char* buffer = read_file("SomeFile.txt", &size);
// Create a preprocessor
ccpp::processor p;
// Add some definitions
p.add_define("SOME_DEFINE");
// Begin processing
p.process(buffer, size);
// Dump output
printf("%s\n", buffer);
return 0;
}
I couldn't find a good simple no-dependencies preprocessor library for general purpose use that was also permissively licensed, so I decided to make my own.
This was made primarily as a preprocessor for Openplanet's scripts.