MINOR: config: add predicate "defined()" to conditional expression blocks
"defined(name)" will return true if <name> is a defined environment variable
otherwise false, regardless of its contents.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index c7a746f..d8ba76a 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -136,6 +136,7 @@
/* supported conditional predicates for .if/.elif */
enum cond_predicate {
CFG_PRED_NONE, // none
+ CFG_PRED_DEFINED, // "defined"
};
struct cond_pred_kw {
@@ -146,6 +147,7 @@
/* supported condition predicates */
const struct cond_pred_kw cond_predicates[] = {
+ { "defined", CFG_PRED_DEFINED, ARG1(1, STR) },
{ NULL, CFG_PRED_NONE, 0 }
};
@@ -1712,6 +1714,10 @@
* arguments, placed in <argp> (which we'll need to free).
*/
switch (cond_pred->prd) {
+ case CFG_PRED_DEFINED: // checks if arg exists as an environment variable
+ ret = getenv(argp[0].data.str.area) != NULL;
+ goto done;
+
default:
memprintf(err, "internal error: unhandled conditional expression predicate '%s'", cond_pred->word);
if (errptr)