2002-03-15 23:42:59 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Insight Consortium. All rights reserved.
|
|
|
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSystemTools.h"
|
2002-04-12 02:17:33 +04:00
|
|
|
#include "time.h"
|
2002-03-15 23:42:59 +03:00
|
|
|
|
|
|
|
void CMakeCommandUsage(const char* program)
|
|
|
|
{
|
|
|
|
std::strstream errorStream;
|
|
|
|
|
2002-04-01 22:34:38 +04:00
|
|
|
errorStream
|
|
|
|
<< "cmake version " << cmMakefile::GetMajorVersion()
|
|
|
|
<< "." << cmMakefile::GetMinorVersion() << "\n";
|
|
|
|
|
|
|
|
errorStream
|
|
|
|
<< "Usage: " << program << " [command] [arguments ...]\n"
|
|
|
|
<< "Available commands: \n"
|
2002-04-12 02:17:33 +04:00
|
|
|
<< " copy file destination - copy file to destination (either file or directory)\n"
|
|
|
|
<< " remove file1 file2 ... - remove the file(s)\n"
|
|
|
|
<< " time command [args] ... - run command and return elapsed time\n"
|
2002-04-01 22:34:38 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2002-04-12 02:17:33 +04:00
|
|
|
<< " write_regv key value - write registry value\n"
|
|
|
|
<< " delete_regv key - delete registry value\n"
|
2002-04-01 22:34:38 +04:00
|
|
|
#endif
|
|
|
|
<< std::ends;
|
|
|
|
|
2002-03-15 23:42:59 +03:00
|
|
|
cmSystemTools::Error(errorStream.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int ac, char** av)
|
|
|
|
{
|
|
|
|
std::vector<std::string> args;
|
|
|
|
for(int i =0; i < ac; ++i)
|
|
|
|
{
|
|
|
|
args.push_back(av[i]);
|
|
|
|
}
|
|
|
|
|
2002-04-01 22:34:38 +04:00
|
|
|
if (args.size() > 1)
|
2002-03-15 23:42:59 +03:00
|
|
|
{
|
2002-04-01 22:34:38 +04:00
|
|
|
// Copy file
|
|
|
|
if (args[1] == "copy" && args.size() == 4)
|
2002-03-15 23:42:59 +03:00
|
|
|
{
|
|
|
|
cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str());
|
2002-03-19 20:25:15 +03:00
|
|
|
return cmSystemTools::GetErrorOccuredFlag();
|
2002-03-15 23:42:59 +03:00
|
|
|
}
|
2002-04-01 22:34:38 +04:00
|
|
|
|
|
|
|
// Remove file
|
|
|
|
else if (args[1] == "remove" && args.size() > 2)
|
2002-03-15 23:42:59 +03:00
|
|
|
{
|
2002-04-01 22:34:38 +04:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc ++)
|
2002-03-15 23:42:59 +03:00
|
|
|
{
|
2002-03-26 20:38:52 +03:00
|
|
|
if(args[cc] != "-f")
|
|
|
|
{
|
|
|
|
if(args[cc] == "\\-f")
|
|
|
|
{
|
|
|
|
args[cc] = "-f";
|
|
|
|
}
|
|
|
|
cmSystemTools::RemoveFile(args[cc].c_str());
|
|
|
|
}
|
2002-03-15 23:42:59 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-01 22:34:38 +04:00
|
|
|
|
2002-04-12 02:17:33 +04:00
|
|
|
// Clock command
|
|
|
|
else if (args[1] == "time" && args.size() > 2)
|
|
|
|
{
|
|
|
|
std::string command = args[2];
|
|
|
|
std::string output;
|
|
|
|
for (std::string::size_type cc = 3; cc < args.size(); cc ++)
|
|
|
|
{
|
|
|
|
command += " ";
|
|
|
|
command += args[cc];
|
|
|
|
}
|
|
|
|
|
|
|
|
clock_t clock_start, clock_finish;
|
|
|
|
time_t time_start, time_finish;
|
|
|
|
|
|
|
|
time(&time_start);
|
|
|
|
clock_start = clock();
|
|
|
|
|
2002-04-12 02:59:34 +04:00
|
|
|
cmSystemTools::RunCommand(command.c_str(), output, 0, true);
|
2002-04-12 02:17:33 +04:00
|
|
|
|
|
|
|
clock_finish = clock();
|
|
|
|
time(&time_finish);
|
|
|
|
|
2002-04-12 02:59:34 +04:00
|
|
|
std::cout << output.c_str();
|
|
|
|
|
2002-04-12 02:17:33 +04:00
|
|
|
double clocks_per_sec = (double)CLOCKS_PER_SEC;
|
|
|
|
std::cout << "Elapsed time: "
|
2002-04-16 17:28:34 +04:00
|
|
|
<< (time_t)(time_finish - time_start) << " s. (time)"
|
2002-04-12 02:17:33 +04:00
|
|
|
<< ", "
|
|
|
|
<< (double)(clock_finish - clock_start) / clocks_per_sec
|
|
|
|
<< " s. (clock)"
|
|
|
|
<< "\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-01 22:34:38 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
// Write registry value
|
|
|
|
else if (args[1] == "write_regv" && args.size() > 3)
|
|
|
|
{
|
|
|
|
return cmSystemTools::WriteRegistryValue(args[2].c_str(),
|
|
|
|
args[3].c_str()) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete registry value
|
|
|
|
else if (args[1] == "delete_regv" && args.size() > 2)
|
|
|
|
{
|
|
|
|
return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-15 23:42:59 +03:00
|
|
|
}
|
2002-04-01 22:34:38 +04:00
|
|
|
|
2002-03-15 23:42:59 +03:00
|
|
|
::CMakeCommandUsage(args[0].c_str());
|
|
|
|
return 1;
|
|
|
|
}
|