Yoshi's Generic Preprocessor (ygpp) is an easy to use generic file preprocessor
which is inspired by the well-known C preprocessor (cpp(1)
).
ygpp is implemented in pure POSIX awk(1)
.
Requirements:
To install ygpp the only requirement is a POSIX compatible awk(1)
and
sh(1)
implementation to be available.
To install ygpp from source:
make AWK=awk prefix=/usr/local install
If you really want to, you can also install the latest version directly from the web:
curl -L -o ~/.local/bin/ygpp https://github.com/riiengineering/ygpp/raw/main/ygpp
You need to adjust the shebang line manually if you don't want to use
/usr/bin/awk
.
[DEF1=value [DEF2=something] ...] ygpp inputfile [concat...]
hello.ygpp
:
#ifndef WORLD
#define WORLD world
#endif
Hello %{WORLD}!
This file when processed using ygpp hello.ygpp
prints:
Hello world!
When processed using WORLD=Yoshi ygpp hello.ygpp
prints:
Hello Yoshi!
Variables can be expanded in the input file by using the %{var}
syntax.
add a comment
define the DEF
definition as VALUE
.
undefine the DEF
definition.
only include the lines between the #if
and #endif
lines if the
SHELL COMMAND
has an exit status of 0
.
All the #defines
will be available as variables in the shell command.
only include the lines between the #ifbool
and #endif
lines if the
environment VARIABLE
is "truthy", i.e. TRUE
/True
/true
or a non-zero
number.
All other values are considered "falsey".
The result can be inverted by prepending exclamation points (!) to the variable name.
only include the lines between #ifdef
and #endif
if VARIABLE
was defined
in the process' environment.
like #ifdef
but negated, i.e. the lines inside this block are printed if
VARIABLE
is not defined in the process' environment.
switch based on the current contents of VARIABLE
.
the #case
s are not fall-through like they are in C-like languages.
The #default
branch will be used if none of the #case
s matched.
Thus #default
must be last.
The behaviour is unspecified when a #case
with the same value occurs more than once.
re-evaluate the lines between #foreach
and #endforeach
once for every ITEM
(a space-separated list of items, including %
-expansions) with the VARIABLE
being set to each of the ITEMS
once.
#foreach
cannot be nested.
The VARIABLE
is scoped to the #foreach
block. The value of VARIABLE
is restored at the end of the foreach loop.
define a reusable block.
insert the contents of BLOCK NAME
as if they were included in the input file
instead of the #useblock
line.
print an error message to stderr
and terminate ygpp with exit status 1.
print a warning message to stderr
, but continue processing the input file.
include the contents of otherfile
as if its contents were included in the
input file in place of the #include
line.