From 92714311c992a924a249bf9f27820f0512af7013 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Fri, 20 Sep 2002 13:14:47 -0400 Subject: Add WRITE_FILE command, which writes string to a file --- Source/cmCommands.cxx | 2 ++ Source/cmWriteFileCommand.cxx | 54 ++++++++++++++++++++++++++++++++ Source/cmWriteFileCommand.h | 71 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 Source/cmWriteFileCommand.cxx create mode 100644 Source/cmWriteFileCommand.h diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 204de61..fb3c6e2 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -88,6 +88,7 @@ #include "cmQTWrapCPPCommand.cxx" #include "cmQTWrapUICommand.cxx" #include "cmWrapExcludeFilesCommand.cxx" +#include "cmWriteFileCommand.cxx" // on regular builds add in the load command command // we do not add it in on the bootstrap because it @@ -171,4 +172,5 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmQTWrapCPPCommand); commands.push_back(new cmQTWrapUICommand); commands.push_back(new cmWrapExcludeFilesCommand); + commands.push_back(new cmWriteFileCommand); } diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx new file mode 100644 index 0000000..04fc579 --- /dev/null +++ b/Source/cmWriteFileCommand.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + + 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 "cmWriteFileCommand.h" +#include "cmCacheManager.h" + +// cmLibraryCommand +bool cmWriteFileCommand::InitialPass(std::vector const& argsIn) +{ + if(argsIn.size() < 2 ) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + std::vector args; + cmSystemTools::ExpandListArguments(argsIn, args); + std::string message; + std::vector::const_iterator i = args.begin(); + + bool send_error = false; + std::string fileName = *i; + i++; + + for(;i != args.end(); ++i) + { + message += *i; + } + + std::ofstream file(fileName.c_str(), std::ios::app); + if ( !file ) + { + cmSystemTools::Error("Internal CMake error when trying to open file: ", + fileName.c_str()); + return false; + } + file << message << endl; + file.close(); + + return true; +} + diff --git a/Source/cmWriteFileCommand.h b/Source/cmWriteFileCommand.h new file mode 100644 index 0000000..c11c023 --- /dev/null +++ b/Source/cmWriteFileCommand.h @@ -0,0 +1,71 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#ifndef cmWriteFileCommand_h +#define cmWriteFileCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +/** \class cmWriteFileCommand + * \brief Writes a message to a file + * + */ +class cmWriteFileCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + virtual cmCommand* Clone() + { + return new cmWriteFileCommand; + } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + virtual bool InitialPass(std::vector const& args); + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() { return "WRITE_FILE";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Write a message to a file."; + } + + /** + * More documentation. + */ + virtual const char* GetFullDocumentation() + { + return + "WRITE_FILE(filename \"message to write\"...)\n" + "The first argument is the file name, the rest of the arguments are messages to write."; + } + + cmTypeMacro(cmWriteFileCommand, cmCommand); +}; + + +#endif -- cgit v0.12