From: <man...@us...> - 2013-05-01 00:34:01
|
Revision: 2000 http://sourceforge.net/p/modplug/code/2000 Author: manxorist Date: 2013-05-01 00:33:53 +0000 (Wed, 01 May 2013) Log Message: ----------- [Ref] Move the version number to a new file common/versionNumber.h and include that only in version.cpp and the ressource file. This prevents rebuild of a bunch of files when only the version number changed. [Ref] Add comments for all functions in version.h Modified Paths: -------------- trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/common/version.cpp trunk/OpenMPT/common/version.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/mptrack/res/MPTRACK.RC2 trunk/OpenMPT/mptrack/tagging.cpp trunk/OpenMPT/mptrack/test/test.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp Added Paths: ----------- trunk/OpenMPT/common/versionNumber.h Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/common/typedefs.h 2013-05-01 00:33:53 UTC (rev 2000) @@ -256,6 +256,13 @@ +//STRINGIZE makes a string of given argument. If used with #defined value, +//the string is made of the contents of the defined value. +#define HELPER_STRINGIZE(x) #x +#define STRINGIZE(x) HELPER_STRINGIZE(x) + + + #ifndef MAX #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif Modified: trunk/OpenMPT/common/version.cpp =================================================================== --- trunk/OpenMPT/common/version.cpp 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/common/version.cpp 2013-05-01 00:33:53 UTC (rev 2000) @@ -12,10 +12,56 @@ #include <sstream> +#include "versionNumber.h" #include "svn_version.h" namespace MptVersion { +const VersionNum num = MPT_VERSION_NUMERIC; + +const char * const str = MPT_VERSION_STR; + +std::string GetOpenMPTVersionStr() +{ + return std::string("OpenMPT ") + std::string(MPT_VERSION_STR); +} + +VersionNum ToNum(const char *const s) +{ + int v1, v2, v3, v4; + sscanf(s, "%x.%x.%x.%x", &v1, &v2, &v3, &v4); + return ((v1 << 24) | (v2 << 16) | (v3 << 8) | v4); +} + +mpt::String ToStr(const VersionNum v) +{ + mpt::String strVersion; + if(v == 0) + { + // Unknown version + strVersion = "Unknown"; + } else if((v & 0xFFFF) == 0) + { + // Only parts of the version number are known (e.g. when reading the version from the IT or S3M file header) + strVersion.Format("%X.%02X", (v >> 24) & 0xFF, (v >> 16) & 0xFF); + } else + { + // Full version info available + strVersion.Format("%X.%02X.%02X.%02X", (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, (v) & 0xFF); + } + return strVersion; +} + +VersionNum RemoveBuildNumber(const VersionNum num) +{ + return (num & 0xFFFFFF00); +} + +bool IsTestBuild(const VersionNum num) +{ + return ((num > MAKE_VERSION_NUMERIC(1,17,02,54) && num < MAKE_VERSION_NUMERIC(1,18,02,00) && num != MAKE_VERSION_NUMERIC(1,18,00,00)) || (num > MAKE_VERSION_NUMERIC(1,18,02,00) && RemoveBuildNumber(num) != num)); +} + bool IsDebugBuild() { #ifdef _DEBUG Modified: trunk/OpenMPT/common/version.h =================================================================== --- trunk/OpenMPT/common/version.h 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/common/version.h 2013-05-01 00:33:53 UTC (rev 2000) @@ -12,91 +12,75 @@ #include <string> -//STRINGIZE makes a string of given argument. If used with #defined value, -//the string is made of the contents of the defined value. -#define HELPER_STRINGIZE(x) #x -#define STRINGIZE(x) HELPER_STRINGIZE(x) -//Version definitions. The only thing that needs to be changed when changing version number. -#define VER_MAJORMAJOR 1 -#define VER_MAJOR 22 -#define VER_MINOR 02 -#define VER_MINORMINOR 04 - //Creates version number from version parts that appears in version string. //For example MAKE_VERSION_NUMERIC(1,17,02,28) gives version number of //version 1.17.02.28. #define MAKE_VERSION_NUMERIC(v0,v1,v2,v3) ((0x##v0 << 24) | (0x##v1<<16) | (0x##v2<<8) | (0x##v3)) -//Version string. For example "1.17.02.28" -#define MPT_VERSION_STR STRINGIZE(VER_MAJORMAJOR)"."STRINGIZE(VER_MAJOR)"."STRINGIZE(VER_MINOR)"."STRINGIZE(VER_MINORMINOR) -//Numerical value of the version. -#define MPT_VERSION_NUMERIC MAKE_VERSION_NUMERIC(VER_MAJORMAJOR,VER_MAJOR,VER_MINOR,VER_MINORMINOR) - namespace MptVersion { + typedef uint32 VersionNum; - const VersionNum num = MPT_VERSION_NUMERIC; - const char* const str = MPT_VERSION_STR; + extern const VersionNum num; // e.g. 0x01170208 + extern const char * const str; // e.g "1.17.02.08" + + // Return a OpenMPT version string suitable for file format tags + std::string GetOpenMPTVersionStr(); // e.g. "OpenMPT 1.17.02.08" + // Returns numerical version value from given version string. - static VersionNum ToNum(const char *const s) - { - int v1, v2, v3, v4; - sscanf(s, "%x.%x.%x.%x", &v1, &v2, &v3, &v4); - return ((v1 << 24) | (v2 << 16) | (v3 << 8) | v4); - } + VersionNum ToNum(const char *const s); // Returns version string from given numerical version value. - static mpt::String ToStr(const VersionNum v) - { - mpt::String strVersion; - if(v == 0) - { - // Unknown version - strVersion = "Unknown"; - } else if((v & 0xFFFF) == 0) - { - // Only parts of the version number are known (e.g. when reading the version from the IT or S3M file header) - strVersion.Format("%X.%02X", (v >> 24) & 0xFF, (v >> 16) & 0xFF); - } else - { - // Full version info available - strVersion.Format("%X.%02X.%02X.%02X", (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, (v) & 0xFF); - } - return strVersion; - } + mpt::String ToStr(const VersionNum v); // Return a version without build number (the last number in the version). // The current versioning scheme uses this number only for test builds, and it should be 00 for official builds, // So sometimes it might be wanted to do comparisons without the build number. - static VersionNum RemoveBuildNumber(const VersionNum num) - { - return (num & 0xFFFFFF00); - } + VersionNum RemoveBuildNumber(const VersionNum num); // Returns true if a given version number is from a test build, false if it's a release build. - static bool IsTestBuild(const VersionNum num = MPT_VERSION_NUMERIC) - { - return ((num > MAKE_VERSION_NUMERIC(1,17,02,54) && num < MAKE_VERSION_NUMERIC(1,18,02,00) && num != MAKE_VERSION_NUMERIC(1,18,00,00)) || (num > MAKE_VERSION_NUMERIC(1,18,02,00) && RemoveBuildNumber(num) != num)); - } + bool IsTestBuild(const VersionNum num = MptVersion::num); + // Return true if this is a debug build with no optimizations bool IsDebugBuild(); + // Return the svn repository url (if built from a svn working copy and tsvn was available during build) std::string GetUrl(); + + // Return the svn revision (if built from a svn working copy and tsvn was available during build) int GetRevision(); + + // Return if the svn working copy had local changes during build (if built from a svn working copy and tsvn was available during build) bool IsDirty(); + + // Return if the svn working copy had files checked out from different revisions and/or branches (if built from a svn working copy and tsvn was available during build) bool HasMixedRevisions(); - std::string GetStateString(); + + // Return a string decribing the working copy state (dirty and/or mixed revisions) (if built from a svn working copy and tsvn was available during build) + std::string GetStateString(); // e.g. "" or "+mixed" or "+mixed+dirty" or "+dirty" + + // Return a string decribing the time of the build process (if built from a svn working copy and tsvn was available during build, otherwise it returns the time version.cpp was last rebuild which could be unreliable as it does not get rebuild every time without tsvn) std::string GetBuildDateString(); - std::string GetBuildFlagsString(); - std::string GetRevisionString(); - std::string GetVersionStringExtended(); - std::string GetVersionUrlString(); + // Return a string decribing some of the buidl features and/or flags + std::string GetBuildFlagsString(); // e.g. " TEST DEBUG NO_VST" + // Return a string decribing the revision of the svn working copy and if it was dirty (+) or had mixed revisions (!) (if built from a svn working copy and tsvn was available during build) + std::string GetRevisionString(); // e.g. "-r1234+" + + // Returns MptVersion::str if the build is a clean release build straight from the repository or an extended strin otherwise (if built from a svn working copy and tsvn was available during build) + std::string GetVersionStringExtended(); // e.g. "1.17.02.08-r1234+ DEBUG" + + // Returns a string combining the repository url and the revision, suitable for checkout if the working copy was clean (if built from a svn working copy and tsvn was available during build) + std::string GetVersionUrlString(); // e.g. "https://svn.code.sf.net/p/modplug/code/trunk/OpenMPT@1234+dirty" + + // Returns a multi-line string containing the full credits for the code base std::string GetFullCreditsString(); + + // Returns a multi-line string containing developer contact and community addresses std::string GetContactString(); }; //namespace MptVersion Added: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h (rev 0) +++ trunk/OpenMPT/common/versionNumber.h 2013-05-01 00:33:53 UTC (rev 2000) @@ -0,0 +1,26 @@ +/* + * versionNumber.h + * --------------- + * Purpose: OpenMPT version handling. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + +#define VER_HELPER_STRINGIZE(x) #x +#define VER_STRINGIZE(x) VER_HELPER_STRINGIZE(x) + +//Version definitions. The only thing that needs to be changed when changing version number. +#define VER_MAJORMAJOR 1 +#define VER_MAJOR 22 +#define VER_MINOR 02 +#define VER_MINORMINOR 05 + +//Version string. For example "1.17.02.28" +#define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR)"."VER_STRINGIZE(VER_MAJOR)"."VER_STRINGIZE(VER_MINOR)"."VER_STRINGIZE(VER_MINORMINOR) + +//Numerical value of the version. +#define MPT_VERSION_NUMERIC MAKE_VERSION_NUMERIC(VER_MAJORMAJOR,VER_MAJOR,VER_MINOR,VER_MINORMINOR) Property changes on: trunk/OpenMPT/common/versionNumber.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-05-01 00:33:53 UTC (rev 2000) @@ -1153,6 +1153,10 @@ > </File> <File + RelativePath="..\common\versionNumber.h" + > + </File> + <File RelativePath=".\view_com.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-05-01 00:33:53 UTC (rev 2000) @@ -520,6 +520,7 @@ <ClInclude Include="..\common\svn_version_default\svn_version.h" /> <ClInclude Include="..\common\typedefs.h" /> <ClInclude Include="..\common\version.h" /> + <ClInclude Include="..\common\versionNumber.h" /> <ClInclude Include="..\sounddev\SoundDevice.h" /> <ClInclude Include="..\sounddev\SoundDevices.h" /> <ClInclude Include="..\sounddsp\AGC.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-05-01 00:33:53 UTC (rev 2000) @@ -912,6 +912,9 @@ <ClInclude Include="..\unarchiver\unrar\CONST.H"> <Filter>Source Files\unarchiver\unrar</Filter> </ClInclude> + <ClInclude Include="..\common\versionNumber.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/mptrack/res/MPTRACK.RC2 =================================================================== --- trunk/OpenMPT/mptrack/res/MPTRACK.RC2 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/mptrack/res/MPTRACK.RC2 2013-05-01 00:33:53 UTC (rev 2000) @@ -10,11 +10,11 @@ ///////////////////////////////////////////////////////////////////////////// // Add manually edited resources here... -#include "../common/version.h" +#include "../common/versionNumber.h" #include <winver.h> #define VER_FILEVERSION VER_MAJORMAJOR,VER_MAJOR,VER_MINOR,VER_MINORMINOR -#define VER_FILEVERSION_STR STRINGIZE(VER_FILEVERSION) +#define VER_FILEVERSION_STR VER_STRINGIZE(VER_FILEVERSION) #ifndef _DEBUG #define VER_DEBUG 0 Modified: trunk/OpenMPT/mptrack/tagging.cpp =================================================================== --- trunk/OpenMPT/mptrack/tagging.cpp 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/mptrack/tagging.cpp 2013-05-01 00:33:53 UTC (rev 2000) @@ -20,7 +20,7 @@ CFileTagging::CFileTagging() //-------------------------- { - encoder = "OpenMPT " MPT_VERSION_STR; + encoder = MptVersion::GetOpenMPTVersionStr(); } /////////////////////////////////////////////////////////////////////////////////////////////////// Modified: trunk/OpenMPT/mptrack/test/test.cpp =================================================================== --- trunk/OpenMPT/mptrack/test/test.cpp 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/mptrack/test/test.cpp 2013-05-01 00:33:53 UTC (rev 2000) @@ -109,8 +109,6 @@ { //Verify that macros and functions work. { - VERIFY_EQUAL( MPT_VERSION_NUMERIC, MptVersion::num ); - VERIFY_EQUAL( CString(MPT_VERSION_STR), CString(MptVersion::str) ); VERIFY_EQUAL( MptVersion::ToNum(MptVersion::ToStr(MptVersion::num)), MptVersion::num ); VERIFY_EQUAL( MptVersion::ToStr(MptVersion::ToNum(MptVersion::str)), MptVersion::str ); VERIFY_EQUAL( MptVersion::ToStr(18285096), "1.17.02.28" ); Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-05-01 00:33:53 UTC (rev 2000) @@ -580,7 +580,8 @@ memcpy(fileHeader.signature, "Extended Module: ", 17); StringFixer::WriteString<StringFixer::spacePadded>(fileHeader.songName, m_szNames[0]); fileHeader.eof = 0x1A; - memcpy(fileHeader.trackerName, "OpenMPT " MPT_VERSION_STR " ", 20); + std::string openMptTrackerName = MptVersion::GetOpenMPTVersionStr(); + StringFixer::WriteString<StringFixer::spacePadded>(fileHeader.trackerName, openMptTrackerName.c_str(), openMptTrackerName.length()); // Writing song header fileHeader.version = 0x0104; // XM Format v1.04 Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-04-28 22:55:08 UTC (rev 1999) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-05-01 00:33:53 UTC (rev 2000) @@ -397,7 +397,8 @@ bool CSoundFile::SaveWAVSample(SAMPLEINDEX nSample, const LPCSTR lpszFileName) const //---------------------------------------------------------------------------------- { - char *softwareId = "OpenMPT " MPT_VERSION_STR; + std::string softwareIdString = MptVersion::GetOpenMPTVersionStr(); + const char *softwareId = softwareIdString.c_str(); size_t softwareIdLength = strlen(softwareId) + 1; WAVEFILEHEADER header; @@ -2166,7 +2167,7 @@ FLAC__StreamMetadata_VorbisComment_Entry entry; FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, "TITLE", m_szNames[nSample]); FLAC__metadata_object_vorbiscomment_append_comment(metadata[0], entry, false); - FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, "ENCODER", "OpenMPT " MPT_VERSION_STR); + FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, "ENCODER", MptVersion::GetOpenMPTVersionStr().c_str()); FLAC__metadata_object_vorbiscomment_append_comment(metadata[0], entry, false); } if(metadata[1]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |