Fixed #7298 (reduce doesn't support --library= and --std= on the command line)

This commit is contained in:
Robert Reif 2016-01-31 12:45:17 +01:00 committed by Daniel Marjamäki
parent b54613a942
commit 0ddb2f1ce1
1 changed files with 60 additions and 1 deletions

View File

@ -634,6 +634,50 @@ static bool cleanupStatements(const ReduceSettings &settings, std::vector<std::s
return changed;
}
static bool tryLoadLibrary(Library& destination, const char* basepath, const char* filename)
{
const Library::Error err = destination.load(basepath, filename);
if (err.errorcode == Library::UNKNOWN_ELEMENT)
std::cout << "reduce: Found unknown elements in configuration file '" << filename << "': " << err.reason << std::endl;
else if (err.errorcode != Library::OK) {
std::string errmsg;
switch (err.errorcode) {
case Library::OK:
break;
case Library::FILE_NOT_FOUND:
errmsg = "File not found";
break;
case Library::BAD_XML:
errmsg = "Bad XML";
break;
case Library::UNKNOWN_ELEMENT:
errmsg = "Unexpected element";
break;
case Library::MISSING_ATTRIBUTE:
errmsg = "Missing attribute";
break;
case Library::BAD_ATTRIBUTE_VALUE:
errmsg = "Bad attribute value";
break;
case Library::UNSUPPORTED_FORMAT:
errmsg = "File is of unsupported format version";
break;
case Library::DUPLICATE_PLATFORM_TYPE:
errmsg = "Duplicate platform type";
break;
case Library::PLATFORM_TYPE_REDEFINED:
errmsg = "Platform type redefined";
break;
}
if (!err.reason.empty())
errmsg += " '" + err.reason + "'";
std::cout << "reduce: Failed to load library configuration file '" << filename << "'. " << errmsg << std::endl;
return false;
}
return true;
}
int main(int argc, char *argv[])
{
@ -733,6 +777,21 @@ int main(int argc, char *argv[])
}
maxconfigs = true;
} else if (std::strncmp(argv[i], "--library=", 10) == 0) {
if (!tryLoadLibrary(settings.library, argv[0], argv[i]+10))
return false;
} else if (std::strcmp(argv[i], "--std=posix") == 0) {
settings.standards.posix = true;
} else if (std::strcmp(argv[i], "--std=c89") == 0) {
settings.standards.c = Standards::C89;
} else if (std::strcmp(argv[i], "--std=c99") == 0) {
settings.standards.c = Standards::C99;
} else if (std::strcmp(argv[i], "--std=c11") == 0) {
settings.standards.c = Standards::C11;
} else if (std::strcmp(argv[i], "--std=c++03") == 0) {
settings.standards.cpp = Standards::CPP03;
} else if (std::strcmp(argv[i], "--std=c++11") == 0) {
settings.standards.cpp = Standards::CPP11;
} else if (settings.filename==nullptr && strchr(argv[i],'.'))
settings.filename = argv[i];
else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
@ -751,7 +810,7 @@ int main(int argc, char *argv[])
if ((!settings.hang && settings.linenr == 0U) || settings.filename == nullptr) {
std::cerr << "Syntax:" << std::endl
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] [--force] [--enable=<id>] [--inconclusive] [--debug-warnings] [--max-configs=<limit>] filename [linenr]" << std::endl;
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] [--force] [--enable=<id>] [--inconclusive] [--debug-warnings] [--max-configs=<limit>] [--platform=<type>] [--library=<cfg>] [--std=<id>] filename [linenr]" << std::endl;
return EXIT_FAILURE;
}