Skip to content

Commit 0ddb2f1

Browse files
IOBYTEdanmar
authored andcommitted
Fixed #7298 (reduce doesn't support --library= and --std= on the command line)
1 parent b54613a commit 0ddb2f1

1 file changed

Lines changed: 60 additions & 1 deletion

File tree

tools/reduce.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,50 @@ static bool cleanupStatements(const ReduceSettings &settings, std::vector<std::s
634634
return changed;
635635
}
636636

637+
static bool tryLoadLibrary(Library& destination, const char* basepath, const char* filename)
638+
{
639+
const Library::Error err = destination.load(basepath, filename);
640+
641+
if (err.errorcode == Library::UNKNOWN_ELEMENT)
642+
std::cout << "reduce: Found unknown elements in configuration file '" << filename << "': " << err.reason << std::endl;
643+
else if (err.errorcode != Library::OK) {
644+
std::string errmsg;
645+
switch (err.errorcode) {
646+
case Library::OK:
647+
break;
648+
case Library::FILE_NOT_FOUND:
649+
errmsg = "File not found";
650+
break;
651+
case Library::BAD_XML:
652+
errmsg = "Bad XML";
653+
break;
654+
case Library::UNKNOWN_ELEMENT:
655+
errmsg = "Unexpected element";
656+
break;
657+
case Library::MISSING_ATTRIBUTE:
658+
errmsg = "Missing attribute";
659+
break;
660+
case Library::BAD_ATTRIBUTE_VALUE:
661+
errmsg = "Bad attribute value";
662+
break;
663+
case Library::UNSUPPORTED_FORMAT:
664+
errmsg = "File is of unsupported format version";
665+
break;
666+
case Library::DUPLICATE_PLATFORM_TYPE:
667+
errmsg = "Duplicate platform type";
668+
break;
669+
case Library::PLATFORM_TYPE_REDEFINED:
670+
errmsg = "Platform type redefined";
671+
break;
672+
}
673+
if (!err.reason.empty())
674+
errmsg += " '" + err.reason + "'";
675+
std::cout << "reduce: Failed to load library configuration file '" << filename << "'. " << errmsg << std::endl;
676+
return false;
677+
}
678+
return true;
679+
}
680+
637681

638682
int main(int argc, char *argv[])
639683
{
@@ -733,6 +777,21 @@ int main(int argc, char *argv[])
733777
}
734778

735779
maxconfigs = true;
780+
} else if (std::strncmp(argv[i], "--library=", 10) == 0) {
781+
if (!tryLoadLibrary(settings.library, argv[0], argv[i]+10))
782+
return false;
783+
} else if (std::strcmp(argv[i], "--std=posix") == 0) {
784+
settings.standards.posix = true;
785+
} else if (std::strcmp(argv[i], "--std=c89") == 0) {
786+
settings.standards.c = Standards::C89;
787+
} else if (std::strcmp(argv[i], "--std=c99") == 0) {
788+
settings.standards.c = Standards::C99;
789+
} else if (std::strcmp(argv[i], "--std=c11") == 0) {
790+
settings.standards.c = Standards::C11;
791+
} else if (std::strcmp(argv[i], "--std=c++03") == 0) {
792+
settings.standards.cpp = Standards::CPP03;
793+
} else if (std::strcmp(argv[i], "--std=c++11") == 0) {
794+
settings.standards.cpp = Standards::CPP11;
736795
} else if (settings.filename==nullptr && strchr(argv[i],'.'))
737796
settings.filename = argv[i];
738797
else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
@@ -751,7 +810,7 @@ int main(int argc, char *argv[])
751810

752811
if ((!settings.hang && settings.linenr == 0U) || settings.filename == nullptr) {
753812
std::cerr << "Syntax:" << std::endl
754-
<< 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;
813+
<< 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;
755814
return EXIT_FAILURE;
756815
}
757816

0 commit comments

Comments
 (0)