Improved handling in main when no parser name given

This commit is contained in:
Robin Jadoul 2017-01-21 11:05:02 +01:00
parent da4f74e2c3
commit 3a646f03e3
1 changed files with 26 additions and 2 deletions

View File

@ -32,11 +32,35 @@ int main(int argc, char** argv) {
return 1;
}
#ifdef _WIN32
const char PATHSEP = '\\';
#else
const char PATHSEP = '/';
#endif
std::string parsername = options["parsername"];
/* Set name of parser, if unset */
if (parsername.empty() && args[0].size() >= 4 && args[0].substr(args[0].size() - 4,4) == ".pds")
parsername = args[0].substr(0, args[0].length() - 4);
if (parsername.empty()) {
if (args[0].size() >= 4 && args[0].substr(args[0].size() - 4,4) == ".pds")
parsername = args[0].substr(0, args[0].length() - 4);
else
parsername = args[0];
std::size_t pos;
// '/' can be used on most platforms (even windows)
pos = parsername.find_last_of('/');
if (pos != parsername.npos) {
parsername = parsername.substr(pos + 1);
}
// strip platform specific as well
pos = parsername.find_last_of(PATHSEP);
if (pos != parsername.npos) {
parsername = parsername.substr(pos + 1);
}
}
auto backendManager = std::make_unique<pds::BackendManager>(pds::BackendManager());
/* Register languages */