GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cppcheck/cli/cmdlineparser.cpp at main · cppcheck-opensource/cppcheck Expand file tree/ Copy pathcmdlineparser.cppMore file actions 2272 lines (2026 loc) · 99.9 KB / Copy pathcmdlineparser.cppFile metadata and controls2272 lines (2026 loc) · 99.9 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 /* * Cppcheck - A tool for static C/C++ code analysis * Copyright (C) 2007-2026 Cppcheck team. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "cmdlineparser.h" #include "addoninfo.h" #include "check.h" #include "checks.h" #include "checkers.h" #include "color.h" #include "config.h" #include "cppcheck.h" #include "errorlogger.h" #include "errortypes.h" #include "filelister.h" #include "filesettings.h" #include "importproject.h" #include "library.h" #include "path.h" #include "pathmatch.h" #include "platform.h" #include "settings.h" #include "standards.h" #include "suppressions.h" #include "utils.h" #include "frontend.h" #include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> // EXIT_FAILURE #include <cstring> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <set> #include <sstream> #include <unordered_set> #include <utility> #ifdef HAVE_RULES #include "regex.h" #include "rule.h" // xml is used for rules #include "xml.h" #include <memory> #endif static bool addFilesToList(const std::string& fileList, std::vector<std::string>& pathNames) { std::istream *files; std::ifstream infile; if (fileList == "-") { // read from stdin files = &std::cin; } else { infile.open(fileList); if (!infile.is_open()) return false; files = &infile; } std::string fileName; while (std::getline(*files, fileName)) { // next line if (!fileName.empty()) { pathNames.emplace_back(std::move(fileName)); } } return true; } static bool addIncludePathsToList(const std::string& fileList, std::list<std::string>& pathNames) { std::ifstream files(fileList); if (files) { std::string pathName; while (std::getline(files, pathName)) { // next line if (!pathName.empty()) { pathName = Path::removeQuotationMarks(std::move(pathName)); pathName = Path::fromNativeSeparators(std::move(pathName)); // If path doesn't end with / or \, add it if (!endsWith(pathName, '/')) pathName += '/'; pathNames.emplace_back(std::move(pathName)); } } return true; } return false; } static bool addPathsToSet(const std::string& fileName, std::set<std::string>& set) { std::list<std::string> templist; if (!addIncludePathsToList(fileName, templist)) return false; set.insert(templist.cbegin(), templist.cend()); return true; } namespace { class XMLErrorMessagesLogger : public ErrorLogger { void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override { std::cout << outmsg << std::endl; } void reportErr(const ErrorMessage &msg) override { reportOut(msg.toXML()); } void reportMetric(const std::string &metric) override { /* Not used here */ (void) metric; } void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override {} }; } CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions) : mLogger(logger) , mSettings(settings) , mSuppressions(suppressions) {} bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) { const Result result = parseFromArgs(argc, argv); switch (result) { case Result::Success: break; case Result::Exit: Settings::terminate(); return true; case Result::Fail: return false; } // Libraries must be loaded before FileLister is executed to ensure markup files will be // listed properly. if (!loadLibraries(mSettings)) return false; if (!loadAddons(mSettings)) return false; // Check that all include paths exist { for (auto iter = mSettings.includePaths.cbegin(); iter != mSettings.includePaths.cend(); ) { const std::string path(Path::toNativeSeparators(*iter)); if (Path::isDirectory(path)) ++iter; else { // TODO: this bypasses the template format and other settings // If the include path is not found, warn user and remove the non-existing path from the list. if (mSettings.severity.isEnabled(Severity::information)) std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl; iter = mSettings.includePaths.erase(iter); } } } // Output a warning for the user if he tries to exclude headers const std::vector<std::string>& ignored = mIgnoredPaths; const bool warn = std::any_of(ignored.cbegin(), ignored.cend(), [](const std::string& i) { return Path::isHeader(i); }); if (warn) { mLogger.printMessage("filename exclusion does not apply to header (.h and .hpp) files."); mLogger.printMessage("Please use --suppress for ignoring results from the header files."); } const std::vector<std::string>& pathnamesRef = mPathNames; const std::list<FileSettings>& fileSettingsRef = mFileSettings; // the inputs can only be used exclusively - CmdLineParser should already handle this assert(!(!pathnamesRef.empty() && !fileSettingsRef.empty())); if (!fileSettingsRef.empty()) { std::list<FileSettings> fileSettings; if (!mSettings.fileFilters.empty()) { // filter only for the selected filenames from all project files PathMatch filtermatcher(mSettings.fileFilters, Path::getCurrentPath()); std::copy_if(fileSettingsRef.cbegin(), fileSettingsRef.cend(), std::back_inserter(fileSettings), [&](const FileSettings &fs) { return filtermatcher.match(fs.filename()); }); if (fileSettings.empty()) { for (const std::string& f: mSettings.fileFilters) mLogger.printError("could not find any files matching the filter:" + f); return false; } } else { fileSettings = fileSettingsRef; } // TODO: de-duplicate mFileSettings.clear(); frontend::applyLang(fileSettings, mSettings, mEnforcedLang); // sort the markup last std::copy_if(fileSettings.cbegin(), fileSettings.cend(), std::back_inserter(mFileSettings), [&](const FileSettings &fs) { return !mSettings.library.markupFile(fs.filename()) || !mSettings.library.processMarkupAfterCode(fs.filename()); }); std::copy_if(fileSettings.cbegin(), fileSettings.cend(), std::back_inserter(mFileSettings), [&](const FileSettings &fs) { return mSettings.library.markupFile(fs.filename()) && mSettings.library.processMarkupAfterCode(fs.filename()); }); if (mFileSettings.empty()) { mLogger.printError("could not find or open any of the paths given."); return false; } } if (!pathnamesRef.empty()) { std::list<FileWithDetails> filesResolved; // Execute recursiveAddFiles() to each given file parameter // TODO: verbose log which files were ignored? const PathMatch matcher(ignored, Path::getCurrentPath()); for (const std::string &pathname : pathnamesRef) { const std::string err = FileLister::recursiveAddFiles(filesResolved, Path::toNativeSeparators(pathname), mSettings.library.markupExtensions(), matcher, mSettings.debugignore); if (!err.empty()) { // TODO: bail out? mLogger.printMessage(err); } } if (filesResolved.empty()) { mLogger.printError("could not find or open any of the paths given."); // TODO: PathMatch should provide the information if files were ignored if (!ignored.empty()) mLogger.printMessage("Maybe all paths were ignored?"); return false; } std::list<FileWithDetails> files; if (!mSettings.fileFilters.empty()) { files = filterFiles(mSettings.fileFilters, filesResolved); if (files.empty()) { for (const std::string& f: mSettings.fileFilters) mLogger.printError("could not find any files matching the filter:" + f); return false; } } else { files = std::move(filesResolved); } // de-duplicate files { auto it = files.begin(); while (it != files.end()) { const std::string& absname = it->abspath(); // TODO: log if duplicated files were dropped files.erase(std::remove_if(std::next(it), files.end(), [&](const FileWithDetails& entry) { return entry.abspath() == absname; }), files.end()); ++it; } } frontend::applyLang(files, mSettings, mEnforcedLang); // sort the markup last std::copy_if(files.cbegin(), files.cend(), std::inserter(mFiles, mFiles.end()), [&](const FileWithDetails& entry) { return !mSettings.library.markupFile(entry.path()) || !mSettings.library.processMarkupAfterCode(entry.path()); }); std::copy_if(files.cbegin(), files.cend(), std::inserter(mFiles, mFiles.end()), [&](const FileWithDetails& entry) { return mSettings.library.markupFile(entry.path()) && mSettings.library.processMarkupAfterCode(entry.path()); }); if (mFiles.empty()) { mLogger.printError("could not find or open any of the paths given."); return false; } } return true; } // TODO: normalize/simplify/native all path parameters // TODO: error out on all missing given files/paths CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const argv[]) { mSettings.exename = Path::getCurrentExecutablePath(argv[0]); bool xmlOptionProvided = false; bool outputFormatOptionProvided = false; // default to --check-level=normal from CLI for now mSettings.setCheckLevel(Settings::CheckLevel::normal); // read --debug-lookup early so the option is available for the cppcheck.cfg loading for (int i = 1; i < argc; i++) { // Show debug warnings for lookup for configuration files if (std::strcmp(argv[i], "--debug-lookup") == 0) mSettings.debuglookup = true; else if (std::strncmp(argv[i], "--debug-lookup=", 15) == 0) { const std::string lookup = argv[i] + 15; if (lookup == "all") mSettings.debuglookup = true; else if (lookup == "addon") mSettings.debuglookupAddon = true; else if (lookup == "config") mSettings.debuglookupConfig = true; else if (lookup == "library") mSettings.debuglookupLibrary = true; else if (lookup == "platform") mSettings.debuglookupPlatform = true; else { mLogger.printError("unknown lookup '" + lookup + "'"); return Result::Fail; } } } if (!loadCppcheckCfg()) return Result::Fail; if (argc <= 1) { printHelp(); return Result::Exit; } // check for exclusive options for (int i = 1; i < argc; i++) { // documentation.. if (std::strcmp(argv[i], "--doc") == 0) { std::ostringstream doc; // Get documentation.. for (const Check * const c : CheckInstances::get()) { const std::string& name(c->name()); const std::string info(c->classInfo()); if (!name.empty() && !info.empty()) doc << "## " << name << " ##\n" << info << "\n"; } mLogger.printRaw(doc.str()); return Result::Exit; } // print all possible error messages.. if (std::strcmp(argv[i], "--errorlist") == 0) { { XMLErrorMessagesLogger xmlLogger; std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName, 2); CppCheck::getErrorMessages(xmlLogger); std::cout << ErrorMessage::getXMLFooter(2) << std::endl; } return Result::Exit; } // Print help if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) { printHelp(); return Result::Exit; } if (std::strcmp(argv[i], "--filesdir") == 0) { #ifdef FILESDIR mLogger.printRaw(FILESDIR); // TODO: should not include newline #endif return Result::Exit; } if (std::strcmp(argv[i], "--version") == 0) { const std::string version = getVersion(); mLogger.printRaw(version); // TODO: should not include newline return Result::Exit; } } bool debug = false; bool inputAsFilter = false; // set by: --file-filter=+ ImportProject::Type projectType = ImportProject::Type::NONE; ImportProject project; std::string vsConfig; std::string platform; char defaultSign = '\0'; std::vector<std::string> lookupPaths{ Path::getCurrentPath(), // TODO: do we want to look in CWD? Path::getPathFromFilename(mSettings.exename), }; bool executorAuto = true; for (int i = 1; i < argc; i++) { if (argv[i][0] != '-') { mPathNames.emplace_back(Path::fromNativeSeparators(Path::removeQuotationMarks(argv[i]))); } // User define else if (std::strncmp(argv[i], "-D", 2) == 0) { std::string define; // "-D define" if (std::strcmp(argv[i], "-D") == 0) { ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-D' is missing."); return Result::Fail; } define = argv[i]; } // "-Ddefine" else { define = 2 + argv[i]; } // No "=", append a "=1" if (define.find('=') == std::string::npos) define += "=1"; if (!mSettings.userDefines.empty()) mSettings.userDefines += ";"; mSettings.userDefines += define; } // -E else if (std::strcmp(argv[i], "-E") == 0) { mSettings.preprocessOnly = true; mSettings.quiet = true; } // -CC else if (std::strcmp(argv[i], "-CC") == 0) { mSettings.keepComments = true; } // Include paths else if (std::strncmp(argv[i], "-I", 2) == 0) { std::string path; // "-I path/" if (std::strcmp(argv[i], "-I") == 0) { ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-I' is missing."); return Result::Fail; } path = argv[i]; } // "-Ipath/" else { path = 2 + argv[i]; } path = Path::removeQuotationMarks(std::move(path)); path = Path::fromNativeSeparators(std::move(path)); // If path doesn't end with / or \, add it if (!endsWith(path,'/')) path += '/'; mSettings.includePaths.emplace_back(std::move(path)); } // User undef else if (std::strncmp(argv[i], "-U", 2) == 0) { std::string undef; // "-U undef" if (std::strcmp(argv[i], "-U") == 0) { ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-U' is missing."); return Result::Fail; } undef = argv[i]; } // "-Uundef" else { undef = 2 + argv[i]; } mSettings.userUndefs.insert(std::move(undef)); } else if (std::strncmp(argv[i], "--addon=", 8) == 0) mSettings.addons.emplace(argv[i]+8); else if (std::strncmp(argv[i],"--addon-python=", 15) == 0) mSettings.addonPython.assign(argv[i]+15); else if (std::strcmp(argv[i],"--analyze-all-vs-configs") == 0) { mSettings.analyzeAllVsConfigs = true; mAnalyzeAllVsConfigsSetOnCmdLine = true; } // Check configuration else if (std::strcmp(argv[i], "--check-config") == 0) mSettings.checkConfiguration = true; else if (std::strcmp(argv[i], "--check-headers") == 0) mSettings.checkHeaders = true; // Check level else if (std::strncmp(argv[i], "--check-level=", 14) == 0) { Settings::CheckLevel level = Settings::CheckLevel::normal; const std::string level_s(argv[i] + 14); if (level_s == "reduced") level = Settings::CheckLevel::reduced; else if (level_s == "normal") level = Settings::CheckLevel::normal; else if (level_s == "exhaustive") level = Settings::CheckLevel::exhaustive; else { mLogger.printError("unknown '--check-level' value '" + level_s + "'."); return Result::Fail; } mSettings.setCheckLevel(level); } // Check library definitions else if (std::strcmp(argv[i], "--check-library") == 0) { mSettings.checkLibrary = true; } else if (std::strcmp(argv[i], "--check-unused-templates") == 0) mSettings.checkUnusedTemplates = true; else if (std::strncmp(argv[i], "--check-version=", 16) == 0) { if (!loadCppcheckCfg()) return Result::Fail; const std::string actualVersion = getVersion(); const std::string wantedVersion = argv[i] + 16; if (actualVersion != wantedVersion) { mLogger.printError("--check-version check failed. Aborting."); return Result::Fail; } } else if (std::strncmp(argv[i], "--checkers-report=", 18) == 0) mSettings.checkersReportFilename = argv[i] + 18; else if (std::strncmp(argv[i], "--checks-max-time=", 18) == 0) { if (!parseNumberArg(argv[i], 18, mSettings.checksMaxTime, true)) return Result::Fail; } else if (std::strcmp(argv[i], "--clang") == 0) { mSettings.clang = true; } else if (std::strncmp(argv[i], "--clang=", 8) == 0) { mSettings.clang = true; mSettings.clangExecutable = argv[i] + 8; } else if (std::strcmp(argv[i], "--clang-tidy") == 0) { mSettings.clangTidy = true; } else if (std::strncmp(argv[i], "--clang-tidy=", 13) == 0) { mSettings.clangTidy = true; mSettings.clangTidyExecutable = argv[i] + 13; } else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) { mSettings.configExcludePaths.insert(Path::fromNativeSeparators(argv[i] + 17)); } else if (std::strncmp(argv[i], "--config-excludes-file=", 23) == 0) { // open this file and read every input file (1 file name per line) const std::string cfgExcludesFile(23 + argv[i]); if (!addPathsToSet(cfgExcludesFile, mSettings.configExcludePaths)) { mLogger.printError("unable to open config excludes file at '" + cfgExcludesFile + "'"); return Result::Fail; } } else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0) { std::string path = Path::fromNativeSeparators(argv[i] + 21); if (path.empty()) { mLogger.printError("no path has been specified for --cppcheck-build-dir"); return Result::Fail; } if (endsWith(path, '/')) path.pop_back(); mSettings.buildDir = std::move(path); } else if (std::strcmp(argv[i], "--cpp-header-probe") == 0) { mSettings.cppHeaderProbe = true; } else if (std::strcmp(argv[i], "--debug-analyzerinfo") == 0) mSettings.debugainfo = true; else if (std::strcmp(argv[i], "--debug-ast") == 0) mSettings.debugast = true; // Show debug warnings for lookup for configuration files else if (std::strcmp(argv[i], "--debug-clang-output") == 0) mSettings.debugClangOutput = true; // Show debug messages for ignored files else if (std::strcmp(argv[i], "--debug-ignore") == 0) mSettings.debugignore = true; else if (std::strcmp(argv[i], "--debug-ipc") == 0) mSettings.debugipc = true; // Show --debug output after the first simplifications else if (std::strcmp(argv[i], "--debug") == 0 || std::strcmp(argv[i], "--debug-normal") == 0) debug = true; else if (std::strcmp(argv[i], "--debug-lookup") == 0) continue; // already handled above else if (std::strncmp(argv[i], "--debug-lookup=", 15) == 0) continue; // already handled above // Flag used for various purposes during debugging else if (std::strcmp(argv[i], "--debug-simplified") == 0) mSettings.debugSimplified = true; else if (std::strcmp(argv[i], "--debug-symdb") == 0) mSettings.debugsymdb = true; // Show template information else if (std::strcmp(argv[i], "--debug-template") == 0) mSettings.debugtemplate = true; else if (std::strcmp(argv[i], "--debug-valueflow") == 0) mSettings.debugvalueflow = true; // Show debug warnings else if (std::strcmp(argv[i], "--debug-warnings") == 0) mSettings.debugwarnings = true; else if (std::strncmp(argv[i], "--disable=", 10) == 0) { const std::string errmsg = mSettings.removeEnabled(argv[i] + 10); if (!errmsg.empty()) { mLogger.printError(errmsg); return Result::Fail; } } // dump cppcheck data else if (std::strcmp(argv[i], "--dump") == 0) mSettings.dump = true; else if (std::strcmp(argv[i], "--emit-duplicates") == 0) mSettings.emitDuplicates = true; else if (std::strncmp(argv[i], "--enable=", 9) == 0) { const std::string enable_arg = argv[i] + 9; const std::string errmsg = mSettings.addEnabled(enable_arg); if (!errmsg.empty()) { mLogger.printError(errmsg); return Result::Fail; } // when "style" is enabled, also enable "warning", "performance" and "portability" if (enable_arg.find("style") != std::string::npos) { mSettings.addEnabled("warning"); mSettings.addEnabled("performance"); mSettings.addEnabled("portability"); } } // --error-exitcode=1 else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) { if (!parseNumberArg(argv[i], 17, mSettings.exitCode)) return Result::Fail; } // Exception handling inside cppcheck client else if (std::strcmp(argv[i], "--exception-handling") == 0) { #if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) mSettings.exceptionHandling = true; #else mLogger.printError("Option --exception-handling is not supported since Cppcheck has not been built with any exception handling enabled."); return Result::Fail; #endif } // Exception handling inside cppcheck client else if (std::strncmp(argv[i], "--exception-handling=", 21) == 0) { #if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) const std::string exceptionOutfilename = argv[i] + 21; if (exceptionOutfilename != "stderr" && exceptionOutfilename != "stdout") { mLogger.printError("invalid '--exception-handling' argument"); return Result::Fail; } mSettings.exceptionHandling = true; mSettings.exceptionOutput = (exceptionOutfilename == "stderr") ? stderr : stdout; #else mLogger.printError("Option --exception-handling is not supported since Cppcheck has not been built with any exception handling enabled."); return Result::Fail; #endif } else if (std::strncmp(argv[i], "--executor=", 11) == 0) { const std::string type = 11 + argv[i]; if (type == "auto") { executorAuto = true; mSettings.executor = Settings::defaultExecutor(); } else if (type == "thread") { #if defined(HAS_THREADING_MODEL_THREAD) executorAuto = false; mSettings.executor = Settings::ExecutorType::Thread; #else mLogger.printError("executor type 'thread' cannot be used as Cppcheck has not been built with a respective threading model."); return Result::Fail; #endif } else if (type == "process") { #if defined(HAS_THREADING_MODEL_FORK) executorAuto = false; mSettings.executor = Settings::ExecutorType::Process; #else mLogger.printError("executor type 'process' cannot be used as Cppcheck has not been built with a respective threading model."); return Result::Fail; #endif } else { mLogger.printError("unknown executor: '" + type + "'."); return Result::Fail; } } else if (std::strncmp(argv[i], "--exitcode-suppress=", 20) == 0) { const std::string suppression = argv[i]+20; const std::string errmsg(mSuppressions.nofail.addSuppressionLine(suppression)); if (!errmsg.empty()) { mLogger.printError(errmsg); return Result::Fail; } } // Filter errors else if (std::strncmp(argv[i], "--exitcode-suppressions=", 24) == 0) { // exitcode-suppressions=filename.txt std::string filename = 24 + argv[i]; std::ifstream f(filename); if (!f.is_open()) { mLogger.printError("couldn't open the file: \"" + filename + "\"."); return Result::Fail; } const std::string errmsg(mSuppressions.nofail.parseFile(f)); if (!errmsg.empty()) { mLogger.printError(errmsg); return Result::Fail; } } // use a file filter else if (std::strncmp(argv[i], "--file-filter=", 14) == 0) { const char *filter = argv[i] + 14; if (std::strcmp(filter, "-") == 0) { if (!addFilesToList(filter, mSettings.fileFilters)) { mLogger.printError("Failed: --file-filter=-"); return Result::Fail; } } else if (std::strcmp(filter, "+") == 0) { inputAsFilter = true; } else { mSettings.fileFilters.emplace_back(filter); } } // file list specified else if (std::strncmp(argv[i], "--file-list=", 12) == 0) { // open this file and read every input file (1 file name per line) const std::string fileList = argv[i] + 12; if (!addFilesToList(fileList, mPathNames)) { mLogger.printError("couldn't open the file: \"" + fileList + "\"."); return Result::Fail; } } // Force checking of files that have "too many" configurations else if (std::strcmp(argv[i], "-f") == 0 || std::strcmp(argv[i], "--force") == 0) { mSettings.force = true; mSettings.maxConfigsOption = Settings::maxConfigsNotAssigned; } else if (std::strcmp(argv[i], "--fsigned-char") == 0) defaultSign = 's'; else if (std::strcmp(argv[i], "--funsigned-char") == 0) defaultSign = 'u'; // Ignored paths else if (std::strncmp(argv[i], "-i", 2) == 0) { std::string path; // "-i path/" if (std::strcmp(argv[i], "-i") == 0) { ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-i' is missing."); return Result::Fail; } path = argv[i]; } // "-ipath/" else { path = 2 + argv[i]; } if (!path.empty()) { mIgnoredPaths.emplace_back(std::move(path)); } } else if (std::strncmp(argv[i], "--include=", 10) == 0) { mSettings.userIncludes.emplace_back(Path::fromNativeSeparators(argv[i] + 10)); } else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) { // open this file and read every input file (1 file name per line) const std::string includesFile(16 + argv[i]); if (!addIncludePathsToList(includesFile, mSettings.includePaths)) { mLogger.printError("unable to open includes file at '" + includesFile + "'"); return Result::Fail; } } // Inconclusive checking else if (std::strcmp(argv[i], "--inconclusive") == 0) mSettings.certainty.enable(Certainty::inconclusive); // Enables inline suppressions. else if (std::strcmp(argv[i], "--inline-suppr") == 0) mSettings.inlineSuppressions = true; // Checking threads else if (std::strncmp(argv[i], "-j", 2) == 0) { std::string numberString; // "-j 3" if (std::strcmp(argv[i], "-j") == 0) { ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-j' is missing."); return Result::Fail; } numberString = argv[i]; } // "-j3" else numberString = argv[i]+2; unsigned int tmp; std::string err; if (!strToInt(numberString, tmp, &err)) { mLogger.printError("argument to '-j' is not valid - " + err + "."); return Result::Fail; } if (tmp == 0) { // TODO: implement get CPU logical core count and use that. // Usually, -j 0 would mean "use all available cores," but // if we get a 0, we just stall and don't do any work. mLogger.printError("argument for '-j' must be greater than 0."); return Result::Fail; } if (tmp > 1024) { // Almost nobody has 1024 logical cores, but somebody out // there does. mLogger.printError("argument for '-j' is allowed to be 1024 at max."); return Result::Fail; } mSettings.jobs = tmp; } else if (std::strncmp(argv[i], "-l", 2) == 0) { #ifdef HAS_THREADING_MODEL_FORK std::string numberString; // "-l 3" if (std::strcmp(argv[i], "-l") == 0) { ++i; if (i >= argc || argv[i][0] == '-') { mLogger.printError("argument to '-l' is missing."); return Result::Fail; } numberString = argv[i]; } // "-l3" else numberString = argv[i]+2; int tmp; std::string err; if (!strToInt(numberString, tmp, &err)) { mLogger.printError("argument to '-l' is not valid - " + err + "."); return Result::Fail; } mSettings.loadAverage = tmp; #else mLogger.printError("Option -l cannot be used as Cppcheck has not been built with fork threading model."); return Result::Fail; #endif } // Enforce language (--language=, -x) else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) { std::string str; if (argv[i][2]) { str = argv[i]+11; } else { i++; if (i >= argc || argv[i][0] == '-') { mLogger.printError("no language given to '-x' option."); return Result::Fail; } str = argv[i]; } if (str == "c") mEnforcedLang = Standards::Language::C; else if (str == "c++") mEnforcedLang = Standards::Language::CPP; else { mLogger.printError("unknown language '" + str + "' enforced."); return Result::Fail; } } // --library else if (std::strncmp(argv[i], "--library=", 10) == 0) { std::vector<std::string> libs = splitString(argv[i] + 10, ','); for (auto& l : libs) { if (l.empty()) { mLogger.printError("empty library specified."); return Result::Fail; } mSettings.libraries.emplace_back(std::move(l)); } } // Set maximum number of #ifdef configurations to check else if (std::strncmp(argv[i], "--max-configs=", 14) == 0) { int tmp; if (!parseNumberArg(argv[i], 14, tmp)) return Result::Fail; if (tmp < 1) { mLogger.printError("argument to '--max-configs=' must be greater than 0."); return Result::Fail; } mSettings.maxConfigsOption = tmp; mSettings.force = false; } // max ctu depth else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0) { int temp = 0; if (!parseNumberArg(argv[i], 16, temp)) |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |