# HG changeset patch # User Teemu Piippo # Date 1406046151 -10800 # Node ID 04a6eb68f226c4c23270437595038cb2f34c60b0 # Parent cf11621ae422b8bedcf33ef4d3203254dc89c05d - having fun with version macros.. diff -r cf11621ae422 -r 04a6eb68f226 src/lexer.cpp --- a/src/lexer.cpp Tue Jul 22 19:05:58 2014 +0300 +++ b/src/lexer.cpp Tue Jul 22 19:22:31 2014 +0300 @@ -130,7 +130,7 @@ if (VERSION_NUMBER < MAKE_VERSION_NUMBER (major, minor, patch)) error ("The script file requires " APPNAME " v%1, this is v%2", - makeVersionString (major, minor, patch), versionString (false)); + makeVersionString (major, minor, patch), versionString()); return true; } diff -r cf11621ae422 -r 04a6eb68f226 src/macros.h --- a/src/macros.h Tue Jul 22 19:05:58 2014 +0300 +++ b/src/macros.h Tue Jul 22 19:22:31 2014 +0300 @@ -45,6 +45,15 @@ #define MAKE_VERSION_NUMBER(MAJ, MIN, PAT) ((MAJ * 10000) + (MIN * 100) + PAT) #define VERSION_NUMBER MAKE_VERSION_NUMBER (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) +#if VERSION_PATCH > 0 +# define VERSION_STRING MACRO_TO_STRING(VERSION_MAJOR) \ + "." MACRO_TO_STRING(VERSION_MINOR) \ + "." MACRO_TO_STRING(VERSION_PATCH) +#else +# define VERSION_STRING MACRO_TO_STRING(VERSION_MAJOR) \ + "." MACRO_TO_STRING(VERSION_MINOR) +#endif + // On Windows, files are case-insensitive #if (defined(WIN32) or defined(_WIN32) or defined(__WIN32)) and !defined(__CYGWIN__) # define FILE_CASEINSENSITIVE diff -r cf11621ae422 -r 04a6eb68f226 src/main.cpp --- a/src/main.cpp Tue Jul 22 19:05:58 2014 +0300 +++ b/src/main.cpp Tue Jul 22 19:22:31 2014 +0300 @@ -37,6 +37,12 @@ #include "commandline.h" #include "enumstrings.h" +#ifdef SVN_REVISION_STRING +#define FULL_VERSION_STRING VERSION_STRING "-" SVN_REVISION_STRING; +#else +#define FULL_VERSION_STRING VERSION_STRING; +#endif + int main (int argc, char** argv) { try @@ -66,9 +72,7 @@ if (not within (args.size(), 1, 2)) { // Print header - String header; - header = format (APPNAME " %1", versionString (true)); - + String header = APPNAME " " FULL_VERSION_STRING; #ifdef DEBUG header += " (debug build)"; #endif @@ -178,16 +182,7 @@ // _________________________________________________________________________________________________ // -String versionString (bool longform) +String versionString() { - String result = makeVersionString (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); - -#ifdef SVN_REVISION_STRING - if (longform) - result += "-" SVN_REVISION_STRING; -#else - (void) longform; // shuts up GCC -#endif - - return result; + return VERSION_STRING; } diff -r cf11621ae422 -r 04a6eb68f226 src/main.h --- a/src/main.h Tue Jul 22 19:05:58 2014 +0300 +++ b/src/main.h Tue Jul 22 19:22:31 2014 +0300 @@ -48,7 +48,7 @@ String makeObjectFileName (String s); DataType getTypeByName (String token); String dataTypeName (DataType type); -String versionString (bool longform); +String versionString(); String makeVersionString (int major, int minor, int patch); template