mirror of
https://github.com/ksherlock/mpw.git
synced 2024-11-25 19:30:50 +00:00
?= conditional environment variables
This commit is contained in:
parent
6eb07f173a
commit
92ef78516c
@ -12,8 +12,19 @@
|
|||||||
//printf("emplacing %s\n", name.c_str());
|
//printf("emplacing %s\n", name.c_str());
|
||||||
// trim any whitespace.
|
// trim any whitespace.
|
||||||
//while (value.length() && isspace(value.back()))
|
//while (value.length() && isspace(value.back()))
|
||||||
// value.pop_back();
|
// value.pop_back();
|
||||||
env[std::move(name)] = std::move(value);
|
// ?= only sets if not already set.
|
||||||
|
|
||||||
|
auto iter = env.find(name);
|
||||||
|
if (iter == env.end())
|
||||||
|
{
|
||||||
|
env[std::move(name)] = std::move(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (overwrite)
|
||||||
|
iter->second = std::move(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value := |*
|
value := |*
|
||||||
@ -53,7 +64,11 @@
|
|||||||
assignment :=
|
assignment :=
|
||||||
word+ ${ name.push_back(fc); }
|
word+ ${ name.push_back(fc); }
|
||||||
ws*
|
ws*
|
||||||
'='
|
(
|
||||||
|
'?=' ${ overwrite = false; }
|
||||||
|
|
|
||||||
|
'=' ${ overwrite = true; }
|
||||||
|
)
|
||||||
ws*
|
ws*
|
||||||
# ws does not include '\n', so that will be handled
|
# ws does not include '\n', so that will be handled
|
||||||
# as a value.
|
# as a value.
|
||||||
@ -62,10 +77,13 @@
|
|||||||
|
|
||||||
main := |*
|
main := |*
|
||||||
ws; # leading space
|
ws; # leading space
|
||||||
|
|
||||||
'\n'; # blank line.
|
'\n'; # blank line.
|
||||||
|
|
||||||
'#' => { fgoto comment; };
|
'#' => { fgoto comment; };
|
||||||
|
|
||||||
word => { fhold; fgoto assignment; };
|
word => { fhold; fgoto assignment; };
|
||||||
*|;
|
*|;
|
||||||
}%%
|
}%%
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -119,6 +137,7 @@ void LoadEnvironment(std::string &envfile, std::unordered_map<std::string, std::
|
|||||||
const char *eof = pe;
|
const char *eof = pe;
|
||||||
const char *te;
|
const char *te;
|
||||||
const char *ts;
|
const char *ts;
|
||||||
|
bool overwrite = true;
|
||||||
|
|
||||||
int cs, act;
|
int cs, act;
|
||||||
|
|
||||||
@ -139,7 +158,7 @@ void LoadEnvironment(std::string &envfile, std::unordered_map<std::string, std::
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
|
// clang++ -DTEST -std=c++11 -stdlib=libc++ environ.cpp
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user