1
0
Fork 0

Simple argument parsing for Props protocol

Maps foo=bar arguments to the top-level arguments dictionary of the
command, as strings only. (We could add CMake style foo:type=bar in
the future if needed). Very basic but this enables a bunch of useful
cases, since SGPropertyNode will do value conversion from string on 
access.
This commit is contained in:
James Turner 2018-11-30 13:58:53 +00:00
parent c09f49e70c
commit 6d68e36523

View file

@ -514,7 +514,20 @@ FGProps::PropsChannel::foundTerminator()
node = args->getNode("file", 0, true);
node->setStringValue( tokens[3].c_str() );
}
} else {
// generic parsing
for ( unsigned int i = 2; i < tokens.size(); ++i ) {
const auto pieces = simgear::strutils::split(tokens.at(i), "=");
if (pieces.size() != 2) {
SG_LOG(SG_NETWORK, SG_WARN, "malformed argument to Props protocol run:" << tokens.at(i));
continue;
}
SGPropertyNode_ptr node= args->getNode(pieces.at(0), 0, true);
node->setStringValue(pieces.at(1));
}
}
if ( !globals->get_commands() ->execute(tokens[1].c_str(), args, nullptr) )
{
SG_LOG( SG_NETWORK, SG_ALERT,