+// Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
+// <type> can be "double" etc. but also only the first letter "d".
+// Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
+static bool
+set_property(const string& arg)
+{
+ string::size_type pos = arg.find('=');
+ if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
+ return false;
+
+ string name = arg.substr(0, pos);
+ string value = arg.substr(pos + 1);
+ string type;
+ pos = name.find(':');
+
+ if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
+ type = name.substr(0, pos);
+ name = name.substr(pos + 1);
+ }
+ SGPropertyNode *n = fgGetNode(name.c_str(), true);
+
+ bool writable = n->getAttribute(SGPropertyNode::WRITE);
+ if (!writable)
+ n->setAttribute(SGPropertyNode::WRITE, true);
+
+ bool ret = false;
+ if (type.empty())
+ ret = n->setUnspecifiedValue(value.c_str());
+ else if (type == "s" || type == "string")
+ ret = n->setStringValue(value.c_str());
+ else if (type == "d" || type == "double")
+ ret = n->setDoubleValue(strtod(value.c_str(), 0));
+ else if (type == "f" || type == "float")
+ ret = n->setFloatValue(atof(value.c_str()));
+ else if (type == "l" || type == "long")
+ ret = n->setLongValue(strtol(value.c_str(), 0, 0));
+ else if (type == "i" || type == "int")
+ ret = n->setIntValue(atoi(value.c_str()));
+ else if (type == "b" || type == "bool")
+ ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
+
+ if (!writable)
+ n->setAttribute(SGPropertyNode::WRITE, false);
+ return ret;
+}
+
+