- having fun with version macros..

Tue, 22 Jul 2014 19:22:31 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 22 Jul 2014 19:22:31 +0300
changeset 140
04a6eb68f226
parent 139
cf11621ae422
child 141
68d60e2cfa76

- having fun with version macros..

src/lexer.cpp file | annotate | diff | comparison | revisions
src/macros.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
--- 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;
 }
--- 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
--- 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;
 }
--- 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<typename T>

mercurial