MINOR: config: support default values for environment variables
Sometimes it is really useful to be able to specify a default value for
an optional environment variable, like the ${name-value} construct in
shell. In fact we're really missing this for a number of settings in
reg tests, starting with timeouts.
This commit simply adds support for the common syntax above. Other
common forms like '+' to replace existing variables, or ':-' and ':+'
to act on empty variables, were not implemented at this stage, as they
are less commonly needed.
diff --git a/src/tools.c b/src/tools.c
index 8fc6716..5d8483d 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -5440,13 +5440,27 @@
}
if (brace) {
- if (*in != '}') {
+ if (*in == '-') {
+ /* default value starts just after the '-' */
+ if (!value)
+ value = in + 1;
+
+ while (*in && *in != '}')
+ in++;
+ if (!*in)
+ goto no_brace;
+ *in = 0; // terminate the default value
+ }
+ else if (*in != '}') {
+ no_brace:
/* unmatched brace */
err |= PARSE_ERR_BRACE;
if (errptr)
*errptr = brace;
goto leave;
}
+
+ /* brace found, skip it */
in++;
brace = NULL;
}