Skip to content

Commit

Permalink
Merge pull request #3076 from leandro-lucarella-sociomantic/cond-conf…
Browse files Browse the repository at this point in the history
…-vars2

ini: Add support to define undefined variables
  • Loading branch information
WalterBright committed Feb 7, 2014
2 parents f9e3f41 + ba95719 commit 10b2e55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 7 additions & 3 deletions docs/man/man5/dmd.conf.5
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions src/inifile.c
Expand Up @@ -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++;
Expand All @@ -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;
}
Expand Down

0 comments on commit 10b2e55

Please sign in to comment.