From d842d9062297435747117bd74b6e184cedd345cc Mon Sep 17 00:00:00 2001 From: David Cole Date: Wed, 5 Dec 2012 09:55:27 -0500 Subject: CMake: Stylistic changes and documentation tweaks ...for the contributed file and string TIMESTAMP sub-commands. --- Source/cmFileCommand.h | 7 ++- Source/cmStringCommand.h | 4 +- Source/cmTimestamp.cxx | 50 ++++++++++++---------- .../String-TIMESTAMP-DefaulFormatUTC.cmake | 2 - 4 files changed, 33 insertions(+), 30 deletions(-) delete mode 100644 Tests/CMakeTests/String-TIMESTAMP-DefaulFormatUTC.cmake diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 5550dbe..5973fa7 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -87,8 +87,7 @@ public: " [TLS_VERIFY on|off] [TLS_CAINFO file])\n" " file(UPLOAD filename url [INACTIVITY_TIMEOUT timeout]\n" " [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS])\n" - " file(TIMESTAMP " - " [] [UTC])\n" + " file(TIMESTAMP filename variable [] [UTC])\n" "WRITE will write a message into a file called 'filename'. It " "overwrites the file if it already exists, and creates the file " "if it does not exist. (If the file is a build input, use " @@ -203,9 +202,9 @@ public: "as status messages until the operation is complete." "\n" "TIMESTAMP will write a string representation of " - "the modification time of to .\n" + "the modification time of filename to variable.\n" "Should the command be unable to obtain a timestamp " - " will be set to the empty string \"\".\n" + "variable will be set to the empty string \"\".\n" "See documentation of the string TIMESTAMP sub-command for more details." "\n" "The file() command also provides COPY and INSTALL signatures:\n" diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index 7e0694e..4423a90 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -145,9 +145,9 @@ public: " by all regular expression-related commands, including \n" " e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).\n" "TIMESTAMP will write a string representation of " - "the current date and/or time to .\n" + "the current date and/or time to the output variable.\n" "Should the command be unable to obtain a timestamp " - " will be set to the empty string \"\".\n" + "the output variable will be set to the empty string \"\".\n" "The optional UTC flag requests the current date/time " "representation to be in Coordinated Universal Time (UTC) " "rather than local time.\n" diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx index f1115e6..c3df495 100644 --- a/Source/cmTimestamp.cxx +++ b/Source/cmTimestamp.cxx @@ -21,62 +21,68 @@ std::string cmTimestamp::CurrentTime( const std::string& formatString, bool utcFlag) { time_t currentTimeT = time(0); - if(currentTimeT == time_t(-1)) return std::string(); + if(currentTimeT == time_t(-1)) + { + return std::string(); + } return CreateTimestampFromTimeT(currentTimeT, formatString, utcFlag); } +//---------------------------------------------------------------------------- std::string cmTimestamp::FileModificationTime(const char* path, const std::string& formatString, bool utcFlag) { #ifdef _WIN32 - struct _stat info; - std::memset(&info, 0, sizeof(info)); - - if(_stat(path, &info) != 0) - return std::string(); - - time_t currentTimeT = info.st_mtime; + #define STAT _stat #else - struct stat info; + #define STAT stat +#endif + + struct STAT info; std::memset(&info, 0, sizeof(info)); - if(stat(path, &info) != 0) + if(STAT(path, &info) != 0) + { return std::string(); + } - time_t currentTimeT = info.st_mtime; -#endif - - return CreateTimestampFromTimeT(currentTimeT, formatString, utcFlag); + return CreateTimestampFromTimeT(info.st_mtime, formatString, utcFlag); } +//---------------------------------------------------------------------------- std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT, std::string formatString, bool utcFlag) { if(formatString.empty()) { formatString = "%Y-%m-%dT%H:%M:%S"; - if(utcFlag) formatString += "Z"; + if(utcFlag) + { + formatString += "Z"; + } } struct tm timeStruct; std::memset(&timeStruct, 0, sizeof(timeStruct)); + struct tm* ptr = (struct tm*) 0; if(utcFlag) { - tm* ptr = gmtime(&timeT); - if(ptr == 0) return std::string(); - - timeStruct = *ptr; + ptr = gmtime(&timeT); } else { - struct tm* ptr = localtime(&timeT); - if(ptr == 0) return std::string(); + ptr = localtime(&timeT); + } - timeStruct = *ptr; + if(ptr == 0) + { + return std::string(); } + timeStruct = *ptr; + std::string result; for(std::string::size_type i = 0; i < formatString.size(); ++i) { diff --git a/Tests/CMakeTests/String-TIMESTAMP-DefaulFormatUTC.cmake b/Tests/CMakeTests/String-TIMESTAMP-DefaulFormatUTC.cmake deleted file mode 100644 index dad6a8d..0000000 --- a/Tests/CMakeTests/String-TIMESTAMP-DefaulFormatUTC.cmake +++ /dev/null @@ -1,2 +0,0 @@ -string(TIMESTAMP output UTC) -message("~${output}~") -- cgit v0.12