+ std::string& res = val_or_string_str;
+ if (val != deflt) {
+ std::ostringstream oss;
+ oss << val;
+ res = oss.str();
+ } else {
+ res = str;
+ }
+ return res.c_str();
+}
+
+template <typename T>
+bool opt_helper::nol_find_prefix(const T& nol, const char* descr,
+ std::string& name)
+{
+ bool result = nol.exists(name);
+ if (!result) {
+ std::stack<std::string> candidates;
+ for (typename T::iterator it = nol.begin() ; it != nol.end() ; ++it) {
+ const std::string& fullname = nol.get_name(it);
+ if (fullname.compare(0, name.length(), name) == 0)
+ candidates.push(fullname);
+ }
+ switch (candidates.size()) {
+ case 0:
+ ERROR2("unknownw %s -- %s", descr, name.c_str());
+ break;
+ case 1:
+ name = candidates.top();
+ candidates.pop();
+ result = true;
+ DEBUG2("infered %s -- %s", descr, name.c_str());
+ break;
+ default:
+ ERROR2("ambiguous %s -- %s", descr, name.c_str());
+ while (!candidates.empty()) {
+ ERROR1(" candidates are -- %s", candidates.top().c_str());
+ candidates.pop();
+ }
+ break;
+ }
+ }
+ return result;
+}
+
+bool opt::parse_args(int* argc, char* argv[])
+{
+ bool result = true;