memtester.cxx.in 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <cmSystemTools.h>
  2. #include <string>
  3. #define RETVAL @_retval@
  4. int
  5. main(int argc, char **argv)
  6. {
  7. std::string exename = argv[0];
  8. std::string logarg;
  9. bool nextarg = false;
  10. if (exename.find("valgrind") != exename.npos)
  11. logarg = "--log-file=";
  12. else if (exename.find("purify") != exename.npos)
  13. #ifdef _WIN32
  14. logarg = "/SAVETEXTDATA=";
  15. #else
  16. logarg = "-log-file=";
  17. #endif
  18. else if (exename.find("BC") != exename.npos)
  19. {
  20. nextarg = true;
  21. logarg = "/X";
  22. }
  23. if (!logarg.empty()) {
  24. std::string logfile;
  25. for (int i = 1; i < argc; i++) {
  26. std::string arg = argv[i];
  27. // stop processing options, this allows to force
  28. // the logfile to be ignored
  29. if (arg == "--")
  30. {
  31. break;
  32. }
  33. if (arg.find(logarg) == 0)
  34. {
  35. if (nextarg)
  36. {
  37. if (i == argc - 1)
  38. return 1; // invalid command line
  39. logfile = argv[i + 1];
  40. }
  41. else
  42. {
  43. logfile = arg.substr(logarg.length());
  44. }
  45. break;
  46. }
  47. }
  48. if (!logfile.empty())
  49. cmSystemTools::Touch(logfile.c_str(), true);
  50. }
  51. return RETVAL;
  52. }