2016-04-27 01:56:16 +08:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include <boost/tokenizer.hpp>
|
|
|
|
#include <regex>
|
2016-10-01 18:12:57 +08:00
|
|
|
#include <list>
|
2016-04-27 01:56:16 +08:00
|
|
|
|
|
|
|
#include "arglist.h"
|
|
|
|
|
2016-10-01 18:12:57 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-04-27 01:56:16 +08:00
|
|
|
typedef boost::escaped_list_separator<char> char_separator_t;
|
|
|
|
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
|
|
|
|
2016-10-01 18:12:57 +08:00
|
|
|
ArgsList getArgsList(const std::string& argsStr)
|
2016-04-27 01:56:16 +08:00
|
|
|
{
|
|
|
|
char_tokenizer_t token(argsStr, char_separator_t("", " \t", "\""));
|
|
|
|
ArgsList argsList;
|
|
|
|
|
|
|
|
for (char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it)
|
|
|
|
{
|
|
|
|
if (*it != "")
|
|
|
|
argsList.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
return argsList;
|
|
|
|
}
|
|
|
|
|
2016-10-01 18:12:57 +08:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
2016-04-27 01:56:16 +08:00
|
|
|
static const std::regex versionRe("^-([2,3])(?:\\.(\\d+))?$");
|
|
|
|
|
2016-10-01 18:12:57 +08:00
|
|
|
Options::Options(const std::string& cmdline) :
|
2016-06-23 07:20:06 +08:00
|
|
|
pyMajorVersion(-1),
|
2016-04-27 01:56:16 +08:00
|
|
|
pyMinorVersion(-1),
|
2016-12-27 05:24:15 +08:00
|
|
|
global(false),
|
2016-04-27 01:56:16 +08:00
|
|
|
showHelp(false)
|
|
|
|
{
|
|
|
|
|
2016-10-01 18:12:57 +08:00
|
|
|
args = getArgsList( cmdline );
|
2016-04-27 01:56:16 +08:00
|
|
|
|
2016-12-27 05:24:15 +08:00
|
|
|
if ( args.empty() )
|
|
|
|
{
|
|
|
|
global = true;
|
|
|
|
}
|
|
|
|
|
2016-04-27 01:56:16 +08:00
|
|
|
for (auto it = args.begin(); it != args.end();)
|
|
|
|
{
|
|
|
|
if (*it == "--global" || *it == "-g")
|
|
|
|
{
|
|
|
|
global = true;
|
|
|
|
it = args.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*it == "--local" || *it == "-l")
|
|
|
|
{
|
|
|
|
global = false;
|
|
|
|
it = args.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*it == "--help" || *it == "-h")
|
|
|
|
{
|
|
|
|
showHelp = true;
|
|
|
|
it = args.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::smatch mres;
|
|
|
|
if (std::regex_match(*it, mres, versionRe))
|
|
|
|
{
|
|
|
|
pyMajorVersion = atol(std::string(mres[1].first, mres[1].second).c_str());
|
|
|
|
|
|
|
|
if (mres[2].matched)
|
|
|
|
{
|
|
|
|
pyMinorVersion = atol(std::string(mres[2].first, mres[2].second).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
it = args.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-01 18:12:57 +08:00
|
|
|
|
2016-04-27 01:56:16 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|