summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in
blob: b141942c156aa16683f53e931ca384c492f3fb91 (plain)
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
#include <cmSystemTools.h>
#include <cmsys/Encoding.hxx>
#include <string>

#define RETVAL @_retval@

int
main(int ac, char **av)
{
  cmsys::Encoding::CommandLineArguments args =
    cmsys::Encoding::CommandLineArguments::Main(ac, av);
  int argc = args.argc();
  const char* const* argv = args.argv();

  std::string exename = argv[0];
  std::string logarg;
  bool nextarg = false;

  if (exename.find("valgrind") != exename.npos)
    logarg = "--log-file=";
  else if (exename.find("purify") != exename.npos)
#ifdef _WIN32
    logarg = "/SAVETEXTDATA=";
#else
    logarg = "-log-file=";
#endif
  else if (exename.find("BC") != exename.npos)
    {
    nextarg = true;
    logarg = "/X";
    }

  if (!logarg.empty()) {
    std::string logfile;
    for (int i = 1; i < argc; i++) {
      std::string arg = argv[i];
      if (arg.find(logarg) == 0)
        {
        if (nextarg)
          {
          if (i == argc - 1)
            return 1; // invalid command line
          logfile = argv[i + 1];
          }
        else
          {
          logfile = arg.substr(logarg.length());
          }
        // keep searching, it may be overridden later to provoke an error
        }
      }

    if (!logfile.empty())
      cmSystemTools::Touch(logfile, true);
  }

  return RETVAL;
}