From 3a646f03e3a95e4151b4e29b0542286796c7ab7b Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Sat, 21 Jan 2017 11:05:02 +0100 Subject: [PATCH] Improved handling in main when no parser name given --- src/main.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1cc83ec..a28e0d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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()); /* Register languages */