diff --git a/docs/man/man5/dmd.conf.5 b/docs/man/man5/dmd.conf.5 index 3dd6ca76aa5b..fe5bcaefea04 100644 --- a/docs/man/man5/dmd.conf.5 +++ b/docs/man/man5/dmd.conf.5 @@ -17,9 +17,13 @@ This is handy to make dmd independent of programs with conflicting use of environment variables. .SH SYNTAX -Environment variables follow the [Environment] section -heading, in name=value pairs. Comments are lines that start -with ;. +Environment variables follow the [Environment] section heading, in +name=value or name?=value pairs. Comments are lines that start with ;. +Variable names are always converted to uppercase, so if you use +name=value, actually the variable with name NAME will be written. If +the name?=value syntax is used, the variable with NAME will only be +written if it was defined before (in that case the original value is +preserved). .PP .SH EXAMPLE diff --git a/src/inifile.c b/src/inifile.c index 8087d30b863d..900f29a8d348 100644 --- a/src/inifile.c +++ b/src/inifile.c @@ -284,7 +284,24 @@ const char *inifile(const char *argv0x, const char *inifilex, const char *envsec { if (islower((utf8_t)*p)) *p &= ~0x20; else if (isspace((utf8_t)*p)) + { memmove(p, p + 1, strlen(p)); + p--; + } + else if (p[0] == '?' && p[1] == '=') + { + *p = '\0'; + if (getenv(p)) + { + pn = NULL; + break; + } + // remove the '?' and resume parsing starting from + // '=' again so the regular variable format is + // parsed + memmove(p, p + 1, strlen(p + 1) + 1); + p--; + } else if (*p == '=') { p++; @@ -294,11 +311,14 @@ const char *inifile(const char *argv0x, const char *inifilex, const char *envsec } } - putenv(strdup(pn)); + if (pn) + { + putenv(strdup(pn)); #if LOG - printf("\tputenv('%s')\n", pn); - //printf("getenv(\"TEST\") = '%s'\n",getenv("TEST")); + printf("\tputenv('%s')\n", pn); + //printf("getenv(\"TEST\") = '%s'\n",getenv("TEST")); #endif + } } break; }